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 |
|
joth
2013/11/04 20:30:38
should we put a comment here about where this was
sgurun-gerrit only
2013/11/21 18:25:43
Done.
| |
| 52 namespace printing { | 47 namespace printing { |
| 53 | 48 |
| 54 namespace { | 49 namespace { |
| 55 | 50 |
| 56 enum PrintPreviewHelperEvents { | 51 enum PrintPreviewHelperEvents { |
| 57 PREVIEW_EVENT_REQUESTED, | 52 PREVIEW_EVENT_REQUESTED, |
| 58 PREVIEW_EVENT_CACHE_HIT, // Unused | 53 PREVIEW_EVENT_CACHE_HIT, // Unused |
| 59 PREVIEW_EVENT_CREATE_DOCUMENT, | 54 PREVIEW_EVENT_CREATE_DOCUMENT, |
| 60 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 55 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
| 61 PREVIEW_EVENT_MAX, | 56 PREVIEW_EVENT_MAX, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 webkit_print_params->paperSize.width = | 268 webkit_print_params->paperSize.width = |
| 274 ConvertUnit(print_params.page_size.width(), dpi, | 269 ConvertUnit(print_params.page_size.width(), dpi, |
| 275 print_params.desired_dpi); | 270 print_params.desired_dpi); |
| 276 webkit_print_params->paperSize.height = | 271 webkit_print_params->paperSize.height = |
| 277 ConvertUnit(print_params.page_size.height(), dpi, | 272 ConvertUnit(print_params.page_size.height(), dpi, |
| 278 print_params.desired_dpi); | 273 print_params.desired_dpi); |
| 279 } | 274 } |
| 280 | 275 |
| 281 WebKit::WebPlugin* GetPlugin(const WebKit::WebFrame* frame) { | 276 WebKit::WebPlugin* GetPlugin(const WebKit::WebFrame* frame) { |
| 282 return frame->document().isPluginDocument() ? | 277 return frame->document().isPluginDocument() ? |
| 283 frame->document().to<WebKit::WebPluginDocument>().plugin() : NULL; | 278 frame->document().to<WebKit::WebPluginDocument>().plugin() : NULL; |
|
joth
2013/11/04 20:30:38
this will always return NULL for webview. Is this
sgurun-gerrit only
2013/11/21 18:25:43
yep
| |
| 284 } | 279 } |
| 285 | 280 |
| 286 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame, | 281 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame, |
| 287 const WebKit::WebNode& node) { | 282 const WebKit::WebNode& node) { |
| 288 if (!node.isNull()) | 283 if (!node.isNull()) |
| 289 return true; | 284 return true; |
| 290 WebKit::WebPlugin* plugin = GetPlugin(frame); | 285 WebKit::WebPlugin* plugin = GetPlugin(frame); |
| 291 return plugin && plugin->supportsPaginatedPrint(); | 286 return plugin && plugin->supportsPaginatedPrint(); |
| 292 } | 287 } |
| 293 | 288 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 353 |
| 359 if (fit_to_page) { | 354 if (fit_to_page) { |
| 360 double factor = FitPrintParamsToPage(params, &result_params); | 355 double factor = FitPrintParamsToPage(params, &result_params); |
| 361 if (scale_factor) | 356 if (scale_factor) |
| 362 *scale_factor = factor; | 357 *scale_factor = factor; |
| 363 } | 358 } |
| 364 return result_params; | 359 return result_params; |
| 365 } | 360 } |
| 366 | 361 |
| 367 bool IsPrintPreviewEnabled() { | 362 bool IsPrintPreviewEnabled() { |
| 368 return CommandLine::ForCurrentProcess()->HasSwitch( | 363 return false; |
| 369 switches::kRendererPrintPreview); | |
| 370 } | 364 } |
| 371 | 365 |
| 372 bool IsPrintThrottlingDisabled() { | 366 bool IsPrintThrottlingDisabled() { |
| 373 return CommandLine::ForCurrentProcess()->HasSwitch( | 367 return true; |
| 374 switches::kDisableScriptedPrintThrottling); | |
| 375 } | 368 } |
| 376 | 369 |
| 377 } // namespace | 370 } // namespace |
| 378 | 371 |
| 379 FrameReference::FrameReference(const WebKit::WebFrame* frame) { | 372 FrameReference::FrameReference(const WebKit::WebFrame* frame) { |
| 380 Reset(frame); | 373 Reset(frame); |
| 381 } | 374 } |
| 382 | 375 |
| 383 FrameReference::FrameReference() { | 376 FrameReference::FrameReference() { |
| 384 Reset(NULL); | 377 Reset(NULL); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 407 | 400 |
| 408 // static - Not anonymous so that platform implementations can use it. | 401 // static - Not anonymous so that platform implementations can use it. |
| 409 void PrintWebViewHelper::PrintHeaderAndFooter( | 402 void PrintWebViewHelper::PrintHeaderAndFooter( |
| 410 WebKit::WebCanvas* canvas, | 403 WebKit::WebCanvas* canvas, |
| 411 int page_number, | 404 int page_number, |
| 412 int total_pages, | 405 int total_pages, |
| 413 float webkit_scale_factor, | 406 float webkit_scale_factor, |
| 414 const PageSizeMargins& page_layout, | 407 const PageSizeMargins& page_layout, |
| 415 const base::DictionaryValue& header_footer_info, | 408 const base::DictionaryValue& header_footer_info, |
| 416 const PrintMsg_Print_Params& params) { | 409 const PrintMsg_Print_Params& params) { |
| 410 #if 0 | |
| 411 // TODO(sgurun) android_webview hack | |
| 417 skia::VectorPlatformDeviceSkia* device = | 412 skia::VectorPlatformDeviceSkia* device = |
| 418 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | 413 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); |
| 419 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | 414 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); |
| 420 | 415 |
| 421 SkAutoCanvasRestore auto_restore(canvas, true); | 416 SkAutoCanvasRestore auto_restore(canvas, true); |
| 422 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 417 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
| 423 | 418 |
| 424 WebKit::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 419 WebKit::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
| 425 page_layout.content_width, | 420 page_layout.content_width, |
| 426 page_layout.margin_top + page_layout.margin_bottom + | 421 page_layout.margin_top + page_layout.margin_bottom + |
| 427 page_layout.content_height); | 422 page_layout.content_height); |
| 428 | 423 |
| 429 WebKit::WebView* web_view = WebKit::WebView::create(NULL); | 424 WebKit::WebView* web_view = WebKit::WebView::create(NULL); |
| 430 web_view->settings()->setJavaScriptEnabled(true); | 425 web_view->settings()->setJavaScriptEnabled(true); |
| 431 web_view->initializeMainFrame(NULL); | 426 web_view->initializeMainFrame(NULL); |
| 432 | 427 |
| 433 WebKit::WebFrame* frame = web_view->mainFrame(); | 428 WebKit::WebFrame* frame = web_view->mainFrame(); |
| 434 | |
| 435 base::StringValue html( | 429 base::StringValue html( |
| 436 ResourceBundle::GetSharedInstance().GetLocalizedString( | 430 ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 437 IDR_PRINT_PREVIEW_PAGE)); | 431 IDR_PRINT_PREVIEW_PAGE)); |
| 438 // Load page with script to avoid async operations. | 432 // Load page with script to avoid async operations. |
| 439 ExecuteScript(frame, kPageLoadScriptFormat, html); | 433 ExecuteScript(frame, kPageLoadScriptFormat, html); |
| 440 | 434 |
| 441 scoped_ptr<base::DictionaryValue> options(header_footer_info.DeepCopy()); | 435 scoped_ptr<base::DictionaryValue> options(header_footer_info.DeepCopy()); |
| 442 options->SetDouble("width", page_size.width); | 436 options->SetDouble("width", page_size.width); |
| 443 options->SetDouble("height", page_size.height); | 437 options->SetDouble("height", page_size.height); |
| 444 options->SetDouble("topMargin", page_layout.margin_top); | 438 options->SetDouble("topMargin", page_layout.margin_top); |
| 445 options->SetDouble("bottomMargin", page_layout.margin_bottom); | 439 options->SetDouble("bottomMargin", page_layout.margin_bottom); |
| 446 options->SetString("pageNumber", | 440 options->SetString("pageNumber", |
| 447 base::StringPrintf("%d/%d", page_number, total_pages)); | 441 base::StringPrintf("%d/%d", page_number, total_pages)); |
| 448 | 442 |
| 449 ExecuteScript(frame, kPageSetupScriptFormat, *options); | 443 ExecuteScript(frame, kPageSetupScriptFormat, *options); |
| 450 | 444 |
| 451 WebKit::WebPrintParams webkit_params(page_size); | 445 WebKit::WebPrintParams webkit_params(page_size); |
| 452 webkit_params.printerDPI = GetDPI(¶ms); | 446 webkit_params.printerDPI = GetDPI(¶ms); |
| 453 | 447 |
| 454 frame->printBegin(webkit_params); | 448 frame->printBegin(webkit_params, WebKit::WebNode(), NULL); |
| 455 frame->printPage(0, canvas); | 449 frame->printPage(0, canvas); |
| 456 frame->printEnd(); | 450 frame->printEnd(); |
| 457 | 451 |
| 458 web_view->close(); | 452 web_view->close(); |
| 459 | 453 |
| 460 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 454 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
| 455 #endif | |
| 461 } | 456 } |
| 462 | 457 |
| 463 // static - Not anonymous so that platform implementations can use it. | 458 // static - Not anonymous so that platform implementations can use it. |
| 464 float PrintWebViewHelper::RenderPageContent(WebKit::WebFrame* frame, | 459 float PrintWebViewHelper::RenderPageContent(WebKit::WebFrame* frame, |
| 465 int page_number, | 460 int page_number, |
| 466 const gfx::Rect& canvas_area, | 461 const gfx::Rect& canvas_area, |
| 467 const gfx::Rect& content_area, | 462 const gfx::Rect& content_area, |
| 468 double scale_factor, | 463 double scale_factor, |
| 469 WebKit::WebCanvas* canvas) { | 464 WebKit::WebCanvas* canvas) { |
| 470 SkAutoCanvasRestore auto_restore(canvas, true); | 465 SkAutoCanvasRestore auto_restore(canvas, true); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 void PrintWebViewHelper::DidStopLoading() { | 744 void PrintWebViewHelper::DidStopLoading() { |
| 750 is_loading_ = false; | 745 is_loading_ = false; |
| 751 ShowScriptedPrintPreview(); | 746 ShowScriptedPrintPreview(); |
| 752 } | 747 } |
| 753 | 748 |
| 754 // Prints |frame| which called window.print(). | 749 // Prints |frame| which called window.print(). |
| 755 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, | 750 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, |
| 756 bool user_initiated) { | 751 bool user_initiated) { |
| 757 DCHECK(frame); | 752 DCHECK(frame); |
| 758 | 753 |
| 754 #if !defined(OS_ANDROID) | |
| 755 // TODO(sgurun) android_webview hack | |
| 759 // Allow Prerendering to cancel this print request if necessary. | 756 // Allow Prerendering to cancel this print request if necessary. |
| 760 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { | 757 if (prerender::PrerenderHelper::IsPrerendering(render_view())) { |
| 761 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 758 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
| 762 return; | 759 return; |
| 763 } | 760 } |
| 761 #endif // !defined(OS_ANDROID) | |
| 764 | 762 |
| 765 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 763 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
| 766 return; | 764 return; |
| 767 IncrementScriptedPrintCount(); | 765 IncrementScriptedPrintCount(); |
| 768 | 766 |
| 769 if (is_preview_enabled_) { | 767 if (is_preview_enabled_) { |
| 770 print_preview_context_.InitWithFrame(frame); | 768 print_preview_context_.InitWithFrame(frame); |
| 771 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 769 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 772 } else { | 770 } else { |
| 773 Print(frame, WebKit::WebNode()); | 771 Print(frame, WebKit::WebNode()); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 DidFinishPrinting(FAIL_PRINT_INIT); | 1189 DidFinishPrinting(FAIL_PRINT_INIT); |
| 1192 return; // Failed to init print page settings. | 1190 return; // Failed to init print page settings. |
| 1193 } | 1191 } |
| 1194 | 1192 |
| 1195 // Some full screen plugins can say they don't want to print. | 1193 // Some full screen plugins can say they don't want to print. |
| 1196 if (!expected_page_count) { | 1194 if (!expected_page_count) { |
| 1197 DidFinishPrinting(FAIL_PRINT); | 1195 DidFinishPrinting(FAIL_PRINT); |
| 1198 return; | 1196 return; |
| 1199 } | 1197 } |
| 1200 | 1198 |
| 1199 #if !defined(OS_ANDROID) | |
| 1200 // TODO(sgurun) android_webview hack | |
| 1201 // Ask the browser to show UI to retrieve the final print settings. | 1201 // Ask the browser to show UI to retrieve the final print settings. |
| 1202 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1202 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
| 1203 expected_page_count)) { | 1203 expected_page_count)) { |
| 1204 DidFinishPrinting(OK); // Release resources and fail silently. | 1204 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1205 return; | 1205 return; |
| 1206 } | 1206 } |
| 1207 #endif // !defined(OS_ANDROID) | |
| 1207 | 1208 |
| 1208 // Render Pages for printing. | 1209 // Render Pages for printing. |
| 1209 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1210 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1210 LOG(ERROR) << "RenderPagesForPrint failed"; | 1211 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1211 DidFinishPrinting(FAIL_PRINT); | 1212 DidFinishPrinting(FAIL_PRINT); |
| 1212 } | 1213 } |
| 1213 ResetScriptedPrintCount(); | 1214 ResetScriptedPrintCount(); |
| 1214 } | 1215 } |
| 1215 | 1216 |
| 1216 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1217 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1235 print_pages_params_->params.document_cookie : 0; | 1236 print_pages_params_->params.document_cookie : 0; |
| 1236 if (notify_browser_of_print_failure_) { | 1237 if (notify_browser_of_print_failure_) { |
| 1237 LOG(ERROR) << "CreatePreviewDocument failed"; | 1238 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 1238 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1239 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
| 1239 } else { | 1240 } else { |
| 1240 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1241 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
| 1241 } | 1242 } |
| 1242 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1243 print_preview_context_.Failed(notify_browser_of_print_failure_); |
| 1243 break; | 1244 break; |
| 1244 } | 1245 } |
| 1246 | |
| 1245 prep_frame_view_.reset(); | 1247 prep_frame_view_.reset(); |
| 1246 print_pages_params_.reset(); | 1248 print_pages_params_.reset(); |
| 1247 notify_browser_of_print_failure_ = true; | 1249 notify_browser_of_print_failure_ = true; |
| 1248 } | 1250 } |
| 1249 | 1251 |
| 1250 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1252 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
| 1251 PrintPages(); | 1253 PrintPages(); |
| 1252 FinishFramePrinting(); | 1254 FinishFramePrinting(); |
| 1253 } | 1255 } |
| 1254 | 1256 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1373 return result; | 1375 return result; |
| 1374 } | 1376 } |
| 1375 | 1377 |
| 1376 bool PrintWebViewHelper::CalculateNumberOfPages(WebKit::WebFrame* frame, | 1378 bool PrintWebViewHelper::CalculateNumberOfPages(WebKit::WebFrame* frame, |
| 1377 const WebKit::WebNode& node, | 1379 const WebKit::WebNode& node, |
| 1378 int* number_of_pages) { | 1380 int* number_of_pages) { |
| 1379 DCHECK(frame); | 1381 DCHECK(frame); |
| 1380 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | 1382 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); |
| 1381 if (!InitPrintSettings(fit_to_paper_size)) { | 1383 if (!InitPrintSettings(fit_to_paper_size)) { |
| 1382 notify_browser_of_print_failure_ = false; | 1384 notify_browser_of_print_failure_ = false; |
| 1385 #if !defined(OS_ANDROID) | |
| 1386 // TODO(sgurun) android_webview hack | |
| 1383 render_view()->RunModalAlertDialog( | 1387 render_view()->RunModalAlertDialog( |
| 1384 frame, | 1388 frame, |
| 1385 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1389 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1390 #endif // !defined(OS_ANDROID) | |
| 1386 return false; | 1391 return false; |
| 1387 } | 1392 } |
| 1388 | 1393 |
| 1389 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1394 const PrintMsg_Print_Params& params = print_pages_params_->params; |
| 1390 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1395 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
| 1391 prepare.StartPrinting(); | 1396 prepare.StartPrinting(); |
| 1392 | 1397 |
| 1393 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1398 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1394 params.document_cookie)); | 1399 params.document_cookie)); |
| 1395 *number_of_pages = prepare.GetExpectedPageCount(); | 1400 *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; | 1436 print_pages_params_->params.document_cookie : 0; |
| 1432 PrintMsg_PrintPages_Params settings; | 1437 PrintMsg_PrintPages_Params settings; |
| 1433 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, | 1438 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), cookie, *job_settings, |
| 1434 &settings)); | 1439 &settings)); |
| 1435 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1440 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1436 | 1441 |
| 1437 if (!PrintMsg_Print_Params_IsValid(settings.params)) { | 1442 if (!PrintMsg_Print_Params_IsValid(settings.params)) { |
| 1438 if (!print_for_preview_) { | 1443 if (!print_for_preview_) { |
| 1439 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1444 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
| 1440 } else { | 1445 } else { |
| 1446 #if !defined(OS_ANDROID) | |
| 1447 // TODO(sgurun) android_webview hack | |
| 1441 // PrintForPrintPreview | 1448 // PrintForPrintPreview |
| 1442 WebKit::WebFrame* print_frame = NULL; | 1449 WebKit::WebFrame* print_frame = NULL; |
| 1443 // This may not be the right frame, but the alert will be modal, | 1450 // This may not be the right frame, but the alert will be modal, |
| 1444 // therefore it works well enough. | 1451 // therefore it works well enough. |
| 1445 GetPrintFrame(&print_frame); | 1452 GetPrintFrame(&print_frame); |
| 1446 if (print_frame) { | 1453 if (print_frame) { |
| 1447 render_view()->RunModalAlertDialog( | 1454 render_view()->RunModalAlertDialog( |
| 1448 print_frame, | 1455 print_frame, |
| 1449 l10n_util::GetStringUTF16( | 1456 l10n_util::GetStringUTF16( |
| 1450 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1457 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1451 } | 1458 } |
| 1459 #endif // !defined(OS_ANDROID) | |
| 1452 } | 1460 } |
| 1453 return false; | 1461 return false; |
| 1454 } | 1462 } |
| 1455 | 1463 |
| 1456 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { | 1464 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) { |
| 1457 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); | 1465 print_preview_context_.set_error(PREVIEW_ERROR_UPDATING_PRINT_SETTINGS); |
| 1458 return false; | 1466 return false; |
| 1459 } | 1467 } |
| 1460 | 1468 |
| 1461 if (!job_settings->GetInteger(kPreviewUIID, &settings.params.preview_ui_id)) { | 1469 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() { | 1619 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 1612 // Reset cancel counter on successful print. | 1620 // Reset cancel counter on successful print. |
| 1613 user_cancelled_scripted_print_count_ = 0; | 1621 user_cancelled_scripted_print_count_ = 0; |
| 1614 } | 1622 } |
| 1615 | 1623 |
| 1616 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1624 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 1617 ++user_cancelled_scripted_print_count_; | 1625 ++user_cancelled_scripted_print_count_; |
| 1618 last_cancelled_script_print_ = base::Time::Now(); | 1626 last_cancelled_script_print_ = base::Time::Now(); |
| 1619 } | 1627 } |
| 1620 | 1628 |
| 1621 | |
| 1622 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1629 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
| 1623 if (is_scripted_preview_delayed_) { | 1630 if (is_scripted_preview_delayed_) { |
| 1624 is_scripted_preview_delayed_ = false; | 1631 is_scripted_preview_delayed_ = false; |
| 1625 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), | 1632 Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), |
| 1626 print_preview_context_.IsModifiable())); | 1633 print_preview_context_.IsModifiable())); |
| 1627 } | 1634 } |
| 1628 } | 1635 } |
| 1629 | 1636 |
| 1630 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1637 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1631 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1638 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1632 const bool has_selection = print_preview_context_.HasSelection(); | 1639 const bool has_selection = print_preview_context_.HasSelection(); |
| 1633 PrintHostMsg_RequestPrintPreview_Params params; | 1640 PrintHostMsg_RequestPrintPreview_Params params; |
| 1634 params.is_modifiable = is_modifiable; | 1641 params.is_modifiable = is_modifiable; |
| 1635 params.has_selection = has_selection; | 1642 params.has_selection = has_selection; |
| 1636 switch (type) { | 1643 switch (type) { |
| 1637 case PRINT_PREVIEW_SCRIPTED: { | 1644 case PRINT_PREVIEW_SCRIPTED: { |
| 1638 // Shows scripted print preview in two stages. | 1645 // Shows scripted print preview in two stages. |
| 1639 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by | 1646 // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| 1640 // pumping messages here. | 1647 // pumping messages here. |
| 1641 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the | 1648 // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the |
| 1642 // document has been loaded. | 1649 // document has been loaded. |
| 1643 is_scripted_preview_delayed_ = true; | 1650 is_scripted_preview_delayed_ = true; |
| 1644 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { | 1651 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { |
| 1645 // Wait for DidStopLoading. Plugins may not know the correct | 1652 // Wait for DidStopLoading. Plugins may not know the correct |
| 1646 // |is_modifiable| value until they are fully loaded, which occurs when | 1653 // |is_modifiable| value until they are fully loaded, which occurs when |
| 1647 // DidStopLoading() is called. Defer showing the preview until then. | 1654 // DidStopLoading() is called. Defer showing the preview until then. |
| 1648 } else { | 1655 } else { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1674 NOTREACHED(); | 1681 NOTREACHED(); |
| 1675 return; | 1682 return; |
| 1676 } | 1683 } |
| 1677 } | 1684 } |
| 1678 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); | 1685 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
| 1679 } | 1686 } |
| 1680 | 1687 |
| 1681 bool PrintWebViewHelper::CheckForCancel() { | 1688 bool PrintWebViewHelper::CheckForCancel() { |
| 1682 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1689 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1683 bool cancel = false; | 1690 bool cancel = false; |
| 1691 | |
| 1684 Send(new PrintHostMsg_CheckForCancel(routing_id(), | 1692 Send(new PrintHostMsg_CheckForCancel(routing_id(), |
| 1685 print_params.preview_ui_id, | 1693 print_params.preview_ui_id, |
| 1686 print_params.preview_request_id, | 1694 print_params.preview_request_id, |
| 1687 &cancel)); | 1695 &cancel)); |
| 1688 if (cancel) | 1696 if (cancel) |
| 1689 notify_browser_of_print_failure_ = false; | 1697 notify_browser_of_print_failure_ = false; |
| 1690 return cancel; | 1698 return cancel; |
| 1691 } | 1699 } |
| 1692 | 1700 |
| 1693 bool PrintWebViewHelper::PreviewPageRendered(int page_number, | 1701 bool PrintWebViewHelper::PreviewPageRendered(int page_number, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1964 } | 1972 } |
| 1965 | 1973 |
| 1966 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1974 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1967 prep_frame_view_.reset(); | 1975 prep_frame_view_.reset(); |
| 1968 metafile_.reset(); | 1976 metafile_.reset(); |
| 1969 pages_to_render_.clear(); | 1977 pages_to_render_.clear(); |
| 1970 error_ = PREVIEW_ERROR_NONE; | 1978 error_ = PREVIEW_ERROR_NONE; |
| 1971 } | 1979 } |
| 1972 | 1980 |
| 1973 } // namespace printing | 1981 } // namespace printing |
| OLD | NEW |