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 // TODO(sgurun) copied from chrome/renderer. Remove after crbug.com/322276 |
| 6 |
| 7 #include "android_webview/renderer/print_web_view_helper.h" |
6 | 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
| 11 #include "android_webview/common/print_messages.h" |
9 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 13 #include "base/command_line.h" |
11 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 15 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
15 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
16 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 21 #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" | 22 #include "content/public/renderer/render_thread.h" |
24 #include "content/public/renderer/render_view.h" | 23 #include "content/public/renderer/render_view.h" |
25 #include "content/public/renderer/web_preferences.h" | 24 #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" | 25 #include "net/base/escape.h" |
29 #include "printing/metafile.h" | 26 #include "printing/metafile.h" |
30 #include "printing/metafile_impl.h" | 27 #include "printing/metafile_impl.h" |
31 #include "printing/units.h" | 28 #include "printing/units.h" |
32 #include "skia/ext/vector_platform_device_skia.h" | 29 #include "skia/ext/vector_platform_device_skia.h" |
33 #include "third_party/WebKit/public/platform/WebSize.h" | 30 #include "third_party/WebKit/public/platform/WebSize.h" |
34 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
35 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 32 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
36 #include "third_party/WebKit/public/web/WebDocument.h" | 33 #include "third_party/WebKit/public/web/WebDocument.h" |
37 #include "third_party/WebKit/public/web/WebElement.h" | 34 #include "third_party/WebKit/public/web/WebElement.h" |
38 #include "third_party/WebKit/public/web/WebFrame.h" | 35 #include "third_party/WebKit/public/web/WebFrame.h" |
39 #include "third_party/WebKit/public/web/WebFrameClient.h" | 36 #include "third_party/WebKit/public/web/WebFrameClient.h" |
40 #include "third_party/WebKit/public/web/WebPlugin.h" | 37 #include "third_party/WebKit/public/web/WebPlugin.h" |
41 #include "third_party/WebKit/public/web/WebPluginDocument.h" | 38 #include "third_party/WebKit/public/web/WebPluginDocument.h" |
42 #include "third_party/WebKit/public/web/WebPrintParams.h" | 39 #include "third_party/WebKit/public/web/WebPrintParams.h" |
43 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | 40 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" |
44 #include "third_party/WebKit/public/web/WebScriptSource.h" | 41 #include "third_party/WebKit/public/web/WebScriptSource.h" |
45 #include "third_party/WebKit/public/web/WebSettings.h" | 42 #include "third_party/WebKit/public/web/WebSettings.h" |
46 #include "third_party/WebKit/public/web/WebView.h" | 43 #include "third_party/WebKit/public/web/WebView.h" |
47 #include "third_party/WebKit/public/web/WebViewClient.h" | 44 #include "third_party/WebKit/public/web/WebViewClient.h" |
48 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
49 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
50 #include "webkit/common/webpreferences.h" | 47 #include "webkit/common/webpreferences.h" |
51 | 48 |
| 49 // This code is copied from chrome/renderer/printing. Code is slightly |
| 50 // modified to run it with webview, and the modifications are marked |
| 51 // using OS_ANDROID. |
| 52 // TODO(sgurun): remove the code as part of componentization of printing. |
| 53 |
52 namespace printing { | 54 namespace printing { |
53 | 55 |
54 namespace { | 56 namespace { |
55 | 57 |
56 enum PrintPreviewHelperEvents { | 58 enum PrintPreviewHelperEvents { |
57 PREVIEW_EVENT_REQUESTED, | 59 PREVIEW_EVENT_REQUESTED, |
58 PREVIEW_EVENT_CACHE_HIT, // Unused | 60 PREVIEW_EVENT_CACHE_HIT, // Unused |
59 PREVIEW_EVENT_CREATE_DOCUMENT, | 61 PREVIEW_EVENT_CREATE_DOCUMENT, |
60 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 62 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
61 PREVIEW_EVENT_MAX, | 63 PREVIEW_EVENT_MAX, |
62 }; | 64 }; |
63 | 65 |
64 const double kMinDpi = 1.0; | 66 const double kMinDpi = 1.0; |
65 | 67 |
| 68 #if 0 |
| 69 // TODO(sgurun) android_webview hack |
66 const char kPageLoadScriptFormat[] = | 70 const char kPageLoadScriptFormat[] = |
67 "document.open(); document.write(%s); document.close();"; | 71 "document.open(); document.write(%s); document.close();"; |
68 | 72 |
69 const char kPageSetupScriptFormat[] = "setup(%s);"; | 73 const char kPageSetupScriptFormat[] = "setup(%s);"; |
70 | 74 |
71 void ExecuteScript(blink::WebFrame* frame, | 75 void ExecuteScript(blink::WebFrame* frame, |
72 const char* script_format, | 76 const char* script_format, |
73 const base::Value& parameters) { | 77 const base::Value& parameters) { |
74 std::string json; | 78 std::string json; |
75 base::JSONWriter::Write(¶meters, &json); | 79 base::JSONWriter::Write(¶meters, &json); |
76 std::string script = base::StringPrintf(script_format, json.c_str()); | 80 std::string script = base::StringPrintf(script_format, json.c_str()); |
77 frame->executeScript(blink::WebString(UTF8ToUTF16(script))); | 81 frame->executeScript(blink::WebString(UTF8ToUTF16(script))); |
78 } | 82 } |
| 83 #endif |
79 | 84 |
80 int GetDPI(const PrintMsg_Print_Params* print_params) { | 85 int GetDPI(const PrintMsg_Print_Params* print_params) { |
81 #if defined(OS_MACOSX) | 86 #if defined(OS_MACOSX) |
82 // On the Mac, the printable area is in points, don't do any scaling based | 87 // On the Mac, the printable area is in points, don't do any scaling based |
83 // on dpi. | 88 // on dpi. |
84 return kPointsPerInch; | 89 return kPointsPerInch; |
85 #else | 90 #else |
86 return static_cast<int>(print_params->dpi); | 91 return static_cast<int>(print_params->dpi); |
87 #endif // defined(OS_MACOSX) | 92 #endif // defined(OS_MACOSX) |
88 } | 93 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 363 |
359 if (fit_to_page) { | 364 if (fit_to_page) { |
360 double factor = FitPrintParamsToPage(params, &result_params); | 365 double factor = FitPrintParamsToPage(params, &result_params); |
361 if (scale_factor) | 366 if (scale_factor) |
362 *scale_factor = factor; | 367 *scale_factor = factor; |
363 } | 368 } |
364 return result_params; | 369 return result_params; |
365 } | 370 } |
366 | 371 |
367 bool IsPrintPreviewEnabled() { | 372 bool IsPrintPreviewEnabled() { |
368 return CommandLine::ForCurrentProcess()->HasSwitch( | 373 return false; |
369 switches::kRendererPrintPreview); | |
370 } | 374 } |
371 | 375 |
372 bool IsPrintThrottlingDisabled() { | 376 bool IsPrintThrottlingDisabled() { |
373 return CommandLine::ForCurrentProcess()->HasSwitch( | 377 return true; |
374 switches::kDisableScriptedPrintThrottling); | |
375 } | 378 } |
376 | 379 |
377 } // namespace | 380 } // namespace |
378 | 381 |
379 FrameReference::FrameReference(const blink::WebFrame* frame) { | 382 FrameReference::FrameReference(const blink::WebFrame* frame) { |
380 Reset(frame); | 383 Reset(frame); |
381 } | 384 } |
382 | 385 |
383 FrameReference::FrameReference() { | 386 FrameReference::FrameReference() { |
384 Reset(NULL); | 387 Reset(NULL); |
(...skipping 22 matching lines...) Expand all Loading... |
407 | 410 |
408 // static - Not anonymous so that platform implementations can use it. | 411 // static - Not anonymous so that platform implementations can use it. |
409 void PrintWebViewHelper::PrintHeaderAndFooter( | 412 void PrintWebViewHelper::PrintHeaderAndFooter( |
410 blink::WebCanvas* canvas, | 413 blink::WebCanvas* canvas, |
411 int page_number, | 414 int page_number, |
412 int total_pages, | 415 int total_pages, |
413 float webkit_scale_factor, | 416 float webkit_scale_factor, |
414 const PageSizeMargins& page_layout, | 417 const PageSizeMargins& page_layout, |
415 const base::DictionaryValue& header_footer_info, | 418 const base::DictionaryValue& header_footer_info, |
416 const PrintMsg_Print_Params& params) { | 419 const PrintMsg_Print_Params& params) { |
| 420 #if 0 |
| 421 // TODO(sgurun) android_webview hack |
417 skia::VectorPlatformDeviceSkia* device = | 422 skia::VectorPlatformDeviceSkia* device = |
418 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | 423 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); |
419 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | 424 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); |
420 | 425 |
421 SkAutoCanvasRestore auto_restore(canvas, true); | 426 SkAutoCanvasRestore auto_restore(canvas, true); |
422 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 427 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
423 | 428 |
424 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 429 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
425 page_layout.content_width, | 430 page_layout.content_width, |
426 page_layout.margin_top + page_layout.margin_bottom + | 431 page_layout.margin_top + page_layout.margin_bottom + |
(...skipping 17 matching lines...) Expand all Loading... |
444 options->SetDouble("topMargin", page_layout.margin_top); | 449 options->SetDouble("topMargin", page_layout.margin_top); |
445 options->SetDouble("bottomMargin", page_layout.margin_bottom); | 450 options->SetDouble("bottomMargin", page_layout.margin_bottom); |
446 options->SetString("pageNumber", | 451 options->SetString("pageNumber", |
447 base::StringPrintf("%d/%d", page_number, total_pages)); | 452 base::StringPrintf("%d/%d", page_number, total_pages)); |
448 | 453 |
449 ExecuteScript(frame, kPageSetupScriptFormat, *options); | 454 ExecuteScript(frame, kPageSetupScriptFormat, *options); |
450 | 455 |
451 blink::WebPrintParams webkit_params(page_size); | 456 blink::WebPrintParams webkit_params(page_size); |
452 webkit_params.printerDPI = GetDPI(¶ms); | 457 webkit_params.printerDPI = GetDPI(¶ms); |
453 | 458 |
454 frame->printBegin(webkit_params); | 459 frame->printBegin(webkit_params, WebKit::WebNode(), NULL); |
455 frame->printPage(0, canvas); | 460 frame->printPage(0, canvas); |
456 frame->printEnd(); | 461 frame->printEnd(); |
457 | 462 |
458 web_view->close(); | 463 web_view->close(); |
459 | 464 |
460 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 465 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
| 466 #endif |
461 } | 467 } |
462 | 468 |
463 // static - Not anonymous so that platform implementations can use it. | 469 // static - Not anonymous so that platform implementations can use it. |
464 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 470 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
465 int page_number, | 471 int page_number, |
466 const gfx::Rect& canvas_area, | 472 const gfx::Rect& canvas_area, |
467 const gfx::Rect& content_area, | 473 const gfx::Rect& content_area, |
468 double scale_factor, | 474 double scale_factor, |
469 blink::WebCanvas* canvas) { | 475 blink::WebCanvas* canvas) { |
470 SkAutoCanvasRestore auto_restore(canvas, true); | 476 SkAutoCanvasRestore auto_restore(canvas, true); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 is_print_ready_metafile_sent_(false), | 719 is_print_ready_metafile_sent_(false), |
714 ignore_css_margins_(false), | 720 ignore_css_margins_(false), |
715 user_cancelled_scripted_print_count_(0), | 721 user_cancelled_scripted_print_count_(0), |
716 is_scripted_printing_blocked_(false), | 722 is_scripted_printing_blocked_(false), |
717 notify_browser_of_print_failure_(true), | 723 notify_browser_of_print_failure_(true), |
718 print_for_preview_(false), | 724 print_for_preview_(false), |
719 print_node_in_progress_(false), | 725 print_node_in_progress_(false), |
720 is_loading_(false), | 726 is_loading_(false), |
721 is_scripted_preview_delayed_(false), | 727 is_scripted_preview_delayed_(false), |
722 weak_ptr_factory_(this) { | 728 weak_ptr_factory_(this) { |
| 729 // TODO(sgurun) enable window.print() for webview crbug.com/322303 |
| 730 SetScriptedPrintBlocked(true); |
723 } | 731 } |
724 | 732 |
725 PrintWebViewHelper::~PrintWebViewHelper() {} | 733 PrintWebViewHelper::~PrintWebViewHelper() {} |
726 | 734 |
727 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 735 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
728 blink::WebFrame* frame, bool user_initiated) { | 736 blink::WebFrame* frame, bool user_initiated) { |
729 #if defined(OS_ANDROID) | 737 #if defined(OS_ANDROID) |
730 return false; | 738 return false; |
731 #endif // defined(OS_ANDROID) | 739 #endif // defined(OS_ANDROID) |
732 if (is_scripted_printing_blocked_) | 740 if (is_scripted_printing_blocked_) |
(...skipping 16 matching lines...) Expand all Loading... |
749 void PrintWebViewHelper::DidStopLoading() { | 757 void PrintWebViewHelper::DidStopLoading() { |
750 is_loading_ = false; | 758 is_loading_ = false; |
751 ShowScriptedPrintPreview(); | 759 ShowScriptedPrintPreview(); |
752 } | 760 } |
753 | 761 |
754 // Prints |frame| which called window.print(). | 762 // Prints |frame| which called window.print(). |
755 void PrintWebViewHelper::PrintPage(blink::WebFrame* frame, | 763 void PrintWebViewHelper::PrintPage(blink::WebFrame* frame, |
756 bool user_initiated) { | 764 bool user_initiated) { |
757 DCHECK(frame); | 765 DCHECK(frame); |
758 | 766 |
| 767 #if !defined(OS_ANDROID) |
| 768 // TODO(sgurun) android_webview hack |
759 // Allow Prerendering to cancel this print request if necessary. | 769 // Allow Prerendering to cancel this print request if necessary. |
760 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { | 770 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { |
761 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 771 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
762 return; | 772 return; |
763 } | 773 } |
| 774 #endif // !defined(OS_ANDROID) |
764 | 775 |
765 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 776 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
766 return; | 777 return; |
767 IncrementScriptedPrintCount(); | 778 IncrementScriptedPrintCount(); |
768 | 779 |
769 if (is_preview_enabled_) { | 780 if (is_preview_enabled_) { |
770 print_preview_context_.InitWithFrame(frame); | 781 print_preview_context_.InitWithFrame(frame); |
771 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 782 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
772 } else { | 783 } else { |
773 Print(frame, blink::WebNode()); | 784 Print(frame, blink::WebNode()); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 bool PrintWebViewHelper::FinalizePrintReadyDocument() { | 1099 bool PrintWebViewHelper::FinalizePrintReadyDocument() { |
1089 DCHECK(!is_print_ready_metafile_sent_); | 1100 DCHECK(!is_print_ready_metafile_sent_); |
1090 print_preview_context_.FinalizePrintReadyDocument(); | 1101 print_preview_context_.FinalizePrintReadyDocument(); |
1091 | 1102 |
1092 // Get the size of the resulting metafile. | 1103 // Get the size of the resulting metafile. |
1093 PreviewMetafile* metafile = print_preview_context_.metafile(); | 1104 PreviewMetafile* metafile = print_preview_context_.metafile(); |
1094 uint32 buf_size = metafile->GetDataSize(); | 1105 uint32 buf_size = metafile->GetDataSize(); |
1095 DCHECK_GT(buf_size, 0u); | 1106 DCHECK_GT(buf_size, 0u); |
1096 | 1107 |
1097 PrintHostMsg_DidPreviewDocument_Params preview_params; | 1108 PrintHostMsg_DidPreviewDocument_Params preview_params; |
| 1109 preview_params.reuse_existing_data = false; |
1098 preview_params.data_size = buf_size; | 1110 preview_params.data_size = buf_size; |
1099 preview_params.document_cookie = print_pages_params_->params.document_cookie; | 1111 preview_params.document_cookie = print_pages_params_->params.document_cookie; |
1100 preview_params.expected_pages_count = | 1112 preview_params.expected_pages_count = |
1101 print_preview_context_.total_page_count(); | 1113 print_preview_context_.total_page_count(); |
1102 preview_params.modifiable = print_preview_context_.IsModifiable(); | 1114 preview_params.modifiable = print_preview_context_.IsModifiable(); |
1103 preview_params.preview_request_id = | 1115 preview_params.preview_request_id = |
1104 print_pages_params_->params.preview_request_id; | 1116 print_pages_params_->params.preview_request_id; |
1105 | 1117 |
1106 // Ask the browser to create the shared memory for us. | 1118 // Ask the browser to create the shared memory for us. |
1107 if (!CopyMetafileDataToSharedMem(metafile, | 1119 if (!CopyMetafileDataToSharedMem(metafile, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 DidFinishPrinting(FAIL_PRINT_INIT); | 1202 DidFinishPrinting(FAIL_PRINT_INIT); |
1191 return; // Failed to init print page settings. | 1203 return; // Failed to init print page settings. |
1192 } | 1204 } |
1193 | 1205 |
1194 // Some full screen plugins can say they don't want to print. | 1206 // Some full screen plugins can say they don't want to print. |
1195 if (!expected_page_count) { | 1207 if (!expected_page_count) { |
1196 DidFinishPrinting(FAIL_PRINT); | 1208 DidFinishPrinting(FAIL_PRINT); |
1197 return; | 1209 return; |
1198 } | 1210 } |
1199 | 1211 |
| 1212 #if !defined(OS_ANDROID) |
| 1213 // TODO(sgurun) android_webview hack |
1200 // Ask the browser to show UI to retrieve the final print settings. | 1214 // Ask the browser to show UI to retrieve the final print settings. |
1201 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1215 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
1202 expected_page_count)) { | 1216 expected_page_count)) { |
1203 DidFinishPrinting(OK); // Release resources and fail silently. | 1217 DidFinishPrinting(OK); // Release resources and fail silently. |
1204 return; | 1218 return; |
1205 } | 1219 } |
| 1220 #endif // !defined(OS_ANDROID) |
1206 | 1221 |
1207 // Render Pages for printing. | 1222 // Render Pages for printing. |
1208 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1223 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1209 LOG(ERROR) << "RenderPagesForPrint failed"; | 1224 LOG(ERROR) << "RenderPagesForPrint failed"; |
1210 DidFinishPrinting(FAIL_PRINT); | 1225 DidFinishPrinting(FAIL_PRINT); |
1211 } | 1226 } |
1212 ResetScriptedPrintCount(); | 1227 ResetScriptedPrintCount(); |
1213 } | 1228 } |
1214 | 1229 |
1215 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1230 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
(...skipping 18 matching lines...) Expand all Loading... |
1234 print_pages_params_->params.document_cookie : 0; | 1249 print_pages_params_->params.document_cookie : 0; |
1235 if (notify_browser_of_print_failure_) { | 1250 if (notify_browser_of_print_failure_) { |
1236 LOG(ERROR) << "CreatePreviewDocument failed"; | 1251 LOG(ERROR) << "CreatePreviewDocument failed"; |
1237 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1252 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
1238 } else { | 1253 } else { |
1239 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1254 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
1240 } | 1255 } |
1241 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1256 print_preview_context_.Failed(notify_browser_of_print_failure_); |
1242 break; | 1257 break; |
1243 } | 1258 } |
| 1259 |
1244 prep_frame_view_.reset(); | 1260 prep_frame_view_.reset(); |
1245 print_pages_params_.reset(); | 1261 print_pages_params_.reset(); |
1246 notify_browser_of_print_failure_ = true; | 1262 notify_browser_of_print_failure_ = true; |
1247 } | 1263 } |
1248 | 1264 |
1249 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1265 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
1250 PrintPages(); | 1266 PrintPages(); |
1251 FinishFramePrinting(); | 1267 FinishFramePrinting(); |
1252 } | 1268 } |
1253 | 1269 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 return result; | 1388 return result; |
1373 } | 1389 } |
1374 | 1390 |
1375 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, | 1391 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, |
1376 const blink::WebNode& node, | 1392 const blink::WebNode& node, |
1377 int* number_of_pages) { | 1393 int* number_of_pages) { |
1378 DCHECK(frame); | 1394 DCHECK(frame); |
1379 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | 1395 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); |
1380 if (!InitPrintSettings(fit_to_paper_size)) { | 1396 if (!InitPrintSettings(fit_to_paper_size)) { |
1381 notify_browser_of_print_failure_ = false; | 1397 notify_browser_of_print_failure_ = false; |
| 1398 #if !defined(OS_ANDROID) |
| 1399 // TODO(sgurun) android_webview hack |
1382 render_view()->RunModalAlertDialog( | 1400 render_view()->RunModalAlertDialog( |
1383 frame, | 1401 frame, |
1384 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1402 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1403 #endif // !defined(OS_ANDROID) |
1385 return false; | 1404 return false; |
1386 } | 1405 } |
1387 | 1406 |
1388 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1407 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1389 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1408 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1390 prepare.StartPrinting(); | 1409 prepare.StartPrinting(); |
1391 | 1410 |
1392 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1411 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
1393 params.document_cookie)); | 1412 params.document_cookie)); |
1394 *number_of_pages = prepare.GetExpectedPageCount(); | 1413 *number_of_pages = prepare.GetExpectedPageCount(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 print_pages_params_->params.document_cookie : 0; | 1449 print_pages_params_->params.document_cookie : 0; |
1431 PrintMsg_PrintPages_Params settings; | 1450 PrintMsg_PrintPages_Params settings; |
1432 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, | 1451 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
1433 &settings)); | 1452 &settings)); |
1434 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1453 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
1435 | 1454 |
1436 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1455 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
1437 if (!print_for_preview_) { | 1456 if (!print_for_preview_) { |
1438 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1457 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
1439 } else { | 1458 } else { |
| 1459 #if !defined(OS_ANDROID) |
| 1460 // TODO(sgurun) android_webview hack |
1440 // PrintForPrintPreview | 1461 // PrintForPrintPreview |
1441 blink::WebFrame* print_frame = NULL; | 1462 blink::WebFrame* print_frame = NULL; |
1442 // This may not be the right frame, but the alert will be modal, | 1463 // This may not be the right frame, but the alert will be modal, |
1443 // therefore it works well enough. | 1464 // therefore it works well enough. |
1444 GetPrintFrame(&print_frame); | 1465 GetPrintFrame(&print_frame); |
1445 if (print_frame) { | 1466 if (print_frame) { |
1446 render_view()->RunModalAlertDialog( | 1467 render_view()->RunModalAlertDialog( |
1447 print_frame, | 1468 print_frame, |
1448 l10n_util::GetStringUTF16( | 1469 l10n_util::GetStringUTF16( |
1449 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1470 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
1450 } | 1471 } |
| 1472 #endif // !defined(OS_ANDROID) |
1451 } | 1473 } |
1452 return false; | 1474 return false; |
1453 } | 1475 } |
1454 | 1476 |
1455 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { | 1477 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { |
1456 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); | 1478 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); |
1457 return false; | 1479 return false; |
1458 } | 1480 } |
1459 | 1481 |
1460 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { | 1482 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 void PrintWebViewHelper::ResetScriptedPrintCount() { | 1632 void PrintWebViewHelper::ResetScriptedPrintCount() { |
1611 // Reset cancel counter on successful print. | 1633 // Reset cancel counter on successful print. |
1612 user_cancelled_scripted_print_count_ = 0; | 1634 user_cancelled_scripted_print_count_ = 0; |
1613 } | 1635 } |
1614 | 1636 |
1615 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1637 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
1616 ++user_cancelled_scripted_print_count_; | 1638 ++user_cancelled_scripted_print_count_; |
1617 last_cancelled_script_print_ = base::Time::Now(); | 1639 last_cancelled_script_print_ = base::Time::Now(); |
1618 } | 1640 } |
1619 | 1641 |
1620 | |
1621 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1642 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
1622 if (is_scripted_preview_delayed_) { | 1643 if (is_scripted_preview_delayed_) { |
1623 is_scripted_preview_delayed_ = false; | 1644 is_scripted_preview_delayed_ = false; |
1624 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), | 1645 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), |
1625 print_preview_context_.IsModifiable())); | 1646 print_preview_context_.IsModifiable())); |
1626 } | 1647 } |
1627 } | 1648 } |
1628 | 1649 |
1629 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1650 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
1630 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1651 const bool is_modifiable = print_preview_context_.IsModifiable(); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 } | 1984 } |
1964 | 1985 |
1965 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1986 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1966 prep_frame_view_.reset(); | 1987 prep_frame_view_.reset(); |
1967 metafile_.reset(); | 1988 metafile_.reset(); |
1968 pages_to_render_.clear(); | 1989 pages_to_render_.clear(); |
1969 error_ = PREVIEW_ERROR_NONE; | 1990 error_ = PREVIEW_ERROR_NONE; |
1970 } | 1991 } |
1971 | 1992 |
1972 } // namespace printing | 1993 } // namespace printing |
OLD | NEW |