| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 DidFinishPrinting(FAIL_PRINT_INIT); | 1202 DidFinishPrinting(FAIL_PRINT_INIT); |
| 1192 return; // Failed to init print page settings. | 1203 return; // Failed to init print page settings. |
| 1193 } | 1204 } |
| 1194 | 1205 |
| 1195 // 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. |
| 1196 if (!expected_page_count) { | 1207 if (!expected_page_count) { |
| 1197 DidFinishPrinting(FAIL_PRINT); | 1208 DidFinishPrinting(FAIL_PRINT); |
| 1198 return; | 1209 return; |
| 1199 } | 1210 } |
| 1200 | 1211 |
| 1212 #if !defined(OS_ANDROID) |
| 1213 // TODO(sgurun) android_webview hack |
| 1201 // 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. |
| 1202 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1215 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
| 1203 expected_page_count)) { | 1216 expected_page_count)) { |
| 1204 DidFinishPrinting(OK); // Release resources and fail silently. | 1217 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1205 return; | 1218 return; |
| 1206 } | 1219 } |
| 1220 #endif // !defined(OS_ANDROID) |
| 1207 | 1221 |
| 1208 // Render Pages for printing. | 1222 // Render Pages for printing. |
| 1209 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1223 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1210 LOG(ERROR) << "RenderPagesForPrint failed"; | 1224 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1211 DidFinishPrinting(FAIL_PRINT); | 1225 DidFinishPrinting(FAIL_PRINT); |
| 1212 } | 1226 } |
| 1213 ResetScriptedPrintCount(); | 1227 ResetScriptedPrintCount(); |
| 1214 } | 1228 } |
| 1215 | 1229 |
| 1216 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1230 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1235 print_pages_params_->params.document_cookie : 0; | 1249 print_pages_params_->params.document_cookie : 0; |
| 1236 if (notify_browser_of_print_failure_) { | 1250 if (notify_browser_of_print_failure_) { |
| 1237 LOG(ERROR) << "CreatePreviewDocument failed"; | 1251 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 1238 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1252 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 1239 } else { | 1253 } else { |
| 1240 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1254 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 1241 } | 1255 } |
| 1242 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1256 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 1243 break; | 1257 break; |
| 1244 } | 1258 } |
| 1259 |
| 1245 prep_frame_view_.reset(); | 1260 prep_frame_view_.reset(); |
| 1246 print_pages_params_.reset(); | 1261 print_pages_params_.reset(); |
| 1247 notify_browser_of_print_failure_ = true; | 1262 notify_browser_of_print_failure_ = true; |
| 1248 } | 1263 } |
| 1249 | 1264 |
| 1250 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1265 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
| 1251 PrintPages(); | 1266 PrintPages(); |
| 1252 FinishFramePrinting(); | 1267 FinishFramePrinting(); |
| 1253 } | 1268 } |
| 1254 | 1269 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 return result; | 1388 return result; |
| 1374 } | 1389 } |
| 1375 | 1390 |
| 1376 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, | 1391 bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebFrame* frame, |
| 1377 const blink::WebNode& node, | 1392 const blink::WebNode& node, |
| 1378 int* number_of_pages) { | 1393 int* number_of_pages) { |
| 1379 DCHECK(frame); | 1394 DCHECK(frame); |
| 1380 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | 1395 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); |
| 1381 if (!InitPrintSettings(fit_to_paper_size)) { | 1396 if (!InitPrintSettings(fit_to_paper_size)) { |
| 1382 notify_browser_of_print_failure_ = false; | 1397 notify_browser_of_print_failure_ = false; |
| 1398 #if !defined(OS_ANDROID) |
| 1399 // TODO(sgurun) android_webview hack |
| 1383 render_view()->RunModalAlertDialog( | 1400 render_view()->RunModalAlertDialog( |
| 1384 frame, | 1401 frame, |
| 1385 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1402 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1403 #endif // !defined(OS_ANDROID) |
| 1386 return false; | 1404 return false; |
| 1387 } | 1405 } |
| 1388 | 1406 |
| 1389 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1407 const PrintMsg_Print_Params& params = print_pages_params_->params; |
| 1390 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1408 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
| 1391 prepare.StartPrinting(); | 1409 prepare.StartPrinting(); |
| 1392 | 1410 |
| 1393 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1411 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1394 params.document_cookie)); | 1412 params.document_cookie)); |
| 1395 *number_of_pages = prepare.GetExpectedPageCount(); | 1413 *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; | 1449 print_pages_params_->params.document_cookie : 0; |
| 1432 PrintMsg_PrintPages_Params settings; | 1450 PrintMsg_PrintPages_Params settings; |
| 1433 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, | 1451 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
| 1434 &settings)); | 1452 &settings)); |
| 1435 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1453 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1436 | 1454 |
| 1437 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1455 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
| 1438 if (!print_for_preview_) { | 1456 if (!print_for_preview_) { |
| 1439 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1457 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
| 1440 } else { | 1458 } else { |
| 1459 #if !defined(OS_ANDROID) |
| 1460 // TODO(sgurun) android_webview hack |
| 1441 // PrintForPrintPreview | 1461 // PrintForPrintPreview |
| 1442 blink::WebFrame* print_frame = NULL; | 1462 blink::WebFrame* print_frame = NULL; |
| 1443 // 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, |
| 1444 // therefore it works well enough. | 1464 // therefore it works well enough. |
| 1445 GetPrintFrame(&print_frame); | 1465 GetPrintFrame(&print_frame); |
| 1446 if (print_frame) { | 1466 if (print_frame) { |
| 1447 render_view()->RunModalAlertDialog( | 1467 render_view()->RunModalAlertDialog( |
| 1448 print_frame, | 1468 print_frame, |
| 1449 l10n_util::GetStringUTF16( | 1469 l10n_util::GetStringUTF16( |
| 1450 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1470 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1451 } | 1471 } |
| 1472 #endif // !defined(OS_ANDROID) |
| 1452 } | 1473 } |
| 1453 return false; | 1474 return false; |
| 1454 } | 1475 } |
| 1455 | 1476 |
| 1456 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { | 1477 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { |
| 1457 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); | 1478 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); |
| 1458 return false; | 1479 return false; |
| 1459 } | 1480 } |
| 1460 | 1481 |
| 1461 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... |
| 1611 void PrintWebViewHelper::ResetScriptedPrintCount() { | 1632 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 1612 // Reset cancel counter on successful print. | 1633 // Reset cancel counter on successful print. |
| 1613 user_cancelled_scripted_print_count_ = 0; | 1634 user_cancelled_scripted_print_count_ = 0; |
| 1614 } | 1635 } |
| 1615 | 1636 |
| 1616 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1637 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 1617 ++user_cancelled_scripted_print_count_; | 1638 ++user_cancelled_scripted_print_count_; |
| 1618 last_cancelled_script_print_ = base::Time::Now(); | 1639 last_cancelled_script_print_ = base::Time::Now(); |
| 1619 } | 1640 } |
| 1620 | 1641 |
| 1621 | |
| 1622 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1642 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
| 1623 if (is_scripted_preview_delayed_) { | 1643 if (is_scripted_preview_delayed_) { |
| 1624 is_scripted_preview_delayed_ = false; | 1644 is_scripted_preview_delayed_ = false; |
| 1625 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), | 1645 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), |
| 1626 print_preview_context_.IsModifiable())); | 1646 print_preview_context_.IsModifiable())); |
| 1627 } | 1647 } |
| 1628 } | 1648 } |
| 1629 | 1649 |
| 1630 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1650 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1631 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... |
| 1964 } | 1984 } |
| 1965 | 1985 |
| 1966 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1986 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1967 prep_frame_view_.reset(); | 1987 prep_frame_view_.reset(); |
| 1968 metafile_.reset(); | 1988 metafile_.reset(); |
| 1969 pages_to_render_.clear(); | 1989 pages_to_render_.clear(); |
| 1970 error_ = PREVIEW_ERROR_NONE; | 1990 error_ = PREVIEW_ERROR_NONE; |
| 1971 } | 1991 } |
| 1972 | 1992 |
| 1973 } // namespace printing | 1993 } // namespace printing |
| OLD | NEW |