| 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 ResetCheckDefaultBrowserPrefOnUIThread( |
| 198 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT) { | 199 const base::FilePath& profile_path) { |
| 200 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 201 Profile* profile = |
| 202 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 203 if (profile) |
| 204 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); |
| 205 } |
| 206 |
| 207 void CheckDefaultBrowserOnFileThread(const base::FilePath& profile_path, |
| 208 bool show_prompt, |
| 209 chrome::HostDesktopType desktop_type) { |
| 210 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 211 ShellIntegration::DefaultWebClientState state = |
| 212 ShellIntegration::GetDefaultBrowser(); |
| 213 if (state == ShellIntegration::IS_DEFAULT) { |
| 214 // Notify the user in the future if Chrome ceases to be the user's chosen |
| 215 // default browser. |
| 216 content::BrowserThread::PostTask( |
| 217 content::BrowserThread::UI, FROM_HERE, |
| 218 base::Bind(&ResetCheckDefaultBrowserPrefOnUIThread, profile_path)); |
| 219 } else if (show_prompt && state == ShellIntegration::NOT_DEFAULT) { |
| 199 ShellIntegration::DefaultWebClientSetPermission default_change_mode = | 220 ShellIntegration::DefaultWebClientSetPermission default_change_mode = |
| 200 ShellIntegration::CanSetAsDefaultBrowser(); | 221 ShellIntegration::CanSetAsDefaultBrowser(); |
| 201 | 222 |
| 202 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { | 223 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { |
| 203 content::BrowserThread::PostTask( | 224 content::BrowserThread::PostTask( |
| 204 content::BrowserThread::UI, FROM_HERE, | 225 content::BrowserThread::UI, FROM_HERE, |
| 205 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); | 226 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); |
| 206 } | 227 } |
| 207 } | 228 } |
| 208 } | 229 } |
| 209 | 230 |
| 210 } // namespace | 231 } // namespace |
| 211 | 232 |
| 212 namespace chrome { | 233 namespace chrome { |
| 213 | 234 |
| 214 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { | 235 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { |
| 215 registry->RegisterStringPref( | 236 registry->RegisterStringPref( |
| 216 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); | 237 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); |
| 217 } | 238 } |
| 218 | 239 |
| 219 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) { | 240 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) { |
| 220 // We do not check if we are the default browser if: | 241 // We do not check if we are the default browser if: |
| 242 // - There is a policy in control of this setting. |
| 243 // 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. | 244 // - 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 | 245 // - The "suppress_default_browser_prompt_for_version" master preference is |
| 224 // set to the current version. | 246 // set to the current version. |
| 225 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser)) | 247 bool show_prompt = |
| 226 return; | 248 profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser); |
| 227 | 249 |
| 228 if (g_browser_process->local_state()->IsManagedPreference( | 250 if (g_browser_process->local_state()->IsManagedPreference( |
| 229 prefs::kDefaultBrowserSettingEnabled)) { | 251 prefs::kDefaultBrowserSettingEnabled)) { |
| 230 if (g_browser_process->local_state()->GetBoolean( | 252 if (g_browser_process->local_state()->GetBoolean( |
| 231 prefs::kDefaultBrowserSettingEnabled)) { | 253 prefs::kDefaultBrowserSettingEnabled)) { |
| 232 content::BrowserThread::PostTask( | 254 content::BrowserThread::PostTask( |
| 233 content::BrowserThread::FILE, FROM_HERE, | 255 content::BrowserThread::FILE, FROM_HERE, |
| 234 base::Bind( | 256 base::Bind( |
| 235 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); | 257 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); |
| 236 } else { | 258 } else { |
| 237 // TODO(pastarmovj): We can't really do anything meaningful here yet but | 259 // TODO(pastarmovj): We can't really do anything meaningful here yet but |
| 238 // just prevent showing the infobar. | 260 // just prevent showing the infobar. |
| 239 } | 261 } |
| 240 return; | 262 return; |
| 241 } | 263 } |
| 242 | 264 |
| 243 const std::string disable_version_string = | 265 if (show_prompt) { |
| 244 g_browser_process->local_state()->GetString( | 266 const std::string disable_version_string = |
| 245 prefs::kBrowserSuppressDefaultBrowserPrompt); | 267 g_browser_process->local_state()->GetString( |
| 246 const Version disable_version(disable_version_string); | 268 prefs::kBrowserSuppressDefaultBrowserPrompt); |
| 247 DCHECK(disable_version_string.empty() || disable_version.IsValid()); | 269 const Version disable_version(disable_version_string); |
| 248 if (disable_version.IsValid()) { | 270 DCHECK(disable_version_string.empty() || disable_version.IsValid()); |
| 249 const chrome::VersionInfo version_info; | 271 if (disable_version.IsValid()) { |
| 250 if (disable_version.Equals(Version(version_info.Version()))) | 272 const chrome::VersionInfo version_info; |
| 251 return; | 273 if (disable_version.Equals(Version(version_info.Version()))) |
| 274 show_prompt = false; |
| 275 } |
| 252 } | 276 } |
| 253 | 277 |
| 254 content::BrowserThread::PostTask( | 278 content::BrowserThread::PostTask( |
| 255 content::BrowserThread::FILE, FROM_HERE, | 279 content::BrowserThread::FILE, FROM_HERE, |
| 256 base::Bind(&CheckDefaultBrowserCallback, desktop_type)); | 280 base::Bind(&CheckDefaultBrowserOnFileThread, profile->GetPath(), |
| 281 show_prompt, desktop_type)); |
| 257 } | 282 } |
| 258 | 283 |
| 259 #if !defined(OS_WIN) | 284 #if !defined(OS_WIN) |
| 260 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 285 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 261 return false; | 286 return false; |
| 262 } | 287 } |
| 263 #endif | 288 #endif |
| 264 | 289 |
| 265 } // namespace chrome | 290 } // namespace chrome |
| OLD | NEW |