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/startup/default_browser_prompt.h" | 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/user_metrics_action.h" | |
| 12 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/version.h" | 17 #include "base/version.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/shell_integration.h" | |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/grit/chromium_strings.h" | 26 #include "chrome/grit/chromium_strings.h" |
| 27 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/infobars/core/confirm_infobar_delegate.h" | 28 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 29 #include "components/infobars/core/infobar.h" | 29 #include "components/infobars/core/infobar.h" |
| 30 #include "components/version_info/version_info.h" | 30 #include "components/version_info/version_info.h" |
| 31 #include "content/public/browser/navigation_details.h" | 31 #include "content/public/browser/navigation_details.h" |
| 32 #include "content/public/browser/user_metrics.h" | |
| 32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 33 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/gfx/vector_icons_public.h" | 36 #include "ui/gfx/vector_icons_public.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // A ShellIntegration::DefaultWebClientObserver that records user metrics for | |
| 40 // the result of making Chrome the default browser. | |
| 41 class SetDefaultBrowserObserver | |
| 42 : public ShellIntegration::DefaultWebClientObserver { | |
| 43 public: | |
| 44 SetDefaultBrowserObserver(); | |
| 45 ~SetDefaultBrowserObserver() override; | |
| 46 | |
| 47 private: | |
| 48 void SetDefaultWebClientUIState( | |
| 49 ShellIntegration::DefaultWebClientUIState state) override; | |
| 50 void OnSetAsDefaultConcluded(bool succeeded) override; | |
| 51 bool IsOwnedByWorker() override; | |
| 52 bool IsInteractiveSetDefaultPermitted() override; | |
| 53 | |
| 54 // True if an interactive flow will be used (i.e., Windows 8+). | |
| 55 bool interactive_; | |
| 56 | |
| 57 // The result of the call to ShellIntegration::SetAsDefaultBrowser() or | |
| 58 // ShellIntegration::SetAsDefaultBrowserInteractive(). | |
| 59 bool interaction_succeeded_ = false; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(SetDefaultBrowserObserver); | |
| 62 }; | |
| 63 | |
| 64 SetDefaultBrowserObserver::SetDefaultBrowserObserver() | |
| 65 : interactive_(ShellIntegration::CanSetAsDefaultBrowser() == | |
| 66 ShellIntegration::SET_DEFAULT_INTERACTIVE) { | |
| 67 // Log that an attempt is about to be made to set one way or the other. | |
| 68 if (interactive_) | |
| 69 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefaultUI", true); | |
| 70 else | |
| 71 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefault", true); | |
| 72 } | |
| 73 | |
| 74 SetDefaultBrowserObserver::~SetDefaultBrowserObserver() {} | |
| 75 | |
| 76 void SetDefaultBrowserObserver::SetDefaultWebClientUIState( | |
| 77 ShellIntegration::DefaultWebClientUIState state) { | |
| 78 if (interactive_ && interaction_succeeded_ && | |
| 79 state == ShellIntegration::STATE_NOT_DEFAULT) { | |
| 80 // The interactive flow succeeded, yet Chrome is not the default browser. | |
| 81 // This likely means that the user selected another browser from the panel. | |
| 82 // Consider this the same as canceling the infobar. | |
| 83 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.DontSetAsDefault", true); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void SetDefaultBrowserObserver::OnSetAsDefaultConcluded(bool succeeded) { | |
| 88 interaction_succeeded_ = succeeded; | |
| 89 if (interactive_ && !succeeded) { | |
| 90 // Log that the interactive flow failed. | |
| 91 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.SetAsDefaultUIFailed", true); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 bool SetDefaultBrowserObserver::IsOwnedByWorker() { | |
| 96 // Instruct the DefaultBrowserWorker to delete this instance when it is done. | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 bool SetDefaultBrowserObserver::IsInteractiveSetDefaultPermitted() { | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 // The delegate for the infobar shown when Chrome is not the default browser. | 40 // The delegate for the infobar shown when Chrome is not the default browser. |
| 105 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 41 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 106 public: | 42 public: |
| 107 // Creates a default browser infobar and delegate and adds the infobar to | 43 // Creates a default browser infobar and delegate and adds the infobar to |
| 108 // |infobar_service|. | 44 // |infobar_service|. |
| 109 static void Create(InfoBarService* infobar_service, PrefService* prefs); | 45 static void Create(InfoBarService* infobar_service, PrefService* prefs); |
| 110 | 46 |
| 111 private: | 47 private: |
| 112 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); | 48 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); |
| 113 ~DefaultBrowserInfoBarDelegate() override; | 49 ~DefaultBrowserInfoBarDelegate() override; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // We want the info-bar to stick-around for few seconds and then be hidden | 93 // We want the info-bar to stick-around for few seconds and then be hidden |
| 158 // on the next navigation after that. | 94 // on the next navigation after that. |
| 159 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 160 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 96 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 161 weak_factory_.GetWeakPtr()), | 97 weak_factory_.GetWeakPtr()), |
| 162 base::TimeDelta::FromSeconds(8)); | 98 base::TimeDelta::FromSeconds(8)); |
| 163 } | 99 } |
| 164 | 100 |
| 165 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 101 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
| 166 if (!action_taken_) | 102 if (!action_taken_) |
| 167 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.Ignored", true); | 103 UMA_HISTOGRAM_BOOLEAN("DefaultBrowser.InfoBar.Ignored", true); |
| 168 } | 104 } |
| 169 | 105 |
| 170 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() | 106 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() |
| 171 const { | 107 const { |
| 172 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
| 173 return WARNING_TYPE; | 109 return WARNING_TYPE; |
| 174 #else | 110 #else |
| 175 return PAGE_ACTION_TYPE; | 111 return PAGE_ACTION_TYPE; |
| 176 #endif | 112 #endif |
| 177 } | 113 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 206 | 142 |
| 207 // Setting an app as the default browser doesn't require elevation directly, but | 143 // Setting an app as the default browser doesn't require elevation directly, but |
| 208 // it does require registering it as the protocol handler for "http", so if | 144 // it does require registering it as the protocol handler for "http", so if |
| 209 // protocol registration in general requires elevation, this does as well. | 145 // protocol registration in general requires elevation, this does as well. |
| 210 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | 146 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { |
| 211 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient(); | 147 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient(); |
| 212 } | 148 } |
| 213 | 149 |
| 214 bool DefaultBrowserInfoBarDelegate::Accept() { | 150 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 215 action_taken_ = true; | 151 action_taken_ = true; |
| 152 content::RecordAction( | |
| 153 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); | |
| 154 UMA_HISTOGRAM_ENUMERATION( | |
|
grt (UTC plus 2)
2015/11/03 21:12:22
I'm not a fan of having an enum in ShellIntegratio
Patrick Monette
2015/11/10 19:22:47
Done.
| |
| 155 "SetDefaultBrowser.Location", | |
| 156 ShellIntegration::SetDefaultBrowserLocation::INFO_BAR, | |
| 157 ShellIntegration::SetDefaultBrowserLocation:: | |
| 158 NUM_SET_DEFAULT_BROWSER_LOCATION_TYPES); | |
| 216 scoped_refptr<ShellIntegration::DefaultBrowserWorker>( | 159 scoped_refptr<ShellIntegration::DefaultBrowserWorker>( |
| 217 new ShellIntegration::DefaultBrowserWorker(new SetDefaultBrowserObserver)) | 160 new ShellIntegration::DefaultBrowserWorker(nullptr)) |
| 218 ->StartSetAsDefault(); | 161 ->StartSetAsDefault(); |
| 219 return true; | 162 return true; |
| 220 } | 163 } |
| 221 | 164 |
| 222 bool DefaultBrowserInfoBarDelegate::Cancel() { | 165 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 223 action_taken_ = true; | 166 action_taken_ = true; |
| 224 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.DontSetAsDefault", true); | 167 content::RecordAction( |
| 168 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); | |
| 225 // User clicked "Don't ask me again", remember that. | 169 // User clicked "Don't ask me again", remember that. |
| 226 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 170 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 227 return true; | 171 return true; |
| 228 } | 172 } |
| 229 | 173 |
| 230 // A ShellIntegration::DefaultWebClientObserver that handles the check to | 174 // A ShellIntegration::DefaultWebClientObserver that handles the check to |
| 231 // determine whether or not to show the default browser prompt. If Chrome is the | 175 // determine whether or not to show the default browser prompt. If Chrome is the |
| 232 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the | 176 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the |
| 233 // prompt is shown. | 177 // prompt is shown. |
| 234 class CheckDefaultBrowserObserver | 178 class CheckDefaultBrowserObserver |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 ->StartCheckIsDefault(); | 298 ->StartCheckIsDefault(); |
| 355 } | 299 } |
| 356 | 300 |
| 357 #if !defined(OS_WIN) | 301 #if !defined(OS_WIN) |
| 358 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 302 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 359 return false; | 303 return false; |
| 360 } | 304 } |
| 361 #endif | 305 #endif |
| 362 | 306 |
| 363 } // namespace chrome | 307 } // namespace chrome |
| OLD | NEW |