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

Side by Side Diff: chrome/browser/ui/startup/default_browser_prompt.cc

Issue 10539169: Prototype version of the first-run dialog for Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed non-windows compilation errors. Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/first_run/first_run.h" 11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 12 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/shell_integration.h" 15 #include "chrome/browser/shell_integration.h"
16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/browser/ui/webui/metroizer_ui.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_details.h" 24 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h"
23 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
26 #include "grit/theme_resources_standard.h" 30 #include "grit/theme_resources_standard.h"
27 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
29 33
30 using content::BrowserThread; 34 using content::BrowserThread;
31 35
32 namespace { 36 namespace {
33 37
34 // Calls the appropriate function for setting Chrome as the default browser. 38 // Calls the appropriate function for setting Chrome as the default browser.
35 // This requires IO access (registry) and may result in interaction with a 39 // This requires IO access (registry) and may result in interaction with a
36 // modal system UI. 40 // modal system UI.
37 void SetChromeAsDefaultBrowser(bool interactive_flow) { 41 void SetChromeAsDefaultBrowser(bool interactive_flow, PrefService* prefs) {
38 if (interactive_flow) { 42 if (interactive_flow) {
39 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); 43 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1);
40 if (!ShellIntegration::SetAsDefaultBrowserInteractive()) 44 if (!ShellIntegration::SetAsDefaultBrowserInteractive()) {
41 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); 45 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1);
46 } else if (!ShellIntegration::IsDefaultBrowser()) {
47 // If the interaction succeeded but we are still not the default browser
48 // it likely means the user simply selected another browser from the
49 // panel. We will respect this choice and write it down as 'no, thanks'.
50 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1);
51 // User clicked "Don't ask me again", remember that.
52 if (prefs)
53 prefs->SetBoolean(prefs::kCheckDefaultBrowser, false);
54 }
42 } else { 55 } else {
43 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); 56 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1);
44 ShellIntegration::SetAsDefaultBrowser(); 57 ShellIntegration::SetAsDefaultBrowser();
45 } 58 }
46 } 59 }
47 60
48 // The delegate for the infobar shown when Chrome is not the default browser. 61 // The delegate for the infobar shown when Chrome is not the default browser.
49 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 62 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
50 public: 63 public:
51 DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, 64 DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 145
133 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { 146 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const {
134 return button == BUTTON_OK; 147 return button == BUTTON_OK;
135 } 148 }
136 149
137 bool DefaultBrowserInfoBarDelegate::Accept() { 150 bool DefaultBrowserInfoBarDelegate::Accept() {
138 action_taken_ = true; 151 action_taken_ = true;
139 BrowserThread::PostTask( 152 BrowserThread::PostTask(
140 BrowserThread::FILE, 153 BrowserThread::FILE,
141 FROM_HERE, 154 FROM_HERE,
142 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_)); 155 base::Bind(&SetChromeAsDefaultBrowser,
grt (UTC plus 2) 2012/06/18 19:19:13 condense
motek. 2012/06/19 18:06:44 Done.
156 interactive_flow_required_,
157 prefs_));
143 158
144 return true; 159 return true;
145 } 160 }
146 161
147 bool DefaultBrowserInfoBarDelegate::Cancel() { 162 bool DefaultBrowserInfoBarDelegate::Cancel() {
148 action_taken_ = true; 163 action_taken_ = true;
149 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); 164 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1);
150 // User clicked "Don't ask me again", remember that. 165 // User clicked "Don't ask me again", remember that.
151 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); 166 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false);
152 return true; 167 return true;
153 } 168 }
154 169
155 void CheckDefaultBrowserCallback() { 170 void CheckDefaultBrowserCallback() {
156 if (!ShellIntegration::IsDefaultBrowser()) { 171 if (!ShellIntegration::IsDefaultBrowser()) {
157 ShellIntegration::DefaultWebClientSetPermission default_change_mode = 172 ShellIntegration::DefaultWebClientSetPermission default_change_mode =
158 ShellIntegration::CanSetAsDefaultBrowser(); 173 ShellIntegration::CanSetAsDefaultBrowser();
159 174
160 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { 175 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 176 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
162 base::Bind(&browser::internal::NotifyNotDefaultBrowserCallback)); 177 base::Bind(&browser::internal::NotifyNotDefaultBrowserCallback));
163 } 178 }
164 } 179 }
165 } 180 }
166 181
182 static void CheckDefaultAndShowMetroizerCallback(
183 Profile* profile, Browser* browser, bool dialog) {
184 if (!ShellIntegration::IsDefaultBrowser() ||
185 (ShellIntegration::CanSetAsDefaultBrowser() ==
186 ShellIntegration::SET_DEFAULT_INTERACTIVE)) {
187 MetroizerUI::Show(profile, browser, dialog);
grt (UTC plus 2) 2012/06/18 19:19:13 de-indent two spaces
motek. 2012/06/19 18:06:44 Done.
188 }
189 }
190
191 class SetMetroBrowserFlowLauncher : public content::NotificationObserver {
192 public:
193 static void LaunchSoon(Profile* profile) {
194 // The instance will manage its own lifetime.
195 new SetMetroBrowserFlowLauncher(profile);
196 }
197
198 private:
199 explicit SetMetroBrowserFlowLauncher(Profile* profile)
200 : profile_(profile) {
201 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
202 content::NotificationService::AllSources());
203 }
204
205 // content::NotificationObserver override:
206 virtual void Observe(int type,
207 const content::NotificationSource& source,
208 const content::NotificationDetails& details) OVERRIDE;
209
210 content::NotificationRegistrar registrar_;
211 Profile* profile_;
212
213 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher);
214 };
215
216 void SetMetroBrowserFlowLauncher::Observe(
217 int type,
218 const content::NotificationSource& source,
219 const content::NotificationDetails& details) {
220 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
221 Browser* browser = browser::FindBrowserWithWebContents(
222 content::Source<content::WebContents>(source).ptr());
grt (UTC plus 2) 2012/06/18 19:19:13 nit: indent two more spaces
motek. 2012/06/19 18:06:44 Done.
223
224 if (!browser || !browser->is_type_tabbed())
225 return;
226
227 // Unregister and delete.
grt (UTC plus 2) 2012/06/18 19:19:13 i don't see the delete. is it handled by the regi
motek. 2012/06/19 18:06:44 You are right, obviously. I must have clipped it i
228 registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
229 content::NotificationService::AllSources());
230
231 bool as_dialog =
232 profile_->GetPrefs()->GetBoolean(prefs::kDefaultBrowserFlowDialog);
233 BrowserThread::PostTask(
grt (UTC plus 2) 2012/06/18 19:19:13 save the whitespace! (args can share lines)
motek. 2012/06/19 18:06:44 Done.
234 BrowserThread::FILE,
235 FROM_HERE,
236 base::Bind(&CheckDefaultAndShowMetroizerCallback,
237 profile_, browser, as_dialog));
238 }
239
167 } // namespace 240 } // namespace
168 241
169 namespace browser { 242 namespace browser {
170 243
171 void ShowDefaultBrowserPrompt(Profile* profile) { 244 void ShowDefaultBrowserPrompt(Profile* profile) {
172 // We do not check if we are the default browser if: 245 // We do not check if we are the default browser if:
173 // - the user said "don't ask me again" on the infobar earlier. 246 // - the user said "don't ask me again" on the infobar earlier.
174 // - this is the first launch after the first run flow. 247 // - this is the first launch after the first run flow.
175 // - There is a policy in control of this setting. 248 // - There is a policy in control of this setting.
176 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || 249 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) ||
(...skipping 12 matching lines...) Expand all
189 // TODO(pastarmovj): We can't really do anything meaningful here yet but 262 // TODO(pastarmovj): We can't really do anything meaningful here yet but
190 // just prevent showing the infobar. 263 // just prevent showing the infobar.
191 } 264 }
192 return; 265 return;
193 } 266 }
194 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 267 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
195 base::Bind(&CheckDefaultBrowserCallback)); 268 base::Bind(&CheckDefaultBrowserCallback));
196 269
197 } 270 }
198 271
272 void ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
273 if (ShellIntegration::SET_DEFAULT_INTERACTIVE ==
274 ShellIntegration::CanSetAsDefaultBrowser()) {
275 // If the only available mode of setting the default browser requires
276 // user interaction, it means this couldn't have been done yet. Perform
277 // this action as a delayed task (including the check).
278 SetMetroBrowserFlowLauncher::LaunchSoon(profile);
279 }
280 }
281
199 namespace internal { 282 namespace internal {
200 283
201 void NotifyNotDefaultBrowserCallback() { 284 void NotifyNotDefaultBrowserCallback() {
202 Browser* browser = BrowserList::GetLastActive(); 285 Browser* browser = BrowserList::GetLastActive();
203 if (!browser) 286 if (!browser)
204 return; // Reached during ui tests. 287 return; // Reached during ui tests.
205 288
206 // In ChromeBot tests, there might be a race. This line appears to get 289 // In ChromeBot tests, there might be a race. This line appears to get
207 // called during shutdown and |tab| can be NULL. 290 // called during shutdown and |tab| can be NULL.
208 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); 291 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper();
209 if (!tab) 292 if (!tab)
210 return; 293 return;
211 294
212 // Don't show the info-bar if there are already info-bars showing. 295 // Don't show the info-bar if there are already info-bars showing.
213 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); 296 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
214 if (infobar_helper->infobar_count() > 0) 297 if (infobar_helper->infobar_count() > 0)
215 return; 298 return;
216 299
217 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == 300 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() ==
218 ShellIntegration::SET_DEFAULT_INTERACTIVE; 301 ShellIntegration::SET_DEFAULT_INTERACTIVE;
219 infobar_helper->AddInfoBar( 302 infobar_helper->AddInfoBar(
220 new DefaultBrowserInfoBarDelegate(infobar_helper, 303 new DefaultBrowserInfoBarDelegate(infobar_helper,
221 tab->profile()->GetPrefs(), 304 tab->profile()->GetPrefs(),
222 interactive_flow)); 305 interactive_flow));
223 } 306 }
224 307
225 } // namespace internal 308 } // namespace internal
226 } // namespace browser 309 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698