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