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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 | 838 |
| 839 if (draft_page_count != -1 && preview_modifiable && | 839 if (draft_page_count != -1 && preview_modifiable && |
| 840 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { | 840 print_preview_ui()->GetAvailableDraftPageCount() != draft_page_count) { |
| 841 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 841 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
| 842 } | 842 } |
| 843 } | 843 } |
| 844 | 844 |
| 845 VLOG(1) << "Print preview request start"; | 845 VLOG(1) << "Print preview request start"; |
| 846 | 846 |
| 847 bool distill_page = false; | 847 bool distill_page = false; |
| 848 bool selection_only = false; | |
| 848 if (!settings->GetBoolean(printing::kSettingDistillPageEnabled, | 849 if (!settings->GetBoolean(printing::kSettingDistillPageEnabled, |
| 849 &distill_page)) { | 850 &distill_page) || |
| 850 NOTREACHED(); | 851 !settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 851 } | |
| 852 | |
| 853 bool selection_only = false; | |
| 854 if (!settings->GetBoolean(printing::kSettingShouldPrintSelectionOnly, | |
| 855 &selection_only)) { | 852 &selection_only)) { |
| 856 NOTREACHED(); | 853 NOTREACHED(); |
| 857 } | 854 } |
| 858 | 855 |
| 859 if (distill_page && !selection_only) { | 856 if (distill_page && !selection_only) { |
| 860 print_preview_distiller_.reset(new PrintPreviewDistiller( | 857 print_preview_distiller_.reset(new PrintPreviewDistiller( |
| 861 initiator, base::Bind(&PrintPreviewUI::OnPrintPreviewFailed, | 858 initiator, |
| 862 print_preview_ui()->GetWeakPtr()), | 859 base::Bind(&PrintPreviewHandler::OnDistillerFailed, |
| 860 weak_factory_.GetWeakPtr()), | |
| 863 settings.Pass())); | 861 settings.Pass())); |
| 864 } else { | 862 } else { |
| 865 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 863 RenderViewHost* rvh = initiator->GetRenderViewHost(); |
| 866 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | 864 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 867 } | 865 } |
| 868 } | 866 } |
| 869 | 867 |
| 870 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { | 868 void PrintPreviewHandler::HandlePrint(const base::ListValue* args) { |
| 871 ReportStats(); | 869 ReportStats(); |
| 872 | 870 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 base::Bind(&PrintPreviewHandler::SendFailedToGetPrinterCapabilities, | 1106 base::Bind(&PrintPreviewHandler::SendFailedToGetPrinterCapabilities, |
| 1109 weak_factory_.GetWeakPtr()); | 1107 weak_factory_.GetWeakPtr()); |
| 1110 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 1108 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1111 base::Bind(&GetPrinterCapabilitiesOnFileThread, | 1109 base::Bind(&GetPrinterCapabilitiesOnFileThread, |
| 1112 printer_name, | 1110 printer_name, |
| 1113 g_browser_process->GetApplicationLocale(), | 1111 g_browser_process->GetApplicationLocale(), |
| 1114 success_cb, failure_cb)); | 1112 success_cb, failure_cb)); |
| 1115 } | 1113 } |
| 1116 | 1114 |
| 1117 void PrintPreviewHandler::OnSigninComplete() { | 1115 void PrintPreviewHandler::OnSigninComplete() { |
| 1118 if (print_preview_ui()) | 1116 print_preview_ui()->OnReloadPrintersList(); |
|
Lei Zhang
2015/08/14 05:44:35
This has nothing to do with your CL, I just don't
| |
| 1119 print_preview_ui()->OnReloadPrintersList(); | |
| 1120 } | 1117 } |
| 1121 | 1118 |
| 1122 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { | 1119 void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { |
| 1123 bool add_account = false; | 1120 bool add_account = false; |
| 1124 bool success = args->GetBoolean(0, &add_account); | 1121 bool success = args->GetBoolean(0, &add_account); |
| 1125 DCHECK(success); | 1122 DCHECK(success); |
| 1126 | 1123 |
| 1127 Profile* profile = Profile::FromBrowserContext( | 1124 Profile* profile = Profile::FromBrowserContext( |
| 1128 preview_web_contents()->GetBrowserContext()); | 1125 preview_web_contents()->GetBrowserContext()); |
| 1129 chrome::ScopedTabbedBrowserDisplayer displayer( | 1126 chrome::ScopedTabbedBrowserDisplayer displayer( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 | 1276 |
| 1280 if (print_preview_ui()->source_is_modifiable()) | 1277 if (print_preview_ui()->source_is_modifiable()) |
| 1281 GetNumberFormatAndMeasurementSystem(&initial_settings); | 1278 GetNumberFormatAndMeasurementSystem(&initial_settings); |
| 1282 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 1279 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
| 1283 | 1280 |
| 1284 WebContents* initiator = GetInitiator(); | 1281 WebContents* initiator = GetInitiator(); |
| 1285 if (initiator && cmdline->HasSwitch(switches::kEnableDomDistiller) && | 1282 if (initiator && cmdline->HasSwitch(switches::kEnableDomDistiller) && |
| 1286 dom_distiller::url_utils::IsUrlDistillable( | 1283 dom_distiller::url_utils::IsUrlDistillable( |
| 1287 initiator->GetLastCommittedURL())) { | 1284 initiator->GetLastCommittedURL())) { |
| 1288 dom_distiller::IsDistillablePage( | 1285 dom_distiller::IsDistillablePage( |
| 1289 initiator, false, | 1286 initiator, false /* is_mobile_optimized? */, |
| 1290 base::Bind(&PrintPreviewHandler::HandleIsPageDistillableResult, | 1287 base::Bind(&PrintPreviewHandler::OnGotPageDistillableResult, |
| 1291 weak_factory_.GetWeakPtr())); | 1288 weak_factory_.GetWeakPtr())); |
| 1292 } | 1289 } |
| 1293 } | 1290 } |
| 1294 | 1291 |
| 1295 void PrintPreviewHandler::HandleIsPageDistillableResult(bool distillable) { | 1292 void PrintPreviewHandler::OnGotPageDistillableResult(bool distillable) { |
| 1296 VLOG(1) << "Distillable page detection finished"; | 1293 VLOG(1) << "Distillable page detection finished"; |
| 1297 if (distillable) | 1294 if (distillable) |
| 1298 web_ui()->CallJavascriptFunction("detectDistillablePage"); | 1295 web_ui()->CallJavascriptFunction("detectDistillablePage"); |
| 1299 } | 1296 } |
| 1300 | 1297 |
| 1298 void PrintPreviewHandler::OnDistillerFailed() { | |
| 1299 print_preview_ui()->OnPrintPreviewFailed(); | |
| 1300 } | |
| 1301 | |
| 1301 void PrintPreviewHandler::ClosePreviewDialog() { | 1302 void PrintPreviewHandler::ClosePreviewDialog() { |
| 1302 print_preview_ui()->OnClosePrintPreviewDialog(); | 1303 print_preview_ui()->OnClosePrintPreviewDialog(); |
| 1303 } | 1304 } |
| 1304 | 1305 |
| 1305 void PrintPreviewHandler::SendAccessToken(const std::string& type, | 1306 void PrintPreviewHandler::SendAccessToken(const std::string& type, |
| 1306 const std::string& access_token) { | 1307 const std::string& access_token) { |
| 1307 VLOG(1) << "Get getAccessToken finished"; | 1308 VLOG(1) << "Get getAccessToken finished"; |
| 1308 web_ui()->CallJavascriptFunction("onDidGetAccessToken", | 1309 web_ui()->CallJavascriptFunction("onDidGetAccessToken", |
| 1309 base::StringValue(type), | 1310 base::StringValue(type), |
| 1310 base::StringValue(access_token)); | 1311 base::StringValue(access_token)); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1806 | 1807 |
| 1807 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1808 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1808 if (gaia_cookie_manager_service_) | 1809 if (gaia_cookie_manager_service_) |
| 1809 gaia_cookie_manager_service_->RemoveObserver(this); | 1810 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1810 } | 1811 } |
| 1811 | 1812 |
| 1812 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1813 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1813 const base::Closure& closure) { | 1814 const base::Closure& closure) { |
| 1814 pdf_file_saved_closure_ = closure; | 1815 pdf_file_saved_closure_ = closure; |
| 1815 } | 1816 } |
| OLD | NEW |