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

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

Issue 1125343004: Add a "Simplify Page" option to the print preview dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring following the proposals in the reviews Created 5 years, 5 months 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 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 12 matching lines...) Expand all
23 #include "base/path_service.h" 23 #include "base/path_service.h"
24 #include "base/prefs/pref_service.h" 24 #include "base/prefs/pref_service.h"
25 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
28 #include "base/threading/thread.h" 28 #include "base/threading/thread.h"
29 #include "base/threading/thread_restrictions.h" 29 #include "base/threading/thread_restrictions.h"
30 #include "base/values.h" 30 #include "base/values.h"
31 #include "chrome/browser/app_mode/app_mode_utils.h" 31 #include "chrome/browser/app_mode/app_mode_utils.h"
32 #include "chrome/browser/browser_process.h" 32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/dom_distiller/tab_utils.h"
33 #include "chrome/browser/platform_util.h" 34 #include "chrome/browser/platform_util.h"
34 #include "chrome/browser/printing/print_dialog_cloud.h" 35 #include "chrome/browser/printing/print_dialog_cloud.h"
35 #include "chrome/browser/printing/print_error_dialog.h" 36 #include "chrome/browser/printing/print_error_dialog.h"
36 #include "chrome/browser/printing/print_job_manager.h" 37 #include "chrome/browser/printing/print_job_manager.h"
37 #include "chrome/browser/printing/print_preview_dialog_controller.h" 38 #include "chrome/browser/printing/print_preview_dialog_controller.h"
38 #include "chrome/browser/printing/print_view_manager.h" 39 #include "chrome/browser/printing/print_view_manager.h"
39 #include "chrome/browser/printing/printer_manager_dialog.h" 40 #include "chrome/browser/printing/printer_manager_dialog.h"
40 #include "chrome/browser/profiles/profile.h" 41 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 42 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
42 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 43 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
43 #include "chrome/browser/signin/signin_manager_factory.h" 44 #include "chrome/browser/signin/signin_manager_factory.h"
44 #include "chrome/browser/ui/browser_finder.h" 45 #include "chrome/browser/ui/browser_finder.h"
45 #include "chrome/browser/ui/browser_tabstrip.h" 46 #include "chrome/browser/ui/browser_tabstrip.h"
46 #include "chrome/browser/ui/chrome_select_file_policy.h" 47 #include "chrome/browser/ui/chrome_select_file_policy.h"
47 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 48 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
48 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 49 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
49 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" 50 #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
50 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" 51 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
51 #include "chrome/common/chrome_paths.h" 52 #include "chrome/common/chrome_paths.h"
52 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" 54 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h"
54 #include "chrome/common/cloud_print/cloud_print_constants.h" 55 #include "chrome/common/cloud_print/cloud_print_constants.h"
55 #include "chrome/common/crash_keys.h" 56 #include "chrome/common/crash_keys.h"
56 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
57 #include "components/cloud_devices/common/cloud_device_description.h" 58 #include "components/cloud_devices/common/cloud_device_description.h"
58 #include "components/cloud_devices/common/cloud_devices_urls.h" 59 #include "components/cloud_devices/common/cloud_devices_urls.h"
59 #include "components/cloud_devices/common/printer_description.h" 60 #include "components/cloud_devices/common/printer_description.h"
61 #include "components/dom_distiller/content/distillable_page_utils.h"
62 #include "components/dom_distiller/core/url_utils.h"
60 #include "components/printing/common/print_messages.h" 63 #include "components/printing/common/print_messages.h"
61 #include "components/signin/core/browser/gaia_cookie_manager_service.h" 64 #include "components/signin/core/browser/gaia_cookie_manager_service.h"
62 #include "components/signin/core/browser/profile_oauth2_token_service.h" 65 #include "components/signin/core/browser/profile_oauth2_token_service.h"
63 #include "components/signin/core/browser/signin_manager.h" 66 #include "components/signin/core/browser/signin_manager.h"
64 #include "components/signin/core/common/profile_management_switches.h" 67 #include "components/signin/core/common/profile_management_switches.h"
65 #include "content/public/browser/browser_context.h" 68 #include "content/public/browser/browser_context.h"
66 #include "content/public/browser/browser_thread.h" 69 #include "content/public/browser/browser_thread.h"
67 #include "content/public/browser/navigation_controller.h" 70 #include "content/public/browser/navigation_controller.h"
68 #include "content/public/browser/navigation_entry.h" 71 #include "content/public/browser/navigation_entry.h"
69 #include "content/public/browser/render_process_host.h" 72 #include "content/public/browser/render_process_host.h"
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 success = args->GetBoolean(2, &preview_modifiable); 835 success = args->GetBoolean(2, &preview_modifiable);
833 DCHECK(success); 836 DCHECK(success);
834 837
835 if (draft_page_count != -1 && preview_modifiable && 838 if (draft_page_count != -1 && preview_modifiable &&
836 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { 839 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) {
837 settings->SetBoolean(printing::kSettingGenerateDraftData, true); 840 settings->SetBoolean(printing::kSettingGenerateDraftData, true);
838 } 841 }
839 } 842 }
840 843
841 VLOG(1) << "Print preview request start"; 844 VLOG(1) << "Print preview request start";
842 RenderViewHost* rvh = initiator->GetRenderViewHost(); 845
843 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); 846 bool distill_page = false;
847 if (!settings->GetBoolean(printing::kSettingDistillPageEnabled,
848 &distill_page)) {
849 NOTREACHED();
850 }
851
852 bool selection_only = false;
853 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly,
854 &selection_only)) {
855 NOTREACHED();
856 }
857
858 if (distill_page && !selection_only) {
859 print_preview_distiller_.reset(new PrintPreviewDistiller(
860 initiator, print_preview_ui(), settings.Pass()));
861 } else {
862 RenderViewHost* rvh = initiator->GetRenderViewHost();
863 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings));
864 }
844 } 865 }
845 866
846 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { 867 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
847 ReportStats(); 868 ReportStats();
848 869
849 // Record the number of times the user requests to regenerate preview data 870 // Record the number of times the user requests to regenerate preview data
850 // before printing. 871 // before printing.
851 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", 872 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint",
852 regenerate_preview_request_count_); 873 regenerate_preview_request_count_);
853 874
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 // In Win8 metro, the system print dialog can only open on the desktop. Doing 1270 // In Win8 metro, the system print dialog can only open on the desktop. Doing
1250 // so will cause the browser to appear hung, so we don't show the link in 1271 // so will cause the browser to appear hung, so we don't show the link in
1251 // metro. 1272 // metro.
1252 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); 1273 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH);
1253 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); 1274 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash);
1254 #endif 1275 #endif
1255 1276
1256 if (print_preview_ui()->source_is_modifiable()) 1277 if (print_preview_ui()->source_is_modifiable())
1257 GetNumberFormatAndMeasurementSystem(&initial_settings); 1278 GetNumberFormatAndMeasurementSystem(&initial_settings);
1258 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); 1279 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings);
1280
1281 WebContents* initiator = GetInitiator();
1282 if (initiator && cmdline->HasSwitch(switches::kEnableDomDistiller) &&
1283 dom_distiller::url_utils::IsUrlDistillable(
1284 initiator->GetLastCommittedURL())) {
1285 dom_distiller::IsDistillablePage(
1286 initiator, false,
1287 base::Bind(&PrintPreviewHandler::HandleIsPageDistillableResult,
1288 weak_factory_.GetWeakPtr()));
1289 }
1290 }
1291
1292 void PrintPreviewHandler::HandleIsPageDistillableResult(bool distillable) {
1293 VLOG(1) << "Distillable page detection finished";
1294 if (distillable)
1295 web_ui()->CallJavascriptFunction("detectDistillablePage");
1259 } 1296 }
1260 1297
1261 void PrintPreviewHandler::ClosePreviewDialog() { 1298 void PrintPreviewHandler::ClosePreviewDialog() {
1262 print_preview_ui()->OnClosePrintPreviewDialog(); 1299 print_preview_ui()->OnClosePrintPreviewDialog();
1263 } 1300 }
1264 1301
1265 void PrintPreviewHandler::SendAccessToken(const std::string& type, 1302 void PrintPreviewHandler::SendAccessToken(const std::string& type,
1266 const std::string& access_token) { 1303 const std::string& access_token) {
1267 VLOG(1) << "Get getAccessToken finished"; 1304 VLOG(1) << "Get getAccessToken finished";
1268 web_ui()->CallJavascriptFunction("onDidGetAccessToken", 1305 web_ui()->CallJavascriptFunction("onDidGetAccessToken",
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 1803
1767 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1804 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1768 if (gaia_cookie_manager_service_) 1805 if (gaia_cookie_manager_service_)
1769 gaia_cookie_manager_service_->RemoveObserver(this); 1806 gaia_cookie_manager_service_->RemoveObserver(this);
1770 } 1807 }
1771 1808
1772 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1809 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1773 const base::Closure& closure) { 1810 const base::Closure& closure) {
1774 pdf_file_saved_closure_ = closure; 1811 pdf_file_saved_closure_ = closure;
1775 } 1812 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698