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/ui/startup/default_browser_prompt.h" | 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 } else { | 49 } else { |
50 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | 50 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); |
51 ShellIntegration::SetAsDefaultBrowser(); | 51 ShellIntegration::SetAsDefaultBrowser(); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 // The delegate for the infobar shown when Chrome is not the default browser. | 55 // The delegate for the infobar shown when Chrome is not the default browser. |
56 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 56 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
57 public: | 57 public: |
| 58 // Creates a default browser delegate and adds it to |infobar_service|. |
| 59 static void Create(InfoBarService* infobar_service, |
| 60 PrefService* prefs, |
| 61 bool interactive_flow_required); |
| 62 |
| 63 private: |
58 DefaultBrowserInfoBarDelegate(InfoBarService* infobar_service, | 64 DefaultBrowserInfoBarDelegate(InfoBarService* infobar_service, |
59 PrefService* prefs, | 65 PrefService* prefs, |
60 bool interactive_flow_required); | 66 bool interactive_flow_required); |
61 | |
62 private: | |
63 virtual ~DefaultBrowserInfoBarDelegate(); | 67 virtual ~DefaultBrowserInfoBarDelegate(); |
64 | 68 |
65 void AllowExpiry() { should_expire_ = true; } | 69 void AllowExpiry() { should_expire_ = true; } |
66 | 70 |
67 // ConfirmInfoBarDelegate: | 71 // ConfirmInfoBarDelegate: |
68 virtual gfx::Image* GetIcon() const OVERRIDE; | 72 virtual gfx::Image* GetIcon() const OVERRIDE; |
69 virtual string16 GetMessageText() const OVERRIDE; | 73 virtual string16 GetMessageText() const OVERRIDE; |
70 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 74 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
71 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; | 75 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; |
72 virtual bool Accept() OVERRIDE; | 76 virtual bool Accept() OVERRIDE; |
(...skipping 13 matching lines...) Expand all Loading... |
86 // Whether changing the default application will require entering the | 90 // Whether changing the default application will require entering the |
87 // modal-UI flow. | 91 // modal-UI flow. |
88 const bool interactive_flow_required_; | 92 const bool interactive_flow_required_; |
89 | 93 |
90 // Used to delay the expiration of the info-bar. | 94 // Used to delay the expiration of the info-bar. |
91 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; | 95 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; |
92 | 96 |
93 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); | 97 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); |
94 }; | 98 }; |
95 | 99 |
| 100 // static |
| 101 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 102 PrefService* prefs, |
| 103 bool interactive_flow_required) { |
| 104 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 105 new DefaultBrowserInfoBarDelegate(infobar_service, prefs, |
| 106 interactive_flow_required))); |
| 107 } |
| 108 |
96 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( | 109 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( |
97 InfoBarService* infobar_service, | 110 InfoBarService* infobar_service, |
98 PrefService* prefs, | 111 PrefService* prefs, |
99 bool interactive_flow_required) | 112 bool interactive_flow_required) |
100 : ConfirmInfoBarDelegate(infobar_service), | 113 : ConfirmInfoBarDelegate(infobar_service), |
101 prefs_(prefs), | 114 prefs_(prefs), |
102 action_taken_(false), | 115 action_taken_(false), |
103 should_expire_(false), | 116 should_expire_(false), |
104 interactive_flow_required_(interactive_flow_required), | 117 interactive_flow_required_(interactive_flow_required), |
105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 118 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 Browser* browser = chrome::FindLastActiveWithHostDesktopType(desktop_type); | 177 Browser* browser = chrome::FindLastActiveWithHostDesktopType(desktop_type); |
165 if (!browser) | 178 if (!browser) |
166 return; // Reached during ui tests. | 179 return; // Reached during ui tests. |
167 | 180 |
168 // In ChromeBot tests, there might be a race. This line appears to get | 181 // In ChromeBot tests, there might be a race. This line appears to get |
169 // called during shutdown and |tab| can be NULL. | 182 // called during shutdown and |tab| can be NULL. |
170 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); | 183 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); |
171 if (!web_contents) | 184 if (!web_contents) |
172 return; | 185 return; |
173 | 186 |
174 // Don't show the info-bar if there are already info-bars showing. | |
175 InfoBarService* infobar_service = | |
176 InfoBarService::FromWebContents(web_contents); | |
177 if (infobar_service->GetInfoBarCount() > 0) | |
178 return; | |
179 | |
180 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == | 187 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == |
181 ShellIntegration::SET_DEFAULT_INTERACTIVE; | 188 ShellIntegration::SET_DEFAULT_INTERACTIVE; |
182 Profile* profile = | 189 Profile* profile = |
183 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 190 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
184 infobar_service->AddInfoBar( | 191 DefaultBrowserInfoBarDelegate::Create( |
185 new DefaultBrowserInfoBarDelegate(infobar_service, | 192 InfoBarService::FromWebContents(web_contents), profile->GetPrefs(), |
186 profile->GetPrefs(), | 193 interactive_flow); |
187 interactive_flow)); | |
188 } | 194 } |
189 | 195 |
190 void CheckDefaultBrowserCallback(chrome::HostDesktopType desktop_type) { | 196 void CheckDefaultBrowserCallback(chrome::HostDesktopType desktop_type) { |
191 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT) { | 197 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT) { |
192 ShellIntegration::DefaultWebClientSetPermission default_change_mode = | 198 ShellIntegration::DefaultWebClientSetPermission default_change_mode = |
193 ShellIntegration::CanSetAsDefaultBrowser(); | 199 ShellIntegration::CanSetAsDefaultBrowser(); |
194 | 200 |
195 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { | 201 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { |
196 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 202 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
197 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); | 203 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 236 |
231 } | 237 } |
232 | 238 |
233 #if !defined(OS_WIN) | 239 #if !defined(OS_WIN) |
234 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 240 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
235 return false; | 241 return false; |
236 } | 242 } |
237 #endif | 243 #endif |
238 | 244 |
239 } // namespace chrome | 245 } // namespace chrome |
OLD | NEW |