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

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: 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
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..3f7961dc5957e151ced2e5d876cef17f37d49c52 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,31 @@ 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
+ // if is_modifiable is available.
+ is_scripted_preview_delayed_ = true;
+ base::Closure task =
+ base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
+ AsWeakPtr());
+ if (is_modifiable && is_loading_ &&
+ GetPlugin(print_preview_context_.source_frame())) {
+ // Plugins may change is_modifiable from True to False after loading
+ // data. It may happen in DidStopLoading handler.
+ // If DidStopLoading was not called in 1min we will use whatever we
+ // have.
+ base::MessageLoop::current()->PostDelayedTask(
Lei Zhang 2013/09/03 20:07:26 I don't think it's worth handling this case. If th
Vitaly Buka (NO REVIEWS) 2013/09/04 00:22:39 Done.
+ FROM_HERE, task, base::TimeDelta::FromMinutes(1));
+ } else {
+ base::MessageLoop::current()->PostTask(FROM_HERE, task);
+ }
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: {

Powered by Google App Engine
This is Rietveld 408576698