Chromium Code Reviews| 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" | 13 #include "chrome/browser/first_run/first_run.h" |
| 15 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/shell_integration.h" | 15 #include "chrome/browser/shell_integration.h" |
| 18 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_dialogs.h" | 17 #include "chrome/browser/ui/browser_dialogs.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_list_observer.h" | 20 #include "chrome/browser/ui/browser_list_observer.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/chrome_pages.h" | 22 #include "chrome/browser/ui/chrome_pages.h" |
| 25 #include "chrome/browser/ui/singleton_tabs.h" | 23 #include "chrome/browser/ui/singleton_tabs.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 48 using content::WebUIMessageHandler; | 46 using content::WebUIMessageHandler; |
| 49 | 47 |
| 50 namespace { | 48 namespace { |
| 51 | 49 |
| 52 const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult"; | 50 const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult"; |
| 53 | 51 |
| 54 // The enum permits registering in UMA the three possible outcomes. | 52 // The enum permits registering in UMA the three possible outcomes. |
| 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. | 56 // ACCEPTED_IMMERSE: as above with a switch to metro mode. OBSOLETE. |
| 59 enum MakeChromeDefaultResult { | 57 enum MakeChromeDefaultResult { |
| 60 MAKE_CHROME_DEFAULT_ACCEPTED, | 58 MAKE_CHROME_DEFAULT_ACCEPTED, |
| 61 MAKE_CHROME_DEFAULT_DECLINED, | 59 MAKE_CHROME_DEFAULT_DECLINED, |
| 62 MAKE_CHROME_DEFAULT_REGRETTED, | 60 MAKE_CHROME_DEFAULT_REGRETTED, |
| 63 MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE, | 61 MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE, // OBSOLETE. Do not re-use. |
|
gab
2014/06/12 18:00:24
Explicitly add a comment above stating that these
grt (UTC plus 2)
2014/06/12 18:29:15
Done.
| |
| 64 MAKE_CHROME_DEFAULT_MAX | 62 MAKE_CHROME_DEFAULT_MAX |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 content::WebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { | 65 content::WebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { |
| 68 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( | 66 content::WebUIDataSource* data_source = content::WebUIDataSource::Create( |
| 69 chrome::kChromeUIMetroFlowHost); | 67 chrome::kChromeUIMetroFlowHost); |
| 70 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); | 68 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); |
| 71 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); | 69 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); |
| 72 data_source->AddLocalizedString("flowDescription", | 70 data_source->AddLocalizedString("flowDescription", |
| 73 IDS_METRO_FLOW_DESCRIPTION); | 71 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; | 111 virtual void OnSetAsDefaultConcluded(bool close_chrome) OVERRIDE; |
| 114 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; | 112 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE; |
| 115 | 113 |
| 116 private: | 114 private: |
| 117 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. | 115 // Handler for the 'Next' (or 'make Chrome the Metro browser') button. |
| 118 void HandleLaunchSetDefaultBrowserFlow(const base::ListValue* args); | 116 void HandleLaunchSetDefaultBrowserFlow(const base::ListValue* args); |
| 119 | 117 |
| 120 // Close this web ui. | 118 // Close this web ui. |
| 121 void ConcludeInteraction(MakeChromeDefaultResult interaction_result); | 119 void ConcludeInteraction(MakeChromeDefaultResult interaction_result); |
| 122 | 120 |
| 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_; | 121 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; |
| 128 bool set_default_returned_; | 122 bool set_default_returned_; |
| 129 bool set_default_result_; | 123 bool set_default_result_; |
| 130 base::WeakPtr<ResponseDelegate> response_delegate_; | 124 base::WeakPtr<ResponseDelegate> response_delegate_; |
| 131 | 125 |
| 132 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); | 126 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserHandler); |
| 133 }; | 127 }; |
| 134 | 128 |
| 135 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( | 129 SetAsDefaultBrowserHandler::SetAsDefaultBrowserHandler( |
| 136 const base::WeakPtr<ResponseDelegate>& response_delegate) | 130 const base::WeakPtr<ResponseDelegate>& response_delegate) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 157 if (!set_default_returned_) | 151 if (!set_default_returned_) |
| 158 return; | 152 return; |
| 159 | 153 |
| 160 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { | 154 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { |
| 161 // The operation concluded, but Chrome is still not the default. | 155 // The operation concluded, but Chrome is still not the default. |
| 162 // If the call has succeeded, this suggests user has decided not to make | 156 // If the call has succeeded, this suggests user has decided not to make |
| 163 // chrome the default. | 157 // chrome the default. |
| 164 ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED); | 158 ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED); |
| 165 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { | 159 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { |
| 166 ConcludeInteraction(ShouldAttemptImmersiveRestart() ? | 160 ConcludeInteraction(MAKE_CHROME_DEFAULT_ACCEPTED); |
| 167 MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE : MAKE_CHROME_DEFAULT_ACCEPTED); | |
| 168 } | 161 } |
| 169 | 162 |
| 170 // Otherwise, keep the dialog open since the user probably didn't make a | 163 // Otherwise, keep the dialog open since the user probably didn't make a |
| 171 // choice. | 164 // choice. |
| 172 } | 165 } |
| 173 | 166 |
| 174 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { | 167 void SetAsDefaultBrowserHandler::OnSetAsDefaultConcluded(bool call_result) { |
| 175 set_default_returned_ = true; | 168 set_default_returned_ = true; |
| 176 set_default_result_ = call_result; | 169 set_default_result_ = call_result; |
| 177 } | 170 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 196 | 189 |
| 197 WebContents* contents = web_ui()->GetWebContents(); | 190 WebContents* contents = web_ui()->GetWebContents(); |
| 198 | 191 |
| 199 if (contents) { | 192 if (contents) { |
| 200 content::WebContentsDelegate* delegate = contents->GetDelegate(); | 193 content::WebContentsDelegate* delegate = contents->GetDelegate(); |
| 201 if (delegate) | 194 if (delegate) |
| 202 delegate->CloseContents(contents); | 195 delegate->CloseContents(contents); |
| 203 } | 196 } |
| 204 } | 197 } |
| 205 | 198 |
| 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 | 199 // A web dialog delegate implementation for when 'Make Chrome Metro' UI |
| 213 // is displayed on a dialog. | 200 // is displayed on a dialog. |
| 214 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate, | 201 class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate, |
| 215 public ResponseDelegate, | 202 public ResponseDelegate, |
| 216 public chrome::BrowserListObserver { | 203 public chrome::BrowserListObserver { |
| 217 public: | 204 public: |
| 218 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); | 205 SetAsDefaultBrowserDialogImpl(Profile* profile, Browser* browser); |
| 219 virtual ~SetAsDefaultBrowserDialogImpl(); | 206 virtual ~SetAsDefaultBrowserDialogImpl(); |
| 220 // Show a modal web dialog with kChromeUIMetroFlowURL page. | 207 // Show a modal web dialog with kChromeUIMetroFlowURL page. |
| 221 void ShowDialog(); | 208 void ShowDialog(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 236 virtual bool HandleContextMenu( | 223 virtual bool HandleContextMenu( |
| 237 const content::ContextMenuParams& params) OVERRIDE; | 224 const content::ContextMenuParams& params) OVERRIDE; |
| 238 | 225 |
| 239 // Overridden from ResponseDelegate: | 226 // Overridden from ResponseDelegate: |
| 240 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result); | 227 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result); |
| 241 | 228 |
| 242 // Overridden from BrowserListObserver: | 229 // Overridden from BrowserListObserver: |
| 243 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 230 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 244 | 231 |
| 245 private: | 232 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_; | 233 Profile* profile_; |
| 253 Browser* browser_; | 234 Browser* browser_; |
| 254 mutable bool owns_handler_; | 235 mutable bool owns_handler_; |
| 255 base::WeakPtrFactory<ResponseDelegate> response_delegate_ptr_factory_; | 236 base::WeakPtrFactory<ResponseDelegate> response_delegate_ptr_factory_; |
| 256 SetAsDefaultBrowserHandler* handler_; | 237 SetAsDefaultBrowserHandler* handler_; |
| 257 MakeChromeDefaultResult dialog_interaction_result_; | 238 MakeChromeDefaultResult dialog_interaction_result_; |
| 258 | 239 |
| 259 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); | 240 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); |
| 260 }; | 241 }; |
| 261 | 242 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 return "[]"; | 303 return "[]"; |
| 323 } | 304 } |
| 324 | 305 |
| 325 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( | 306 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( |
| 326 const std::string& json_retval) { | 307 const std::string& json_retval) { |
| 327 // Register the user's response in UMA. | 308 // Register the user's response in UMA. |
| 328 UMA_HISTOGRAM_ENUMERATION(kSetAsDefaultBrowserHistogram, | 309 UMA_HISTOGRAM_ENUMERATION(kSetAsDefaultBrowserHistogram, |
| 329 dialog_interaction_result_, | 310 dialog_interaction_result_, |
| 330 MAKE_CHROME_DEFAULT_MAX); | 311 MAKE_CHROME_DEFAULT_MAX); |
| 331 | 312 |
| 332 if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE) { | 313 // If the user explicitly elected *not to* make Chrome default, we won't |
| 333 BrowserThread::PostTask( | 314 // ask again. |
| 334 BrowserThread::FILE, FROM_HERE, | 315 if (dialog_interaction_result_ == MAKE_CHROME_DEFAULT_REGRETTED) { |
| 335 base::Bind(&SetAsDefaultBrowserDialogImpl:: | 316 PrefService* prefs = profile_->GetPrefs(); |
| 336 AttemptImmersiveFirstRunRestartOnFileThread)); | 317 prefs->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 337 } else { | 318 } |
| 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 | 319 |
| 345 // Carry on with a normal chrome session. For the purpose of surfacing this | 320 // 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 | 321 // dialog the actual browser window had to remain hidden. Now it's time to |
| 347 // show it. | 322 // show it. |
| 348 if (browser_) { | 323 if (browser_) { |
| 349 BrowserWindow* window = browser_->window(); | 324 BrowserWindow* window = browser_->window(); |
| 350 WebContents* contents = | 325 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
| 351 browser_->tab_strip_model()->GetActiveWebContents(); | 326 window->Show(); |
| 352 window->Show(); | 327 if (contents) |
| 353 if (contents) | 328 contents->SetInitialFocus(); |
| 354 contents->SetInitialFocus(); | |
| 355 } | |
| 356 } | 329 } |
| 357 | 330 |
| 358 delete this; | 331 delete this; |
| 359 } | 332 } |
| 360 | 333 |
| 361 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, | 334 void SetAsDefaultBrowserDialogImpl::OnCloseContents(WebContents* source, |
| 362 bool* out_close_dialog) { | 335 bool* out_close_dialog) { |
| 363 *out_close_dialog = true; | 336 *out_close_dialog = true; |
| 364 } | 337 } |
| 365 | 338 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 377 dialog_interaction_result_ = result; | 350 dialog_interaction_result_ = result; |
| 378 } | 351 } |
| 379 | 352 |
| 380 void SetAsDefaultBrowserDialogImpl::OnBrowserRemoved(Browser* browser) { | 353 void SetAsDefaultBrowserDialogImpl::OnBrowserRemoved(Browser* browser) { |
| 381 if (browser_ == browser) { | 354 if (browser_ == browser) { |
| 382 browser_ = NULL; | 355 browser_ = NULL; |
| 383 BrowserList::RemoveObserver(this); | 356 BrowserList::RemoveObserver(this); |
| 384 } | 357 } |
| 385 } | 358 } |
| 386 | 359 |
| 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(); | |
|
gab
2014/06/12 18:00:24
This was the last caller to first_run::RemoveSenti
grt (UTC plus 2)
2014/06/12 18:29:15
Wahoo!
| |
| 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 | 360 } // namespace |
| 406 | 361 |
| 407 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) | 362 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) |
| 408 : ui::WebDialogUI(web_ui) { | 363 : ui::WebDialogUI(web_ui) { |
| 409 content::WebUIDataSource::Add( | 364 content::WebUIDataSource::Add( |
| 410 Profile::FromWebUI(web_ui), CreateSetAsDefaultBrowserUIHTMLSource()); | 365 Profile::FromWebUI(web_ui), CreateSetAsDefaultBrowserUIHTMLSource()); |
| 411 } | 366 } |
| 412 | 367 |
| 413 // static | 368 // static |
| 414 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { | 369 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { |
| 415 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 370 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 416 SetAsDefaultBrowserDialogImpl* dialog = | 371 SetAsDefaultBrowserDialogImpl* dialog = |
| 417 new SetAsDefaultBrowserDialogImpl(profile, browser); | 372 new SetAsDefaultBrowserDialogImpl(profile, browser); |
| 418 dialog->ShowDialog(); | 373 dialog->ShowDialog(); |
| 419 } | 374 } |
| OLD | NEW |