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