summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorivandavid@chromium.org <ivandavid@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-15 21:21:17 +0000
committerivandavid@chromium.org <ivandavid@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-15 21:22:51 +0000
commit4dc0a3b7b1fe7b844a215ecf86fd2b7ad49dab7c (patch)
treee99cf21214787ec5c7bb00b4692fe80a6de9d8bc /chrome/renderer
parent4aae9986448ac493c92e84c45080a37c6b2aba00 (diff)
downloadchromium_src-4dc0a3b7b1fe7b844a215ecf86fd2b7ad49dab7c.zip
chromium_src-4dc0a3b7b1fe7b844a215ecf86fd2b7ad49dab7c.tar.gz
chromium_src-4dc0a3b7b1fe7b844a215ecf86fd2b7ad49dab7c.tar.bz2
Defer request to print a PDF when the user initiates the entire frame and the PDF hasn't loaded.
Original fix: https://codereview.chromium.org/427723004/ The original fix was reverted, however it actually shouldn't have been because it was mostly correct. This fix is the same as the old one, with an additional change. The call to DidStopLoading() in Instance::DocumentLoadComplete was moved to an earlier part of the function, causing DidStopLoading to be called before the print preview request. BUG=376969 Review URL: https://codereview.chromium.org/467343003 Cr-Commit-Position: refs/heads/master@{#290010} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/printing/print_web_view_helper.cc28
-rw-r--r--chrome/renderer/printing/print_web_view_helper.h7
2 files changed, 34 insertions, 1 deletions
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index e4129ee..5e1328f 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -820,7 +820,10 @@ void PrintWebViewHelper::DidStartLoading() {
void PrintWebViewHelper::DidStopLoading() {
is_loading_ = false;
- ShowScriptedPrintPreview();
+ if (!on_stop_loading_closure_.is_null()) {
+ on_stop_loading_closure_.Run();
+ on_stop_loading_closure_.Reset();
+ }
}
// Prints |frame| which called window.print().
@@ -1711,6 +1714,9 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
// 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.
+ on_stop_loading_closure_ =
+ base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
+ base::Unretained(this));
} else {
base::MessageLoop::current()->PostTask(
FROM_HERE,
@@ -1725,14 +1731,34 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
return;
}
case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
+ // Wait for DidStopLoading. Continuing with this function while
+ // |is_loading_| is true will cause print preview to hang when try to
+ // print a PDF document.
+ if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
+ on_stop_loading_closure_ =
+ base::Bind(&PrintWebViewHelper::RequestPrintPreview,
+ base::Unretained(this),
+ type);
+ return;
+ }
+
break;
}
case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
DCHECK(has_selection);
+ DCHECK(!GetPlugin(print_preview_context_.source_frame()));
params.selection_only = has_selection;
break;
}
case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: {
+ if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
+ on_stop_loading_closure_ =
+ base::Bind(&PrintWebViewHelper::RequestPrintPreview,
+ base::Unretained(this),
+ type);
+ return;
+ }
+
params.webnode_only = true;
break;
}
diff --git a/chrome/renderer/printing/print_web_view_helper.h b/chrome/renderer/printing/print_web_view_helper.h
index 71ff88c..6c254c8 100644
--- a/chrome/renderer/printing/print_web_view_helper.h
+++ b/chrome/renderer/printing/print_web_view_helper.h
@@ -7,6 +7,7 @@
#include <vector>
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h"
@@ -461,6 +462,12 @@ class PrintWebViewHelper
bool is_loading_;
bool is_scripted_preview_delayed_;
base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_;
+
+ // Used to fix a race condition where the source is a PDF and print preview
+ // hangs because RequestPrintPreview is called before DidStopLoading() is
+ // called. This is a store for the RequestPrintPreview() call and its
+ // parameters so that it can be invoked after DidStopLoading.
+ base::Closure on_stop_loading_closure_;
DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
};