Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/task_runner_util.h" | 30 #include "base/task_runner_util.h" |
| 31 #include "base/threading/thread.h" | 31 #include "base/threading/thread.h" |
| 32 #include "base/threading/thread_restrictions.h" | 32 #include "base/threading/thread_restrictions.h" |
| 33 #include "base/values.h" | 33 #include "base/values.h" |
| 34 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| 35 #include "chrome/browser/app_mode/app_mode_utils.h" | 35 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 36 #include "chrome/browser/browser_process.h" | 36 #include "chrome/browser/browser_process.h" |
| 37 #include "chrome/browser/dom_distiller/tab_utils.h" | |
| 38 #include "chrome/browser/platform_util.h" | 37 #include "chrome/browser/platform_util.h" |
| 39 #include "chrome/browser/printing/print_dialog_cloud.h" | 38 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 40 #include "chrome/browser/printing/print_error_dialog.h" | 39 #include "chrome/browser/printing/print_error_dialog.h" |
| 41 #include "chrome/browser/printing/print_job_manager.h" | 40 #include "chrome/browser/printing/print_job_manager.h" |
| 42 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 41 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
| 43 #include "chrome/browser/printing/print_view_manager.h" | 42 #include "chrome/browser/printing/print_view_manager.h" |
| 44 #include "chrome/browser/printing/printer_manager_dialog.h" | 43 #include "chrome/browser/printing/printer_manager_dialog.h" |
| 45 #include "chrome/browser/profiles/profile.h" | 44 #include "chrome/browser/profiles/profile.h" |
| 46 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" | 45 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
| 47 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 46 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 48 #include "chrome/browser/signin/signin_manager_factory.h" | 47 #include "chrome/browser/signin/signin_manager_factory.h" |
| 49 #include "chrome/browser/ui/browser_finder.h" | 48 #include "chrome/browser/ui/browser_finder.h" |
| 50 #include "chrome/browser/ui/browser_tabstrip.h" | 49 #include "chrome/browser/ui/browser_tabstrip.h" |
| 51 #include "chrome/browser/ui/chrome_select_file_policy.h" | 50 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 52 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 51 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 53 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 52 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 54 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" | 53 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" |
| 55 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" | 54 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" |
| 56 #include "chrome/common/chrome_paths.h" | 55 #include "chrome/common/chrome_paths.h" |
| 57 #include "chrome/common/chrome_switches.h" | 56 #include "chrome/common/chrome_switches.h" |
| 58 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" | 57 #include "chrome/common/cloud_print/cloud_print_cdd_conversion.h" |
| 59 #include "chrome/common/cloud_print/cloud_print_constants.h" | 58 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 60 #include "chrome/common/crash_keys.h" | 59 #include "chrome/common/crash_keys.h" |
| 61 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
| 62 #include "components/cloud_devices/common/cloud_device_description.h" | 61 #include "components/cloud_devices/common/cloud_device_description.h" |
| 63 #include "components/cloud_devices/common/cloud_devices_urls.h" | 62 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 64 #include "components/cloud_devices/common/printer_description.h" | 63 #include "components/cloud_devices/common/printer_description.h" |
| 65 #include "components/dom_distiller/core/dom_distiller_switches.h" | |
| 66 #include "components/dom_distiller/core/url_utils.h" | |
| 67 #include "components/prefs/pref_service.h" | 64 #include "components/prefs/pref_service.h" |
| 68 #include "components/printing/common/print_messages.h" | 65 #include "components/printing/common/print_messages.h" |
| 69 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 66 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
| 70 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 67 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 71 #include "components/signin/core/browser/signin_manager.h" | 68 #include "components/signin/core/browser/signin_manager.h" |
| 72 #include "components/signin/core/common/profile_management_switches.h" | 69 #include "components/signin/core/common/profile_management_switches.h" |
| 73 #include "content/public/browser/browser_context.h" | 70 #include "content/public/browser/browser_context.h" |
| 74 #include "content/public/browser/browser_thread.h" | 71 #include "content/public/browser/browser_thread.h" |
| 75 #include "content/public/browser/navigation_controller.h" | 72 #include "content/public/browser/navigation_controller.h" |
| 76 #include "content/public/browser/navigation_entry.h" | 73 #include "content/public/browser/navigation_entry.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 TOTAL, | 126 TOTAL, |
| 130 HEADERS_AND_FOOTERS, | 127 HEADERS_AND_FOOTERS, |
| 131 CSS_BACKGROUND, | 128 CSS_BACKGROUND, |
| 132 SELECTION_ONLY, | 129 SELECTION_ONLY, |
| 133 EXTERNAL_PDF_PREVIEW, | 130 EXTERNAL_PDF_PREVIEW, |
| 134 PAGE_RANGE, | 131 PAGE_RANGE, |
| 135 DEFAULT_MEDIA, | 132 DEFAULT_MEDIA, |
| 136 NON_DEFAULT_MEDIA, | 133 NON_DEFAULT_MEDIA, |
| 137 COPIES, | 134 COPIES, |
| 138 NON_DEFAULT_MARGINS, | 135 NON_DEFAULT_MARGINS, |
| 139 DISTILL_PAGE, | 136 DISTILL_PAGE, // UNUSED |
|
Lei Zhang
2016/06/28 19:00:38
asvitkine: Should I modify the corresponding entry
Alexei Svitkine (slow)
2016/06/28 19:02:06
Up to you, it doesn't hurt. Maybe you can just add
Lei Zhang
2016/06/28 20:56:56
Done.
| |
| 140 PRINT_SETTINGS_BUCKET_BOUNDARY | 137 PRINT_SETTINGS_BUCKET_BOUNDARY |
| 141 }; | 138 }; |
| 142 | 139 |
| 143 void ReportUserActionHistogram(enum UserActionBuckets event) { | 140 void ReportUserActionHistogram(enum UserActionBuckets event) { |
| 144 UMA_HISTOGRAM_ENUMERATION("PrintPreview.UserAction", event, | 141 UMA_HISTOGRAM_ENUMERATION("PrintPreview.UserAction", event, |
| 145 USERACTION_BUCKET_BOUNDARY); | 142 USERACTION_BUCKET_BOUNDARY); |
| 146 } | 143 } |
| 147 | 144 |
| 148 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) { | 145 void ReportPrintSettingHistogram(enum PrintSettingsBuckets setting) { |
| 149 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting, | 146 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PrintSettings", setting, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 if (settings.GetBoolean(printing::kSettingShouldPrintSelectionOnly, | 272 if (settings.GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 276 &selection_only) && selection_only) { | 273 &selection_only) && selection_only) { |
| 277 ReportPrintSettingHistogram(SELECTION_ONLY); | 274 ReportPrintSettingHistogram(SELECTION_ONLY); |
| 278 } | 275 } |
| 279 | 276 |
| 280 bool external_preview = false; | 277 bool external_preview = false; |
| 281 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview, | 278 if (settings.GetBoolean(printing::kSettingOpenPDFInPreview, |
| 282 &external_preview) && external_preview) { | 279 &external_preview) && external_preview) { |
| 283 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW); | 280 ReportPrintSettingHistogram(EXTERNAL_PDF_PREVIEW); |
| 284 } | 281 } |
| 285 | |
| 286 bool distill_page = false; | |
| 287 if (settings.GetBoolean(printing::kSettingDistillPageEnabled, | |
| 288 &distill_page) && distill_page) { | |
| 289 ReportPrintSettingHistogram(DISTILL_PAGE); | |
| 290 } | |
| 291 } | 282 } |
| 292 | 283 |
| 293 // Callback that stores a PDF file on disk. | 284 // Callback that stores a PDF file on disk. |
| 294 void PrintToPdfCallback(const scoped_refptr<base::RefCountedBytes>& data, | 285 void PrintToPdfCallback(const scoped_refptr<base::RefCountedBytes>& data, |
| 295 const base::FilePath& path, | 286 const base::FilePath& path, |
| 296 const base::Closure& pdf_file_saved_closure) { | 287 const base::Closure& pdf_file_saved_closure) { |
| 297 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 288 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 298 base::File file(path, | 289 base::File file(path, |
| 299 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); | 290 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 300 file.WriteAtCurrentPos(reinterpret_cast<const char*>(data->front()), | 291 file.WriteAtCurrentPos(reinterpret_cast<const char*>(data->front()), |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 DCHECK(success); | 828 DCHECK(success); |
| 838 | 829 |
| 839 if (draft_page_count != -1 && preview_modifiable && | 830 if (draft_page_count != -1 && preview_modifiable && |
| 840 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { | 831 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { |
| 841 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 832 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
| 842 } | 833 } |
| 843 } | 834 } |
| 844 | 835 |
| 845 VLOG(1) << "Print preview request start"; | 836 VLOG(1) << "Print preview request start"; |
| 846 | 837 |
| 847 bool distill_page = false; | |
| 848 if (!settings->GetBoolean(printing::kSettingDistillPageEnabled, | |
| 849 &distill_page)) { | |
| 850 NOTREACHED(); | |
| 851 } | |
| 852 | |
| 853 bool selection_only = false; | 838 bool selection_only = false; |
| 854 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, | 839 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 855 &selection_only)) { | 840 &selection_only)) { |
| 856 NOTREACHED(); | 841 NOTREACHED(); |
| 857 } | 842 } |
| 858 | 843 |
| 859 if (distill_page && !selection_only) { | 844 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 860 print_preview_distiller_.reset(new PrintPreviewDistiller( | 845 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 861 initiator, base::Bind(&PrintPreviewUI::OnPrintPreviewFailed, | |
| 862 print_preview_ui()->GetWeakPtr()), | |
| 863 std::move(settings))); | |
| 864 } else { | |
| 865 RenderViewHost* rvh = initiator->GetRenderViewHost(); | |
| 866 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | |
| 867 } | |
| 868 } | 846 } |
| 869 | 847 |
| 870 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 848 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
| 871 ReportStats(); | 849 ReportStats(); |
| 872 | 850 |
| 873 // Record the number of times the user requests to regenerate preview data | 851 // Record the number of times the user requests to regenerate preview data |
| 874 // before printing. | 852 // before printing. |
| 875 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 853 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
| 876 regenerate_preview_request_count_); | 854 regenerate_preview_request_count_); |
| 877 | 855 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1287 const std::string rules_str = | 1265 const std::string rules_str = |
| 1288 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); | 1266 prefs->GetString(prefs::kPrintPreviewDefaultDestinationSelectionRules); |
| 1289 if (!rules_str.empty()) | 1267 if (!rules_str.empty()) |
| 1290 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); | 1268 initial_settings.SetString(kDefaultDestinationSelectionRules, rules_str); |
| 1291 } | 1269 } |
| 1292 | 1270 |
| 1293 if (print_preview_ui()->source_is_modifiable()) | 1271 if (print_preview_ui()->source_is_modifiable()) |
| 1294 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1272 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1295 web_ui()->CallJavascriptFunctionUnsafe("setInitialSettings", | 1273 web_ui()->CallJavascriptFunctionUnsafe("setInitialSettings", |
| 1296 initial_settings); | 1274 initial_settings); |
| 1297 | |
| 1298 if (PrintPreviewDistiller::IsEnabled()) { | |
| 1299 using dom_distiller::url_utils::IsUrlDistillable; | |
| 1300 WebContents* initiator = GetInitiator(); | |
| 1301 if (initiator && IsUrlDistillable(initiator->GetLastCommittedURL())) | |
| 1302 web_ui()->CallJavascriptFunctionUnsafe("allowDistillPage"); | |
| 1303 } | |
| 1304 } | 1275 } |
| 1305 | 1276 |
| 1306 void PrintPreviewHandler::ClosePreviewDialog() { | 1277 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1307 print_preview_ui()->OnClosePrintPreviewDialog(); | 1278 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1308 } | 1279 } |
| 1309 | 1280 |
| 1310 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1281 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1311 const std::string& access_token) { | 1282 const std::string& access_token) { |
| 1312 VLOG(1) << "Get getAccessToken finished"; | 1283 VLOG(1) << "Get getAccessToken finished"; |
| 1313 web_ui()->CallJavascriptFunctionUnsafe("onDidGetAccessToken", | 1284 web_ui()->CallJavascriptFunctionUnsafe("onDidGetAccessToken", |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1794 | 1765 |
| 1795 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1766 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1796 if (gaia_cookie_manager_service_) | 1767 if (gaia_cookie_manager_service_) |
| 1797 gaia_cookie_manager_service_->RemoveObserver(this); | 1768 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1798 } | 1769 } |
| 1799 | 1770 |
| 1800 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1771 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1801 const base::Closure& closure) { | 1772 const base::Closure& closure) { |
| 1802 pdf_file_saved_closure_ = closure; | 1773 pdf_file_saved_closure_ = closure; |
| 1803 } | 1774 } |
| OLD | NEW |