Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 16035020: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed failing tests. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f84abbe21c027d19f891a5be143590ff03eeace2..b3b9b07611cd0168281ed2c617b0ec47aa0bd579 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -4,12 +4,16 @@
#include "chrome/browser/ui/search/search_tab_helper.h"
+#include "chrome/browser/google/google_util.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_entry.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 +34,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 +54,9 @@ SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
if (!is_search_enabled_)
return;
+ // Observe for NOTIFICATION_NAV_ENTRY_COMMITTED event to reset the local
+ // states (such as mode, last known most visited items, instant support state,
+ // etc).
registrar_.Add(
this,
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -84,12 +99,48 @@ 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);
+
samarth 2013/06/18 04:33:17 The notification details tell you whether this not
kmadhusu 2013/06/18 20:58:23 Done.
UpdateMode();
+
+ content::NavigationController* controller =
samarth 2013/06/18 04:33:17 I played with this and is_in_page is generally the
kmadhusu 2013/06/18 20:58:23 Done.
+ content::Source<content::NavigationController>(source).ptr();
+ content::NavigationEntry *entry = controller->GetActiveEntry();
+ if (!entry)
+ return;
+
+ // If the commit is a GENERATED commit with a Google search URL, then it is an
+ // Omnibox search.
+ //
+ // Do not reset instant support state if the navigation entry is a Google
+ // search url and it is not from the Omnibox.
+ //
+ // For e.g. When an user switches mode in the search result page, we generate
+ // a Google search url which is not an omnibox search url. Since we have
+ // already determined the instant support state for that page, do not reset
+ // the instant support state.
+ if (google_util::IsGoogleSearchUrl(entry->GetURL().spec()) &&
+ !google_util::IsOmniboxGoogleSearchNavigation(*entry)) {
+ return;
+ }
+
+ model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN);
}
bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) {
@@ -99,11 +150,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;
@@ -126,12 +188,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);
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698