| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/ui/webui/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> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/i18n/file_util_icu.h" | 15 #include "base/i18n/file_util_icu.h" |
| 16 #include "base/i18n/number_formatting.h" | 16 #include "base/i18n/number_formatting.h" |
| 17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/platform_util.h" | 26 #include "chrome/browser/platform_util.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | |
| 28 #include "chrome/browser/printing/background_printing_manager.h" | 27 #include "chrome/browser/printing/background_printing_manager.h" |
| 29 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 28 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 30 #include "chrome/browser/printing/print_dialog_cloud.h" | 29 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 31 #include "chrome/browser/printing/print_job_manager.h" | 30 #include "chrome/browser/printing/print_job_manager.h" |
| 32 #include "chrome/browser/printing/print_preview_tab_controller.h" | 31 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 33 #include "chrome/browser/printing/print_system_task_proxy.h" | 32 #include "chrome/browser/printing/print_system_task_proxy.h" |
| 34 #include "chrome/browser/printing/print_view_manager.h" | 33 #include "chrome/browser/printing/print_view_manager.h" |
| 35 #include "chrome/browser/printing/printer_manager_dialog.h" | 34 #include "chrome/browser/printing/printer_manager_dialog.h" |
| 36 #include "chrome/browser/profiles/profile.h" | |
| 37 #include "chrome/browser/sessions/restore_tab_helper.h" | 35 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 38 #include "chrome/browser/tabs/tab_strip_model.h" | 36 #include "chrome/browser/tabs/tab_strip_model.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 41 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" | 39 #include "chrome/browser/ui/webui/cloud_print_signin_dialog.h" |
| 42 #include "chrome/browser/ui/webui/print_preview_ui.h" | 40 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 43 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
| 44 #include "chrome/common/pref_names.h" | |
| 45 #include "chrome/common/print_messages.h" | 42 #include "chrome/common/print_messages.h" |
| 46 #include "content/browser/renderer_host/render_view_host.h" | 43 #include "content/browser/renderer_host/render_view_host.h" |
| 47 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
| 48 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 49 #include "printing/backend/print_backend.h" | 46 #include "printing/backend/print_backend.h" |
| 50 #include "printing/metafile.h" | 47 #include "printing/metafile.h" |
| 51 #include "printing/metafile_impl.h" | 48 #include "printing/metafile_impl.h" |
| 52 #include "printing/page_range.h" | 49 #include "printing/page_range.h" |
| 53 #include "printing/print_settings.h" | 50 #include "printing/print_settings.h" |
| 54 #include "unicode/ulocdata.h" | 51 #include "unicode/ulocdata.h" |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 default_printer, | 651 default_printer, |
| 655 cloud_print_data); | 652 cloud_print_data); |
| 656 } | 653 } |
| 657 | 654 |
| 658 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { | 655 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { |
| 659 SendCloudPrintEnabled(); | 656 SendCloudPrintEnabled(); |
| 660 web_ui_->CallJavascriptFunction("setPrinters", printers); | 657 web_ui_->CallJavascriptFunction("setPrinters", printers); |
| 661 } | 658 } |
| 662 | 659 |
| 663 void PrintPreviewHandler::SendCloudPrintEnabled() { | 660 void PrintPreviewHandler::SendCloudPrintEnabled() { |
| 664 Profile* profile = BrowserList::GetLastActive()->profile(); | 661 GURL gcp_url(CloudPrintURL(BrowserList::GetLastActive()->profile()). |
| 665 PrefService* prefs = profile->GetPrefs(); | 662 GetCloudPrintServiceURL()); |
| 666 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { | 663 base::StringValue gcp_url_value(gcp_url.spec()); |
| 667 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); | 664 web_ui_->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); |
| 668 base::StringValue gcp_url_value(gcp_url.spec()); | |
| 669 web_ui_->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); | |
| 670 } | |
| 671 } | 665 } |
| 672 | 666 |
| 673 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 667 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
| 674 std::string print_ticket) { | 668 std::string print_ticket) { |
| 675 scoped_refptr<RefCountedBytes> data; | 669 scoped_refptr<RefCountedBytes> data; |
| 676 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 670 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 677 print_preview_ui->GetPrintPreviewDataForIndex( | 671 print_preview_ui->GetPrintPreviewDataForIndex( |
| 678 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 672 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 679 CHECK(data.get()); | 673 CHECK(data.get()); |
| 680 DCHECK_GT(data->size(), 0U); | 674 DCHECK_GT(data->size(), 0U); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return; | 849 return; |
| 856 | 850 |
| 857 // We no longer require the initiator tab details. Remove those details | 851 // We no longer require the initiator tab details. Remove those details |
| 858 // associated with the preview tab to allow the initiator tab to create | 852 // associated with the preview tab to allow the initiator tab to create |
| 859 // another preview tab. | 853 // another preview tab. |
| 860 printing::PrintPreviewTabController* tab_controller = | 854 printing::PrintPreviewTabController* tab_controller = |
| 861 printing::PrintPreviewTabController::GetInstance(); | 855 printing::PrintPreviewTabController::GetInstance(); |
| 862 if (tab_controller) | 856 if (tab_controller) |
| 863 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 857 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 864 } | 858 } |
| OLD | NEW |