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

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: Compile the test only on desktop platforms 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 bool IsStickyDefaultBrowserPromptEnabled() {
25 #if defined(OS_WIN)
26 // The flow to set the default browser is only asynchronous on Windows 10+.
27 return base::win::GetVersion() >= base::win::VERSION_WIN10 &&
28 base::FeatureList::IsEnabled(kStickyDefaultBrowserPrompt);
29 #else
30 return false;
31 #endif
32 }
33
34 // static
35 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service,
36 Profile* profile) {
37 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
38 std::unique_ptr<ConfirmInfoBarDelegate>(
39 new DefaultBrowserInfoBarDelegate(profile))));
40 }
41
42 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile)
43 : ConfirmInfoBarDelegate(),
44 profile_(profile),
45 should_expire_(false),
46 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 void DefaultBrowserInfoBarDelegate::AllowExpiry() {
58 should_expire_ = true;
59 }
60
61 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType()
62 const {
63 #if defined(OS_WIN)
64 return WARNING_TYPE;
65 #else
66 return PAGE_ACTION_TYPE;
67 #endif
68 }
69
70 infobars::InfoBarDelegate::InfoBarIdentifier
71 DefaultBrowserInfoBarDelegate::GetIdentifier() const {
72 return DEFAULT_BROWSER_INFOBAR_DELEGATE;
73 }
74
75 int DefaultBrowserInfoBarDelegate::GetIconId() const {
76 return IDR_PRODUCT_LOGO_32;
77 }
78
79 gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const {
80 #if defined(OS_MACOSX) || defined(OS_ANDROID)
81 return gfx::VectorIconId::VECTOR_ICON_NONE;
82 #else
83 return gfx::VectorIconId::CHROME_PRODUCT;
84 #endif
85 }
86
87 bool DefaultBrowserInfoBarDelegate::ShouldExpire(
88 const NavigationDetails& details) const {
89 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
90 }
91
92 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() {
93 content::RecordAction(
94 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss"));
95 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
96 IGNORE_INFO_BAR,
97 NUM_INFO_BAR_USER_INTERACTION_TYPES);
98 }
99
100 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const {
101 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT);
102 }
103
104 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel(
105 InfoBarButton button) const {
106 #if defined(OS_WIN)
107 // On Windows 10, the "OK" button opens the Windows Settings application,
108 // through which the user must make their default browser choice.
109 const int kSetAsDefaultButtonMessageId =
110 base::win::GetVersion() >= base::win::VERSION_WIN10
111 ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10
112 : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
113 #else
114 const int kSetAsDefaultButtonMessageId =
115 IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
116 #endif
117 return l10n_util::GetStringUTF16(
118 button == BUTTON_OK ? kSetAsDefaultButtonMessageId
119 : IDS_DEFAULT_BROWSER_INFOBAR_CANCEL_BUTTON_LABEL);
120 }
121
122 // Setting an app as the default browser doesn't require elevation directly, but
123 // it does require registering it as the protocol handler for "http", so if
124 // protocol registration in general requires elevation, this does as well.
125 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
126 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient();
127 }
128
129 bool DefaultBrowserInfoBarDelegate::Accept() {
130 content::RecordAction(
131 base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
132 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
133 ACCEPT_INFO_BAR,
134 NUM_INFO_BAR_USER_INTERACTION_TYPES);
135
136 bool close_infobar = true;
137 shell_integration::DefaultWebClientWorkerCallback set_as_default_callback;
138
139 if (IsStickyDefaultBrowserPromptEnabled()) {
140 // When the experiment is enabled, the infobar is only closed when the
141 // DefaultBrowserWorker is finished.
142 set_as_default_callback =
143 base::Bind(&DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished,
144 weak_factory_.GetWeakPtr());
145 close_infobar = false;
146 }
147
148 // The worker pointer is reference counted. While it is running, the
149 // message loops of the FILE and UI thread will hold references to it
150 // and it will be automatically freed once all its tasks have finished.
151 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault();
152 return close_infobar;
153 }
154
155 bool DefaultBrowserInfoBarDelegate::Cancel() {
156 // This can get reached in tests where profile_ is null.
157 if (profile_)
158 chrome::DefaultBrowserPromptDeclined(profile_);
159 content::RecordAction(
160 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel"));
161 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
162 CANCEL_INFO_BAR,
163 NUM_INFO_BAR_USER_INTERACTION_TYPES);
164 return true;
165 }
166
167 scoped_refptr<shell_integration::DefaultBrowserWorker>
168 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker(
169 const shell_integration::DefaultWebClientWorkerCallback& callback) {
170 return new shell_integration::DefaultBrowserWorker(callback);
171 }
172
173 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished(
174 shell_integration::DefaultWebClientState state) {
175 infobar()->owner()->RemoveInfoBar(infobar());
176 }
177
178 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698