summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 00:10:59 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-10 00:10:59 +0000
commit82808d0a2f8404400662b0362b04d83f65d0b7f2 (patch)
treeca874ccdbda8c7dd92c031b66c8e20250ed0839a
parent8b66900f4c510b01f8f447f82f7c0a1d0c45fef5 (diff)
downloadchromium_src-82808d0a2f8404400662b0362b04d83f65d0b7f2.zip
chromium_src-82808d0a2f8404400662b0362b04d83f65d0b7f2.tar.gz
chromium_src-82808d0a2f8404400662b0362b04d83f65d0b7f2.tar.bz2
Implement SearchTabHelperDelegate.
This CL, - Removes chrome::FindBrowser...() function calls from search_tab_helper.cc. - Creates a SearchTabHelperDelegate interface and have the Browser object implement that interface to provide the necessary functionality to SearchTabHelper. BUG=272583 TEST=none Review URL: https://codereview.chromium.org/222923007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262871 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/browser.cc54
-rw-r--r--chrome/browser/ui/browser.h17
-rw-r--r--chrome/browser/ui/search/search_tab_helper.cc105
-rw-r--r--chrome/browser/ui/search/search_tab_helper.h12
-rw-r--r--chrome/browser/ui/search/search_tab_helper_delegate.cc26
-rw-r--r--chrome/browser/ui/search/search_tab_helper_delegate.h50
-rw-r--r--chrome/chrome_browser_ui.gypi2
7 files changed, 170 insertions, 96 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index ea8e8dc..b353ff2 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -59,6 +59,7 @@
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/infobars/simple_alert_infobar_delegate.h"
#include "chrome/browser/lifetime/application_lifetime.h"
@@ -131,6 +132,7 @@
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
#include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
#include "chrome/browser/ui/unload_controller.h"
#include "chrome/browser/ui/validation_message_bubble.h"
@@ -773,12 +775,6 @@ void Browser::VisibleSSLStateChanged(content::WebContents* web_contents) {
UpdateToolbar(false);
}
-void Browser::OnWebContentsInstantSupportDisabled(
- const content::WebContents* web_contents) {
- DCHECK(web_contents);
- if (tab_strip_model_->GetActiveWebContents() == web_contents)
- UpdateToolbar(false);
-}
///////////////////////////////////////////////////////////////////////////////
// Browser, Assorted browser commands:
@@ -1761,6 +1757,51 @@ void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
}
///////////////////////////////////////////////////////////////////////////////
+// Browser, SearchTabHelperDelegate implementation:
+
+void Browser::NavigateOnThumbnailClick(const GURL& url,
+ WindowOpenDisposition disposition,
+ content::WebContents* source_contents) {
+ DCHECK(source_contents);
+ // We're guaranteed that AUTO_BOOKMARK is the right transition since this only
+ // gets called to handle clicks in the new tab page (to navigate to most
+ // visited item URLs) and in the search results page (to navigate to
+ // privileged destinations (e.g. chrome://URLs)).
+ //
+ // TODO(kmadhusu): Page transitions to privileged destinations should be
+ // marked as "LINK" instead of "AUTO_BOOKMARK"?
+ chrome::NavigateParams params(this, url,
+ content::PAGE_TRANSITION_AUTO_BOOKMARK);
+ params.referrer = content::Referrer();
+ params.source_contents = source_contents;
+ params.disposition = disposition;
+ params.is_renderer_initiated = false;
+ params.initiating_profile = profile_;
+ chrome::Navigate(&params);
+}
+
+void Browser::OnWebContentsInstantSupportDisabled(
+ const content::WebContents* web_contents) {
+ DCHECK(web_contents);
+ if (tab_strip_model_->GetActiveWebContents() == web_contents)
+ UpdateToolbar(false);
+}
+
+OmniboxView* Browser::GetOmniboxView() {
+ return window_->GetLocationBar()->GetOmniboxView();
+}
+
+std::set<std::string> Browser::GetOpenUrls() {
+ history::TopSites* top_sites = profile_->GetTopSites();
+ if (!top_sites) // NULL for Incognito profiles.
+ return std::set<std::string>();
+
+ std::set<std::string> open_urls;
+ chrome::GetOpenUrls(*tab_strip_model_, *top_sites, &open_urls);
+ return open_urls;
+}
+
+///////////////////////////////////////////////////////////////////////////////
// Browser, web_modal::WebContentsModalDialogManagerDelegate implementation:
void Browser::SetWebContentsBlocked(content::WebContents* web_contents,
@@ -2143,6 +2184,7 @@ void Browser::SetAsDelegate(WebContents* web_contents, Browser* delegate) {
SetDelegate(delegate);
CoreTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
SearchEngineTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
+ SearchTabHelper::FromWebContents(web_contents)->set_delegate(delegate);
ZoomController::FromWebContents(web_contents)->set_observer(delegate);
TranslateTabHelper* translate_tab_helper =
TranslateTabHelper::FromWebContents(web_contents);
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 2544bfc..ccb83b9 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -25,6 +25,7 @@
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/browser/ui/search/search_tab_helper_delegate.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
@@ -97,6 +98,7 @@ class Browser : public TabStripModelObserver,
public content::WebContentsDelegate,
public CoreTabHelperDelegate,
public SearchEngineTabHelperDelegate,
+ public SearchTabHelperDelegate,
public ChromeWebModalDialogManagerDelegate,
public BookmarkTabHelperDelegate,
public ZoomObserver,
@@ -353,11 +355,6 @@ class Browser : public TabStripModelObserver,
// Invoked when visible SSL state (as defined by SSLStatus) changes.
void VisibleSSLStateChanged(content::WebContents* web_contents);
- // Invoked when the |web_contents| no longer supports Instant. Refreshes the
- // omnibox so it no longer shows search terms.
- void OnWebContentsInstantSupportDisabled(
- const content::WebContents* web_contents);
-
// Assorted browser commands ////////////////////////////////////////////////
// NOTE: Within each of the following sections, the IDs are ordered roughly by
@@ -662,6 +659,16 @@ class Browser : public TabStripModelObserver,
virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
Profile* profile) OVERRIDE;
+ // Overridden from SearchTabHelperDelegate:
+ virtual void NavigateOnThumbnailClick(
+ const GURL& url,
+ WindowOpenDisposition disposition,
+ content::WebContents* source_contents) OVERRIDE;
+ virtual void OnWebContentsInstantSupportDisabled(
+ const content::WebContents* web_contents) OVERRIDE;
+ virtual OmniboxView* GetOmniboxView() OVERRIDE;
+ virtual std::set<std::string> GetOpenUrls() OVERRIDE;
+
// Overridden from WebContentsModalDialogManagerDelegate:
virtual void SetWebContentsBlocked(content::WebContents* web_contents,
bool blocked) OVERRIDE;
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 0dd787b..1dc0cf6 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -10,18 +10,14 @@
#include "base/metrics/histogram.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
-#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/most_visited_tiles_experiment.h"
-#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
@@ -29,9 +25,8 @@
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/search_ipc_router_policy_impl.h"
+#include "chrome/browser/ui/search/search_tab_helper_delegate.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
#include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/signin_manager.h"
@@ -113,20 +108,6 @@ bool InInstantProcess(Profile* profile,
contents->GetRenderProcessHost()->GetID());
}
-// Updates the location bar to reflect |contents| Instant support state.
-void UpdateLocationBar(content::WebContents* contents) {
-// iOS and Android don't use the Instant framework.
-#if !defined(OS_IOS) && !defined(OS_ANDROID)
- if (!contents)
- return;
-
- Browser* browser = chrome::FindBrowserWithWebContents(contents);
- if (!browser)
- return;
- browser->OnWebContentsInstantSupportDisabled(contents);
-#endif
-}
-
// Called when an NTP finishes loading. If the load start time was noted,
// calculates and logs the total load time.
void RecordNewTabLoadTime(content::WebContents* contents) {
@@ -140,19 +121,6 @@ void RecordNewTabLoadTime(content::WebContents* contents) {
core_tab_helper->set_new_tab_start_time(base::TimeTicks());
}
-// Returns the OmniboxView for |contents| or NULL if not available.
-OmniboxView* GetOmniboxView(content::WebContents* contents) {
- // iOS and Android don't use the Instant framework.
-#if defined(OS_IOS) || defined(OS_ANDROID)
- return NULL;
-#else
- if (!contents)
- return NULL;
- Browser* browser = chrome::FindBrowserWithWebContents(contents);
- return browser ? browser->window()->GetLocationBar()->GetOmniboxView() : NULL;
-#endif
-}
-
} // namespace
SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
@@ -162,7 +130,8 @@ SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
ipc_router_(web_contents, this,
make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents))
.PassAs<SearchIPCRouter::Policy>()),
- instant_service_(NULL) {
+ instant_service_(NULL),
+ delegate_(NULL) {
if (!is_search_enabled_)
return;
@@ -226,8 +195,8 @@ void SearchTabHelper::InstantSupportChanged(bool instant_support) {
web_contents_->GetController().GetVisibleEntry();
if (entry) {
chrome::SetInstantSupportStateInNavigationEntry(new_state, entry);
- if (!instant_support)
- UpdateLocationBar(web_contents_);
+ if (delegate_ && !instant_support)
+ delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
}
}
@@ -382,8 +351,8 @@ void SearchTabHelper::NavigationEntryCommitted(
// location bar from here to turn off search terms replacement.
chrome::SetInstantSupportStateInNavigationEntry(model_.instant_support(),
entry);
- if (model_.instant_support() == INSTANT_SUPPORT_NO)
- UpdateLocationBar(web_contents_);
+ if (delegate_ && model_.instant_support() == INSTANT_SUPPORT_NO)
+ delegate_->OnWebContentsInstantSupportDisabled(web_contents_);
return;
}
@@ -418,38 +387,18 @@ void SearchTabHelper::OmniboxStartMarginChanged(int omnibox_start_margin) {
void SearchTabHelper::MaybeRemoveMostVisitedItems(
std::vector<InstantMostVisitedItem>* items) {
-// The code below uses APIs not available on Android and the experiment should
-// not run there.
-#if !defined(OS_ANDROID)
- if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled())
+ if (!delegate_)
return;
- Profile* profile =
- Profile::FromBrowserContext(web_contents_->GetBrowserContext());
- if (!profile)
- return;
-
- Browser* browser = chrome::FindBrowserWithProfile(profile,
- chrome::GetActiveDesktop());
- if (!browser)
- return;
-
- TabStripModel* tab_strip_model = browser->tab_strip_model();
- history::TopSites* top_sites = profile->GetTopSites();
- if (!tab_strip_model || !top_sites) {
- NOTREACHED();
+ if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled())
return;
- }
- std::set<std::string> open_urls;
- chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls);
history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs(
- open_urls, items);
-#endif
+ delegate_->GetOpenUrls(), items);
}
void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) {
- OmniboxView* omnibox = GetOmniboxView(web_contents());
+ OmniboxView* omnibox = GetOmniboxView();
if (!omnibox)
return;
@@ -489,31 +438,13 @@ void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) {
void SearchTabHelper::NavigateToURL(const GURL& url,
WindowOpenDisposition disposition,
bool is_most_visited_item_url) {
-// iOS and Android don't use the Instant framework.
-#if !defined(OS_IOS) && !defined(OS_ANDROID)
- // TODO(kmadhusu): Remove chrome::FindBrowser...() function call from here.
- // Create a SearchTabHelperDelegate interface and have the Browser object
- // implement that interface to provide the necessary functionality.
- Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
- Profile* profile =
- Profile::FromBrowserContext(web_contents_->GetBrowserContext());
- if (!browser || !profile)
- return;
-
if (is_most_visited_item_url) {
content::RecordAction(
base::UserMetricsAction("InstantExtended.MostVisitedClicked"));
}
- chrome::NavigateParams params(browser, url,
- content::PAGE_TRANSITION_AUTO_BOOKMARK);
- params.referrer = content::Referrer();
- params.source_contents = web_contents_;
- params.disposition = disposition;
- params.is_renderer_initiated = false;
- params.initiating_profile = profile;
- chrome::Navigate(&params);
-#endif
+ if (delegate_)
+ delegate_->NavigateOnThumbnailClick(url, disposition, web_contents_);
}
void SearchTabHelper::OnDeleteMostVisitedItem(const GURL& url) {
@@ -551,7 +482,7 @@ void SearchTabHelper::OnLogMostVisitedNavigation(
}
void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) {
- OmniboxView* omnibox = GetOmniboxView(web_contents());
+ OmniboxView* omnibox = GetOmniboxView();
if (!omnibox)
return;
@@ -597,7 +528,7 @@ void SearchTabHelper::UpdateMode(bool update_origin, bool is_preloaded_ntp) {
if (!update_origin)
origin = model_.mode().origin;
- OmniboxView* omnibox = GetOmniboxView(web_contents());
+ OmniboxView* omnibox = GetOmniboxView();
if (omnibox && omnibox->model()->user_input_in_progress())
type = SearchMode::MODE_SEARCH_SUGGESTIONS;
@@ -639,7 +570,11 @@ void SearchTabHelper::RedirectToLocalNTP() {
}
bool SearchTabHelper::IsInputInProgress() const {
- OmniboxView* omnibox = GetOmniboxView(web_contents());
+ OmniboxView* omnibox = GetOmniboxView();
return !model_.mode().is_ntp() && omnibox &&
omnibox->model()->focus_state() == OMNIBOX_FOCUS_VISIBLE;
}
+
+OmniboxView* SearchTabHelper::GetOmniboxView() const {
+ return delegate_ ? delegate_->GetOmniboxView() : NULL;
+}
diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h
index 00ee8af..38e6bd0 100644
--- a/chrome/browser/ui/search/search_tab_helper.h
+++ b/chrome/browser/ui/search/search_tab_helper.h
@@ -28,8 +28,10 @@ struct LoadCommittedDetails;
class GURL;
class InstantPageTest;
class InstantService;
+class OmniboxView;
class Profile;
class SearchIPCRouterTest;
+class SearchTabHelperDelegate;
// Per-tab search "helper". Acts as the owner and controller of the tab's
// search UI model.
@@ -92,6 +94,8 @@ class SearchTabHelper : public content::WebContentsObserver,
// Returns true if the underlying page is a search results page.
bool IsSearchResultsPage();
+ void set_delegate(SearchTabHelperDelegate* delegate) { delegate_ = delegate; }
+
private:
friend class content::WebContentsUserData<SearchTabHelper>;
friend class InstantPageTest;
@@ -211,6 +215,9 @@ class SearchTabHelper : public content::WebContentsObserver,
// active tab is in mode SEARCH_SUGGESTIONS.
bool IsInputInProgress() const;
+ // Returns the OmniboxView for |web_contents_| or NULL if not available.
+ OmniboxView* GetOmniboxView() const;
+
const bool is_search_enabled_;
// Model object for UI that cares about search state.
@@ -222,6 +229,11 @@ class SearchTabHelper : public content::WebContentsObserver,
InstantService* instant_service_;
+ // Delegate for notifying our owner about the SearchTabHelper state. Not owned
+ // by us.
+ // NULL on iOS and Android because they don't use the Instant framework.
+ SearchTabHelperDelegate* delegate_;
+
DISALLOW_COPY_AND_ASSIGN(SearchTabHelper);
};
diff --git a/chrome/browser/ui/search/search_tab_helper_delegate.cc b/chrome/browser/ui/search/search_tab_helper_delegate.cc
new file mode 100644
index 0000000..97f350e
--- /dev/null
+++ b/chrome/browser/ui/search/search_tab_helper_delegate.cc
@@ -0,0 +1,26 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/search/search_tab_helper_delegate.h"
+
+void SearchTabHelperDelegate::NavigateOnThumbnailClick(
+ const GURL& url,
+ WindowOpenDisposition disposition,
+ content::WebContents* source_contents) {
+}
+
+void SearchTabHelperDelegate::OnWebContentsInstantSupportDisabled(
+ const content::WebContents* web_contents) {
+}
+
+OmniboxView* SearchTabHelperDelegate::GetOmniboxView() {
+ return NULL;
+}
+
+std::set<std::string> SearchTabHelperDelegate::GetOpenUrls() {
+ return std::set<std::string>();
+}
+
+SearchTabHelperDelegate::~SearchTabHelperDelegate() {
+}
diff --git a/chrome/browser/ui/search/search_tab_helper_delegate.h b/chrome/browser/ui/search/search_tab_helper_delegate.h
new file mode 100644
index 0000000..8bbbfe2
--- /dev/null
+++ b/chrome/browser/ui/search/search_tab_helper_delegate.h
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_DELEGATE_H_
+#define CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_DELEGATE_H_
+
+#include <set>
+#include <string>
+
+#include "ui/base/window_open_disposition.h"
+
+namespace content {
+class WebContents;
+}
+
+class GURL;
+class OmniboxView;
+
+// Objects implement this interface to get notified about changes in the
+// SearchTabHelper and to provide necessary functionality.
+class SearchTabHelperDelegate {
+ public:
+ // Navigates the page to |url| in response to a click event. Usually used
+ // by the page to navigate to privileged destinations (e.g. chrome:// URLs) or
+ // to navigate to URLs that are hidden from the page using Restricted IDs
+ // (rid in the API).
+ //
+ // TODO(kmadhusu): Handle search results page navigations to privileged
+ // destinations in a seperate function. This function should handle only the
+ // new tab page thumbnail click events.
+ virtual void NavigateOnThumbnailClick(const GURL& url,
+ WindowOpenDisposition disposition,
+ content::WebContents* source_contents);
+
+ // Invoked when the |web_contents| no longer supports Instant.
+ virtual void OnWebContentsInstantSupportDisabled(
+ const content::WebContents* web_contents);
+
+ // Returns the OmniboxView or NULL if not available.
+ virtual OmniboxView* GetOmniboxView();
+
+ // Returns a set containing the canonical URLs of the currently open tabs.
+ virtual std::set<std::string> GetOpenUrls();
+
+ protected:
+ virtual ~SearchTabHelperDelegate();
+};
+
+#endif // CHROME_BROWSER_UI_SEARCH_SEARCH_TAB_HELPER_DELEGATE_H_
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 240c99d..e25e53a 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1554,6 +1554,8 @@
'browser/ui/search/search_model_observer.h',
'browser/ui/search/search_tab_helper.cc',
'browser/ui/search/search_tab_helper.h',
+ 'browser/ui/search/search_tab_helper_delegate.cc',
+ 'browser/ui/search/search_tab_helper_delegate.h',
'browser/ui/search/search_ui.cc',
'browser/ui/search/search_ui.h',
'browser/ui/search_engines/edit_search_engine_controller.cc',