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/browser/distillable_page_utils.h" |
| 62 #include "components/dom_distiller/core/dom_distiller_switches.h" |
| 63 #include "components/dom_distiller/core/url_utils.h" |
60 #include "components/printing/common/print_messages.h" | 64 #include "components/printing/common/print_messages.h" |
61 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | 65 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
62 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 66 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
63 #include "components/signin/core/browser/signin_manager.h" | 67 #include "components/signin/core/browser/signin_manager.h" |
64 #include "components/signin/core/common/profile_management_switches.h" | 68 #include "components/signin/core/common/profile_management_switches.h" |
65 #include "content/public/browser/browser_context.h" | 69 #include "content/public/browser/browser_context.h" |
66 #include "content/public/browser/browser_thread.h" | 70 #include "content/public/browser/browser_thread.h" |
67 #include "content/public/browser/navigation_controller.h" | 71 #include "content/public/browser/navigation_controller.h" |
68 #include "content/public/browser/navigation_entry.h" | 72 #include "content/public/browser/navigation_entry.h" |
69 #include "content/public/browser/render_process_host.h" | 73 #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); | 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 distill_page = false; |
| 848 if (!settings->GetBoolean(printing::kSettingDistillPageEnabled, |
| 849 &distill_page)) { |
| 850 NOTREACHED(); |
| 851 } |
| 852 |
| 853 bool selection_only = false; |
| 854 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 855 &selection_only)) { |
| 856 NOTREACHED(); |
| 857 } |
| 858 |
| 859 if (distill_page && !selection_only) { |
| 860 print_preview_distiller_.reset(new PrintPreviewDistiller( |
| 861 initiator, base::Bind(&PrintPreviewUI::OnPrintPreviewFailed, |
| 862 print_preview_ui()->GetWeakPtr()), |
| 863 settings.Pass())); |
| 864 } else { |
| 865 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 866 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 867 } |
844 } | 868 } |
845 | 869 |
846 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 870 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
847 ReportStats(); | 871 ReportStats(); |
848 | 872 |
849 // Record the number of times the user requests to regenerate preview data | 873 // Record the number of times the user requests to regenerate preview data |
850 // before printing. | 874 // before printing. |
851 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 875 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
852 regenerate_preview_request_count_); | 876 regenerate_preview_request_count_); |
853 | 877 |
(...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 | 1273 // 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 | 1274 // so will cause the browser to appear hung, so we don't show the link in |
1251 // metro. | 1275 // metro. |
1252 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); | 1276 bool is_ash = (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH); |
1253 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); | 1277 initial_settings.SetBoolean(kHidePrintWithSystemDialogLink, is_ash); |
1254 #endif | 1278 #endif |
1255 | 1279 |
1256 if (print_preview_ui()->source_is_modifiable()) | 1280 if (print_preview_ui()->source_is_modifiable()) |
1257 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1281 GetNumberFormatAndMeasurementSystem(&initial_settings); |
1258 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1282 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
| 1283 |
| 1284 WebContents* initiator = GetInitiator(); |
| 1285 if (initiator && cmdline->HasSwitch(switches::kEnableDomDistiller) && |
| 1286 dom_distiller::url_utils::IsUrlDistillable( |
| 1287 initiator->GetLastCommittedURL())) { |
| 1288 dom_distiller::IsDistillablePage( |
| 1289 initiator, false, |
| 1290 base::Bind(&PrintPreviewHandler::HandleIsPageDistillableResult, |
| 1291 weak_factory_.GetWeakPtr())); |
| 1292 } |
| 1293 } |
| 1294 |
| 1295 void PrintPreviewHandler::HandleIsPageDistillableResult(bool distillable) { |
| 1296 VLOG(1) << "Distillable page detection finished"; |
| 1297 if (distillable) |
| 1298 web_ui()->CallJavascriptFunction("detectDistillablePage"); |
1259 } | 1299 } |
1260 | 1300 |
1261 void PrintPreviewHandler::ClosePreviewDialog() { | 1301 void PrintPreviewHandler::ClosePreviewDialog() { |
1262 print_preview_ui()->OnClosePrintPreviewDialog(); | 1302 print_preview_ui()->OnClosePrintPreviewDialog(); |
1263 } | 1303 } |
1264 | 1304 |
1265 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1305 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
1266 const std::string& access_token) { | 1306 const std::string& access_token) { |
1267 VLOG(1) << "Get getAccessToken finished"; | 1307 VLOG(1) << "Get getAccessToken finished"; |
1268 web_ui()->CallJavascriptFunction("onDidGetAccessToken", | 1308 web_ui()->CallJavascriptFunction("onDidGetAccessToken", |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 | 1806 |
1767 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1807 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
1768 if (gaia_cookie_manager_service_) | 1808 if (gaia_cookie_manager_service_) |
1769 gaia_cookie_manager_service_->RemoveObserver(this); | 1809 gaia_cookie_manager_service_->RemoveObserver(this); |
1770 } | 1810 } |
1771 | 1811 |
1772 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1812 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
1773 const base::Closure& closure) { | 1813 const base::Closure& closure) { |
1774 pdf_file_saved_closure_ = closure; | 1814 pdf_file_saved_closure_ = closure; |
1775 } | 1815 } |
OLD | NEW |