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 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "components/prefs/pref_service.h" | 65 #include "components/prefs/pref_service.h" |
66 #include "components/printing/common/print_messages.h" | 66 #include "components/printing/common/print_messages.h" |
67 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 67 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
68 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 68 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
69 #include "components/signin/core/browser/signin_manager.h" | 69 #include "components/signin/core/browser/signin_manager.h" |
70 #include "components/signin/core/common/profile_management_switches.h" | 70 #include "components/signin/core/common/profile_management_switches.h" |
71 #include "content/public/browser/browser_context.h" | 71 #include "content/public/browser/browser_context.h" |
72 #include "content/public/browser/browser_thread.h" | 72 #include "content/public/browser/browser_thread.h" |
73 #include "content/public/browser/navigation_controller.h" | 73 #include "content/public/browser/navigation_controller.h" |
74 #include "content/public/browser/navigation_entry.h" | 74 #include "content/public/browser/navigation_entry.h" |
75 #include "content/public/browser/render_frame_host.h" | |
76 #include "content/public/browser/render_process_host.h" | 75 #include "content/public/browser/render_process_host.h" |
| 76 #include "content/public/browser/render_view_host.h" |
77 #include "content/public/browser/web_contents.h" | 77 #include "content/public/browser/web_contents.h" |
78 #include "content/public/browser/web_ui.h" | 78 #include "content/public/browser/web_ui.h" |
79 #include "google_apis/gaia/oauth2_token_service.h" | 79 #include "google_apis/gaia/oauth2_token_service.h" |
80 #include "net/base/url_util.h" | 80 #include "net/base/url_util.h" |
81 #include "printing/backend/print_backend.h" | 81 #include "printing/backend/print_backend.h" |
82 #include "printing/backend/print_backend_consts.h" | 82 #include "printing/backend/print_backend_consts.h" |
83 #include "printing/features/features.h" | 83 #include "printing/features/features.h" |
84 #include "printing/pdf_render_settings.h" | 84 #include "printing/pdf_render_settings.h" |
85 #include "printing/print_settings.h" | 85 #include "printing/print_settings.h" |
86 #include "printing/printing_context.h" | 86 #include "printing/printing_context.h" |
87 #include "printing/units.h" | 87 #include "printing/units.h" |
88 #include "third_party/icu/source/i18n/unicode/ulocdata.h" | 88 #include "third_party/icu/source/i18n/unicode/ulocdata.h" |
89 | 89 |
90 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
91 #include "chrome/browser/chromeos/printing/printer_pref_manager.h" | 91 #include "chrome/browser/chromeos/printing/printer_pref_manager.h" |
92 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" | 92 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" |
93 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 93 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
94 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 94 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
95 #include "chrome/common/url_constants.h" | 95 #include "chrome/common/url_constants.h" |
96 #include "chromeos/printing/printer_configuration.h" | 96 #include "chromeos/printing/printer_configuration.h" |
97 #endif | 97 #endif |
98 | 98 |
99 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) | 99 #if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) |
100 #include "chrome/browser/printing/cloud_print/privet_constants.h" | 100 #include "chrome/browser/printing/cloud_print/privet_constants.h" |
101 #endif | 101 #endif |
102 | 102 |
103 using content::BrowserThread; | 103 using content::BrowserThread; |
104 using content::RenderFrameHost; | 104 using content::RenderViewHost; |
105 using content::WebContents; | 105 using content::WebContents; |
106 using printing::PrintViewManager; | 106 using printing::PrintViewManager; |
107 | 107 |
108 namespace { | 108 namespace { |
109 | 109 |
110 enum UserActionBuckets { | 110 enum UserActionBuckets { |
111 PRINT_TO_PRINTER, | 111 PRINT_TO_PRINTER, |
112 PRINT_TO_PDF, | 112 PRINT_TO_PDF, |
113 CANCEL, | 113 CANCEL, |
114 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, | 114 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 // Add an additional key in order to identify |print_preview_ui| later on | 694 // Add an additional key in order to identify |print_preview_ui| later on |
695 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 695 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
696 // thread. | 696 // thread. |
697 settings->SetInteger(printing::kPreviewUIID, | 697 settings->SetInteger(printing::kPreviewUIID, |
698 print_preview_ui()->GetIDForPrintPreviewUI()); | 698 print_preview_ui()->GetIDForPrintPreviewUI()); |
699 | 699 |
700 // Increment request count. | 700 // Increment request count. |
701 ++regenerate_preview_request_count_; | 701 ++regenerate_preview_request_count_; |
702 | 702 |
703 WebContents* initiator = GetInitiator(); | 703 WebContents* initiator = GetInitiator(); |
704 content::RenderFrameHost* rfh = | 704 if (!initiator) { |
705 initiator | |
706 ? PrintViewManager::FromWebContents(initiator)->print_preview_rfh() | |
707 : nullptr; | |
708 if (!rfh) { | |
709 ReportUserActionHistogram(INITIATOR_CLOSED); | 705 ReportUserActionHistogram(INITIATOR_CLOSED); |
710 print_preview_ui()->OnClosePrintPreviewDialog(); | 706 print_preview_ui()->OnClosePrintPreviewDialog(); |
711 return; | 707 return; |
712 } | 708 } |
713 | 709 |
714 // Retrieve the page title and url and send it to the renderer process if | 710 // Retrieve the page title and url and send it to the renderer process if |
715 // headers and footers are to be displayed. | 711 // headers and footers are to be displayed. |
716 bool display_header_footer = false; | 712 bool display_header_footer = false; |
717 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, | 713 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, |
718 &display_header_footer)) { | 714 &display_header_footer)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 752 } |
757 | 753 |
758 VLOG(1) << "Print preview request start"; | 754 VLOG(1) << "Print preview request start"; |
759 | 755 |
760 bool selection_only = false; | 756 bool selection_only = false; |
761 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, | 757 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
762 &selection_only)) { | 758 &selection_only)) { |
763 NOTREACHED(); | 759 NOTREACHED(); |
764 } | 760 } |
765 | 761 |
766 rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), *settings)); | 762 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 763 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
767 } | 764 } |
768 | 765 |
769 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 766 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
770 ReportStats(); | 767 ReportStats(); |
771 | 768 |
772 // Record the number of times the user requests to regenerate preview data | 769 // Record the number of times the user requests to regenerate preview data |
773 // before printing. | 770 // before printing. |
774 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 771 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
775 regenerate_preview_request_count_); | 772 regenerate_preview_request_count_); |
776 | 773 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 | 919 |
923 // The PDF being printed contains only the pages that the user selected, | 920 // The PDF being printed contains only the pages that the user selected, |
924 // so ignore the page range and print all pages. | 921 // so ignore the page range and print all pages. |
925 settings->Remove(printing::kSettingPageRange, NULL); | 922 settings->Remove(printing::kSettingPageRange, NULL); |
926 // Reset selection only flag for the same reason. | 923 // Reset selection only flag for the same reason. |
927 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); | 924 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); |
928 | 925 |
929 // Set ID to know whether printing is for preview. | 926 // Set ID to know whether printing is for preview. |
930 settings->SetInteger(printing::kPreviewUIID, | 927 settings->SetInteger(printing::kPreviewUIID, |
931 print_preview_ui()->GetIDForPrintPreviewUI()); | 928 print_preview_ui()->GetIDForPrintPreviewUI()); |
932 RenderFrameHost* rfh = preview_web_contents()->GetMainFrame(); | 929 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); |
933 rfh->Send( | 930 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), |
934 new PrintMsg_PrintForPrintPreview(rfh->GetRoutingID(), *settings)); | 931 *settings)); |
935 | 932 |
936 // For all other cases above, the preview dialog will stay open until the | 933 // For all other cases above, the preview dialog will stay open until the |
937 // printing has finished. Then the dialog closes and PrintPreviewDone() gets | 934 // printing has finished. Then the dialog closes and PrintPreviewDone() gets |
938 // called. In the case below, since the preview dialog will be hidden and | 935 // called. In the case below, since the preview dialog will be hidden and |
939 // not closed, we need to make this call. | 936 // not closed, we need to make this call. |
940 if (initiator) { | 937 if (initiator) { |
941 auto* print_view_manager = PrintViewManager::FromWebContents(initiator); | 938 auto* print_view_manager = PrintViewManager::FromWebContents(initiator); |
942 print_view_manager->PrintPreviewDone(); | 939 print_view_manager->PrintPreviewDone(); |
943 } | 940 } |
944 #else | 941 #else |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 | 1688 |
1692 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1689 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
1693 if (gaia_cookie_manager_service_) | 1690 if (gaia_cookie_manager_service_) |
1694 gaia_cookie_manager_service_->RemoveObserver(this); | 1691 gaia_cookie_manager_service_->RemoveObserver(this); |
1695 } | 1692 } |
1696 | 1693 |
1697 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1694 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
1698 const base::Closure& closure) { | 1695 const base::Closure& closure) { |
1699 pdf_file_saved_closure_ = closure; | 1696 pdf_file_saved_closure_ = closure; |
1700 } | 1697 } |
OLD | NEW |