summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 19:05:07 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 19:05:07 +0000
commitef01920da052e2e52acd193c93792a11744295ab (patch)
treeeabe4a35e3a9e49479d31ed6d1caad1bbab34142
parent1dd534aedf5661cdc4703a57124c902b39d6f2b0 (diff)
downloadchromium_src-ef01920da052e2e52acd193c93792a11744295ab.zip
chromium_src-ef01920da052e2e52acd193c93792a11744295ab.tar.gz
chromium_src-ef01920da052e2e52acd193c93792a11744295ab.tar.bz2
Switch OmniboxSearchHint to use WebContentsUserData.
BUG=107201 TEST=no visible change Review URL: https://chromiumcodereview.appspot.com/10951008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157392 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/omnibox_search_hint.cc40
-rw-r--r--chrome/browser/omnibox_search_hint.h20
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents.cc7
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents.h2
4 files changed, 41 insertions, 28 deletions
diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc
index b284e57..93b5cf1 100644
--- a/chrome/browser/omnibox_search_hint.cc
+++ b/chrome/browser/omnibox_search_hint.cc
@@ -42,6 +42,8 @@
using content::NavigationController;
using content::NavigationEntry;
+int OmniboxSearchHint::kUserDataKey;
+
// The URLs of search engines for which we want to trigger the infobar.
const char* const kSearchEngineURLs[] = {
"http://www.google.com/",
@@ -57,7 +59,8 @@ const char* const kSearchEngineURLs[] = {
class HintInfoBar : public ConfirmInfoBarDelegate {
public:
- explicit HintInfoBar(OmniboxSearchHint* omnibox_hint);
+ HintInfoBar(OmniboxSearchHint* omnibox_hint,
+ InfoBarTabHelper* infobar_tab_helper);
private:
virtual ~HintInfoBar();
@@ -90,8 +93,9 @@ class HintInfoBar : public ConfirmInfoBarDelegate {
DISALLOW_COPY_AND_ASSIGN(HintInfoBar);
};
-HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint)
- : ConfirmInfoBarDelegate(omnibox_hint->tab()->infobar_tab_helper()),
+HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint,
+ InfoBarTabHelper* infobar_tab_helper)
+ : ConfirmInfoBarDelegate(infobar_tab_helper),
omnibox_hint_(omnibox_hint),
action_taken_(false),
should_expire_(false),
@@ -155,8 +159,9 @@ bool HintInfoBar::ShouldExpireInternal(
// OmniboxSearchHint ----------------------------------------------------------
-OmniboxSearchHint::OmniboxSearchHint(TabContents* tab) : tab_(tab) {
- NavigationController* controller = &(tab->web_contents()->GetController());
+OmniboxSearchHint::OmniboxSearchHint(content::WebContents* web_contents)
+ : web_contents_(web_contents) {
+ NavigationController* controller = &(web_contents->GetController());
notification_registrar_.Add(
this,
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -165,10 +170,12 @@ OmniboxSearchHint::OmniboxSearchHint(TabContents* tab) : tab_(tab) {
for (size_t i = 0; i < arraysize(kSearchEngineURLs); ++i)
search_engine_urls_[kSearchEngineURLs[i]] = 1;
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
// Listen for omnibox to figure-out when the user searches from the omnibox.
notification_registrar_.Add(this,
chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
- content::Source<Profile>(tab->profile()));
+ content::Source<Profile>(profile));
}
OmniboxSearchHint::~OmniboxSearchHint() {
@@ -179,15 +186,17 @@ void OmniboxSearchHint::Observe(int type,
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
content::NavigationEntry* entry =
- tab_->web_contents()->GetController().GetActiveEntry();
+ web_contents_->GetController().GetActiveEntry();
if (search_engine_urls_.find(entry->GetURL().spec()) ==
search_engine_urls_.end()) {
// The search engine is not in our white-list, bail.
return;
}
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext());
const TemplateURL* const default_provider =
- TemplateURLServiceFactory::GetForProfile(tab_->profile())->
- GetDefaultSearchProvider();
+ TemplateURLServiceFactory::GetForProfile(profile)->
+ GetDefaultSearchProvider();
if (!default_provider)
return;
@@ -206,12 +215,14 @@ void OmniboxSearchHint::Observe(int type,
}
void OmniboxSearchHint::ShowInfoBar() {
- tab_->infobar_tab_helper()->AddInfoBar(new HintInfoBar(this));
+ InfoBarTabHelper* infobar_tab_helper =
+ TabContents::FromWebContents(web_contents_)->infobar_tab_helper();
+ infobar_tab_helper->AddInfoBar(new HintInfoBar(this, infobar_tab_helper));
}
void OmniboxSearchHint::ShowEnteringQuery() {
LocationBar* location_bar = browser::FindBrowserWithWebContents(
- tab_->web_contents())->window()->GetLocationBar();
+ web_contents_)->window()->GetLocationBar();
OmniboxView* omnibox_view = location_bar->GetLocationEntry();
location_bar->FocusLocation(true);
omnibox_view->SetUserText(
@@ -227,8 +238,9 @@ void OmniboxSearchHint::DisableHint() {
// OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint
// prefs to false, none of them are needed anymore.
notification_registrar_.RemoveAll();
- tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint,
- false);
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext());
+ profile->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, false);
}
// static
@@ -237,5 +249,5 @@ bool OmniboxSearchHint::IsEnabled(Profile* profile) {
// the user did not dismiss the infobar before.
return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) &&
CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kSearchInOmniboxHint);
+ switches::kSearchInOmniboxHint);
}
diff --git a/chrome/browser/omnibox_search_hint.h b/chrome/browser/omnibox_search_hint.h
index 90fd9b4..2364669 100644
--- a/chrome/browser/omnibox_search_hint.h
+++ b/chrome/browser/omnibox_search_hint.h
@@ -9,20 +9,24 @@
#include <string>
#include "base/compiler_specific.h"
+#include "chrome/browser/tab_contents/web_contents_user_data.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
-class TabContents;
+
+namespace content {
+class WebContents;
+}
// This class is responsible for showing an info-bar that tells the user she
// can type her search query directly in the omnibox.
// It is displayed when the user visits a known search engine URL and has not
// searched from the omnibox before, or has not previously dismissed a similar
// info-bar.
-class OmniboxSearchHint : public content::NotificationObserver {
+class OmniboxSearchHint : public content::NotificationObserver,
+ public WebContentsUserData<OmniboxSearchHint> {
public:
- explicit OmniboxSearchHint(TabContents* tab);
virtual ~OmniboxSearchHint();
// content::NotificationObserver method:
@@ -34,8 +38,6 @@ class OmniboxSearchHint : public content::NotificationObserver {
// queries can be typed directly in there.
void ShowEnteringQuery();
- TabContents* tab() { return tab_; }
-
// Disables the hint infobar permanently, so that it does not show ever again.
void DisableHint();
@@ -44,12 +46,16 @@ class OmniboxSearchHint : public content::NotificationObserver {
static bool IsEnabled(Profile* profile);
private:
+ explicit OmniboxSearchHint(content::WebContents* web_contents);
+ static int kUserDataKey;
+ friend class WebContentsUserData<OmniboxSearchHint>;
+
void ShowInfoBar();
content::NotificationRegistrar notification_registrar_;
- // The tab we are associated with.
- TabContents* tab_;
+ // The contents we are associated with.
+ content::WebContents* web_contents_;
// A map containing the URLs of the search engine for which we want to
// trigger the hint.
diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc
index bb7bb91..93e0c78 100644
--- a/chrome/browser/ui/tab_contents/tab_contents.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents.cc
@@ -165,6 +165,8 @@ TabContents::TabContents(WebContents* contents)
#endif
#if !defined(OS_ANDROID)
+ if (OmniboxSearchHint::IsEnabled(profile()))
+ OmniboxSearchHint::CreateForWebContents(contents);
PDFTabHelper::CreateForWebContents(contents);
sad_tab_helper_.reset(new SadTabHelper(contents));
web_intent_picker_controller_.reset(new WebIntentPickerController(this));
@@ -179,11 +181,6 @@ TabContents::TabContents(WebContents* contents)
webnavigation_observer_.reset(
new extensions::WebNavigationTabObserver(contents));
-#if !defined(OS_ANDROID)
- if (OmniboxSearchHint::IsEnabled(profile()))
- omnibox_search_hint_.reset(new OmniboxSearchHint(this));
-#endif
-
#if defined(ENABLE_PRINTING)
print_view_manager_.reset(new printing::PrintViewManager(this));
print_preview_.reset(new printing::PrintPreviewMessageHandler(contents));
diff --git a/chrome/browser/ui/tab_contents/tab_contents.h b/chrome/browser/ui/tab_contents/tab_contents.h
index e9ea020..2c9c419 100644
--- a/chrome/browser/ui/tab_contents/tab_contents.h
+++ b/chrome/browser/ui/tab_contents/tab_contents.h
@@ -40,7 +40,6 @@ class InfoBarTabHelper;
class InstantLoader;
class NavigationMetricsRecorder;
class OffscreenTabContentsCreator;
-class OmniboxSearchHint;
class PanelHost;
class PasswordManager;
class PasswordManagerDelegate;
@@ -355,7 +354,6 @@ class TabContents : public content::WebContentsObserver {
scoped_ptr<extensions::WebNavigationTabObserver> webnavigation_observer_;
scoped_ptr<ExternalProtocolObserver> external_protocol_observer_;
scoped_ptr<NavigationMetricsRecorder> navigation_metrics_recorder_;
- scoped_ptr<OmniboxSearchHint> omnibox_search_hint_;
#if defined(ENABLE_ONE_CLICK_SIGNIN)
scoped_ptr<OneClickSigninHelper> one_click_signin_helper_;
#endif