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 | 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/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 Loading... | |
| 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 print_friendly = false; |
| 847 if (!settings->GetBoolean(printing::kSettingPrintFriendlyEnabled, | |
| 848 &print_friendly)) { | |
| 849 NOTREACHED(); | |
| 850 } | |
| 851 | |
| 852 if (print_friendly) { | |
| 853 hidden_print_preview_.reset( | |
| 854 new HiddenPrintPreview(initiator, print_preview_ui(), settings.Pass())); | |
| 855 } else { | |
| 856 RenderViewHost* rvh = initiator->GetRenderViewHost(); | |
| 857 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | |
| 858 } | |
| 844 } | 859 } |
| 845 | 860 |
| 846 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 861 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
| 847 ReportStats(); | 862 ReportStats(); |
| 848 | 863 |
| 849 // Record the number of times the user requests to regenerate preview data | 864 // Record the number of times the user requests to regenerate preview data |
| 850 // before printing. | 865 // before printing. |
| 851 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 866 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
| 852 regenerate_preview_request_count_); | 867 regenerate_preview_request_count_); |
| 853 | 868 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1249 // In Win8 metro, the system print dialog can only open on the desktop. Doing | 1264 // 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 | 1265 // so will cause the browser to appear hung, so we don't show the link in |
| 1251 // metro. | 1266 // metro. |
| 1252 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1267 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
| 1253 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1268 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
| 1254 #endif | 1269 #endif |
| 1255 | 1270 |
| 1256 if (print_preview_ui()->source_is_modifiable()) | 1271 if (print_preview_ui()->source_is_modifiable()) |
| 1257 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1272 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1258 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1273 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
| 1274 | |
| 1275 WebContents* initiator = GetInitiator(); | |
| 1276 if (initiator && cmdline->HasSwitch(switches::kEnableDomDistiller) && | |
| 1277 dom_distiller::url_utils::IsUrlDistillable( | |
| 1278 initiator->GetLastCommittedURL())) { | |
| 1279 dom_distiller::IsDistillablePage(initiator, false, | |
|
Vitaly Buka (NO REVIEWS)
2015/07/13 07:00:31
I don't see guaranty that HandleIsPageDistillableR
| |
| 1280 base::Bind(&PrintPreviewHandler::HandleIsPageDistillableResult, | |
| 1281 base::Unretained(this))); | |
| 1282 } | |
| 1283 } | |
| 1284 | |
| 1285 void PrintPreviewHandler::HandleIsPageDistillableResult(bool distillable) { | |
| 1286 VLOG(1) << "Distillable page detection finished"; | |
| 1287 if (distillable) | |
| 1288 web_ui()->CallJavascriptFunction("onDetectedSimplifiablePage"); | |
| 1259 } | 1289 } |
| 1260 | 1290 |
| 1261 void PrintPreviewHandler::ClosePreviewDialog() { | 1291 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1262 print_preview_ui()->OnClosePrintPreviewDialog(); | 1292 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1263 } | 1293 } |
| 1264 | 1294 |
| 1265 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1295 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1266 const std::string& access_token) { | 1296 const std::string& access_token) { |
| 1267 VLOG(1) << "Get getAccessToken finished"; | 1297 VLOG(1) << "Get getAccessToken finished"; |
| 1268 web_ui()->CallJavascriptFunction("onDidGetAccessToken", | 1298 web_ui()->CallJavascriptFunction("onDidGetAccessToken", |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1766 | 1796 |
| 1767 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1797 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1768 if (gaia_cookie_manager_service_) | 1798 if (gaia_cookie_manager_service_) |
| 1769 gaia_cookie_manager_service_->RemoveObserver(this); | 1799 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1770 } | 1800 } |
| 1771 | 1801 |
| 1772 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1802 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1773 const base::Closure& closure) { | 1803 const base::Closure& closure) { |
| 1774 pdf_file_saved_closure_ = closure; | 1804 pdf_file_saved_closure_ = closure; |
| 1775 } | 1805 } |
| OLD | NEW |