Chromium Code Reviews| 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/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/policy/policy_path_parser.h" | 16 #include "chrome/browser/policy/policy_path_parser.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 20 #include "components/version_info/version_info.h" | 20 #include "components/version_info/version_info.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 | 22 |
| 23 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 24 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 #if defined(OS_WIN) | |
| 28 #include "base/win/windows_version.h" | |
| 29 #include "chrome/browser/shell_integration_win.h" | |
| 30 #endif | |
| 31 | |
| 27 #if !defined(OS_WIN) | 32 #if !defined(OS_WIN) |
| 28 #include "chrome/common/channel_info.h" | 33 #include "chrome/common/channel_info.h" |
| 29 #include "chrome/grit/chromium_strings.h" | 34 #include "chrome/grit/chromium_strings.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 31 #endif | 36 #endif |
| 32 | 37 |
| 33 using content::BrowserThread; | 38 using content::BrowserThread; |
| 34 | 39 |
| 35 namespace shell_integration { | 40 namespace shell_integration { |
| 36 | 41 |
| 37 namespace { | 42 namespace { |
| 38 | 43 |
| 39 const struct AppModeInfo* gAppModeInfo = nullptr; | 44 const struct AppModeInfo* gAppModeInfo = nullptr; |
| 40 | 45 |
| 41 } // namespace | 46 } // namespace |
| 42 | 47 |
| 43 #if !defined(OS_WIN) | 48 bool CanSetAsDefaultBrowser() { |
| 44 bool SetAsDefaultBrowserInteractive() { | 49 return GetDefaultWebClientSetPermission() != SET_DEFAULT_NOT_ALLOWED; |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 bool SetAsDefaultProtocolClientInteractive(const std::string& protocol) { | |
| 49 return false; | |
| 50 } | |
| 51 #endif // !defined(OS_WIN) | |
| 52 | |
| 53 DefaultWebClientSetPermission CanSetAsDefaultProtocolClient() { | |
| 54 // Allowed as long as the browser can become the operating system default | |
| 55 // browser. | |
| 56 return CanSetAsDefaultBrowser(); | |
| 57 } | 50 } |
| 58 | 51 |
| 59 #if !defined(OS_WIN) | 52 #if !defined(OS_WIN) |
| 60 bool IsElevationNeededForSettingDefaultProtocolClient() { | 53 bool IsElevationNeededForSettingDefaultProtocolClient() { |
| 61 return false; | 54 return false; |
| 62 } | 55 } |
| 63 #endif // !defined(OS_WIN) | 56 #endif // !defined(OS_WIN) |
| 64 | 57 |
| 65 void SetAppModeInfo(const struct AppModeInfo* info) { | 58 void SetAppModeInfo(const struct AppModeInfo* info) { |
| 66 gAppModeInfo = info; | 59 gAppModeInfo = info; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 173 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 181 DefaultWebClientState state = CheckIsDefaultImpl(); | 174 DefaultWebClientState state = CheckIsDefaultImpl(); |
| 182 BrowserThread::PostTask( | 175 BrowserThread::PostTask( |
| 183 BrowserThread::UI, FROM_HERE, | 176 BrowserThread::UI, FROM_HERE, |
| 184 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, | 177 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, |
| 185 is_following_set_as_default)); | 178 is_following_set_as_default)); |
| 186 } | 179 } |
| 187 | 180 |
| 188 void DefaultWebClientWorker::SetAsDefault() { | 181 void DefaultWebClientWorker::SetAsDefault() { |
| 189 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 182 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 190 SetAsDefaultImpl(); | 183 |
| 191 CheckIsDefault(true); | 184 // SetAsDefaultImpl will make sure the callback is executed exactly once. |
| 185 SetAsDefaultImpl( | |
| 186 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true)); | |
| 192 } | 187 } |
| 193 | 188 |
| 194 void DefaultWebClientWorker::ReportSetDefaultResult( | 189 void DefaultWebClientWorker::ReportSetDefaultResult( |
| 195 DefaultWebClientState state) { | 190 DefaultWebClientState state) { |
| 196 base::LinearHistogram::FactoryGet( | 191 base::LinearHistogram::FactoryGet( |
| 197 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, | 192 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1, |
| 198 DefaultWebClientState::NUM_DEFAULT_STATES, | 193 DefaultWebClientState::NUM_DEFAULT_STATES, |
| 199 DefaultWebClientState::NUM_DEFAULT_STATES + 1, | 194 DefaultWebClientState::NUM_DEFAULT_STATES + 1, |
| 200 base::HistogramBase::kUmaTargetedHistogramFlag) | 195 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 201 ->Add(state); | 196 ->Add(state); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 230 | 225 |
| 231 /////////////////////////////////////////////////////////////////////////////// | 226 /////////////////////////////////////////////////////////////////////////////// |
| 232 // DefaultBrowserWorker, private: | 227 // DefaultBrowserWorker, private: |
| 233 | 228 |
| 234 DefaultBrowserWorker::~DefaultBrowserWorker() = default; | 229 DefaultBrowserWorker::~DefaultBrowserWorker() = default; |
| 235 | 230 |
| 236 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() { | 231 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() { |
| 237 return GetDefaultBrowser(); | 232 return GetDefaultBrowser(); |
| 238 } | 233 } |
| 239 | 234 |
| 240 void DefaultBrowserWorker::SetAsDefaultImpl() { | 235 void DefaultBrowserWorker::SetAsDefaultImpl( |
| 241 switch (CanSetAsDefaultBrowser()) { | 236 const base::Closure& on_finished_callback) { |
| 237 switch (GetDefaultWebClientSetPermission()) { | |
| 242 case SET_DEFAULT_NOT_ALLOWED: | 238 case SET_DEFAULT_NOT_ALLOWED: |
| 243 NOTREACHED(); | 239 NOTREACHED(); |
| 244 break; | 240 break; |
| 245 case SET_DEFAULT_UNATTENDED: | 241 case SET_DEFAULT_UNATTENDED: |
| 246 SetAsDefaultBrowser(); | 242 SetAsDefaultBrowser(); |
| 247 break; | 243 break; |
| 248 case SET_DEFAULT_INTERACTIVE: | 244 case SET_DEFAULT_INTERACTIVE: |
| 249 if (interactive_permitted_) | 245 #if defined(OS_WIN) |
| 250 SetAsDefaultBrowserInteractive(); | 246 if (interactive_permitted_) { |
| 247 // The Windows 8 API for choosing the default browser was deprecated on | |
| 248 // Windows 10. | |
| 249 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | |
| 250 win::SetAsDefaultBrowserUsingSystemSettings(on_finished_callback); | |
| 251 return; | |
| 252 } else { | |
|
grt (UTC plus 2)
2016/04/12 13:36:44
nit for the future: omit "else" when the "if" clau
| |
| 253 win::SetAsDefaultBrowserUsingIntentPicker(); | |
| 254 } | |
| 255 } | |
| 256 #endif // defined(OS_WIN) | |
| 251 break; | 257 break; |
| 252 } | 258 } |
| 259 on_finished_callback.Run(); | |
| 253 } | 260 } |
| 254 | 261 |
| 255 /////////////////////////////////////////////////////////////////////////////// | 262 /////////////////////////////////////////////////////////////////////////////// |
| 256 // DefaultProtocolClientWorker | 263 // DefaultProtocolClientWorker |
| 257 // | 264 // |
| 258 | 265 |
| 259 DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 266 DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
| 260 const DefaultWebClientWorkerCallback& callback, | 267 const DefaultWebClientWorkerCallback& callback, |
| 261 const std::string& protocol) | 268 const std::string& protocol) |
| 262 : DefaultWebClientWorker(callback, "DefaultProtocolClient"), | 269 : DefaultWebClientWorker(callback, "DefaultProtocolClient"), |
| 263 protocol_(protocol) {} | 270 protocol_(protocol) {} |
| 264 | 271 |
| 265 /////////////////////////////////////////////////////////////////////////////// | 272 /////////////////////////////////////////////////////////////////////////////// |
| 266 // DefaultProtocolClientWorker, protected: | 273 // DefaultProtocolClientWorker, protected: |
| 267 | 274 |
| 268 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default; | 275 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default; |
| 269 | 276 |
| 270 /////////////////////////////////////////////////////////////////////////////// | 277 /////////////////////////////////////////////////////////////////////////////// |
| 271 // DefaultProtocolClientWorker, private: | 278 // DefaultProtocolClientWorker, private: |
| 272 | 279 |
| 273 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() { | 280 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() { |
| 274 return IsDefaultProtocolClient(protocol_); | 281 return IsDefaultProtocolClient(protocol_); |
| 275 } | 282 } |
| 276 | 283 |
| 277 void DefaultProtocolClientWorker::SetAsDefaultImpl() { | 284 void DefaultProtocolClientWorker::SetAsDefaultImpl( |
| 278 switch (CanSetAsDefaultProtocolClient()) { | 285 const base::Closure& on_finished_callback) { |
| 286 switch (GetDefaultWebClientSetPermission()) { | |
| 279 case SET_DEFAULT_NOT_ALLOWED: | 287 case SET_DEFAULT_NOT_ALLOWED: |
| 280 // Not allowed, do nothing. | 288 // Not allowed, do nothing. |
| 281 break; | 289 break; |
| 282 case SET_DEFAULT_UNATTENDED: | 290 case SET_DEFAULT_UNATTENDED: |
| 283 SetAsDefaultProtocolClient(protocol_); | 291 SetAsDefaultProtocolClient(protocol_); |
| 284 break; | 292 break; |
| 285 case SET_DEFAULT_INTERACTIVE: | 293 case SET_DEFAULT_INTERACTIVE: |
| 286 if (interactive_permitted_) { | 294 #if defined(OS_WIN) |
| 287 SetAsDefaultProtocolClientInteractive(protocol_); | 295 // TODO(pmonette): Implement a working flow for Windows 10. |
| 288 } | 296 if (interactive_permitted_) |
| 297 win::SetAsDefaultProtocolClientUsingIntentPicker(protocol_); | |
| 298 #endif // defined(OS_WIN) | |
| 289 break; | 299 break; |
| 290 } | 300 } |
| 301 on_finished_callback.Run(); | |
| 291 } | 302 } |
| 292 | 303 |
| 293 } // namespace shell_integration | 304 } // namespace shell_integration |
| OLD | NEW |