Chromium Code Reviews| Index: chrome/browser/ui/search/search_tab_helper.cc |
| diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc |
| index 4cbbd8aa2dfe33e1049e180d742d98c106842fdc..aba9f2d2ec7035dc7b60d9a1f9998ccd7bdbe3a9 100644 |
| --- a/chrome/browser/ui/search/search_tab_helper.cc |
| +++ b/chrome/browser/ui/search/search_tab_helper.cc |
| @@ -4,12 +4,17 @@ |
| #include "chrome/browser/ui/search/search_tab_helper.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/search/search.h" |
| #include "chrome/common/render_messages.h" |
| #include "chrome/common/url_constants.h" |
| +#include "content/public/browser/navigation_controller.h" |
| +#include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/navigation_type.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| +#include "content/public/browser/web_contents.h" |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(SearchTabHelper); |
| @@ -30,6 +35,14 @@ bool IsSearchResults(const content::WebContents* contents) { |
| return !chrome::GetSearchTerms(contents).empty(); |
| } |
| +// TODO(kmadhusu): Move this helper from anonymous namespace to chrome |
| +// namespace and remove InstantPage::IsLocal(). |
| +bool IsLocal(const content::WebContents* contents) { |
| + return contents && |
| + (contents->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || |
| + contents->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); |
| +} |
| + |
| } // namespace |
| SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| @@ -42,6 +55,9 @@ SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| if (!is_search_enabled_) |
| return; |
| + // Observe for NOTIFICATION_NAV_ENTRY_COMMITTED event to reset the local |
|
samarth
2013/06/19 05:25:02
nit: Observe NOTIFICATION_NAV_ENTRY_COMMITTED even
kmadhusu
2013/06/19 16:28:15
Done.
|
| + // states (such as mode, last known most visited items, instant support state, |
| + // etc). |
| registrar_.Add( |
| this, |
| content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| @@ -84,13 +100,39 @@ bool SearchTabHelper::UpdateLastKnownMostVisitedItems( |
| return true; |
| } |
| +void SearchTabHelper::InstantSupportChanged(bool instant_support) { |
| + if (!is_search_enabled_) |
| + return; |
| + |
| + model_.SetInstantSupportState(instant_support ? INSTANT_SUPPORT_YES : |
| + INSTANT_SUPPORT_NO); |
| +} |
| + |
| +bool SearchTabHelper::SupportsInstant() const { |
| + return model_.instant_support() == INSTANT_SUPPORT_YES; |
| +} |
| + |
| void SearchTabHelper::Observe( |
| int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
| + content::LoadCommittedDetails* load_details = |
| + content::Details<content::LoadCommittedDetails>(details).ptr(); |
| + if (!load_details->is_main_frame) |
| + return; |
| + |
| UpdateMode(); |
| last_known_most_visited_items_.clear(); |
| + |
| + // Already determined the instant support state for this page, do not reset |
| + // the instant support state. |
| + if (load_details->is_in_page || |
|
samarth
2013/06/19 05:25:02
Add a comment why we check both fields and link to
kmadhusu
2013/06/19 16:28:15
Done.
|
| + load_details->type == content::NAVIGATION_TYPE_IN_PAGE) { |
| + return; |
| + } |
| + |
| + model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN); |
| } |
| bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| @@ -100,11 +142,22 @@ bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| OnSearchBoxShowBars) |
| IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| OnSearchBoxHideBars) |
| + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| + OnInstantSupportDetermined) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| } |
| +void SearchTabHelper::DidFinishLoad( |
| + int64 /* frame_id */, |
| + const GURL& /* validated_url */, |
| + bool is_main_frame, |
| + content::RenderViewHost* /* render_view_host */) { |
| + if (is_main_frame) |
| + DetermineIfPageSupportsInstant(); |
| +} |
| + |
| void SearchTabHelper::UpdateMode() { |
| SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| @@ -127,12 +180,39 @@ void SearchTabHelper::UpdateMode() { |
| // OmniboxEditModel::SetInputInProgress() which is called from |
| // OmniboxEditModel::Revert(). |
| model_.SetState(SearchModel::State(SearchMode(type, origin), |
| - model_.state().top_bars_visible)); |
| + model_.state().top_bars_visible, |
| + model_.instant_support())); |
| } else { |
| model_.SetMode(SearchMode(type, origin)); |
| } |
| } |
| +void SearchTabHelper::DetermineIfPageSupportsInstant() { |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| + if (!chrome::ShouldAssignURLToInstantRenderer(web_contents_->GetURL(), |
| + profile)) { |
| + // The page is not in the Instant process. This page does not support |
| + // instant. If we send an IPC message to a page that is not in the Instant |
| + // process, it will never receive it and will never respond. Therefore, |
| + // return immediately. |
| + InstantSupportChanged(false); |
| + } else if (IsLocal(web_contents_)) { |
| + // Local pages always support Instant. |
| + InstantSupportChanged(true); |
| + } else { |
| + Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| + } |
| +} |
| + |
| +void SearchTabHelper::OnInstantSupportDetermined(int page_id, |
| + bool instant_support) { |
| + if (!web_contents()->IsActiveEntry(page_id)) |
| + return; |
| + |
| + InstantSupportChanged(instant_support); |
| +} |
| + |
| void SearchTabHelper::OnSearchBoxShowBars(int page_id) { |
| if (web_contents()->IsActiveEntry(page_id)) |
| model_.SetTopBarsVisible(true); |