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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/gfx/vector_icons_public.h" | 38 #include "ui/gfx/vector_icons_public.h" |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // The delegate for the infobar shown when Chrome is not the default browser. | 42 // The delegate for the infobar shown when Chrome is not the default browser. |
| 43 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 43 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 44 public: | 44 public: |
| 45 // Creates a default browser infobar and delegate and adds the infobar to | 45 // Creates a default browser infobar and delegate and adds the infobar to |
| 46 // |infobar_service|. | 46 // |infobar_service|. |
| 47 static void Create(InfoBarService* infobar_service, PrefService* prefs); | 47 static void Create(InfoBarService* infobar_service, Profile* profile); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // Possible user interactions with the default browser info bar. | 50 // Possible user interactions with the default browser info bar. |
| 51 // Do not modify the ordering as it is important for UMA. | 51 // Do not modify the ordering as it is important for UMA. |
| 52 enum InfoBarUserInteraction { | 52 enum InfoBarUserInteraction { |
| 53 // The user clicked the "Set as default" button. | 53 // The user clicked the "Set as default" button. |
| 54 START_SET_AS_DEFAULT, | 54 START_SET_AS_DEFAULT, |
| 55 // The user doesn't want to be reminded again. | 55 // The user doesn't want to be reminded again. |
| 56 DONT_ASK_AGAIN, | 56 DONT_ASK_AGAIN, |
| 57 // The user did not interact with the info bar. | 57 // The user did not interact with the info bar. |
| 58 IGNORE_INFO_BAR, | 58 IGNORE_INFO_BAR, |
| 59 NUM_INFO_BAR_USER_INTERACTION_TYPES | 59 NUM_INFO_BAR_USER_INTERACTION_TYPES |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); | 62 explicit DefaultBrowserInfoBarDelegate(Profile* profile); |
| 63 ~DefaultBrowserInfoBarDelegate() override; | 63 ~DefaultBrowserInfoBarDelegate() override; |
| 64 | 64 |
| 65 void AllowExpiry() { should_expire_ = true; } | 65 void AllowExpiry() { should_expire_ = true; } |
| 66 | 66 |
| 67 // ConfirmInfoBarDelegate: | 67 // ConfirmInfoBarDelegate: |
| 68 Type GetInfoBarType() const override; | 68 Type GetInfoBarType() const override; |
| 69 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 69 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 70 int GetIconId() const override; | 70 int GetIconId() const override; |
| 71 gfx::VectorIconId GetVectorIconId() const override; | 71 gfx::VectorIconId GetVectorIconId() const override; |
| 72 bool ShouldExpire(const NavigationDetails& details) const override; | 72 bool ShouldExpire(const NavigationDetails& details) const override; |
| 73 base::string16 GetMessageText() const override; | 73 base::string16 GetMessageText() const override; |
| 74 base::string16 GetButtonLabel(InfoBarButton button) const override; | 74 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 75 bool OKButtonTriggersUACPrompt() const override; | 75 bool OKButtonTriggersUACPrompt() const override; |
| 76 bool Accept() override; | 76 bool Accept() override; |
| 77 bool Cancel() override; | 77 bool Cancel() override; |
| 78 | 78 |
| 79 // The prefs to use. | 79 // The WebContents's corresponding profile. |
| 80 PrefService* prefs_; | 80 Profile* profile_; |
| 81 | 81 |
| 82 // Whether the user clicked one of the buttons. | 82 // Whether the user clicked one of the buttons. |
| 83 bool action_taken_; | 83 bool action_taken_; |
| 84 | 84 |
| 85 // Whether the info-bar should be dismissed on the next navigation. | 85 // Whether the info-bar should be dismissed on the next navigation. |
| 86 bool should_expire_; | 86 bool should_expire_; |
| 87 | 87 |
| 88 // Used to delay the expiration of the info-bar. | 88 // Used to delay the expiration of the info-bar. |
| 89 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; | 89 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, | 95 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 96 PrefService* prefs) { | 96 Profile* profile) { |
| 97 infobar_service->AddInfoBar( | 97 infobar_service->AddInfoBar( |
| 98 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 98 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 99 new DefaultBrowserInfoBarDelegate(prefs)))); | 99 new DefaultBrowserInfoBarDelegate(profile)))); |
| 100 } | 100 } |
| 101 | 101 |
| 102 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(PrefService* prefs) | 102 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) |
| 103 : ConfirmInfoBarDelegate(), | 103 : ConfirmInfoBarDelegate(), |
| 104 prefs_(prefs), | 104 profile_(profile), |
| 105 action_taken_(false), | 105 action_taken_(false), |
| 106 should_expire_(false), | 106 should_expire_(false), |
| 107 weak_factory_(this) { | 107 weak_factory_(this) { |
| 108 // We want the info-bar to stick-around for few seconds and then be hidden | 108 // We want the info-bar to stick-around for few seconds and then be hidden |
| 109 // on the next navigation after that. | 109 // on the next navigation after that. |
| 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 111 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 111 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 112 weak_factory_.GetWeakPtr()), | 112 weak_factory_.GetWeakPtr()), |
| 113 base::TimeDelta::FromSeconds(8)); | 113 base::TimeDelta::FromSeconds(8)); |
| 114 } | 114 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool DefaultBrowserInfoBarDelegate::Cancel() { | 189 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 190 action_taken_ = true; | 190 action_taken_ = true; |
| 191 content::RecordAction( | 191 content::RecordAction( |
| 192 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain")); | 192 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain")); |
| 193 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 193 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 194 InfoBarUserInteraction::DONT_ASK_AGAIN, | 194 InfoBarUserInteraction::DONT_ASK_AGAIN, |
| 195 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 195 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 196 // User clicked "Don't ask me again", remember that. | 196 // User clicked "Don't ask me again", remember that. |
| 197 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 197 chrome::DefaultBrowserPromptDeclined(profile_); |
| 198 return true; | 198 return true; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) { | 201 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) { |
| 202 Profile* profile = | 202 Profile* profile = |
| 203 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | 203 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 204 if (profile) | 204 if (profile) |
| 205 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); | 205 chrome::ResetDefaultBrowserPrompt(profile); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ShowPrompt() { | 208 void ShowPrompt() { |
| 209 Browser* browser = chrome::FindLastActive(); | 209 Browser* browser = chrome::FindLastActive(); |
| 210 if (!browser) | 210 if (!browser) |
| 211 return; // Reached during ui tests. | 211 return; // Reached during ui tests. |
| 212 | 212 |
| 213 // In ChromeBot tests, there might be a race. This line appears to get | 213 // In ChromeBot tests, there might be a race. This line appears to get |
| 214 // called during shutdown and |tab| can be NULL. | 214 // called during shutdown and |tab| can be NULL. |
| 215 content::WebContents* web_contents = | 215 content::WebContents* web_contents = |
| 216 browser->tab_strip_model()->GetActiveWebContents(); | 216 browser->tab_strip_model()->GetActiveWebContents(); |
| 217 if (!web_contents) | 217 if (!web_contents) |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 DefaultBrowserInfoBarDelegate::Create( | 220 DefaultBrowserInfoBarDelegate::Create( |
| 221 InfoBarService::FromWebContents(web_contents), | 221 InfoBarService::FromWebContents(web_contents), browser->profile()); |
| 222 Profile::FromBrowserContext(web_contents->GetBrowserContext()) | |
| 223 ->GetPrefs()); | |
| 224 } | 222 } |
| 225 | 223 |
| 226 void OnCheckIsDefaultBrowserFinished( | 224 void OnCheckIsDefaultBrowserFinished( |
| 227 const base::FilePath& profile_path, | 225 const base::FilePath& profile_path, |
| 228 bool show_prompt, | 226 bool show_prompt, |
| 229 shell_integration::DefaultWebClientState state) { | 227 shell_integration::DefaultWebClientState state) { |
| 230 if (state == shell_integration::IS_DEFAULT) { | 228 if (state == shell_integration::IS_DEFAULT) { |
| 231 // Notify the user in the future if Chrome ceases to be the user's chosen | 229 // Notify the user in the future if Chrome ceases to be the user's chosen |
| 232 // default browser. | 230 // default browser. |
| 233 ResetCheckDefaultBrowserPref(profile_path); | 231 ResetCheckDefaultBrowserPref(profile_path); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 254 prefs::kDefaultBrowserSettingEnabled)) { | 252 prefs::kDefaultBrowserSettingEnabled)) { |
| 255 // Handling of the browser.default_browser_setting_enabled policy setting is | 253 // Handling of the browser.default_browser_setting_enabled policy setting is |
| 256 // taken care of in BrowserProcessImpl. | 254 // taken care of in BrowserProcessImpl. |
| 257 return; | 255 return; |
| 258 } | 256 } |
| 259 | 257 |
| 260 PrefService* prefs = profile->GetPrefs(); | 258 PrefService* prefs = profile->GetPrefs(); |
| 261 // Reset preferences if kResetCheckDefaultBrowser is true. | 259 // Reset preferences if kResetCheckDefaultBrowser is true. |
| 262 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) { | 260 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) { |
| 263 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false); | 261 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false); |
| 264 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); | 262 ResetDefaultBrowserPrompt(profile); |
| 265 } | 263 } |
| 266 | 264 |
| 267 // Check if Chrome is the default browser but do not prompt if: | 265 // Check if Chrome is the default browser but do not prompt if: |
| 268 // - The user said "don't ask me again" on the infobar earlier. | 266 // - The user said "don't ask me again" on the infobar earlier. |
| 269 // - The "suppress_default_browser_prompt_for_version" master preference is | 267 // - The "suppress_default_browser_prompt_for_version" master preference is |
| 270 // set to the current version. | 268 // set to the current version. |
| 271 bool show_prompt = prefs->GetBoolean(prefs::kCheckDefaultBrowser); | 269 bool show_prompt = prefs->GetBoolean(prefs::kCheckDefaultBrowser); |
| 272 if (show_prompt) { | 270 if (show_prompt) { |
| 273 const std::string disable_version_string = | 271 const std::string disable_version_string = |
| 274 g_browser_process->local_state()->GetString( | 272 g_browser_process->local_state()->GetString( |
| 275 prefs::kBrowserSuppressDefaultBrowserPrompt); | 273 prefs::kBrowserSuppressDefaultBrowserPrompt); |
| 276 const Version disable_version(disable_version_string); | 274 const Version disable_version(disable_version_string); |
| 277 DCHECK(disable_version_string.empty() || disable_version.IsValid()); | 275 DCHECK(disable_version_string.empty() || disable_version.IsValid()); |
| 278 if (disable_version.IsValid() && | 276 if (disable_version.IsValid() && |
| 279 disable_version == Version(version_info::GetVersionNumber())) { | 277 disable_version == Version(version_info::GetVersionNumber())) { |
| 280 show_prompt = false; | 278 show_prompt = false; |
| 281 } | 279 } |
| 282 } | 280 } |
| 283 | 281 |
| 284 scoped_refptr<shell_integration::DefaultBrowserWorker>( | 282 scoped_refptr<shell_integration::DefaultBrowserWorker>( |
| 285 new shell_integration::DefaultBrowserWorker(base::Bind( | 283 new shell_integration::DefaultBrowserWorker(base::Bind( |
| 286 &OnCheckIsDefaultBrowserFinished, profile->GetPath(), show_prompt))) | 284 &OnCheckIsDefaultBrowserFinished, profile->GetPath(), show_prompt))) |
| 287 ->StartCheckIsDefault(); | 285 ->StartCheckIsDefault(); |
| 288 } | 286 } |
| 289 | 287 |
| 288 void DefaultBrowserPromptDeclined(Profile* profile) { | |
| 289 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, false); | |
| 290 } | |
| 291 | |
| 292 void ResetDefaultBrowserPrompt(Profile* profile) { | |
| 293 profile->GetPrefs()->ClearPref(prefs::kCheckDefaultBrowser); | |
|
msw
2016/04/06 22:04:55
q: does this yield equivalent behavior as setting
grt (UTC plus 2)
2016/04/07 00:49:30
The default is true at the point of registration (
msw
2016/04/07 01:42:59
Not afaik, so that sg. Still lgtm
| |
| 294 } | |
| 295 | |
| 290 #if !defined(OS_WIN) | 296 #if !defined(OS_WIN) |
| 291 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 297 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 292 return false; | 298 return false; |
| 293 } | 299 } |
| 294 #endif | 300 #endif |
| 295 | 301 |
| 296 } // namespace chrome | 302 } // namespace chrome |
| OLD | NEW |