diff options
-rw-r--r-- | chrome/browser/ui/search/search_tab_helper.cc | 103 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_tab_helper.h | 57 | ||||
-rw-r--r-- | chrome/browser/ui/search/search_types.h | 5 |
3 files changed, 19 insertions, 146 deletions
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index 36ea960..aa7f1dd 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -13,7 +13,6 @@ #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" -#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper) @@ -40,9 +39,7 @@ SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) : WebContentsObserver(web_contents), is_search_enabled_(IsSearchEnabled(web_contents)), is_initial_navigation_commit_(true), - model_(web_contents), - ntp_load_state_(DEFAULT), - main_frame_id_(0) { + model_(web_contents) { if (!is_search_enabled_) return; @@ -64,13 +61,13 @@ void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, if (user_input_in_progress) model_.SetMode(Mode(Mode::MODE_SEARCH_SUGGESTIONS, true)); else if (cancelling) - UpdateModelBasedOnURL(web_contents()->GetURL(), ntp_load_state_, true); + UpdateModelBasedOnURL(web_contents()->GetURL(), true); } void SearchTabHelper::NavigationEntryUpdated() { if (!is_search_enabled_) return; - UpdateModelBasedOnURL(web_contents()->GetURL(), ntp_load_state_, true); + UpdateModelBasedOnURL(web_contents()->GetURL(), true); } void SearchTabHelper::NavigateToPendingEntry( @@ -79,97 +76,33 @@ void SearchTabHelper::NavigateToPendingEntry( if (!is_search_enabled_) return; - ntp_load_state_ = DEFAULT; - main_frame_id_ = 0; - // Do not animate if this url is the very first navigation for the tab. // NTP mode changes are initiated at "pending", all others are initiated // when "committed". This is because NTP is rendered natively so is faster // to render than the web contents and we need to coordinate the animations. - if (IsNTP(url)) { - ntp_load_state_ = WAITING_FOR_FRAME_ID; - UpdateModelBasedOnURL(url, ntp_load_state_, !is_initial_navigation_commit_); - } -} - -void SearchTabHelper::DidStartProvisionalLoadForFrame( - int64 frame_id, - int64 parent_frame_id, - bool is_main_frame, - const GURL& validated_url, - bool is_error_page, - content::RenderViewHost* render_view_host) { - if (ntp_load_state_ == WAITING_FOR_FRAME_ID && - is_main_frame && IsNTP(validated_url)) { - content::NavigationEntry* pending_entry = - web_contents()->GetController().GetPendingEntry(); - if (pending_entry && IsNTP(pending_entry->GetURL())) { - ntp_load_state_ = WAITING_FOR_FRAME_LOAD; - main_frame_id_ = frame_id; - } - } -} - -void SearchTabHelper::DocumentLoadedInFrame( - int64 frame_id, - content::RenderViewHost* render_view_host) { - if (ntp_load_state_ == WAITING_FOR_FRAME_LOAD && main_frame_id_ == frame_id) { - ntp_load_state_ = WAITING_FOR_PAINT; - registrar_.Add( - this, - content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, - content::Source<content::RenderWidgetHost>(GetRenderWidgetHost())); - } + if (IsNTP(url)) + UpdateModelBasedOnURL(url, !is_initial_navigation_commit_); } void SearchTabHelper::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { - content::LoadCommittedDetails* committed_details = - content::Details<content::LoadCommittedDetails>(details).ptr(); - // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. - if (!IsNTP(committed_details->entry->GetURL())) { - UpdateModelBasedOnURL(committed_details->entry->GetURL(), - ntp_load_state_, - !is_initial_navigation_commit_); - } - is_initial_navigation_commit_ = false; - break; - } - - case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE: { - if (ntp_load_state_ == WAITING_FOR_PAINT) { - DCHECK_EQ(GetRenderWidgetHost(), - content::Source<content::RenderWidgetHost>(source).ptr()); - DCHECK(IsNTP(web_contents()->GetURL())); - ntp_load_state_ = PAINTED; - if (model_.mode().is_ntp()) { - UpdateModelBasedOnURL(web_contents()->GetURL(), - ntp_load_state_, - false); - } - registrar_.Remove( - this, - content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, - content::Source<content::RenderWidgetHost>(GetRenderWidgetHost())); - } - break; - } - - default: - NOTREACHED() << "Unexpected notification type."; + DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); + content::LoadCommittedDetails* committed_details = + content::Details<content::LoadCommittedDetails>(details).ptr(); + // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. + if (!IsNTP(committed_details->entry->GetURL())) { + UpdateModelBasedOnURL(committed_details->entry->GetURL(), + !is_initial_navigation_commit_); } + is_initial_navigation_commit_ = false; } -void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, - NTPLoadState load_state, - bool animate) { +void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { Mode::Type type = Mode::MODE_DEFAULT; if (IsNTP(url)) - type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; + type = Mode::MODE_NTP; else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) type = Mode::MODE_SEARCH_RESULTS; model_.SetMode(Mode(type, animate)); @@ -179,11 +112,5 @@ const content::WebContents* SearchTabHelper::web_contents() const { return model_.web_contents(); } -content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { - content::RenderWidgetHostView* rwhv = - web_contents()->GetRenderWidgetHostView(); - return rwhv ? rwhv->GetRenderWidgetHost() : NULL; -} - } // namespace search } // namespace chrome diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h index 295af6d..5a40934d 100644 --- a/chrome/browser/ui/search/search_tab_helper.h +++ b/chrome/browser/ui/search/search_tab_helper.h @@ -15,8 +15,6 @@ class OmniboxEditModel; namespace content { -class RenderViewHost; -class RenderWidgetHost; class WebContents; } @@ -49,16 +47,6 @@ class SearchTabHelper : public content::WebContentsObserver, virtual void NavigateToPendingEntry( const GURL& url, content::NavigationController::ReloadType reload_type) OVERRIDE; - virtual void DidStartProvisionalLoadForFrame( - int64 frame_id, - int64 parent_frame_id, - bool is_main_frame, - const GURL& validated_url, - bool is_error_page, - content::RenderViewHost* render_view_host) OVERRIDE; - virtual void DocumentLoadedInFrame( - int64 frame_id, - content::RenderViewHost* render_view_host) OVERRIDE; // Overridden from content::NotificationObserver: virtual void Observe(int type, @@ -69,46 +57,13 @@ class SearchTabHelper : public content::WebContentsObserver, explicit SearchTabHelper(content::WebContents* web_contents); friend class content::WebContentsUserData<SearchTabHelper>; - // Enum of the load states for the NTP. - // - // Once the user loads the NTP the |ntp_load_state_| changes to - // WAITING_FOR_FRAME_ID and the search::mode::Type changes to - // MODE_NTP_LOADING. The |ntp_load_state_| progresses through the remaining - // states and when done search::mode::Type is changed to MODE_NTP. - // - // This code is intended to avoid a flash between white (default background - // color) and the background the pages wants (gray). We know the CSS has been - // applied once we get DocumentLoadedInFrame() and we know the backing store - // has been updated once we get a paint. - enum NTPLoadState { - // The default initial state. - DEFAULT, - - // The user loaded the NTP and we're waiting for the id of the main frame. - WAITING_FOR_FRAME_ID, - - // We got the frame id (in |main_frame_id_|) and are waiting for the frame - // to complete loading. - WAITING_FOR_FRAME_LOAD, - - // The document finished loading. We're now waiting for a paint. - WAITING_FOR_PAINT, - - // The document finished painting. - PAINTED, - }; - - // Sets the mode of the model based on |url|. |state| distinguishes between - // loading and loaded ntp states. |animate| is based on initial navigation - // and used for the mode change on the |model_|. - void UpdateModelBasedOnURL(const GURL& url, NTPLoadState state, bool animate); + // Sets the mode of the model based on |url|. |animate| is based on initial + // navigation and used for the mode change on the |model_|. + void UpdateModelBasedOnURL(const GURL& url, bool animate); // Returns the web contents associated with the tab that owns this helper. const content::WebContents* web_contents() const; - // Returns the current RenderWidgetHost of the |web_contents()|. - content::RenderWidgetHost* GetRenderWidgetHost(); - const bool is_search_enabled_; bool is_initial_navigation_commit_; @@ -118,12 +73,6 @@ class SearchTabHelper : public content::WebContentsObserver, content::NotificationRegistrar registrar_; - // See description above NTPLoadState. - NTPLoadState ntp_load_state_; - - // See description above NTPLoadState. - int64 main_frame_id_; - DISALLOW_COPY_AND_ASSIGN(SearchTabHelper); }; diff --git a/chrome/browser/ui/search/search_types.h b/chrome/browser/ui/search/search_types.h index 9755bbc..b4804c1 100644 --- a/chrome/browser/ui/search/search_types.h +++ b/chrome/browser/ui/search/search_types.h @@ -46,9 +46,6 @@ struct Mode { // The default state means anything but the following states. MODE_DEFAULT, - // On the NTP page but the NTP web contents are not yet rendered. - MODE_NTP_LOADING, - // On the NTP page and the NTP is ready to be displayed. MODE_NTP, @@ -75,7 +72,7 @@ struct Mode { } bool is_ntp() const { - return mode == MODE_NTP || mode == MODE_NTP_LOADING; + return mode == MODE_NTP; } bool is_search() const { |