Chromium Code Reviews| Index: chrome/renderer/printing/print_web_view_helper.cc |
| diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc |
| index d3023418b8496de4de01a2449f3235c660421b3d..875719f6dabf7a6eb05e543b33ac425625500bf1 100644 |
| --- a/chrome/renderer/printing/print_web_view_helper.cc |
| +++ b/chrome/renderer/printing/print_web_view_helper.cc |
| @@ -304,14 +304,16 @@ void ComputeWebKitPrintParamsInDesiredDpi( |
| print_params.desired_dpi); |
| } |
| +WebKit::WebPlugin* GetPlugin(const WebKit::WebFrame* frame) { |
| + return frame->document().isPluginDocument() ? |
| + frame->document().to<WebKit::WebPluginDocument>().plugin() : NULL; |
| +} |
| + |
| bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame, |
| const WebKit::WebNode& node) { |
| if (!node.isNull()) |
| return true; |
| - if (!frame->document().isPluginDocument()) |
| - return false; |
| - WebKit::WebPlugin* plugin = |
| - frame->document().to<WebKit::WebPluginDocument>().plugin(); |
| + WebKit::WebPlugin* plugin = GetPlugin(frame); |
| return plugin && plugin->supportsPaginatedPrint(); |
| } |
| @@ -741,7 +743,9 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
| is_scripted_printing_blocked_(false), |
| notify_browser_of_print_failure_(true), |
| print_for_preview_(false), |
| - print_node_in_progress_(false) { |
| + print_node_in_progress_(false), |
| + is_loading_(false), |
| + is_scripted_preview_delayed_(false) { |
| } |
| PrintWebViewHelper::~PrintWebViewHelper() {} |
| @@ -761,6 +765,15 @@ bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
| return true; |
| } |
| +void PrintWebViewHelper::DidStartLoading() { |
| + is_loading_ = true; |
| +} |
| + |
| +void PrintWebViewHelper::DidStopLoading() { |
| + is_loading_ = false; |
| + ShowScriptedPrintPreview(); |
| +} |
| + |
| // Prints |frame| which called window.print(). |
| void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame, |
| bool user_initiated) { |
| @@ -1658,6 +1671,15 @@ void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| last_cancelled_script_print_ = base::Time::Now(); |
| } |
| + |
| +void PrintWebViewHelper::ShowScriptedPrintPreview() { |
| + if (is_scripted_preview_delayed_) { |
| + is_scripted_preview_delayed_ = false; |
| + Send(new PrintHostMsg_ShowScriptedPrintPreview(routing_id(), |
| + print_preview_context_.IsModifiable())); |
| + } |
| +} |
| + |
| void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| const bool is_modifiable = print_preview_context_.IsModifiable(); |
| const bool has_selection = print_preview_context_.HasSelection(); |
| @@ -1667,10 +1689,27 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| params.has_selection = has_selection; |
| switch (type) { |
| case PRINT_PREVIEW_SCRIPTED: { |
| + // Shows scripted print preview in two stages. |
| + // 1. PrintHostMsg_SetupScriptedPrintPreview blocks this call and JS by |
| + // pumping messages here. |
|
Lei Zhang
2013/09/04 01:06:34
nit: Align it like:
// 1. Foo ...
// bar.
Vitaly Buka (NO REVIEWS)
2013/09/04 01:49:49
Done.
|
| + // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview |
| + // if is_modifiable is available. |
|
Lei Zhang
2013/09/04 01:06:34
"once the document has been loaded" ?
Vitaly Buka (NO REVIEWS)
2013/09/04 01:49:49
Done.
|
| + is_scripted_preview_delayed_ = true; |
| + if (is_modifiable && is_loading_ && |
|
Lei Zhang
2013/09/04 01:06:34
I recommend not checking GetPlugin() or |is_modifi
Vitaly Buka (NO REVIEWS)
2013/09/04 01:49:49
I afraid that we can get some frames that loading
Lei Zhang
2013/09/04 02:18:12
Sure.
|
| + GetPlugin(print_preview_context_.source_frame())) { |
| + // Wait for DidStopLoading. Plugins may change is_modifiable from True |
|
Lei Zhang
2013/09/04 01:06:34
nit: "Plugins may not know the correct |is_modifia
Vitaly Buka (NO REVIEWS)
2013/09/04 01:49:49
Done.
|
| + // to False after loading data. It may happen in DidStopLoading handler. |
| + } else { |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, |
| + AsWeakPtr())); |
| + } |
| IPC::SyncMessage* msg = |
| - new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); |
| + new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); |
| msg->EnableMessagePumping(); |
| Send(msg); |
| + is_scripted_preview_delayed_ = false; |
| return; |
| } |
| case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |