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 <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "components/cloud_devices/common/cloud_devices_urls.h" | 57 #include "components/cloud_devices/common/cloud_devices_urls.h" |
58 #include "components/cloud_devices/common/printer_description.h" | 58 #include "components/cloud_devices/common/printer_description.h" |
59 #include "components/signin/core/browser/account_reconcilor.h" | 59 #include "components/signin/core/browser/account_reconcilor.h" |
60 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 60 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
61 #include "components/signin/core/browser/signin_manager.h" | 61 #include "components/signin/core/browser/signin_manager.h" |
62 #include "components/signin/core/common/profile_management_switches.h" | 62 #include "components/signin/core/common/profile_management_switches.h" |
63 #include "content/public/browser/browser_context.h" | 63 #include "content/public/browser/browser_context.h" |
64 #include "content/public/browser/browser_thread.h" | 64 #include "content/public/browser/browser_thread.h" |
65 #include "content/public/browser/navigation_controller.h" | 65 #include "content/public/browser/navigation_controller.h" |
66 #include "content/public/browser/navigation_entry.h" | 66 #include "content/public/browser/navigation_entry.h" |
| 67 #include "content/public/browser/render_process_host.h" |
67 #include "content/public/browser/render_view_host.h" | 68 #include "content/public/browser/render_view_host.h" |
68 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
69 #include "content/public/browser/web_ui.h" | 70 #include "content/public/browser/web_ui.h" |
70 #include "google_apis/gaia/oauth2_token_service.h" | 71 #include "google_apis/gaia/oauth2_token_service.h" |
71 #include "printing/backend/print_backend.h" | 72 #include "printing/backend/print_backend.h" |
72 #include "printing/backend/print_backend_consts.h" | 73 #include "printing/backend/print_backend_consts.h" |
73 #include "printing/metafile.h" | 74 #include "printing/metafile.h" |
74 #include "printing/metafile_impl.h" | 75 #include "printing/metafile_impl.h" |
75 #include "printing/pdf_render_settings.h" | 76 #include "printing/pdf_render_settings.h" |
76 #include "printing/print_settings.h" | 77 #include "printing/print_settings.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 255 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
255 | 256 |
256 scoped_refptr<printing::PrintBackend> print_backend( | 257 scoped_refptr<printing::PrintBackend> print_backend( |
257 printing::PrintBackend::CreateInstance(NULL)); | 258 printing::PrintBackend::CreateInstance(NULL)); |
258 | 259 |
259 std::string default_printer = print_backend->GetDefaultPrinterName(); | 260 std::string default_printer = print_backend->GetDefaultPrinterName(); |
260 VLOG(1) << "Default Printer: " << default_printer; | 261 VLOG(1) << "Default Printer: " << default_printer; |
261 return default_printer; | 262 return default_printer; |
262 } | 263 } |
263 | 264 |
| 265 class PrintingContextDelegate : public printing::PrintingContext::Delegate { |
| 266 public: |
| 267 // PrintingContext::Delegate methods. |
| 268 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } |
| 269 virtual std::string GetAppLocale() OVERRIDE { |
| 270 return g_browser_process->GetApplicationLocale(); |
| 271 } |
| 272 }; |
| 273 |
264 gfx::Size GetDefaultPdfMediaSizeMicrons() { | 274 gfx::Size GetDefaultPdfMediaSizeMicrons() { |
| 275 PrintingContextDelegate delegate; |
265 scoped_ptr<printing::PrintingContext> printing_context( | 276 scoped_ptr<printing::PrintingContext> printing_context( |
266 printing::PrintingContext::Create( | 277 printing::PrintingContext::Create(&delegate)); |
267 g_browser_process->GetApplicationLocale())); | |
268 if (printing::PrintingContext::OK != printing_context->UsePdfSettings() || | 278 if (printing::PrintingContext::OK != printing_context->UsePdfSettings() || |
269 printing_context->settings().device_units_per_inch() <= 0) { | 279 printing_context->settings().device_units_per_inch() <= 0) { |
270 return gfx::Size(); | 280 return gfx::Size(); |
271 } | 281 } |
272 gfx::Size pdf_media_size = printing_context->GetPdfPaperSizeDeviceUnits(); | 282 gfx::Size pdf_media_size = printing_context->GetPdfPaperSizeDeviceUnits(); |
273 float deviceMicronsPerDeviceUnit = | 283 float deviceMicronsPerDeviceUnit = |
274 (printing::kHundrethsMMPerInch * 10.0f) / | 284 (printing::kHundrethsMMPerInch * 10.0f) / |
275 printing_context->settings().device_units_per_inch(); | 285 printing_context->settings().device_units_per_inch(); |
276 return gfx::Size(pdf_media_size.width() * deviceMicronsPerDeviceUnit, | 286 return gfx::Size(pdf_media_size.width() * deviceMicronsPerDeviceUnit, |
277 pdf_media_size.height() * deviceMicronsPerDeviceUnit); | 287 pdf_media_size.height() * deviceMicronsPerDeviceUnit); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 838 |
829 // This tries to activate the initiator as well, so do not clear the | 839 // This tries to activate the initiator as well, so do not clear the |
830 // association with the initiator yet. | 840 // association with the initiator yet. |
831 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 841 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
832 web_ui()->GetController()); | 842 web_ui()->GetController()); |
833 print_preview_ui->OnHidePreviewDialog(); | 843 print_preview_ui->OnHidePreviewDialog(); |
834 | 844 |
835 // Do this so the initiator can open a new print preview dialog, while the | 845 // Do this so the initiator can open a new print preview dialog, while the |
836 // current print preview dialog is still handling its print job. | 846 // current print preview dialog is still handling its print job. |
837 WebContents* initiator = GetInitiator(); | 847 WebContents* initiator = GetInitiator(); |
| 848 if (initiator) { |
| 849 // Save initiator IDs. |PrintingMessageFilter::OnUpdatePrintSettings| |
| 850 // would be called when initiator info is cleared. |
| 851 settings->SetInteger(printing::kPreviewInitiatorHostId, |
| 852 initiator->GetRenderProcessHost()->GetID()); |
| 853 settings->SetInteger(printing::kPreviewInitiatorRoutingId, |
| 854 initiator->GetRoutingID()); |
| 855 } |
| 856 |
838 ClearInitiatorDetails(); | 857 ClearInitiatorDetails(); |
839 | 858 |
840 // The PDF being printed contains only the pages that the user selected, | 859 // The PDF being printed contains only the pages that the user selected, |
841 // so ignore the page range and print all pages. | 860 // so ignore the page range and print all pages. |
842 settings->Remove(printing::kSettingPageRange, NULL); | 861 settings->Remove(printing::kSettingPageRange, NULL); |
843 // Reset selection only flag for the same reason. | 862 // Reset selection only flag for the same reason. |
844 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); | 863 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); |
845 | 864 |
846 // Set ID to know whether printing is for preview. | 865 // Set ID to know whether printing is for preview. |
847 settings->SetInteger(printing::kPreviewUIID, | 866 settings->SetInteger(printing::kPreviewUIID, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 WebContents* initiator = GetInitiator(); | 1032 WebContents* initiator = GetInitiator(); |
1014 if (!initiator) | 1033 if (!initiator) |
1015 return; | 1034 return; |
1016 | 1035 |
1017 printing::PrintViewManager* print_view_manager = | 1036 printing::PrintViewManager* print_view_manager = |
1018 printing::PrintViewManager::FromWebContents(initiator); | 1037 printing::PrintViewManager::FromWebContents(initiator); |
1019 print_view_manager->set_observer(this); | 1038 print_view_manager->set_observer(this); |
1020 print_view_manager->PrintForSystemDialogNow(); | 1039 print_view_manager->PrintForSystemDialogNow(); |
1021 | 1040 |
1022 // Cancel the pending preview request if exists. | 1041 // Cancel the pending preview request if exists. |
1023 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 1042 PrintPreviewUI* print_preview_ui = |
1024 web_ui()->GetController()); | 1043 static_cast<PrintPreviewUI*>(web_ui()->GetController()); |
1025 print_preview_ui->OnCancelPendingPreviewRequest(); | 1044 print_preview_ui->OnCancelPendingPreviewRequest(); |
1026 } | 1045 } |
1027 | 1046 |
1028 void PrintPreviewHandler::HandleManagePrinters( | 1047 void PrintPreviewHandler::HandleManagePrinters( |
1029 const base::ListValue* /*args*/) { | 1048 const base::ListValue* /*args*/) { |
1030 ++manage_printers_dialog_request_count_; | 1049 ++manage_printers_dialog_request_count_; |
1031 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 1050 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
1032 } | 1051 } |
1033 | 1052 |
1034 void PrintPreviewHandler::HandlePrintWithCloudPrintDialog( | 1053 void PrintPreviewHandler::HandlePrintWithCloudPrintDialog( |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 | 1575 |
1557 void PrintPreviewHandler::UnregisterForMergeSession() { | 1576 void PrintPreviewHandler::UnregisterForMergeSession() { |
1558 if (reconcilor_) | 1577 if (reconcilor_) |
1559 reconcilor_->RemoveMergeSessionObserver(this); | 1578 reconcilor_->RemoveMergeSessionObserver(this); |
1560 } | 1579 } |
1561 | 1580 |
1562 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1581 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
1563 const base::Closure& closure) { | 1582 const base::Closure& closure) { |
1564 pdf_file_saved_closure_ = closure; | 1583 pdf_file_saved_closure_ = closure; |
1565 } | 1584 } |
OLD | NEW |