Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/startup/default_browser_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/metrics/histogram_macros.h" | |
| 8 #include "base/threading/thread_task_runner_handle.h" | |
| 9 #include "chrome/browser/ui/startup/default_browser_prompt.h" | |
| 10 #include "chrome/grit/chromium_strings.h" | |
| 11 #include "chrome/grit/generated_resources.h" | |
| 12 #include "components/infobars/core/infobar.h" | |
| 13 #include "content/public/browser/user_metrics.h" | |
| 14 #include "grit/theme_resources.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 #include "ui/gfx/vector_icons_public.h" | |
| 17 | |
| 18 #if defined(OS_WIN) | |
| 19 #include "base/win/windows_version.h" | |
| 20 #endif | |
| 21 | |
| 22 namespace chrome { | |
| 23 /* | |
| 24 const base::Feature kStickyDefaultBrowserPrompt{ | |
| 25 "StickyDefaultBrowserPrompt", base::FEATURE_DISABLED_BY_DEFAULT};*/ | |
|
Peter Kasting
2016/06/01 19:32:10
Remove
Patrick Monette
2016/06/01 22:07:40
Done.
| |
| 26 | |
| 27 bool IsStickyDefaultBrowserPromptEnabled() { | |
| 28 #if defined(OS_WIN) | |
| 29 // The flow to set the default browser is only asynchronous on Windows 10+. | |
| 30 return base::win::GetVersion() >= base::win::VERSION_WIN10 && | |
| 31 base::FeatureList::IsEnabled(kStickyDefaultBrowserPrompt); | |
| 32 #else | |
| 33 return false; | |
| 34 #endif | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, | |
| 39 Profile* profile) { | |
| 40 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | |
| 41 std::unique_ptr<ConfirmInfoBarDelegate>( | |
| 42 new DefaultBrowserInfoBarDelegate(profile)))); | |
| 43 } | |
| 44 | |
| 45 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile) | |
| 46 : ConfirmInfoBarDelegate(), | |
| 47 profile_(profile), | |
| 48 should_expire_(false), | |
| 49 weak_factory_(this) { | |
| 50 // We want the info-bar to stick-around for few seconds and then be hidden | |
| 51 // on the next navigation after that. | |
| 52 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 53 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | |
| 54 weak_factory_.GetWeakPtr()), | |
| 55 base::TimeDelta::FromSeconds(8)); | |
| 56 } | |
| 57 | |
| 58 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() = default; | |
| 59 | |
| 60 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() | |
| 61 const { | |
| 62 #if defined(OS_WIN) | |
| 63 return WARNING_TYPE; | |
| 64 #else | |
| 65 return PAGE_ACTION_TYPE; | |
| 66 #endif | |
| 67 } | |
| 68 | |
| 69 infobars::InfoBarDelegate::InfoBarIdentifier | |
| 70 DefaultBrowserInfoBarDelegate::GetIdentifier() const { | |
| 71 return DEFAULT_BROWSER_INFOBAR_DELEGATE; | |
| 72 } | |
| 73 | |
| 74 int DefaultBrowserInfoBarDelegate::GetIconId() const { | |
| 75 return IDR_PRODUCT_LOGO_32; | |
| 76 } | |
| 77 | |
| 78 gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const { | |
| 79 #if defined(OS_MACOSX) || defined(OS_ANDROID) | |
| 80 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 81 #else | |
| 82 return gfx::VectorIconId::CHROME_PRODUCT; | |
| 83 #endif | |
| 84 } | |
| 85 | |
| 86 bool DefaultBrowserInfoBarDelegate::ShouldExpire( | |
| 87 const NavigationDetails& details) const { | |
| 88 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); | |
| 89 } | |
| 90 | |
| 91 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { | |
| 92 content::RecordAction( | |
| 93 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); | |
| 94 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | |
| 95 IGNORE_INFO_BAR, | |
| 96 NUM_INFO_BAR_USER_INTERACTION_TYPES); | |
| 97 } | |
| 98 | |
| 99 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { | |
| 100 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); | |
| 101 } | |
| 102 | |
| 103 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( | |
| 104 InfoBarButton button) const { | |
| 105 #if defined(OS_WIN) | |
| 106 // On Windows 10, the "OK" button opens the Windows Settings application, | |
| 107 // through which the user must make their default browser choice. | |
| 108 const int kSetAsDefaultButtonMessageId = | |
| 109 base::win::GetVersion() >= base::win::VERSION_WIN10 | |
| 110 ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10 | |
| 111 : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; | |
| 112 #else | |
| 113 const int kSetAsDefaultButtonMessageId = | |
| 114 IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; | |
| 115 #endif | |
| 116 return l10n_util::GetStringUTF16( | |
| 117 button == BUTTON_OK ? kSetAsDefaultButtonMessageId | |
| 118 : IDS_DEFAULT_BROWSER_INFOBAR_CANCEL_BUTTON_LABEL); | |
| 119 } | |
| 120 | |
| 121 // Setting an app as the default browser doesn't require elevation directly, but | |
| 122 // it does require registering it as the protocol handler for "http", so if | |
| 123 // protocol registration in general requires elevation, this does as well. | |
| 124 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | |
| 125 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); | |
| 126 } | |
| 127 | |
| 128 bool DefaultBrowserInfoBarDelegate::Accept() { | |
| 129 content::RecordAction( | |
| 130 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); | |
| 131 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | |
| 132 ACCEPT_INFO_BAR, | |
| 133 NUM_INFO_BAR_USER_INTERACTION_TYPES); | |
| 134 | |
| 135 bool close_infobar = true; | |
| 136 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback; | |
| 137 | |
| 138 if (IsStickyDefaultBrowserPromptEnabled()) { | |
| 139 // When the experiment is enabled, the infobar is only closed when the | |
| 140 // DefaultBrowserWorker is finished. | |
| 141 set_as_default_callback = | |
| 142 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished, | |
| 143 weak_factory_.GetWeakPtr()); | |
| 144 close_infobar = false; | |
| 145 } | |
| 146 | |
| 147 // The worker pointer is reference counted. While it is running, the | |
| 148 // message loops of the FILE and UI thread will hold references to it | |
| 149 // and it will be automatically freed once all its tasks have finished. | |
| 150 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault(); | |
| 151 return close_infobar; | |
| 152 } | |
| 153 | |
| 154 bool DefaultBrowserInfoBarDelegate::Cancel() { | |
| 155 // This can get reached in tests where profile_ is null. | |
| 156 if (profile_) | |
| 157 chrome::DefaultBrowserPromptDeclined(profile_); | |
| 158 content::RecordAction( | |
| 159 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); | |
| 160 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | |
| 161 CANCEL_INFO_BAR, | |
| 162 NUM_INFO_BAR_USER_INTERACTION_TYPES); | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 scoped_refptr<shell_integration::DefaultBrowserWorker> | |
| 167 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker( | |
| 168 const shell_integration::DefaultWebClientWorkerCallback& callback) { | |
| 169 return new shell_integration::DefaultBrowserWorker(callback); | |
| 170 } | |
| 171 | |
| 172 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( | |
| 173 shell_integration::DefaultWebClientState state) { | |
| 174 infobar()->owner()->RemoveInfoBar(infobar()); | |
| 175 } | |
| 176 | |
| 177 } // namespace chrome | |
| OLD | NEW |