diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 21:57:58 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 21:57:58 +0000 |
commit | 32d4e102a3a871f96b47bb71699994b58f5a4a08 (patch) | |
tree | 32ed21a7b3bb2a36a7a11a0a0fb56dc6c90c958c /chrome | |
parent | 2c39338321bfcd99727813c9ae55f8ad4927b5df (diff) | |
download | chromium_src-32d4e102a3a871f96b47bb71699994b58f5a4a08.zip chromium_src-32d4e102a3a871f96b47bb71699994b58f5a4a08.tar.gz chromium_src-32d4e102a3a871f96b47bb71699994b58f5a4a08.tar.bz2 |
Support instant in GoogleURLTracker.
This should fix crashes due to bogus NAV_ENTRY_PENDING observations by treating either NAV_ENTRY_PENDING or INSTANT_COMMITTED as "search became pending". (INSTANT_COMMITTED then goes further and does the "search committed" actions as well.)
BUG=110158
TEST=Enable instant. Tweak the local settings data on disk or launch Chrome on a proxy such that Chrome will prompt to switch Google domains. Verify that hitting enter once the instant results have completely loaded causes the infobar to appear.
Review URL: https://chromiumcodereview.appspot.com/10380037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135736 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/google/google_url_tracker.cc | 47 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.h | 38 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker_unittest.cc | 5 |
3 files changed, 67 insertions, 23 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index 7db8d27..0c5c76e 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -368,7 +368,7 @@ void GoogleURLTracker::Observe(int type, OnNavigationCommittedOrTabClosed(source, content::Source<content::WebContents>(contents), TabContentsWrapper::GetCurrentWrapperForContents(contents)-> - infobar_tab_helper(), type); + infobar_tab_helper(), true); break; } @@ -379,7 +379,22 @@ void GoogleURLTracker::Observe(int type, content::Source<content::NavigationController>(&contents-> GetController()), source, TabContentsWrapper::GetCurrentWrapperForContents(contents)-> - infobar_tab_helper(), type); + infobar_tab_helper(), false); + break; + } + + case chrome::NOTIFICATION_INSTANT_COMMITTED: { + TabContentsWrapper* wrapper = + content::Source<TabContentsWrapper>(source).ptr(); + content::WebContents* contents = wrapper->web_contents(); + content::Source<content::NavigationController> source( + &contents->GetController()); + content::Source<content::WebContents> contents_source(contents); + InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); + OnNavigationPending(source, contents_source, infobar_helper, + contents->GetURL()); + OnNavigationCommittedOrTabClosed(source, contents_source, infobar_helper, + true); break; } @@ -399,19 +414,23 @@ void GoogleURLTracker::SearchCommitted() { // currently in. registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, content::NotificationService::AllBrowserContextsAndSources()); + registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, + content::NotificationService::AllBrowserContextsAndSources()); } } void GoogleURLTracker::OnNavigationPending( - const content::NotificationSource& source, - const content::NotificationSource& contents_source, + const content::NotificationSource& navigation_controller_source, + const content::NotificationSource& web_contents_source, InfoBarTabHelper* infobar_helper, const GURL& search_url) { registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, content::NotificationService::AllBrowserContextsAndSources()); + registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, + content::NotificationService::AllBrowserContextsAndSources()); if (registrar_.IsRegistered(this, - content::NOTIFICATION_WEB_CONTENTS_DESTROYED, contents_source)) { + content::NOTIFICATION_WEB_CONTENTS_DESTROYED, web_contents_source)) { // If the previous load hasn't committed and the user triggers a new load, // we don't need to re-register our listeners; just kill the old, // never-shown infobar (to be replaced by a new one below). @@ -423,9 +442,10 @@ void GoogleURLTracker::OnNavigationPending( // the tab close command since that means the load will never commit. Note // that in this case we don't need to close any previous infobar for this // tab since this navigation will close it. - registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); + registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, + navigation_controller_source); registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, - contents_source); + web_contents_source); } infobar_map_[infobar_helper] = (*infobar_creator_)(infobar_helper, search_url, @@ -433,18 +453,19 @@ void GoogleURLTracker::OnNavigationPending( } void GoogleURLTracker::OnNavigationCommittedOrTabClosed( - const content::NotificationSource& source, - const content::NotificationSource& contents_source, + const content::NotificationSource& navigation_controller_source, + const content::NotificationSource& web_contents_source, const InfoBarTabHelper* infobar_helper, - int type) { - registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); + bool navigated) { + registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, + navigation_controller_source); registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, - contents_source); + web_contents_source); InfoBarMap::iterator i(infobar_map_.find(infobar_helper)); DCHECK(i != infobar_map_.end()); DCHECK(need_to_prompt_); - if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) + if (navigated) i->second->Show(); else i->second->Close(false); // Close manually since it's not added to a tab. diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 565a32a..b85fb66b 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -126,16 +126,40 @@ class GoogleURLTracker : public content::URLFetcherDelegate, // NetworkChangeNotifier::IPAddressObserver virtual void OnIPAddressChanged() OVERRIDE; + // Called each time the user performs a search. This checks whether we need + // to prompt the user about a domain change, and if so, starts listening for + // the notifications sent when the actual load is triggered. void SearchCommitted(); - void OnNavigationPending(const content::NotificationSource& source, - const content::NotificationSource& contents_source, - InfoBarTabHelper* infobar_helper, - const GURL& search_url); + + // Called by Observe() after SearchCommitted() registers notification + // listeners, to indicate that we've received the "load now pending" + // notification. |navigation_controller_source| and |web_contents_source| are + // NotificationSources pointing to the associated NavigationController and + // WebContents, respectively, for this load; |infobar_helper| is the + // InfoBarTabHelper of the associated tab; and |search_url| is the actual + // search performed by the user, which if necessary we'll re-do on a new + // domain later. This function creates a (still-invisible) InfoBarDelegate + // for the associated tab and begins listening for the "load committed" + // notification that will tell us it's safe to show the infobar. + void OnNavigationPending( + const content::NotificationSource& navigation_controller_source, + const content::NotificationSource& web_contents_source, + InfoBarTabHelper* infobar_helper, + const GURL& search_url); + + // Called by Observe() once a load we're watching commits, or the associated + // tab is closed. The first three args are the same as for + // OnNavigationPending(); |navigated| is true when this call is due to a + // successful navigation (indicating that we should show our infobar) as + // opposed to tab closue (which means we should delete the infobar). void OnNavigationCommittedOrTabClosed( - const content::NotificationSource& source, - const content::NotificationSource& contents_source, + const content::NotificationSource& navigation_controller_source, + const content::NotificationSource& web_contents_source, const InfoBarTabHelper* infobar_helper, - int type); + bool navigated); + + // Closes all open infobars. If |redo_searches| is true, this also triggers + // each tab to re-perform the user's search, but on the new Google TLD. void CloseAllInfoBars(bool redo_searches); content::NotificationRegistrar registrar_; diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index c7e43f1..ba70121 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -245,8 +245,7 @@ void GoogleURLTrackerTest::CommitSearch(int unique_id) { google_url_tracker_->OnNavigationCommittedOrTabClosed(source, content::Source<content::WebContents>( reinterpret_cast<content::WebContents*>(unique_id)), - reinterpret_cast<InfoBarTabHelper*>(unique_id), - content::NOTIFICATION_NAV_ENTRY_COMMITTED); + reinterpret_cast<InfoBarTabHelper*>(unique_id), true); } } @@ -260,7 +259,7 @@ void GoogleURLTrackerTest::CloseTab(int unique_id) { google_url_tracker_->OnNavigationCommittedOrTabClosed( content::Source<content::NavigationController>( reinterpret_cast<content::NavigationController*>(unique_id)), - source, infobar_helper, content::NOTIFICATION_WEB_CONTENTS_DESTROYED); + source, infobar_helper, false); } else { // Normally, closing a tab with an infobar showing will close the infobar. // Since we don't have real tabs and are just faking things with magic |