diff options
author | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-30 22:05:29 +0000 |
---|---|---|
committer | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-30 22:05:29 +0000 |
commit | 802dc1e3cde70a4db050fe49b63dedb80874bc1f (patch) | |
tree | a6459b9429d7e5efae54b3e71ebaf965067d0cee /chrome | |
parent | 98ce1ee2b9754b6b89f5fad0c939712c19d76aef (diff) | |
download | chromium_src-802dc1e3cde70a4db050fe49b63dedb80874bc1f.zip chromium_src-802dc1e3cde70a4db050fe49b63dedb80874bc1f.tar.gz chromium_src-802dc1e3cde70a4db050fe49b63dedb80874bc1f.tar.bz2 |
Stops the throbber from spinning if the user cancels a beforeunload dialog,
if the dialog is triggered by a reload or location bar entry.
BUG=22004
TEST=BrowserTest.ReloadThenCancelBeforeUnload
Review URL: http://codereview.chromium.org/256015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 23 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 9 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 5 |
3 files changed, 37 insertions, 0 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index ee63646..d19fd66 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -18,6 +18,11 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" +const std::string BEFORE_UNLOAD_HTML = + "<html><head><title>beforeunload</title></head><body>" + "<script>window.onbeforeunload=function(e){return 'foo'}</script>" + "</body></html>"; + namespace { // Given a page title, returns the expected window caption string. @@ -138,3 +143,21 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ThirtyFourTabs) { EXPECT_LE(CountRenderProcessHosts(), 23); } } + +// Test for crbug.com/22004. Reloading a page with a before unload handler and +// then canceling the dialog should not leave the throbber spinning. +IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { + GURL url("data:text/html," + BEFORE_UNLOAD_HTML); + ui_test_utils::NavigateToURL(browser(), url); + + // Navigate to another page, but click cancel in the dialog. Make sure that + // the throbber stops spinning. + browser()->Reload(); + AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); + alert->CloseModalDialog(); + EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading()); + + // Clear the beforeunload handler so the test can easily exit. + browser()->GetSelectedTabContents()->render_view_host()-> + ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;"); +} diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 4184d43..46d4cdf 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -110,6 +110,7 @@ RenderViewHost::RenderViewHost(SiteInstance* instance, navigations_suspended_(false), suspended_nav_message_(NULL), run_modal_reply_msg_(NULL), + is_showing_before_unload_dialog_(false), is_waiting_for_unload_ack_(false), unload_ack_is_for_cross_site_transition_(false), are_javascript_messages_suppressed_(false), @@ -578,6 +579,13 @@ void RenderViewHost::JavaScriptMessageBoxClosed(IPC::Message* reply_msg, StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); } + if (is_showing_before_unload_dialog_ && !success) { + // If a beforeunload dialog is canceled, we need to stop the throbber from + // spinning, since we forced it to start spinning in Navigate. + delegate_->DidStopLoading(this); + } + is_showing_before_unload_dialog_ = false; + ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, success, prompt); Send(reply_msg); @@ -1301,6 +1309,7 @@ void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, // shouldn't process input events. process()->set_ignore_input_events(true); StopHangMonitorTimeout(); + is_showing_before_unload_dialog_ = true; delegate_->RunBeforeUnloadConfirm(message, reply_msg); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index e2710c3..328a566 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -625,6 +625,11 @@ class RenderViewHost : public RenderWidgetHost, // must return to the renderer to unblock it. IPC::Message* run_modal_reply_msg_; + // Set to true when there is an active "before unload" dialog. When true, + // we've forced the throbber to start in Navigate, and we need to remember to + // turn it off in JavaScriptMessageBoxClosed if the navigation is canceled. + bool is_showing_before_unload_dialog_; + // Set to true when there is a pending ViewMsg_ShouldClose message pending. // This ensures we don't spam the renderer many times to close. When true, // the value of unload_ack_is_for_cross_site_transition_ indicates which type |