Revert of Fix for race condition where print preview hangs when attempting to...

Revert of Fix for race condition where print preview hangs when attempting to print a PDF that hasn't loaded. (https://codereview.chromium.org/427723004/)

Reason for revert:
The changes fix an issue, but cause a more serious one. 

crbug.com/402402

Original issue's description:
> Fix for race condition where print preview hangs when attempting to print a PDF that hasn't loaded.
> 
> If |type| in RequestPrintPreview() equals PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME and |is_loading_| is true, RequestPrintPreview() returns,
> then is called again, right after |is_loading_| is set to false in DidStopLoading(). 
> 
> 
> BUG=376969
> TEST=See bug for steps to reproduce.
> 
> Additional way to reproduce:
> Build blink_tests and browser_tests in out/Release. Then in src/webkit/tools/layout_tests run this command:
> ./run_webkit_tests.py --platform browser_test.linux source_pdf/
> 
> you can replace linux with win or mac depending on your platform.
> 
> The program will attempt to save a PDF as a PDF through print preview. It will eventually fail because Print Preview will hang due to this bug.
> If you want visual confirmation that this will happen open:
> src/third_party/WebKit/Tools/Scripts/webkitpy/layout_tests/port/browser_test_driver.py.
> 
> Then add this line of code to the function cmd_line.
> cmd.append('--enable-pixel-output-in-tests')
> 
> Then run the script again. Enabling pixel output will also make it significantly more likely for the bug to occur.
> Its also more likely to happen on windows for some reason.
> 
> This is how I came across the bug.
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=287982

Review URL: https://codereview.chromium.org/463123004

Cr-Commit-Position: refs/heads/master@{#289181}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289181 0039d316-1c4b-4281-b951-d872f2087c98
parent f4728fb3
...@@ -820,8 +820,7 @@ void PrintWebViewHelper::DidStartLoading() { ...@@ -820,8 +820,7 @@ void PrintWebViewHelper::DidStartLoading() {
void PrintWebViewHelper::DidStopLoading() { void PrintWebViewHelper::DidStopLoading() {
is_loading_ = false; is_loading_ = false;
if (!on_stop_loading_closure_.is_null()) ShowScriptedPrintPreview();
on_stop_loading_closure_.Run();
} }
// Prints |frame| which called window.print(). // Prints |frame| which called window.print().
...@@ -1712,9 +1711,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { ...@@ -1712,9 +1711,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
// Wait for DidStopLoading. Plugins may not know the correct // Wait for DidStopLoading. Plugins may not know the correct
// |is_modifiable| value until they are fully loaded, which occurs when // |is_modifiable| value until they are fully loaded, which occurs when
// DidStopLoading() is called. Defer showing the preview until then. // DidStopLoading() is called. Defer showing the preview until then.
on_stop_loading_closure_ =
base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
base::Unretained(this));
} else { } else {
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -1729,17 +1725,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { ...@@ -1729,17 +1725,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
return; return;
} }
case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 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; break;
} }
case PRINT_PREVIEW_USER_INITIATED_SELECTION: { case PRINT_PREVIEW_USER_INITIATED_SELECTION: {
...@@ -1748,15 +1733,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { ...@@ -1748,15 +1733,6 @@ void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) {
break; break;
} }
case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: {
// Same situation as in PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME.
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; params.webnode_only = true;
break; break;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
...@@ -462,12 +461,6 @@ class PrintWebViewHelper ...@@ -462,12 +461,6 @@ class PrintWebViewHelper
bool is_loading_; bool is_loading_;
bool is_scripted_preview_delayed_; bool is_scripted_preview_delayed_;
base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; 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); DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment