Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 2426503002: Make printing work better with OOPIF. (Closed)
Patch Set: Better plumbing in AwPrintManager Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/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::RenderViewHost; 104 using content::RenderFrameHost;
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
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 if (!initiator) { 704 content::RenderFrameHost* rfh =
705 initiator
706 ? PrintViewManager::FromWebContents(initiator)->print_preview_rfh()
707 : nullptr;
708 if (!rfh) {
705 ReportUserActionHistogram(INITIATOR_CLOSED); 709 ReportUserActionHistogram(INITIATOR_CLOSED);
706 print_preview_ui()->OnClosePrintPreviewDialog(); 710 print_preview_ui()->OnClosePrintPreviewDialog();
707 return; 711 return;
708 } 712 }
709 713
710 // Retrieve the page title and url and send it to the renderer process if 714 // Retrieve the page title and url and send it to the renderer process if
711 // headers and footers are to be displayed. 715 // headers and footers are to be displayed.
712 bool display_header_footer = false; 716 bool display_header_footer = false;
713 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, 717 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled,
714 &display_header_footer)) { 718 &display_header_footer)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 } 756 }
753 757
754 VLOG(1) << "Print preview request start"; 758 VLOG(1) << "Print preview request start";
755 759
756 bool selection_only = false; 760 bool selection_only = false;
757 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, 761 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly,
758 &selection_only)) { 762 &selection_only)) {
759 NOTREACHED(); 763 NOTREACHED();
760 } 764 }
761 765
762 RenderViewHost* rvh = initiator->GetRenderViewHost(); 766 rfh->Send(new PrintMsg_PrintPreview(rfh->GetRoutingID(), *settings));
763 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings));
764 } 767 }
765 768
766 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { 769 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
767 ReportStats(); 770 ReportStats();
768 771
769 // Record the number of times the user requests to regenerate preview data 772 // Record the number of times the user requests to regenerate preview data
770 // before printing. 773 // before printing.
771 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", 774 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint",
772 regenerate_preview_request_count_); 775 regenerate_preview_request_count_);
773 776
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 922
920 // The PDF being printed contains only the pages that the user selected, 923 // The PDF being printed contains only the pages that the user selected,
921 // so ignore the page range and print all pages. 924 // so ignore the page range and print all pages.
922 settings->Remove(printing::kSettingPageRange, NULL); 925 settings->Remove(printing::kSettingPageRange, NULL);
923 // Reset selection only flag for the same reason. 926 // Reset selection only flag for the same reason.
924 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false); 927 settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false);
925 928
926 // Set ID to know whether printing is for preview. 929 // Set ID to know whether printing is for preview.
927 settings->SetInteger(printing::kPreviewUIID, 930 settings->SetInteger(printing::kPreviewUIID,
928 print_preview_ui()->GetIDForPrintPreviewUI()); 931 print_preview_ui()->GetIDForPrintPreviewUI());
929 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); 932 RenderFrameHost* rfh = preview_web_contents()->GetMainFrame();
930 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), 933 rfh->Send(
931 *settings)); 934 new PrintMsg_PrintForPrintPreview(rfh->GetRoutingID(), *settings));
932 935
933 // For all other cases above, the preview dialog will stay open until the 936 // For all other cases above, the preview dialog will stay open until the
934 // printing has finished. Then the dialog closes and PrintPreviewDone() gets 937 // printing has finished. Then the dialog closes and PrintPreviewDone() gets
935 // called. In the case below, since the preview dialog will be hidden and 938 // called. In the case below, since the preview dialog will be hidden and
936 // not closed, we need to make this call. 939 // not closed, we need to make this call.
937 if (initiator) { 940 if (initiator) {
938 auto* print_view_manager = PrintViewManager::FromWebContents(initiator); 941 auto* print_view_manager = PrintViewManager::FromWebContents(initiator);
939 print_view_manager->PrintPreviewDone(); 942 print_view_manager->PrintPreviewDone();
940 } 943 }
941 #else 944 #else
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1691
1689 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1692 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1690 if (gaia_cookie_manager_service_) 1693 if (gaia_cookie_manager_service_)
1691 gaia_cookie_manager_service_->RemoveObserver(this); 1694 gaia_cookie_manager_service_->RemoveObserver(this);
1692 } 1695 }
1693 1696
1694 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1697 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1695 const base::Closure& closure) { 1698 const base::Closure& closure) {
1696 pdf_file_saved_closure_ = closure; 1699 pdf_file_saved_closure_ = closure;
1697 } 1700 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698