| 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 success = args->GetBoolean(2, &preview_modifiable); | 820 success = args->GetBoolean(2, &preview_modifiable); |
| 817 DCHECK(success); | 821 DCHECK(success); |
| 818 | 822 |
| 819 if (draft_page_count != -1 && preview_modifiable && | 823 if (draft_page_count != -1 && preview_modifiable && |
| 820 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { | 824 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { |
| 821 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 825 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
| 822 } | 826 } |
| 823 } | 827 } |
| 824 | 828 |
| 825 VLOG(1) << "Print preview request start"; | 829 VLOG(1) << "Print preview request start"; |
| 826 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 830 |
| 827 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | 831 bool print_friendly = false; |
| 832 if (!settings->GetBoolean(printing::kSettingPrintFriendlyEnabled, |
| 833 &print_friendly)) { |
| 834 NOTREACHED(); |
| 835 } |
| 836 |
| 837 if (print_friendly) { |
| 838 if (!hidden_print_preview_) |
| 839 MaybeStartDistillation(initiator); |
| 840 |
| 841 hidden_print_preview_.reset( |
| 842 new HiddenPrintPreview(initiator, print_preview_ui())); |
| 843 hidden_print_preview_->SetSettings(settings.Pass()); |
| 844 } else { |
| 845 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 846 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 847 } |
| 828 } | 848 } |
| 829 | 849 |
| 830 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 850 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
| 831 ReportStats(); | 851 ReportStats(); |
| 832 | 852 |
| 833 // Record the number of times the user requests to regenerate preview data | 853 // Record the number of times the user requests to regenerate preview data |
| 834 // before printing. | 854 // before printing. |
| 835 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 855 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
| 836 regenerate_preview_request_count_); | 856 regenerate_preview_request_count_); |
| 837 | 857 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 initial_settings.SetBoolean(kAppKioskMode, | 1250 initial_settings.SetBoolean(kAppKioskMode, |
| 1231 chrome::IsRunningInForcedAppMode()); | 1251 chrome::IsRunningInForcedAppMode()); |
| 1232 #if defined(OS_WIN) | 1252 #if defined(OS_WIN) |
| 1233 // In Win8 metro, the system print dialog can only open on the desktop. Doing | 1253 // In Win8 metro, the system print dialog can only open on the desktop. Doing |
| 1234 // so will cause the browser to appear hung, so we don't show the link in | 1254 // so will cause the browser to appear hung, so we don't show the link in |
| 1235 // metro. | 1255 // metro. |
| 1236 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1256 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
| 1237 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1257 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
| 1238 #endif | 1258 #endif |
| 1239 | 1259 |
| 1260 WebContents* initiator = GetInitiator(); |
| 1261 bool can_simplify = false; |
| 1262 if (initiator) { |
| 1263 can_simplify = cmdline->HasSwitch(switches::kEnableDomDistiller) && |
| 1264 dom_distiller::url_utils::IsUrlDistillable( |
| 1265 initiator->GetLastCommittedURL()); |
| 1266 } |
| 1267 initial_settings.SetBoolean(kPrintFriendlyEnabled, can_simplify); |
| 1268 |
| 1240 if (print_preview_ui()->source_is_modifiable()) | 1269 if (print_preview_ui()->source_is_modifiable()) |
| 1241 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1270 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1242 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1271 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
| 1243 } | 1272 } |
| 1244 | 1273 |
| 1245 void PrintPreviewHandler::ClosePreviewDialog() { | 1274 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1246 print_preview_ui()->OnClosePrintPreviewDialog(); | 1275 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1247 } | 1276 } |
| 1248 | 1277 |
| 1249 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1278 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 | 1765 |
| 1737 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1766 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1738 if (gaia_cookie_manager_service_) | 1767 if (gaia_cookie_manager_service_) |
| 1739 gaia_cookie_manager_service_->RemoveObserver(this); | 1768 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1740 } | 1769 } |
| 1741 | 1770 |
| 1742 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1771 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1743 const base::Closure& closure) { | 1772 const base::Closure& closure) { |
| 1744 pdf_file_saved_closure_ = closure; | 1773 pdf_file_saved_closure_ = closure; |
| 1745 } | 1774 } |
| OLD | NEW |