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 "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/first_run/first_run.h" | 14 #include "chrome/browser/first_run/first_run.h" |
15 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | |
17 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
25 #include "chrome/installer/util/master_preferences.h" | 26 #include "chrome/installer/util/master_preferences.h" |
26 #include "chrome/installer/util/master_preferences_constants.h" | 27 #include "chrome/installer/util/master_preferences_constants.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 return; | 188 return; |
188 | 189 |
189 DefaultBrowserInfoBarDelegate::Create( | 190 DefaultBrowserInfoBarDelegate::Create( |
190 InfoBarService::FromWebContents(web_contents), | 191 InfoBarService::FromWebContents(web_contents), |
191 Profile::FromBrowserContext( | 192 Profile::FromBrowserContext( |
192 web_contents->GetBrowserContext())->GetPrefs(), | 193 web_contents->GetBrowserContext())->GetPrefs(), |
193 (ShellIntegration::CanSetAsDefaultBrowser() == | 194 (ShellIntegration::CanSetAsDefaultBrowser() == |
194 ShellIntegration::SET_DEFAULT_INTERACTIVE)); | 195 ShellIntegration::SET_DEFAULT_INTERACTIVE)); |
195 } | 196 } |
196 | 197 |
197 void CheckDefaultBrowserCallback(chrome::HostDesktopType desktop_type) { | 198 void CheckDefaultBrowserCallback(bool show_prompt, |
198 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT) { | 199 chrome::HostDesktopType desktop_type) { |
200 ShellIntegration::DefaultWebClientState state = | |
201 ShellIntegration::GetDefaultBrowser(); | |
202 if (state == ShellIntegration::IS_DEFAULT) { | |
203 // Notify the user in the future if Chrome ceases to be the user's chosen | |
204 // default browser. | |
205 PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs(); | |
msw
2015/06/16 19:23:01
It seems odd to change the last used profile, mayb
grt (UTC plus 2)
2015/06/16 19:31:53
Ah, what I've done here may be unsafe for several
msw
2015/06/16 20:29:49
Maybe use profile->GetPath(), like ProfileSizeTask
grt (UTC plus 2)
2015/06/16 21:04:09
Done.
| |
206 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); | |
207 } else if (show_prompt && state == ShellIntegration::NOT_DEFAULT) { | |
199 ShellIntegration::DefaultWebClientSetPermission default_change_mode = | 208 ShellIntegration::DefaultWebClientSetPermission default_change_mode = |
200 ShellIntegration::CanSetAsDefaultBrowser(); | 209 ShellIntegration::CanSetAsDefaultBrowser(); |
201 | 210 |
202 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { | 211 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { |
203 content::BrowserThread::PostTask( | 212 content::BrowserThread::PostTask( |
204 content::BrowserThread::UI, FROM_HERE, | 213 content::BrowserThread::UI, FROM_HERE, |
205 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); | 214 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); |
206 } | 215 } |
207 } | 216 } |
208 } | 217 } |
209 | 218 |
210 } // namespace | 219 } // namespace |
211 | 220 |
212 namespace chrome { | 221 namespace chrome { |
213 | 222 |
214 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { | 223 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { |
215 registry->RegisterStringPref( | 224 registry->RegisterStringPref( |
216 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); | 225 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); |
217 } | 226 } |
218 | 227 |
219 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) { | 228 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) { |
220 // We do not check if we are the default browser if: | 229 // We do not check if we are the default browser if: |
230 // - There is a policy in control of this setting. | |
231 // We check if we are the default browser but do not prompt if: | |
221 // - The user said "don't ask me again" on the infobar earlier. | 232 // - The user said "don't ask me again" on the infobar earlier. |
222 // - There is a policy in control of this setting. | |
223 // - The "suppress_default_browser_prompt_for_version" master preference is | 233 // - The "suppress_default_browser_prompt_for_version" master preference is |
224 // set to the current version. | 234 // set to the current version. |
225 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser)) | 235 bool show_prompt = |
226 return; | 236 profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser); |
227 | 237 |
228 if (g_browser_process->local_state()->IsManagedPreference( | 238 if (g_browser_process->local_state()->IsManagedPreference( |
229 prefs::kDefaultBrowserSettingEnabled)) { | 239 prefs::kDefaultBrowserSettingEnabled)) { |
230 if (g_browser_process->local_state()->GetBoolean( | 240 if (g_browser_process->local_state()->GetBoolean( |
231 prefs::kDefaultBrowserSettingEnabled)) { | 241 prefs::kDefaultBrowserSettingEnabled)) { |
232 content::BrowserThread::PostTask( | 242 content::BrowserThread::PostTask( |
233 content::BrowserThread::FILE, FROM_HERE, | 243 content::BrowserThread::FILE, FROM_HERE, |
234 base::Bind( | 244 base::Bind( |
235 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); | 245 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); |
236 } else { | 246 } else { |
237 // TODO(pastarmovj): We can't really do anything meaningful here yet but | 247 // TODO(pastarmovj): We can't really do anything meaningful here yet but |
238 // just prevent showing the infobar. | 248 // just prevent showing the infobar. |
239 } | 249 } |
240 return; | 250 return; |
241 } | 251 } |
242 | 252 |
243 const std::string disable_version_string = | 253 const std::string disable_version_string = |
msw
2015/06/16 19:23:01
nit: maybe avoid this whole check if show_prompt i
grt (UTC plus 2)
2015/06/16 19:31:53
Done.
| |
244 g_browser_process->local_state()->GetString( | 254 g_browser_process->local_state()->GetString( |
245 prefs::kBrowserSuppressDefaultBrowserPrompt); | 255 prefs::kBrowserSuppressDefaultBrowserPrompt); |
246 const Version disable_version(disable_version_string); | 256 const Version disable_version(disable_version_string); |
247 DCHECK(disable_version_string.empty() || disable_version.IsValid()); | 257 DCHECK(disable_version_string.empty() || disable_version.IsValid()); |
248 if (disable_version.IsValid()) { | 258 if (disable_version.IsValid()) { |
249 const chrome::VersionInfo version_info; | 259 const chrome::VersionInfo version_info; |
250 if (disable_version.Equals(Version(version_info.Version()))) | 260 if (disable_version.Equals(Version(version_info.Version()))) |
251 return; | 261 show_prompt = false; |
msw
2015/06/16 19:23:01
nit: show_prompt &= disable_version.Equals(Version
grt (UTC plus 2)
2015/06/16 19:31:53
I don't like that pattern since it's using a bitwi
| |
252 } | 262 } |
253 | 263 |
254 content::BrowserThread::PostTask( | 264 content::BrowserThread::PostTask( |
255 content::BrowserThread::FILE, FROM_HERE, | 265 content::BrowserThread::FILE, FROM_HERE, |
256 base::Bind(&CheckDefaultBrowserCallback, desktop_type)); | 266 base::Bind(&CheckDefaultBrowserCallback, show_prompt, desktop_type)); |
257 } | 267 } |
258 | 268 |
259 #if !defined(OS_WIN) | 269 #if !defined(OS_WIN) |
260 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 270 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
261 return false; | 271 return false; |
262 } | 272 } |
263 #endif | 273 #endif |
264 | 274 |
265 } // namespace chrome | 275 } // namespace chrome |
OLD | NEW |