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 12 matching lines...) Expand all Loading... |
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/core/url_utils.h" |
60 #include "components/printing/common/print_messages.h" | 62 #include "components/printing/common/print_messages.h" |
61 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 63 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
62 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 64 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
63 #include "components/signin/core/browser/signin_manager.h" | 65 #include "components/signin/core/browser/signin_manager.h" |
64 #include "components/signin/core/common/profile_management_switches.h" | 66 #include "components/signin/core/common/profile_management_switches.h" |
65 #include "content/public/browser/browser_context.h" | 67 #include "content/public/browser/browser_context.h" |
66 #include "content/public/browser/browser_thread.h" | 68 #include "content/public/browser/browser_thread.h" |
67 #include "content/public/browser/navigation_controller.h" | 69 #include "content/public/browser/navigation_controller.h" |
68 #include "content/public/browser/navigation_entry.h" | 70 #include "content/public/browser/navigation_entry.h" |
69 #include "content/public/browser/render_process_host.h" | 71 #include "content/public/browser/render_process_host.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Dictionary field to indicate whether Chrome is running in forced app (app | 160 // Dictionary field to indicate whether Chrome is running in forced app (app |
159 // kiosk) mode. It's not the same as desktop Chrome kiosk (the one above). | 161 // kiosk) mode. It's not the same as desktop Chrome kiosk (the one above). |
160 const char kAppKioskMode[] = "appKioskMode"; | 162 const char kAppKioskMode[] = "appKioskMode"; |
161 // Dictionary field to store Cloud Print base URL. | 163 // Dictionary field to store Cloud Print base URL. |
162 const char kCloudPrintUrl[] = "cloudPrintUrl"; | 164 const char kCloudPrintUrl[] = "cloudPrintUrl"; |
163 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
164 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; | 166 const char kHidePrintWithSystemDialogLink[] = "hidePrintWithSystemDialogLink"; |
165 #endif | 167 #endif |
166 // Name of a dictionary field holding the state of selection for document. | 168 // Name of a dictionary field holding the state of selection for document. |
167 const char kDocumentHasSelection[] = "documentHasSelection"; | 169 const char kDocumentHasSelection[] = "documentHasSelection"; |
| 170 // Dictionary field indicating whether to simplify the page. |
| 171 const char kPrintFriendlyEnabled[] = "printFriendlyEnabled"; |
168 | 172 |
169 // Id of the predefined PDF printer. | 173 // Id of the predefined PDF printer. |
170 const char kLocalPdfPrinterId[] = "Save as PDF"; | 174 const char kLocalPdfPrinterId[] = "Save as PDF"; |
171 | 175 |
172 // Additional printer capability setting keys. | 176 // Additional printer capability setting keys. |
173 const char kPrinterId[] = "printerId"; | 177 const char kPrinterId[] = "printerId"; |
174 const char kPrinterCapabilities[] = "capabilities"; | 178 const char kPrinterCapabilities[] = "capabilities"; |
175 | 179 |
176 // Get the print job settings dictionary from |args|. The caller takes | 180 // Get the print job settings dictionary from |args|. The caller takes |
177 // ownership of the returned DictionaryValue. Returns NULL on failure. | 181 // ownership of the returned DictionaryValue. Returns NULL on failure. |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 success = args->GetBoolean(2, &preview_modifiable); | 836 success = args->GetBoolean(2, &preview_modifiable); |
833 DCHECK(success); | 837 DCHECK(success); |
834 | 838 |
835 if (draft_page_count != -1 && preview_modifiable && | 839 if (draft_page_count != -1 && preview_modifiable && |
836 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { | 840 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { |
837 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 841 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
838 } | 842 } |
839 } | 843 } |
840 | 844 |
841 VLOG(1) << "Print preview request start"; | 845 VLOG(1) << "Print preview request start"; |
842 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 846 |
843 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | 847 bool print_friendly = false; |
| 848 if (!settings->GetBoolean(printing::kSettingPrintFriendlyEnabled, |
| 849 &print_friendly)) { |
| 850 NOTREACHED(); |
| 851 } |
| 852 |
| 853 if (print_friendly) { |
| 854 hidden_print_preview_.reset( |
| 855 new HiddenPrintPreview(initiator, print_preview_ui(), settings.Pass())); |
| 856 } else { |
| 857 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 858 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 859 } |
844 } | 860 } |
845 | 861 |
846 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 862 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
847 ReportStats(); | 863 ReportStats(); |
848 | 864 |
849 // Record the number of times the user requests to regenerate preview data | 865 // Record the number of times the user requests to regenerate preview data |
850 // before printing. | 866 // before printing. |
851 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 867 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
852 regenerate_preview_request_count_); | 868 regenerate_preview_request_count_); |
853 | 869 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 initial_settings.SetBoolean(kAppKioskMode, | 1262 initial_settings.SetBoolean(kAppKioskMode, |
1247 chrome::IsRunningInForcedAppMode()); | 1263 chrome::IsRunningInForcedAppMode()); |
1248 #if defined(OS_WIN) | 1264 #if defined(OS_WIN) |
1249 // In Win8 metro, the system print dialog can only open on the desktop. Doing | 1265 // 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 | 1266 // so will cause the browser to appear hung, so we don't show the link in |
1251 // metro. | 1267 // metro. |
1252 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1268 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
1253 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1269 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
1254 #endif | 1270 #endif |
1255 | 1271 |
| 1272 WebContents* initiator = GetInitiator(); |
| 1273 bool can_simplify = false; |
| 1274 if (initiator) { |
| 1275 can_simplify = cmdline->HasSwitch(switches::kEnableDomDistiller) && |
| 1276 dom_distiller::url_utils::IsUrlDistillable( |
| 1277 initiator->GetLastCommittedURL()); |
| 1278 } |
| 1279 initial_settings.SetBoolean(kPrintFriendlyEnabled, can_simplify); |
| 1280 |
1256 if (print_preview_ui()->source_is_modifiable()) | 1281 if (print_preview_ui()->source_is_modifiable()) |
1257 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1282 GetNumberFormatAndMeasurementSystem(&initial_settings); |
1258 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1283 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
1259 } | 1284 } |
1260 | 1285 |
1261 void PrintPreviewHandler::ClosePreviewDialog() { | 1286 void PrintPreviewHandler::ClosePreviewDialog() { |
1262 print_preview_ui()->OnClosePrintPreviewDialog(); | 1287 print_preview_ui()->OnClosePrintPreviewDialog(); |
1263 } | 1288 } |
1264 | 1289 |
1265 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1290 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 | 1791 |
1767 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1792 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
1768 if (gaia_cookie_manager_service_) | 1793 if (gaia_cookie_manager_service_) |
1769 gaia_cookie_manager_service_->RemoveObserver(this); | 1794 gaia_cookie_manager_service_->RemoveObserver(this); |
1770 } | 1795 } |
1771 | 1796 |
1772 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1797 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
1773 const base::Closure& closure) { | 1798 const base::Closure& closure) { |
1774 pdf_file_saved_closure_ = closure; | 1799 pdf_file_saved_closure_ = closure; |
1775 } | 1800 } |
OLD | NEW |