Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/renderer/printing/print_web_view_helper.h" | 5 #include "android_webview/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/common/print_messages.h" | |
| 9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/common/chrome_switches.h" | |
| 20 #include "chrome/common/print_messages.h" | |
| 21 #include "chrome/common/render_messages.h" | |
| 22 #include "chrome/renderer/prerender/prerender_helper.h" | |
| 23 #include "content/public/renderer/render_thread.h" | 20 #include "content/public/renderer/render_thread.h" |
| 24 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
| 25 #include "content/public/renderer/web_preferences.h" | 22 #include "content/public/renderer/web_preferences.h" |
| 26 #include "grit/browser_resources.h" | |
| 27 #include "grit/generated_resources.h" | |
| 28 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 29 #include "printing/metafile.h" | 24 #include "printing/metafile.h" |
| 30 #include "printing/metafile_impl.h" | 25 #include "printing/metafile_impl.h" |
| 31 #include "printing/units.h" | 26 #include "printing/units.h" |
| 32 #include "skia/ext/vector_platform_device_skia.h" | 27 #include "skia/ext/vector_platform_device_skia.h" |
| 33 #include "third_party/WebKit/public/platform/WebSize.h" | 28 #include "third_party/WebKit/public/platform/WebSize.h" |
| 34 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 35 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 30 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 36 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 37 #include "third_party/WebKit/public/web/WebElement.h" | 32 #include "third_party/WebKit/public/web/WebElement.h" |
| 38 #include "third_party/WebKit/public/web/WebFrame.h" | 33 #include "third_party/WebKit/public/web/WebFrame.h" |
| 39 #include "third_party/WebKit/public/web/WebFrameClient.h" | 34 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 40 #include "third_party/WebKit/public/web/WebPlugin.h" | 35 #include "third_party/WebKit/public/web/WebPlugin.h" |
| 41 #include "third_party/WebKit/public/web/WebPluginDocument.h" | 36 #include "third_party/WebKit/public/web/WebPluginDocument.h" |
| 42 #include "third_party/WebKit/public/web/WebPrintParams.h" | 37 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 43 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 38 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
| 44 #include "third_party/WebKit/public/web/WebScriptSource.h" | 39 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 45 #include "third_party/WebKit/public/web/WebSettings.h" | 40 #include "third_party/WebKit/public/web/WebSettings.h" |
| 46 #include "third_party/WebKit/public/web/WebView.h" | 41 #include "third_party/WebKit/public/web/WebView.h" |
| 47 #include "third_party/WebKit/public/web/WebViewClient.h" | 42 #include "third_party/WebKit/public/web/WebViewClient.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 49 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 50 #include "webkit/common/webpreferences.h" | 45 #include "webkit/common/webpreferences.h" |
| 51 | 46 |
| 47 // This code is copied from chrome/renderer/printing. Code is slightly | |
| 48 // modified to run it with webview, and the modifications are marked | |
| 49 // using OS_ANDROID. | |
| 50 // TODO(sgurun): remove the code as part of componentization of printing. | |
| 51 | |
| 52 namespace printing { | 52 namespace printing { |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 enum PrintPreviewHelperEvents { | 56 enum PrintPreviewHelperEvents { |
| 57 PREVIEW_EVENT_REQUESTED, | 57 PREVIEW_EVENT_REQUESTED, |
| 58 PREVIEW_EVENT_CACHE_HIT, // Unused | 58 PREVIEW_EVENT_CACHE_HIT, // Unused |
| 59 PREVIEW_EVENT_CREATE_DOCUMENT, | 59 PREVIEW_EVENT_CREATE_DOCUMENT, |
| 60 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 60 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
| 61 PREVIEW_EVENT_MAX, | 61 PREVIEW_EVENT_MAX, |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 358 |
| 359 if (fit_to_page) { | 359 if (fit_to_page) { |
| 360 double factor = FitPrintParamsToPage(params, &result_params); | 360 double factor = FitPrintParamsToPage(params, &result_params); |
| 361 if (scale_factor) | 361 if (scale_factor) |
| 362 *scale_factor = factor; | 362 *scale_factor = factor; |
| 363 } | 363 } |
| 364 return result_params; | 364 return result_params; |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool IsPrintPreviewEnabled() { | 367 bool IsPrintPreviewEnabled() { |
| 368 return CommandLine::ForCurrentProcess()->HasSwitch( | 368 return false; |
| 369 switches::kRendererPrintPreview); | |
| 370 } | 369 } |
| 371 | 370 |
| 372 bool IsPrintThrottlingDisabled() { | 371 bool IsPrintThrottlingDisabled() { |
| 373 return CommandLine::ForCurrentProcess()->HasSwitch( | 372 return true; |
| 374 switches::kDisableScriptedPrintThrottling); | |
| 375 } | 373 } |
| 376 | 374 |
| 377 } // namespace | 375 } // namespace |
| 378 | 376 |
| 379 FrameReference::FrameReference(const blink::WebFrame* frame) { | 377 FrameReference::FrameReference(const blink::WebFrame* frame) { |
| 380 Reset(frame); | 378 Reset(frame); |
| 381 } | 379 } |
| 382 | 380 |
| 383 FrameReference::FrameReference() { | 381 FrameReference::FrameReference() { |
| 384 Reset(NULL); | 382 Reset(NULL); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 407 | 405 |
| 408 // static - Not anonymous so that platform implementations can use it. | 406 // static - Not anonymous so that platform implementations can use it. |
| 409 void PrintWebViewHelper::PrintHeaderAndFooter( | 407 void PrintWebViewHelper::PrintHeaderAndFooter( |
| 410 blink::WebCanvas* canvas, | 408 blink::WebCanvas* canvas, |
| 411 int page_number, | 409 int page_number, |
| 412 int total_pages, | 410 int total_pages, |
| 413 float webkit_scale_factor, | 411 float webkit_scale_factor, |
| 414 const PageSizeMargins& page_layout, | 412 const PageSizeMargins& page_layout, |
| 415 const base::DictionaryValue& header_footer_info, | 413 const base::DictionaryValue& header_footer_info, |
| 416 const PrintMsg_Print_Params& params) { | 414 const PrintMsg_Print_Params& params) { |
| 415 #if 0 | |
| 416 // TODO(sgurun) android_webview hack | |
| 417 skia::VectorPlatformDeviceSkia* device = | 417 skia::VectorPlatformDeviceSkia* device = |
| 418 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | 418 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); |
| 419 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | 419 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); |
| 420 | 420 |
| 421 SkAutoCanvasRestore auto_restore(canvas, true); | 421 SkAutoCanvasRestore auto_restore(canvas, true); |
| 422 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 422 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
| 423 | 423 |
| 424 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 424 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
| 425 page_layout.content_width, | 425 page_layout.content_width, |
| 426 page_layout.margin_top + page_layout.margin_bottom + | 426 page_layout.margin_top + page_layout.margin_bottom + |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 444 options->SetDouble("topMargin", page_layout.margin_top); | 444 options->SetDouble("topMargin", page_layout.margin_top); |
| 445 options->SetDouble("bottomMargin", page_layout.margin_bottom); | 445 options->SetDouble("bottomMargin", page_layout.margin_bottom); |
| 446 options->SetString("pageNumber", | 446 options->SetString("pageNumber", |
| 447 base::StringPrintf("%d/%d", page_number, total_pages)); | 447 base::StringPrintf("%d/%d", page_number, total_pages)); |
| 448 | 448 |
| 449 ExecuteScript(frame, kPageSetupScriptFormat, *options); | 449 ExecuteScript(frame, kPageSetupScriptFormat, *options); |
| 450 | 450 |
| 451 blink::WebPrintParams webkit_params(page_size); | 451 blink::WebPrintParams webkit_params(page_size); |
| 452 webkit_params.printerDPI = GetDPI(¶ms); | 452 webkit_params.printerDPI = GetDPI(¶ms); |
| 453 | 453 |
| 454 frame->printBegin(webkit_params); | 454 frame->printBegin(webkit_params, WebKit::WebNode(), NULL); |
| 455 frame->printPage(0, canvas); | 455 frame->printPage(0, canvas); |
| 456 frame->printEnd(); | 456 frame->printEnd(); |
| 457 | 457 |
| 458 web_view->close(); | 458 web_view->close(); |
| 459 | 459 |
| 460 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 460 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
| 461 #endif | |
| 461 } | 462 } |
| 462 | 463 |
| 463 // static - Not anonymous so that platform implementations can use it. | 464 // static - Not anonymous so that platform implementations can use it. |
| 464 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 465 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
| 465 int page_number, | 466 int page_number, |
| 466 const gfx::Rect& canvas_area, | 467 const gfx::Rect& canvas_area, |
| 467 const gfx::Rect& content_area, | 468 const gfx::Rect& content_area, |
| 468 double scale_factor, | 469 double scale_factor, |
| 469 blink::WebCanvas* canvas) { | 470 blink::WebCanvas* canvas) { |
| 470 SkAutoCanvasRestore auto_restore(canvas, true); | 471 SkAutoCanvasRestore auto_restore(canvas, true); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 void PrintWebViewHelper::DidStopLoading() { | 750 void PrintWebViewHelper::DidStopLoading() { |
| 750 is_loading_ = false; | 751 is_loading_ = false; |
| 751 ShowScriptedPrintPreview(); | 752 ShowScriptedPrintPreview(); |
| 752 } | 753 } |
| 753 | 754 |
| 754 // Prints |frame| which called window.print(). | 755 // Prints |frame| which called window.print(). |
| 755 void PrintWebViewHelper::PrintPage(blink::WebFrame* frame, | 756 void PrintWebViewHelper::PrintPage(blink::WebFrame* frame, |
| 756 bool user_initiated) { | 757 bool user_initiated) { |
| 757 DCHECK(frame); | 758 DCHECK(frame); |
| 758 | 759 |
| 760 #if !defined(OS_ANDROID) | |
| 761 // TODO(sgurun) android_webview hack | |
| 759 // Allow Prerendering to cancel this print request if necessary. | 762 // Allow Prerendering to cancel this print request if necessary. |
| 760 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { | 763 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { |
| 761 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 764 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
| 762 return; | 765 return; |
| 763 } | 766 } |
| 767 #endif // !defined(OS_ANDROID) | |
| 764 | 768 |
| 765 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 769 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
| 766 return; | 770 return; |
| 767 IncrementScriptedPrintCount(); | 771 IncrementScriptedPrintCount(); |
| 768 | 772 |
| 769 if (is_preview_enabled_) { | 773 if (is_preview_enabled_) { |
| 770 print_preview_context_.InitWithFrame(frame); | 774 print_preview_context_.InitWithFrame(frame); |
| 771 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 775 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 772 } else { | 776 } else { |
| 773 Print(frame, blink::WebNode()); | 777 Print(frame, blink::WebNode()); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 DidFinishPrinting(FAIL_PRINT_INIT); | 1195 DidFinishPrinting(FAIL_PRINT_INIT); |
| 1192 return; // Failed to init print page settings. | 1196 return; // Failed to init print page settings. |
| 1193 } | 1197 } |
| 1194 | 1198 |
| 1195 // Some full screen plugins can say they don't want to print. | 1199 // Some full screen plugins can say they don't want to print. |
| 1196 if (!expected_page_count) { | 1200 if (!expected_page_count) { |
| 1197 DidFinishPrinting(FAIL_PRINT); | 1201 DidFinishPrinting(FAIL_PRINT); |
| 1198 return; | 1202 return; |
| 1199 } | 1203 } |
| 1200 | 1204 |
| 1205 #if !defined(OS_ANDROID) | |
| 1206 // TODO(sgurun) android_webview hack | |
| 1201 // Ask the browser to show UI to retrieve the final print settings. | 1207 // Ask the browser to show UI to retrieve the final print settings. |
| 1202 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1208 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
| 1203 expected_page_count)) { | 1209 expected_page_count)) { |
| 1204 DidFinishPrinting(OK); // Release resources and fail silently. | 1210 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1205 return; | 1211 return; |
| 1206 } | 1212 } |
| 1213 #endif // !defined(OS_ANDROID) | |
| 1207 | 1214 |
| 1208 // Render Pages for printing. | 1215 // Render Pages for printing. |
| 1209 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1216 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1210 LOG(ERROR) << "RenderPagesForPrint failed"; | 1217 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1211 DidFinishPrinting(FAIL_PRINT); | 1218 DidFinishPrinting(FAIL_PRINT); |
| 1212 } | 1219 } |
| 1213 ResetScriptedPrintCount(); | 1220 ResetScriptedPrintCount(); |
| 1214 } | 1221 } |
| 1215 | 1222 |
| 1216 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1223 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1235 print_pages_params_->params.document_cookie : 0; | 1242 print_pages_params_->params.document_cookie : 0; |
| 1236 if (notify_browser_of_print_failure_) { | 1243 if (notify_browser_of_print_failure_) { |
| 1237 LOG(ERROR) << "CreatePreviewDocument failed"; | 1244 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 1238 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1245 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 1239 } else { | 1246 } else { |
| 1240 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1247 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 1241 } | 1248 } |
| 1242 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1249 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 1243 break; | 1250 break; |
| 1244 } | 1251 } |
| 1252 | |
| 1245 prep_frame_view_.reset(); | 1253 prep_frame_view_.reset(); |
| 1246 print_pages_params_.reset(); | 1254 print_pages_params_.reset(); |
| 1247 notify_browser_of_print_failure_ = true; | 1255 notify_browser_of_print_failure_ = true; |
| 1248 } | 1256 } |
| 1249 | 1257 |
| 1250 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1258 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
| 1251 PrintPages(); | 1259 PrintPages(); |
| 1252 FinishFramePrinting(); | 1260 FinishFramePrinting(); |
| 1253 } | 1261 } |
| 1254 | 1262 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1373 return result; | 1381 return result; |
| 1374 } | 1382 } |
| 1375 | 1383 |
| 1376 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, | 1384 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, |
| 1377 const blink::WebNode& node, | 1385 const blink::WebNode& node, |
| 1378 int* number_of_pages) { | 1386 int* number_of_pages) { |
| 1379 DCHECK(frame); | 1387 DCHECK(frame); |
| 1380 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | 1388 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); |
| 1381 if (!InitPrintSettings(fit_to_paper_size)) { | 1389 if (!InitPrintSettings(fit_to_paper_size)) { |
| 1382 notify_browser_of_print_failure_ = false; | 1390 notify_browser_of_print_failure_ = false; |
| 1391 #if !defined(OS_ANDROID) | |
| 1392 // TODO(sgurun) android_webview hack | |
| 1383 render_view()->RunModalAlertDialog( | 1393 render_view()->RunModalAlertDialog( |
| 1384 frame, | 1394 frame, |
| 1385 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1395 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1396 #endif // !defined(OS_ANDROID) | |
| 1386 return false; | 1397 return false; |
| 1387 } | 1398 } |
| 1388 | 1399 |
| 1389 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1400 const PrintMsg_Print_Params& params = print_pages_params_->params; |
| 1390 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1401 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
| 1391 prepare.StartPrinting(); | 1402 prepare.StartPrinting(); |
| 1392 | 1403 |
| 1393 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1404 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1394 params.document_cookie)); | 1405 params.document_cookie)); |
| 1395 *number_of_pages = prepare.GetExpectedPageCount(); | 1406 *number_of_pages = prepare.GetExpectedPageCount(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1431 print_pages_params_->params.document_cookie : 0; | 1442 print_pages_params_->params.document_cookie : 0; |
| 1432 PrintMsg_PrintPages_Params settings; | 1443 PrintMsg_PrintPages_Params settings; |
| 1433 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, | 1444 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
| 1434 &settings)); | 1445 &settings)); |
| 1435 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1446 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1436 | 1447 |
| 1437 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1448 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
| 1438 if (!print_for_preview_) { | 1449 if (!print_for_preview_) { |
| 1439 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1450 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
| 1440 } else { | 1451 } else { |
| 1452 #if !defined(OS_ANDROID) | |
| 1453 // TODO(sgurun) android_webview hack | |
| 1441 // PrintForPrintPreview | 1454 // PrintForPrintPreview |
| 1442 blink::WebFrame* print_frame = NULL; | 1455 blink::WebFrame* print_frame = NULL; |
| 1443 // This may not be the right frame, but the alert will be modal, | 1456 // This may not be the right frame, but the alert will be modal, |
| 1444 // therefore it works well enough. | 1457 // therefore it works well enough. |
| 1445 GetPrintFrame(&print_frame); | 1458 GetPrintFrame(&print_frame); |
| 1446 if (print_frame) { | 1459 if (print_frame) { |
| 1447 render_view()->RunModalAlertDialog( | 1460 render_view()->RunModalAlertDialog( |
| 1448 print_frame, | 1461 print_frame, |
| 1449 l10n_util::GetStringUTF16( | 1462 l10n_util::GetStringUTF16( |
| 1450 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1463 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1451 } | 1464 } |
| 1465 #endif // !defined(OS_ANDROID) | |
| 1452 } | 1466 } |
| 1453 return false; | 1467 return false; |
| 1454 } | 1468 } |
| 1455 | 1469 |
| 1456 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { | 1470 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { |
| 1457 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); | 1471 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); |
| 1458 return false; | 1472 return false; |
| 1459 } | 1473 } |
| 1460 | 1474 |
| 1461 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { | 1475 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 void PrintWebViewHelper::ResetScriptedPrintCount() { | 1625 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 1612 // Reset cancel counter on successful print. | 1626 // Reset cancel counter on successful print. |
| 1613 user_cancelled_scripted_print_count_ = 0; | 1627 user_cancelled_scripted_print_count_ = 0; |
| 1614 } | 1628 } |
| 1615 | 1629 |
| 1616 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1630 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 1617 ++user_cancelled_scripted_print_count_; | 1631 ++user_cancelled_scripted_print_count_; |
| 1618 last_cancelled_script_print_ = base::Time::Now(); | 1632 last_cancelled_script_print_ = base::Time::Now(); |
| 1619 } | 1633 } |
| 1620 | 1634 |
| 1621 | |
| 1622 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1635 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
| 1623 if (is_scripted_preview_delayed_) { | 1636 if (is_scripted_preview_delayed_) { |
| 1624 is_scripted_preview_delayed_ = false; | 1637 is_scripted_preview_delayed_ = false; |
| 1625 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), | 1638 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), |
| 1626 print_preview_context_.IsModifiable())); | 1639 print_preview_context_.IsModifiable())); |
| 1627 } | 1640 } |
| 1628 } | 1641 } |
| 1629 | 1642 |
| 1630 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1643 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1631 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1644 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1632 const bool has_selection = print_preview_context_.HasSelection(); | 1645 const bool has_selection = print_preview_context_.HasSelection(); |
| 1633 PrintHostMsg_RequestPrintPreview_Params params; | 1646 PrintHostMsg_RequestPrintPreview_Params params; |
| 1634 params.is_modifiable = is_modifiable; | 1647 params.is_modifiable = is_modifiable; |
| 1635 params.has_selection = has_selection; | 1648 params.has_selection = has_selection; |
| 1636 switch (type) { | 1649 switch (type) { |
| 1637 case PRINT_PREVIEW_SCRIPTED: { | 1650 case PRINT_PREVIEW_SCRIPTED: { |
| 1638 // Shows scripted print preview in two stages. | 1651 // Shows scripted print preview in two stages. |
|
joth
2013/11/21 19:38:03
nit indent
sgurun-gerrit only
2013/11/23 01:49:11
Done.
| |
| 1639 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1652 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| 1640 // pumping messages here. | 1653 // pumping messages here. |
| 1641 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1654 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1642 // document has been loaded. | 1655 // document has been loaded. |
| 1643 is_scripted_preview_delayed_ = true; | 1656 is_scripted_preview_delayed_ = true; |
| 1644 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1657 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1645 // Wait for DidStopLoading. Plugins may not know the correct | 1658 // Wait for DidStopLoading. Plugins may not know the correct |
| 1646 // |is_modifiable| value until they are fully loaded, which occurs when | 1659 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1647 // DidStopLoading() is called. Defer showing the preview until then. | 1660 // DidStopLoading() is called. Defer showing the preview until then. |
| 1648 } else { | 1661 } else { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1674 NOTREACHED(); | 1687 NOTREACHED(); |
| 1675 return; | 1688 return; |
| 1676 } | 1689 } |
| 1677 } | 1690 } |
| 1678 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); | 1691 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
| 1679 } | 1692 } |
| 1680 | 1693 |
| 1681 bool PrintWebViewHelper::CheckForCancel() { | 1694 bool PrintWebViewHelper::CheckForCancel() { |
| 1682 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1695 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1683 bool cancel = false; | 1696 bool cancel = false; |
| 1697 | |
|
joth
2013/11/21 19:38:03
nit - \n
sgurun-gerrit only
2013/11/23 01:49:11
Done.
| |
| 1684 Send(new PrintHostMsg_CheckForCancel(routing_id(), | 1698 Send(new PrintHostMsg_CheckForCancel(routing_id(), |
| 1685 print_params.preview_ui_id, | 1699 print_params.preview_ui_id, |
| 1686 print_params.preview_request_id, | 1700 print_params.preview_request_id, |
| 1687 &cancel)); | 1701 &cancel)); |
| 1688 if (cancel) | 1702 if (cancel) |
| 1689 notify_browser_of_print_failure_ = false; | 1703 notify_browser_of_print_failure_ = false; |
| 1690 return cancel; | 1704 return cancel; |
| 1691 } | 1705 } |
| 1692 | 1706 |
| 1693 bool PrintWebViewHelper::PreviewPageRendered(int page_number, | 1707 bool PrintWebViewHelper::PreviewPageRendered(int page_number, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1964 } | 1978 } |
| 1965 | 1979 |
| 1966 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1980 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1967 prep_frame_view_.reset(); | 1981 prep_frame_view_.reset(); |
| 1968 metafile_.reset(); | 1982 metafile_.reset(); |
| 1969 pages_to_render_.clear(); | 1983 pages_to_render_.clear(); |
| 1970 error_ = PREVIEW_ERROR_NONE; | 1984 error_ = PREVIEW_ERROR_NONE; |
| 1971 } | 1985 } |
| 1972 | 1986 |
| 1973 } // namespace printing | 1987 } // namespace printing |
| OLD | NEW |