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/webui/set_as_default_browser_ui.h" | 5 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/win/win_util.h" | |
14 #include "chrome/browser/first_run/first_run.h" | |
15 #include "chrome/browser/lifetime/application_lifetime.h" | |
16 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/shell_integration.h" | 14 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_dialogs.h" | 16 #include "chrome/browser/ui/browser_dialogs.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/browser/ui/browser_list_observer.h" | 19 #include "chrome/browser/ui/browser_list_observer.h" |
23 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
25 #include "chrome/browser/ui/singleton_tabs.h" | 22 #include "chrome/browser/ui/singleton_tabs.h" |
(...skipping 18 matching lines...) Expand all Loading... |
44 #include "ui/web_dialogs/web_dialog_delegate.h" | 41 #include "ui/web_dialogs/web_dialog_delegate.h" |
45 | 42 |
46 using content::BrowserThread; | 43 using content::BrowserThread; |
47 using content::WebContents; | 44 using content::WebContents; |
48 using content::WebUIMessageHandler; | 45 using content::WebUIMessageHandler; |
49 | 46 |
50 namespace { | 47 namespace { |
51 | 48 |
52 const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult"; | 49 const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult"; |
53 | 50 |
54 // The enum permits registering in UMA the three possible outcomes. | 51 // The enum permits registering in UMA the three possible outcomes (do not |
| 52 // reorder these). |
55 // ACCEPTED: user pressed Next and made Chrome default. | 53 // ACCEPTED: user pressed Next and made Chrome default. |
56 // DECLINED: user simply closed the dialog without making Chrome default. | 54 // DECLINED: user simply closed the dialog without making Chrome default. |
57 // REGRETTED: user pressed Next but then elected a different default browser. | 55 // REGRETTED: user pressed Next but then elected a different default browser. |
58 // ACCEPTED_IMMERSE: as above with a switch to metro mode. | |
59 enum MakeChromeDefaultResult { | 56 enum MakeChromeDefaultResult { |
60 MAKE_CHROME_DEFAULT_ACCEPTED, | 57 MAKE_CHROME_DEFAULT_ACCEPTED = 0, |
61 MAKE_CHROME_DEFAULT_DECLINED, | 58 MAKE_CHROME_DEFAULT_DECLINED = 1, |
62 MAKE_CHROME_DEFAULT_REGRETTED, | 59 MAKE_CHROME_DEFAULT_REGRETTED = 2, |
63 MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE, | 60 // MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE = 3, // Deprecated. |
64 MAKE_CHROME_DEFAULT_MAX | 61 MAKE_CHROME_DEFAULT_MAX |
65 }; | 62 }; |
66 | 63 |
67 content::WebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { | 64 content::WebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { |
68 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( | 65 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( |
69 chrome::kChromeUIMetroFlowHost); | 66 chrome::kChromeUIMetroFlowHost); |
70 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); | 67 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); |
71 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); | 68 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); |
72 data_source->AddLocalizedString("flowDescription", | 69 data_source->AddLocalizedString("flowDescription", |
73 IDS_METRO_FLOW_DESCRIPTION); | 70 IDS_METRO_FLOW_DESCRIPTION); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE; | 110 virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE; |
114 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; | 111 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; |
115 | 112 |
116 private: | 113 private: |
117 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. | 114 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. |
118 void HandleLaunchSetDefaultBrowserFlow(const base::ListValue* args); | 115 void HandleLaunchSetDefaultBrowserFlow(const base::ListValue* args); |
119 | 116 |
120 // Close this web ui. | 117 // Close this web ui. |
121 void ConcludeInteraction(MakeChromeDefaultResult interaction_result); | 118 void ConcludeInteraction(MakeChromeDefaultResult interaction_result); |
122 | 119 |
123 // Returns true if Chrome should be restarted in immersive mode upon being | |
124 // made the default browser. | |
125 bool ShouldAttemptImmersiveRestart(); | |
126 | |
127 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; | 120 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; |
128 bool set_default_returned_; | 121 bool set_default_returned_; |
129 bool set_default_result_; | 122 bool set_default_result_; |
130 base::WeakPtr<ResponseDelegate> response_delegate_; | 123 base::WeakPtr<ResponseDelegate> response_delegate_; |
131 | 124 |
132 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); | 125 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); |
133 }; | 126 }; |
134 | 127 |
135 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( | 128 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( |
136 const base::WeakPtr<ResponseDelegate>& response_delegate) | 129 const base::WeakPtr<ResponseDelegate>& response_delegate) |
(...skipping 19 matching lines...) Expand all Loading... |
156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 149 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
157 if (!set_default_returned_) | 150 if (!set_default_returned_) |
158 return; | 151 return; |
159 | 152 |
160 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { | 153 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { |
161 // The operation concluded, but Chrome is still not the default. | 154 // The operation concluded, but Chrome is still not the default. |
162 // If the call has succeeded, this suggests user has decided not to make | 155 // If the call has succeeded, this suggests user has decided not to make |
163 // chrome the default. | 156 // chrome the default. |
164 ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED); | 157 ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED); |
165 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { | 158 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { |
166 ConcludeInteraction(ShouldAttemptImmersiveRestart() ? | 159 ConcludeInteraction(MAKE_CHROME_DEFAULT_ACCEPTED); |
167 MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE : MAKE_CHROME_DEFAULT_ACCEPTED); | |
168 } | 160 } |
169 | 161 |
170 // Otherwise, keep the dialog open since the user probably didn't make a | 162 // Otherwise, keep the dialog open since the user probably didn't make a |
171 // choice. | 163 // choice. |
172 } | 164 } |
173 | 165 |
174 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { | 166 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { |
175 set_default_returned_ = true; | 167 set_default_returned_ = true; |
176 set_default_result_ = call_result; | 168 set_default_result_ = call_result; |
177 } | 169 } |
(...skipping 18 matching lines...) Expand all Loading... |
196 | 188 |
197 WebContents* contents = web_ui()->GetWebContents(); | 189 WebContents* contents = web_ui()->GetWebContents(); |
198 | 190 |
199 if (contents) { | 191 if (contents) { |
200 content::WebContentsDelegate* delegate = contents->GetDelegate(); | 192 content::WebContentsDelegate* delegate = contents->GetDelegate(); |
201 if (delegate) | 193 if (delegate) |
202 delegate->CloseContents(contents); | 194 delegate->CloseContents(contents); |
203 } | 195 } |
204 } | 196 } |
205 | 197 |
206 bool SetAsDefaultBrowserHandler::ShouldAttemptImmersiveRestart() { | |
207 return (base::win::IsTouchEnabledDevice() && | |
208 !Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( | |
209 prefs::kSuppressSwitchToMetroModeOnSetDefault)); | |
210 } | |
211 | |
212 // A web dialog delegate implementation for when 'Make Chrome Metro' UI | 198 // A web dialog delegate implementation for when 'Make Chrome Metro' UI |
213 // is displayed on a dialog. | 199 // is displayed on a dialog. |
214 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate, | 200 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate, |
215 public ResponseDelegate, | 201 public ResponseDelegate, |
216 public chrome::BrowserListObserver { | 202 public chrome::BrowserListObserver { |
217 public: | 203 public: |
218 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); | 204 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); |
219 virtual ~SetAsDefaultBrowserDialogImpl(); | 205 virtual ~SetAsDefaultBrowserDialogImpl(); |
220 // Show a modal web dialog with kChromeUIMetroFlowURL page. | 206 // Show a modal web dialog with kChromeUIMetroFlowURL page. |
221 void ShowDialog(); | 207 void ShowDialog(); |
(...skipping 14 matching lines...) Expand all Loading... |
236 virtual bool HandleContextMenu( | 222 virtual bool HandleContextMenu( |
237 const content::ContextMenuParams& params) OVERRIDE; | 223 const content::ContextMenuParams& params) OVERRIDE; |
238 | 224 |
239 // Overridden from ResponseDelegate: | 225 // Overridden from ResponseDelegate: |
240 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result); | 226 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result); |
241 | 227 |
242 // Overridden from BrowserListObserver: | 228 // Overridden from BrowserListObserver: |
243 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 229 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
244 | 230 |
245 private: | 231 private: |
246 // Reset the first-run sentinel file, so must be called on the FILE thread. | |
247 // This is needed if the browser should be restarted in immersive mode. | |
248 // The method is static because the dialog could be destroyed | |
249 // before the task arrives on the FILE thread. | |
250 static void AttemptImmersiveFirstRunRestartOnFileThread(); | |
251 | |
252 Profile* profile_; | 232 Profile* profile_; |
253 Browser* browser_; | 233 Browser* browser_; |
254 mutable bool owns_handler_; | 234 mutable bool owns_handler_; |
255 base::WeakPtrFactory<ResponseDelegate> response_delegate_ptr_factory_; | 235 base::WeakPtrFactory<ResponseDelegate> response_delegate_ptr_factory_; |
256 SetAsDefaultBrowserHandler* handler_; | 236 SetAsDefaultBrowserHandler* handler_; |
257 MakeChromeDefaultResult dialog_interaction_result_; | 237 MakeChromeDefaultResult dialog_interaction_result_; |
258 | 238 |
259 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); | 239 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); |
260 }; | 240 }; |
261 | 241 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 return "[]"; | 302 return "[]"; |
323 } | 303 } |
324 | 304 |
325 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( | 305 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( |
326 const std::string& json_retval) { | 306 const std::string& json_retval) { |
327 // Register the user's response in UMA. | 307 // Register the user's response in UMA. |
328 UMA_HISTOGRAM_ENUMERATION(kSetAsDefaultBrowserHistogram, | 308 UMA_HISTOGRAM_ENUMERATION(kSetAsDefaultBrowserHistogram, |
329 dialog_interaction_result_, | 309 dialog_interaction_result_, |
330 MAKE_CHROME_DEFAULT_MAX); | 310 MAKE_CHROME_DEFAULT_MAX); |
331 | 311 |
332 if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE) { | 312 // If the user explicitly elected *not to* make Chrome default, we won't |
333 BrowserThread::PostTask( | 313 // ask again. |
334 BrowserThread::FILE, FROM_HERE, | 314 if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_REGRETTED) { |
335 base::Bind(&SetAsDefaultBrowserDialogImpl:: | 315 PrefService* prefs = profile_->GetPrefs(); |
336 AttemptImmersiveFirstRunRestartOnFileThread)); | 316 prefs->SetBoolean(prefs::kCheckDefaultBrowser, false); |
337 } else { | 317 } |
338 // If the user explicitly elected *not to* make Chrome default, we won't | |
339 // ask again. | |
340 if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_REGRETTED) { | |
341 PrefService* prefs = profile_->GetPrefs(); | |
342 prefs->SetBoolean(prefs::kCheckDefaultBrowser, false); | |
343 } | |
344 | 318 |
345 // Carry on with a normal chrome session. For the purpose of surfacing this | 319 // Carry on with a normal chrome session. For the purpose of surfacing this |
346 // dialog the actual browser window had to remain hidden. Now it's time to | 320 // dialog the actual browser window had to remain hidden. Now it's time to |
347 // show it. | 321 // show it. |
348 if (browser_) { | 322 if (browser_) { |
349 BrowserWindow* window = browser_->window(); | 323 BrowserWindow* window = browser_->window(); |
350 WebContents* contents = | 324 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
351 browser_->tab_strip_model()->GetActiveWebContents(); | 325 window->Show(); |
352 window->Show(); | 326 if (contents) |
353 if (contents) | 327 contents->SetInitialFocus(); |
354 contents->SetInitialFocus(); | |
355 } | |
356 } | 328 } |
357 | 329 |
358 delete this; | 330 delete this; |
359 } | 331 } |
360 | 332 |
361 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, | 333 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, |
362 bool* out_close_dialog) { | 334 bool* out_close_dialog) { |
363 *out_close_dialog = true; | 335 *out_close_dialog = true; |
364 } | 336 } |
365 | 337 |
(...skipping 11 matching lines...) Expand all Loading... |
377 dialog_interaction_result_ = result; | 349 dialog_interaction_result_ = result; |
378 } | 350 } |
379 | 351 |
380 void SetAsDefaultBrowserDialogImpl::OnBrowserRemoved(Browser* browser) { | 352 void SetAsDefaultBrowserDialogImpl::OnBrowserRemoved(Browser* browser) { |
381 if (browser_ == browser) { | 353 if (browser_ == browser) { |
382 browser_ = NULL; | 354 browser_ = NULL; |
383 BrowserList::RemoveObserver(this); | 355 BrowserList::RemoveObserver(this); |
384 } | 356 } |
385 } | 357 } |
386 | 358 |
387 void SetAsDefaultBrowserDialogImpl:: | |
388 AttemptImmersiveFirstRunRestartOnFileThread() { | |
389 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
390 | |
391 // If the sentinel was created for this launch, remove it before restarting | |
392 // in immersive mode so that the user is taken through the full first-run | |
393 // flow there. | |
394 if (first_run::IsChromeFirstRun()) | |
395 first_run::RemoveSentinel(); | |
396 | |
397 // Do a straight-up restart rather than a mode-switch restart. | |
398 // delegate_execute.exe will choose an immersive launch on the basis of the | |
399 // same IsTouchEnabledDevice check, but will not store this as the user's | |
400 // choice. | |
401 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
402 base::Bind(&chrome::AttemptRestart)); | |
403 } | |
404 | |
405 } // namespace | 359 } // namespace |
406 | 360 |
407 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) | 361 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) |
408 : ui::WebDialogUI(web_ui) { | 362 : ui::WebDialogUI(web_ui) { |
409 content::WebUIDataSource::Add( | 363 content::WebUIDataSource::Add( |
410 Profile::FromWebUI(web_ui), CreateSetAsDefaultBrowserUIHTMLSource()); | 364 Profile::FromWebUI(web_ui), CreateSetAsDefaultBrowserUIHTMLSource()); |
411 } | 365 } |
412 | 366 |
413 // static | 367 // static |
414 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { | 368 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { |
415 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 369 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
416 SetAsDefaultBrowserDialogImpl* dialog = | 370 SetAsDefaultBrowserDialogImpl* dialog = |
417 new SetAsDefaultBrowserDialogImpl(profile, browser); | 371 new SetAsDefaultBrowserDialogImpl(profile, browser); |
418 dialog->ShowDialog(); | 372 dialog->ShowDialog(); |
419 } | 373 } |
OLD | NEW |