diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 04:53:19 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 04:53:19 +0000 |
commit | 5376c266169f8a87be61a1fc42bfe30cb95395c9 (patch) | |
tree | a31838d1ab5f988d443fc90c5f285e9aece5d53a /chrome/browser/instant | |
parent | 6beeb9f192aeea63e7a8ead066218c2c9ce8d990 (diff) | |
download | chromium_src-5376c266169f8a87be61a1fc42bfe30cb95395c9.zip chromium_src-5376c266169f8a87be61a1fc42bfe30cb95395c9.tar.gz chromium_src-5376c266169f8a87be61a1fc42bfe30cb95395c9.tar.bz2 |
Prevent Instant from swapping when it has a pending navigation.
BUG=93728
TEST=InstantTest.PendingRenderViewHost
Review URL: http://codereview.chromium.org/7817002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_browsertest.cc | 59 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 9 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 61 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 4 |
4 files changed, 103 insertions, 30 deletions
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 92e7c4c..b2f4895 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -945,3 +945,62 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DontPersistSearchbox) { &result)); EXPECT_TRUE(result); } + +// Verify that when the TabContents has a pending RenderViewHost, we won't use +// the Instant TabContents. +// DISABLED http://crbug.com/80118 +#if defined(OS_LINUX) +IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PendingRenderViewHost) { +#else +IN_PROC_BROWSER_TEST_F(InstantTest, PendingRenderViewHost) { +#endif // OS_LINUX + ASSERT_TRUE(test_server()->Start()); + EnableInstant(); + + // Open and load URL. + GURL url(test_server()->GetURL("files/instant/empty.html")); + ASSERT_NO_FATAL_FAILURE(SetLocationBarText(url.spec())); + + // Check that we have a preview TabContents. + ASSERT_TRUE(browser()->instant()); + TabContentsWrapper* preview_contents_wrapper = + browser()->instant()->GetPreviewContents(); + ASSERT_TRUE(preview_contents_wrapper); + ASSERT_TRUE(preview_contents_wrapper->tab_contents()); + + // Enter "chrome://about" in the location bar, as it will trigger a cross-site + // navigation in Instant's TabContents. + ASSERT_NO_FATAL_FAILURE(FindLocationBar()); + location_bar_->location_entry()->SetUserText( + ASCIIToUTF16(chrome::kChromeUIAboutURL)); + + // Check that we reused the same Instant TabContentsWrapper. + ASSERT_TRUE(browser()->instant()); + ASSERT_EQ(preview_contents_wrapper, + browser()->instant()->GetPreviewContents()); + + // Check that a new site instance is pending, indicating a cross-site + // navigation that has yet to complete. + ASSERT_NE(preview_contents_wrapper->tab_contents()->GetSiteInstance(), + preview_contents_wrapper->tab_contents()->GetPendingSiteInstance()); + + // We want to be able to wait until the old TabContents has navigated to + // the about page. Since we navigate while the preview still has a pending + // RenderView, the navigation will occur in the original TabContents instead. + TabContents* contents = browser()->GetSelectedTabContents(); + ui_test_utils::WindowedNotificationObserver notification_observer( + content::NOTIFICATION_LOAD_STOP, + Source<NavigationController>(&contents->controller())); + + ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); + + // Check that we did not swap in the Instant TabContents, but destroyed it + // instead. + ASSERT_EQ(browser()->GetSelectedTabContents(), contents); + ASSERT_FALSE(browser()->instant()->GetPreviewContents()); + ASSERT_FALSE(browser()->instant()->is_active()); + + // Make sure we navigated to the correct URL. + notification_observer.Wait(); + EXPECT_EQ(contents->GetURL().spec(), std::string(chrome::kChromeUIAboutURL)); +} diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 7334e48..deac866 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -286,8 +286,11 @@ void InstantController::DestroyPreviewContentsAndLeaveActive() { } bool InstantController::IsCurrent() { + // TODO(mmenke): See if we can do something more intelligent in the + // navigation pending case. return loader_manager_.get() && loader_manager_->active_loader() && loader_manager_->active_loader()->ready() && + !loader_manager_->active_loader()->IsNavigationPending() && !loader_manager_->active_loader()->needs_reload() && !update_timer_.IsRunning(); } @@ -335,7 +338,8 @@ void InstantController::OnAutocompleteLostFocus( // not receive a mouseDown event. Therefore, we should destroy the preview. // Otherwise, the RWHV was clicked, so we commit the preview. if (!is_displayable() || !GetPreviewContents() || - !IsMouseDownFromActivate()) { + !IsMouseDownFromActivate() || + loader_manager_->active_loader()->IsNavigationPending()) { DestroyPreviewContents(); } else if (IsShowingInstant()) { SetCommitOnMouseUp(); @@ -346,7 +350,8 @@ void InstantController::OnAutocompleteLostFocus( #else void InstantController::OnAutocompleteLostFocus( gfx::NativeView view_gaining_focus) { - if (!is_active() || !GetPreviewContents()) { + if (!is_active() || !GetPreviewContents() || + loader_manager_->active_loader()->IsNavigationPending()) { DestroyPreviewContents(); return; } diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index da42231..1a71176 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -771,6 +771,39 @@ void InstantLoader::MaybeLoadInstantURL(TabContentsWrapper* tab_contents, string16(), true); } +bool InstantLoader::IsNavigationPending() const { + return preview_contents_.get() && + preview_contents_->controller().pending_entry(); +} + +void InstantLoader::Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) { +#if defined(OS_MACOSX) + if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { + if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { + preview_contents_->tab_contents()->GetRenderWidgetHostView()-> + SetTakesFocusOnlyOnMouseDown(true); + } + return; + } +#endif + if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { + content::LoadCommittedDetails* load_details = + Details<content::LoadCommittedDetails>(details).ptr(); + if (load_details->is_main_frame) { + if (load_details->http_status_code == kHostBlacklistStatusCode) { + delegate_->AddToBlacklist(this, load_details->entry->url()); + } else { + SetHTTPStatusOK(load_details->http_status_code == 200); + } + } + return; + } + + NOTREACHED() << "Got a notification we didn't register for."; +} + void InstantLoader::SetCompleteSuggestedText( const string16& complete_suggested_text, InstantCompleteBehavior behavior) { @@ -842,34 +875,6 @@ void InstantLoader::ShowPreview() { } } -void InstantLoader::Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) { -#if defined(OS_MACOSX) - if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { - if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { - preview_contents_->tab_contents()->GetRenderWidgetHostView()-> - SetTakesFocusOnlyOnMouseDown(true); - } - return; - } -#endif - if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { - content::LoadCommittedDetails* load_details = - Details<content::LoadCommittedDetails>(details).ptr(); - if (load_details->is_main_frame) { - if (load_details->http_status_code == kHostBlacklistStatusCode) { - delegate_->AddToBlacklist(this, load_details->entry->url()); - } else { - SetHTTPStatusOK(load_details->http_status_code == 200); - } - } - return; - } - - NOTREACHED() << "Got a notification we didn't register for."; -} - void InstantLoader::PageFinishedLoading() { frame_load_observer_.reset(); diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index daa6631..515a5df 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -74,6 +74,10 @@ class InstantLoader : public NotificationObserver { void MaybeLoadInstantURL(TabContentsWrapper* tab_contents, const TemplateURL* template_url); + // Returns true if the preview NavigationController's TabContents has a + // pending NavigationEntry. + bool IsNavigationPending() const; + // NotificationObserver: virtual void Observe(int type, const NotificationSource& source, |