| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/omnibox_search_hint.h" | 5 #include "chrome/browser/omnibox_search_hint.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "content/public/browser/navigation_details.h" | 30 #include "content/public/browser/navigation_details.h" |
| 31 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 32 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | |
| 40 | 39 |
| 41 using content::NavigationController; | 40 using content::NavigationController; |
| 42 using content::NavigationEntry; | 41 using content::NavigationEntry; |
| 43 | 42 |
| 44 | 43 |
| 45 // HintInfoBarDelegate --------------------------------------------------------- | 44 // HintInfoBarDelegate --------------------------------------------------------- |
| 46 | 45 |
| 47 class HintInfoBarDelegate : public ConfirmInfoBarDelegate { | 46 class HintInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 48 public: | 47 public: |
| 49 // If the active entry for |web_contents| is a navigation to the user's | 48 // If the active entry for |web_contents| is a navigation to the user's |
| 50 // default search engine, and the engine is on a small whitelist, creates a | 49 // default search engine, and the engine is on a small whitelist, creates a |
| 51 // "you can search from the omnibox" hint delegate and adds it to the | 50 // "you can search from the omnibox" hint delegate and adds it to the |
| 52 // InfoBarService for |web_contents|. | 51 // InfoBarService for |web_contents|. |
| 53 static void Create(content::WebContents* web_contents, | 52 static void Create(content::WebContents* web_contents, |
| 54 OmniboxSearchHint* omnibox_hint); | 53 OmniboxSearchHint* omnibox_hint); |
| 55 | 54 |
| 56 private: | 55 private: |
| 57 HintInfoBarDelegate(OmniboxSearchHint* omnibox_hint, | 56 HintInfoBarDelegate(OmniboxSearchHint* omnibox_hint, |
| 58 InfoBarService* infobar_service); | 57 InfoBarService* infobar_service); |
| 59 virtual ~HintInfoBarDelegate(); | 58 virtual ~HintInfoBarDelegate(); |
| 60 | 59 |
| 61 void AllowExpiry() { should_expire_ = true; } | 60 void AllowExpiry() { should_expire_ = true; } |
| 62 | 61 |
| 63 // ConfirmInfoBarDelegate: | 62 // ConfirmInfoBarDelegate: |
| 64 virtual void InfoBarDismissed() OVERRIDE; | 63 virtual void InfoBarDismissed() OVERRIDE; |
| 65 virtual gfx::Image* GetIcon() const OVERRIDE; | 64 virtual int GetIconID() const OVERRIDE; |
| 66 virtual Type GetInfoBarType() const OVERRIDE; | 65 virtual Type GetInfoBarType() const OVERRIDE; |
| 67 virtual string16 GetMessageText() const OVERRIDE; | 66 virtual string16 GetMessageText() const OVERRIDE; |
| 68 virtual int GetButtons() const OVERRIDE; | 67 virtual int GetButtons() const OVERRIDE; |
| 69 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 68 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 70 virtual bool Accept() OVERRIDE; | 69 virtual bool Accept() OVERRIDE; |
| 71 virtual bool ShouldExpireInternal( | 70 virtual bool ShouldExpireInternal( |
| 72 const content::LoadCommittedDetails& details) const OVERRIDE; | 71 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 73 | 72 |
| 74 // The omnibox hint that shows us. | 73 // The omnibox hint that shows us. |
| 75 OmniboxSearchHint* omnibox_hint_; | 74 OmniboxSearchHint* omnibox_hint_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); | 147 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void HintInfoBarDelegate::InfoBarDismissed() { | 150 void HintInfoBarDelegate::InfoBarDismissed() { |
| 152 action_taken_ = true; | 151 action_taken_ = true; |
| 153 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Closed", 1); | 152 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Closed", 1); |
| 154 // User closed the infobar, let's not bug him again with this in the future. | 153 // User closed the infobar, let's not bug him again with this in the future. |
| 155 omnibox_hint_->DisableHint(); | 154 omnibox_hint_->DisableHint(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 gfx::Image* HintInfoBarDelegate::GetIcon() const { | 157 int HintInfoBarDelegate::GetIconID() const { |
| 159 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 158 return IDR_INFOBAR_QUESTION_MARK; |
| 160 IDR_INFOBAR_QUESTION_MARK); | |
| 161 } | 159 } |
| 162 | 160 |
| 163 InfoBarDelegate::Type HintInfoBarDelegate::GetInfoBarType() const { | 161 InfoBarDelegate::Type HintInfoBarDelegate::GetInfoBarType() const { |
| 164 return PAGE_ACTION_TYPE; | 162 return PAGE_ACTION_TYPE; |
| 165 } | 163 } |
| 166 | 164 |
| 167 string16 HintInfoBarDelegate::GetMessageText() const { | 165 string16 HintInfoBarDelegate::GetMessageText() const { |
| 168 return l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_INFOBAR_TEXT); | 166 return l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_INFOBAR_TEXT); |
| 169 } | 167 } |
| 170 | 168 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 254 } |
| 257 | 255 |
| 258 // static | 256 // static |
| 259 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 257 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 260 // The infobar can only be shown if the correct switch has been provided and | 258 // The infobar can only be shown if the correct switch has been provided and |
| 261 // the user did not dismiss the infobar before. | 259 // the user did not dismiss the infobar before. |
| 262 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 260 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 263 CommandLine::ForCurrentProcess()->HasSwitch( | 261 CommandLine::ForCurrentProcess()->HasSwitch( |
| 264 switches::kSearchInOmniboxHint); | 262 switches::kSearchInOmniboxHint); |
| 265 } | 263 } |
| OLD | NEW |