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

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: Addressed nits 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 4cbbd8aa2dfe33e1049e180d742d98c106842fdc..d191ce9c87921ce9f3d54c8b7c48d7726363a516 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 NOTIFICATION_NAV_ENTRY_COMMITTED events so we can reset state
+ // associated with the WebContents (such as mode, last known most visited
+ // items, instant support state etc).
registrar_.Add(
this,
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -84,13 +100,47 @@ 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.
+ //
+ // When we get a navigation entry committed event, there seem to be two ways
+ // to tell whether the navigation was "in-page". Ideally, when
+ // LoadCommittedDetails::is_in_page is true, we should have
+ // LoadCommittedDetails::type to be NAVIGATION_TYPE_IN_PAGE. Unfortunately,
+ // they are different in some cases. To workaround this bug, we are checking
+ // (is_in_page || type == NAVIGATION_TYPE_IN_PAGE). Please refer to
+ // crbug.com/251330 for more details.
+ if (load_details->is_in_page ||
+ load_details->type == content::NAVIGATION_TYPE_IN_PAGE) {
+ return;
+ }
+
+ model_.SetInstantSupportState(INSTANT_SUPPORT_UNKNOWN);
}
bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) {
@@ -100,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;
@@ -127,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