Chromium Code Reviews| 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/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/i18n/number_formatting.h" | 19 #include "base/i18n/number_formatting.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/browser_thread.h" | 46 #include "content/browser/browser_thread.h" |
| 44 #include "content/browser/renderer_host/render_view_host.h" | 47 #include "content/browser/renderer_host/render_view_host.h" |
| 45 #include "content/browser/tab_contents/tab_contents.h" | 48 #include "content/browser/tab_contents/tab_contents.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->IsManagedPreference(prefs::kCloudPrintSubmitEnabled) || |
|
pastarmovj
2011/10/27 09:01:23
I don't think you need the IsManagedPreference che
Albert Bodenhamer
2011/10/27 18:18:38
Done.
| |
| 664 web_ui_->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); | 667 prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { |
| 668 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); | |
| 669 base::StringValue gcp_url_value(gcp_url.spec()); | |
| 670 web_ui_->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); | |
| 671 } | |
| 665 } | 672 } |
| 666 | 673 |
| 667 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 674 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
| 668 std::string print_ticket) { | 675 std::string print_ticket) { |
| 669 scoped_refptr<RefCountedBytes> data; | 676 scoped_refptr<RefCountedBytes> data; |
| 670 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 677 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 671 print_preview_ui->GetPrintPreviewDataForIndex( | 678 print_preview_ui->GetPrintPreviewDataForIndex( |
| 672 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 679 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 673 CHECK(data.get()); | 680 CHECK(data.get()); |
| 674 DCHECK_GT(data->size(), 0U); | 681 DCHECK_GT(data->size(), 0U); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 return; | 856 return; |
| 850 | 857 |
| 851 // We no longer require the initiator tab details. Remove those details | 858 // We no longer require the initiator tab details. Remove those details |
| 852 // associated with the preview tab to allow the initiator tab to create | 859 // associated with the preview tab to allow the initiator tab to create |
| 853 // another preview tab. | 860 // another preview tab. |
| 854 printing::PrintPreviewTabController* tab_controller = | 861 printing::PrintPreviewTabController* tab_controller = |
| 855 printing::PrintPreviewTabController::GetInstance(); | 862 printing::PrintPreviewTabController::GetInstance(); |
| 856 if (tab_controller) | 863 if (tab_controller) |
| 857 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 864 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 858 } | 865 } |
| OLD | NEW |