| 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: |
| 48 // Possible user interactions with the default browser info bar. |
| 49 // Do not modify the ordering as it is important for UMA. |
| 50 enum InfoBarUserInteraction { |
| 51 // The user clicked the "Set as default" button. |
| 52 StartSetAsDefault, |
| 53 // The user doesn't want to be reminded again. |
| 54 DontAskAgain, |
| 55 // The user did not interact with the info bar. |
| 56 Ignore, |
| 57 NUM_INFO_BAR_USER_INTERACTION_TYPES |
| 58 }; |
| 59 |
| 112 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); | 60 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); |
| 113 ~DefaultBrowserInfoBarDelegate() override; | 61 ~DefaultBrowserInfoBarDelegate() override; |
| 114 | 62 |
| 115 void AllowExpiry() { should_expire_ = true; } | 63 void AllowExpiry() { should_expire_ = true; } |
| 116 | 64 |
| 117 // ConfirmInfoBarDelegate: | 65 // ConfirmInfoBarDelegate: |
| 118 Type GetInfoBarType() const override; | 66 Type GetInfoBarType() const override; |
| 119 int GetIconId() const override; | 67 int GetIconId() const override; |
| 120 gfx::VectorIconId GetVectorIconId() const override; | 68 gfx::VectorIconId GetVectorIconId() const override; |
| 121 bool ShouldExpire(const NavigationDetails& details) const override; | 69 bool ShouldExpire(const NavigationDetails& details) const override; |
| (...skipping 35 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 | 105 // We want the info-bar to stick-around for few seconds and then be hidden |
| 158 // on the next navigation after that. | 106 // on the next navigation after that. |
| 159 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 107 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 160 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 108 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 161 weak_factory_.GetWeakPtr()), | 109 weak_factory_.GetWeakPtr()), |
| 162 base::TimeDelta::FromSeconds(8)); | 110 base::TimeDelta::FromSeconds(8)); |
| 163 } | 111 } |
| 164 | 112 |
| 165 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 113 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
| 166 if (!action_taken_) | 114 if (!action_taken_) |
| 167 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.Ignored", true); | 115 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 116 InfoBarUserInteraction::Ignore, |
| 117 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 168 } | 118 } |
| 169 | 119 |
| 170 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() | 120 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() |
| 171 const { | 121 const { |
| 172 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
| 173 return WARNING_TYPE; | 123 return WARNING_TYPE; |
| 174 #else | 124 #else |
| 175 return PAGE_ACTION_TYPE; | 125 return PAGE_ACTION_TYPE; |
| 176 #endif | 126 #endif |
| 177 } | 127 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 206 | 156 |
| 207 // Setting an app as the default browser doesn't require elevation directly, but | 157 // 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 | 158 // it does require registering it as the protocol handler for "http", so if |
| 209 // protocol registration in general requires elevation, this does as well. | 159 // protocol registration in general requires elevation, this does as well. |
| 210 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | 160 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { |
| 211 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient(); | 161 return ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient(); |
| 212 } | 162 } |
| 213 | 163 |
| 214 bool DefaultBrowserInfoBarDelegate::Accept() { | 164 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 215 action_taken_ = true; | 165 action_taken_ = true; |
| 166 content::RecordAction( |
| 167 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); |
| 168 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 169 InfoBarUserInteraction::StartSetAsDefault, |
| 170 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 216 scoped_refptr<ShellIntegration::DefaultBrowserWorker>( | 171 scoped_refptr<ShellIntegration::DefaultBrowserWorker>( |
| 217 new ShellIntegration::DefaultBrowserWorker(new SetDefaultBrowserObserver)) | 172 new ShellIntegration::DefaultBrowserWorker(nullptr)) |
| 218 ->StartSetAsDefault(); | 173 ->StartSetAsDefault(); |
| 219 return true; | 174 return true; |
| 220 } | 175 } |
| 221 | 176 |
| 222 bool DefaultBrowserInfoBarDelegate::Cancel() { | 177 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 223 action_taken_ = true; | 178 action_taken_ = true; |
| 224 UMA_HISTOGRAM_BOOLEAN("DefaultBrowserWarning.DontSetAsDefault", true); | 179 content::RecordAction( |
| 180 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain")); |
| 181 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 182 InfoBarUserInteraction::DontAskAgain, |
| 183 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 225 // User clicked "Don't ask me again", remember that. | 184 // User clicked "Don't ask me again", remember that. |
| 226 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 185 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 227 return true; | 186 return true; |
| 228 } | 187 } |
| 229 | 188 |
| 230 // A ShellIntegration::DefaultWebClientObserver that handles the check to | 189 // A ShellIntegration::DefaultWebClientObserver that handles the check to |
| 231 // determine whether or not to show the default browser prompt. If Chrome is the | 190 // 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 | 191 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the |
| 233 // prompt is shown. | 192 // prompt is shown. |
| 234 class CheckDefaultBrowserObserver | 193 class CheckDefaultBrowserObserver |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 ->StartCheckIsDefault(); | 313 ->StartCheckIsDefault(); |
| 355 } | 314 } |
| 356 | 315 |
| 357 #if !defined(OS_WIN) | 316 #if !defined(OS_WIN) |
| 358 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 317 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 359 return false; | 318 return false; |
| 360 } | 319 } |
| 361 #endif | 320 #endif |
| 362 | 321 |
| 363 } // namespace chrome | 322 } // namespace chrome |
| OLD | NEW |