Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Unified Diff: chrome/renderer/printing/print_web_view_helper.cc

Issue 23855002: Fixing spreadsheets printing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..330040f0605f86655ee4ec35465e9240164873ed 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,10 @@ 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),
+ weak_ptr_factory_(this) {
}
PrintWebViewHelper::~PrintWebViewHelper() {}
@@ -761,6 +766,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 +1672,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 +1690,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.
+ // 2. PrintHostMsg_ShowScriptedPrintPreview shows preview once the
+ // document has been loaded.
+ is_scripted_preview_delayed_ = true;
+ if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
+ // Wait for DidStopLoading. Plugins may not know the correct
+ // |is_modifiable| value until they are fully loaded, which occurs when
+ // DidStopLoading() is called. Defer showing the preview until then.
+ } else {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
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: {
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698