Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/ui/startup/default_browser_infobar_delegate.cc

Issue 1974153002: Add an experiment for the default browser infobar on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Specific include rule for unittests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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};
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(), profile_(profile), weak_factory_(this) {
47 // We want the info-bar to stick-around for few seconds and then be hidden
48 // on the next navigation after that.
49 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
50 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry,
51 weak_factory_.GetWeakPtr()),
52 base::TimeDelta::FromSeconds(8));
53 }
54
55 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() = default;
56
57 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType()
58 const {
59 #if defined(OS_WIN)
60 return WARNING_TYPE;
61 #else
62 return PAGE_ACTION_TYPE;
63 #endif
64 }
65
66 infobars::InfoBarDelegate::InfoBarIdentifier
67 DefaultBrowserInfoBarDelegate::GetIdentifier() const {
68 return DEFAULT_BROWSER_INFOBAR_DELEGATE;
69 }
70
71 int DefaultBrowserInfoBarDelegate::GetIconId() const {
72 return IDR_PRODUCT_LOGO_32;
73 }
74
75 gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const {
76 #if defined(OS_MACOSX) || defined(OS_ANDROID)
77 return gfx::VectorIconId::VECTOR_ICON_NONE;
78 #else
79 return gfx::VectorIconId::CHROME_PRODUCT;
80 #endif
81 }
82
83 bool DefaultBrowserInfoBarDelegate::ShouldExpire(
84 const NavigationDetails& details) const {
85 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
86 }
87
88 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() {
89 content::RecordAction(
90 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss"));
91 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
92 IGNORE_INFO_BAR,
93 NUM_INFO_BAR_USER_INTERACTION_TYPES);
94 }
95
96 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const {
97 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT);
98 }
99
100 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel(
101 InfoBarButton button) const {
102 #if defined(OS_WIN)
103 // On Windows 10, the "OK" button opens the Windows Settings application,
104 // through which the user must make their default browser choice.
105 const int kSetAsDefaultButtonMessageId =
106 base::win::GetVersion() >= base::win::VERSION_WIN10
107 ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10
108 : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
109 #else
110 const int kSetAsDefaultButtonMessageId =
111 IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
112 #endif
113 return l10n_util::GetStringUTF16(
114 button == BUTTON_OK ? kSetAsDefaultButtonMessageId
115 : IDS_DEFAULT_BROWSER_INFOBAR_CANCEL_BUTTON_LABEL);
116 }
117
118 // Setting an app as the default browser doesn't require elevation directly, but
119 // it does require registering it as the protocol handler for "http", so if
120 // protocol registration in general requires elevation, this does as well.
121 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
122 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient();
123 }
124
125 bool DefaultBrowserInfoBarDelegate::Accept() {
126 content::RecordAction(
127 base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
128 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
129 ACCEPT_INFO_BAR,
130 NUM_INFO_BAR_USER_INTERACTION_TYPES);
131
132 bool close_infobar = true;
133 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback;
134
135 if (IsStickyDefaultBrowserPromptEnabled()) {
136 // When the experiment is enabled, the infobar is only closed when the
137 // DefaultBrowserWorker is finished.
138 set_as_default_callback =
139 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished,
140 weak_factory_.GetWeakPtr());
141 close_infobar = false;
142 }
143
144 // The worker pointer is reference counted. While it is running, the
145 // message loops of the FILE and UI thread will hold references to it
146 // and it will be automatically freed once all its tasks have finished.
147 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault();
148 return close_infobar;
149 }
150
151 bool DefaultBrowserInfoBarDelegate::Cancel() {
152 // This can get reached in tests where profile_ is null.
153 if (profile_)
154 chrome::DefaultBrowserPromptDeclined(profile_);
155 content::RecordAction(
156 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel"));
157 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
158 CANCEL_INFO_BAR,
159 NUM_INFO_BAR_USER_INTERACTION_TYPES);
160 return true;
161 }
162
163 scoped_refptr<shell_integration::DefaultBrowserWorker>
164 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker(
165 const shell_integration::DefaultWebClientWorkerCallback& callback) {
166 return new shell_integration::DefaultBrowserWorker(callback);
167 }
168
169 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished(
170 shell_integration::DefaultWebClientState state) {
171 infobar()->owner()->RemoveInfoBar(infobar());
172 }
173
174 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698