OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 710 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
711 std::string print_ticket) { | 711 std::string print_ticket) { |
712 scoped_refptr<base::RefCountedBytes> data; | 712 scoped_refptr<base::RefCountedBytes> data; |
713 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 713 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
714 web_ui()->GetController()); | 714 web_ui()->GetController()); |
715 print_preview_ui->GetPrintPreviewDataForIndex( | 715 print_preview_ui->GetPrintPreviewDataForIndex( |
716 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 716 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
717 if (data->size() > 0U && data->front()) { | 717 if (data.get() && data->size() > 0U && data->front()) { |
718 string16 print_job_title_utf16 = | 718 string16 print_job_title_utf16 = |
719 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); | 719 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); |
720 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); | 720 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); |
721 std::string printer_id; | 721 std::string printer_id; |
722 settings.GetString(printing::kSettingCloudPrintId, &printer_id); | 722 settings.GetString(printing::kSettingCloudPrintId, &printer_id); |
723 // BASE64 encode the job data. | 723 // BASE64 encode the job data. |
724 std::string raw_data(reinterpret_cast<const char*>(data->front()), | 724 std::string raw_data(reinterpret_cast<const char*>(data->front()), |
725 data->size()); | 725 data->size()); |
726 std::string base64_data; | 726 std::string base64_data; |
727 if (!base::Base64Encode(raw_data, &base64_data)) { | 727 if (!base::Base64Encode(raw_data, &base64_data)) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 // Updating |save_path_| to the newly selected folder. | 833 // Updating |save_path_| to the newly selected folder. |
834 GetStickySettings()->StoreSavePath(path.DirName()); | 834 GetStickySettings()->StoreSavePath(path.DirName()); |
835 | 835 |
836 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 836 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
837 web_ui()->GetController()); | 837 web_ui()->GetController()); |
838 print_preview_ui->web_ui()->CallJavascriptFunction("fileSelectionCompleted"); | 838 print_preview_ui->web_ui()->CallJavascriptFunction("fileSelectionCompleted"); |
839 scoped_refptr<base::RefCountedBytes> data; | 839 scoped_refptr<base::RefCountedBytes> data; |
840 print_preview_ui->GetPrintPreviewDataForIndex( | 840 print_preview_ui->GetPrintPreviewDataForIndex( |
841 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 841 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
842 print_to_pdf_path_.reset(new FilePath(path)); | 842 print_to_pdf_path_.reset(new FilePath(path)); |
843 if (data.get()) | 843 PostPrintToPdfTask(data); |
844 PostPrintToPdfTask(data); | |
845 } | 844 } |
846 | 845 |
847 void PrintPreviewHandler::PostPrintToPdfTask( | 846 void PrintPreviewHandler::PostPrintToPdfTask(base::RefCountedBytes* data) { |
848 scoped_refptr<base::RefCountedBytes> data) { | 847 if (!data) { |
| 848 NOTREACHED(); |
| 849 return; |
| 850 } |
849 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 851 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
850 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 852 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
851 // PrintToPdfCallback takes ownership of |metafile|. | 853 // PrintToPdfCallback takes ownership of |metafile|. |
852 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 854 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
853 base::Bind(&PrintToPdfCallback, metafile, | 855 base::Bind(&PrintToPdfCallback, metafile, |
854 *print_to_pdf_path_)); | 856 *print_to_pdf_path_)); |
855 print_to_pdf_path_.reset(); | 857 print_to_pdf_path_.reset(); |
856 ActivateInitiatorTabAndClosePreviewTab(); | 858 ActivateInitiatorTabAndClosePreviewTab(); |
857 } | 859 } |
858 | 860 |
859 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 861 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
860 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 862 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
861 web_ui()->GetController()); | 863 web_ui()->GetController()); |
862 print_preview_ui->OnFileSelectionCancelled(); | 864 print_preview_ui->OnFileSelectionCancelled(); |
863 } | 865 } |
864 | 866 |
865 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 867 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
866 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 868 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
867 if (!initiator_tab) | 869 if (!initiator_tab) |
868 return; | 870 return; |
869 | 871 |
870 // We no longer require the initiator tab details. Remove those details | 872 // We no longer require the initiator tab details. Remove those details |
871 // associated with the preview tab to allow the initiator tab to create | 873 // associated with the preview tab to allow the initiator tab to create |
872 // another preview tab. | 874 // another preview tab. |
873 printing::PrintPreviewTabController* tab_controller = | 875 printing::PrintPreviewTabController* tab_controller = |
874 printing::PrintPreviewTabController::GetInstance(); | 876 printing::PrintPreviewTabController::GetInstance(); |
875 if (tab_controller) | 877 if (tab_controller) |
876 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 878 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
877 } | 879 } |
OLD | NEW |