OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_infobar_delegate.h" | 5 #include "chrome/browser/ui/startup/default_browser_infobar_delegate.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 9 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
10 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 // We want the info-bar to stick-around for few seconds and then be hidden | 62 // We want the info-bar to stick-around for few seconds and then be hidden |
63 // on the next navigation after that. | 63 // on the next navigation after that. |
64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
65 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 65 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
66 weak_factory_.GetWeakPtr()), | 66 weak_factory_.GetWeakPtr()), |
67 base::TimeDelta::FromSeconds(8)); | 67 base::TimeDelta::FromSeconds(8)); |
68 } | 68 } |
69 | 69 |
70 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 70 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
71 if (!action_taken_) { | 71 if (!action_taken_) { |
72 content::RecordAction( | |
73 base::UserMetricsAction("DefaultBrowserInfoBar_Ignore")); | |
72 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 74 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
73 IGNORE_INFO_BAR, | 75 IGNORE_INFO_BAR, |
74 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 76 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 void DefaultBrowserInfoBarDelegate::AllowExpiry() { | 80 void DefaultBrowserInfoBarDelegate::AllowExpiry() { |
79 should_expire_ = true; | 81 should_expire_ = true; |
80 } | 82 } |
81 | 83 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 130 } |
129 #endif // defined(OS_WIN) | 131 #endif // defined(OS_WIN) |
130 | 132 |
131 bool DefaultBrowserInfoBarDelegate::ShouldExpire( | 133 bool DefaultBrowserInfoBarDelegate::ShouldExpire( |
132 const NavigationDetails& details) const { | 134 const NavigationDetails& details) const { |
133 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); | 135 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); |
134 } | 136 } |
135 | 137 |
136 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { | 138 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() { |
137 action_taken_ = true; | 139 action_taken_ = true; |
140 // This can get reached in tests where profile_ is null. | |
msw
2016/07/14 19:55:36
optional nit: // |profile_| may be null in tests.
| |
141 if (profile_) | |
142 chrome::DefaultBrowserPromptDeclined(profile_); | |
138 content::RecordAction( | 143 content::RecordAction( |
139 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); | 144 base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss")); |
140 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 145 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
141 DISMISS_INFO_BAR, | 146 DISMISS_INFO_BAR, |
142 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 147 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
143 } | 148 } |
144 | 149 |
145 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { | 150 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { |
146 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); | 151 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); |
147 } | 152 } |
148 | 153 |
154 int DefaultBrowserInfoBarDelegate::GetButtons() const { | |
155 return BUTTON_OK; | |
156 } | |
157 | |
149 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( | 158 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( |
150 InfoBarButton button) const { | 159 InfoBarButton button) const { |
160 DCHECK_EQ(BUTTON_OK, button); | |
151 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
152 // On Windows 10, the "OK" button opens the Windows Settings application, | 162 // On Windows 10, the "OK" button opens the Windows Settings application, |
153 // through which the user must make their default browser choice. | 163 // through which the user must make their default browser choice. |
154 const int kSetAsDefaultButtonMessageId = | 164 const int kSetAsDefaultButtonMessageId = |
155 base::win::GetVersion() >= base::win::VERSION_WIN10 | 165 base::win::GetVersion() >= base::win::VERSION_WIN10 |
156 ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10 | 166 ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10 |
157 : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; | 167 : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; |
158 #else | 168 #else |
159 const int kSetAsDefaultButtonMessageId = | 169 const int kSetAsDefaultButtonMessageId = |
160 IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; | 170 IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL; |
161 #endif | 171 #endif |
162 return l10n_util::GetStringUTF16( | 172 return l10n_util::GetStringUTF16(kSetAsDefaultButtonMessageId); |
163 button == BUTTON_OK ? kSetAsDefaultButtonMessageId | |
164 : IDS_DEFAULT_BROWSER_INFOBAR_CANCEL_BUTTON_LABEL); | |
165 } | 173 } |
166 | 174 |
167 // Setting an app as the default browser doesn't require elevation directly, but | 175 // Setting an app as the default browser doesn't require elevation directly, but |
168 // it does require registering it as the protocol handler for "http", so if | 176 // it does require registering it as the protocol handler for "http", so if |
169 // protocol registration in general requires elevation, this does as well. | 177 // protocol registration in general requires elevation, this does as well. |
170 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { | 178 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { |
171 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); | 179 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); |
172 } | 180 } |
173 | 181 |
174 bool DefaultBrowserInfoBarDelegate::Accept() { | 182 bool DefaultBrowserInfoBarDelegate::Accept() { |
(...skipping 16 matching lines...) Expand all Loading... | |
191 close_infobar = false; | 199 close_infobar = false; |
192 } | 200 } |
193 | 201 |
194 // The worker pointer is reference counted. While it is running, the | 202 // The worker pointer is reference counted. While it is running, the |
195 // message loops of the FILE and UI thread will hold references to it | 203 // message loops of the FILE and UI thread will hold references to it |
196 // and it will be automatically freed once all its tasks have finished. | 204 // and it will be automatically freed once all its tasks have finished. |
197 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault(); | 205 CreateDefaultBrowserWorker(set_as_default_callback)->StartSetAsDefault(); |
198 return close_infobar; | 206 return close_infobar; |
199 } | 207 } |
200 | 208 |
201 bool DefaultBrowserInfoBarDelegate::Cancel() { | |
202 action_taken_ = true; | |
203 // This can get reached in tests where profile_ is null. | |
204 if (profile_) | |
205 chrome::DefaultBrowserPromptDeclined(profile_); | |
206 content::RecordAction( | |
207 base::UserMetricsAction("DefaultBrowserInfoBar_Cancel")); | |
208 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | |
209 CANCEL_INFO_BAR, | |
210 NUM_INFO_BAR_USER_INTERACTION_TYPES); | |
211 return true; | |
212 } | |
213 | |
214 scoped_refptr<shell_integration::DefaultBrowserWorker> | 209 scoped_refptr<shell_integration::DefaultBrowserWorker> |
215 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker( | 210 DefaultBrowserInfoBarDelegate::CreateDefaultBrowserWorker( |
216 const shell_integration::DefaultWebClientWorkerCallback& callback) { | 211 const shell_integration::DefaultWebClientWorkerCallback& callback) { |
217 return new shell_integration::DefaultBrowserWorker(callback); | 212 return new shell_integration::DefaultBrowserWorker(callback); |
218 } | 213 } |
219 | 214 |
220 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( | 215 void DefaultBrowserInfoBarDelegate::OnSetAsDefaultFinished( |
221 shell_integration::DefaultWebClientState state) { | 216 shell_integration::DefaultWebClientState state) { |
222 infobar()->owner()->RemoveInfoBar(infobar()); | 217 infobar()->owner()->RemoveInfoBar(infobar()); |
223 } | 218 } |
224 | 219 |
225 } // namespace chrome | 220 } // namespace chrome |
OLD | NEW |