| 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_win.h" | 5 #include "chrome/browser/shell_integration_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
| 9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
| 10 #include <propkey.h> // Needs to come after shobjidl.h. | 10 #include <propkey.h> // Needs to come after shobjidl.h. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/browser/policy/policy_path_parser.h" | 37 #include "chrome/browser/policy/policy_path_parser.h" |
| 38 #include "chrome/browser/shell_integration.h" | 38 #include "chrome/browser/shell_integration.h" |
| 39 #include "chrome/browser/web_applications/web_app.h" | 39 #include "chrome/browser/web_applications/web_app.h" |
| 40 #include "chrome/common/chrome_constants.h" | 40 #include "chrome/common/chrome_constants.h" |
| 41 #include "chrome/common/chrome_paths_internal.h" | 41 #include "chrome/common/chrome_paths_internal.h" |
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/installer/setup/setup_util.h" | 43 #include "chrome/installer/setup/setup_util.h" |
| 44 #include "chrome/installer/util/browser_distribution.h" | 44 #include "chrome/installer/util/browser_distribution.h" |
| 45 #include "chrome/installer/util/create_reg_key_work_item.h" | 45 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 46 #include "chrome/installer/util/install_util.h" | 46 #include "chrome/installer/util/install_util.h" |
| 47 #include "chrome/installer/util/scoped_user_protocol_entry.h" |
| 47 #include "chrome/installer/util/set_reg_value_work_item.h" | 48 #include "chrome/installer/util/set_reg_value_work_item.h" |
| 48 #include "chrome/installer/util/shell_util.h" | 49 #include "chrome/installer/util/shell_util.h" |
| 49 #include "chrome/installer/util/util_constants.h" | 50 #include "chrome/installer/util/util_constants.h" |
| 50 #include "chrome/installer/util/work_item.h" | 51 #include "chrome/installer/util/work_item.h" |
| 51 #include "chrome/installer/util/work_item_list.h" | 52 #include "chrome/installer/util/work_item_list.h" |
| 52 #include "components/variations/variations_associated_data.h" | 53 #include "components/variations/variations_associated_data.h" |
| 53 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
| 54 | 55 |
| 55 using content::BrowserThread; | 56 using content::BrowserThread; |
| 56 | 57 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // interaction early when it is clear that the user made a choice (e.g. http | 232 // interaction early when it is clear that the user made a choice (e.g. http |
| 232 // and https for default browser). | 233 // and https for default browser). |
| 233 // | 234 // |
| 234 // This helper class manages both the timer and the registry watchers and makes | 235 // This helper class manages both the timer and the registry watchers and makes |
| 235 // sure the callback for the end of the settings interaction is only run once. | 236 // sure the callback for the end of the settings interaction is only run once. |
| 236 // This class also manages its own lifetime. | 237 // This class also manages its own lifetime. |
| 237 class OpenSystemSettingsHelper { | 238 class OpenSystemSettingsHelper { |
| 238 public: | 239 public: |
| 239 // Begin the monitoring and will call |on_finished_callback| when done. | 240 // Begin the monitoring and will call |on_finished_callback| when done. |
| 240 // Takes in a null-terminated array of |protocols| whose registry keys must be | 241 // Takes in a null-terminated array of |protocols| whose registry keys must be |
| 241 // watched. | 242 // watched. The array must contain at least one element. |
| 242 static void Begin(const wchar_t* const protocols[], | 243 static void Begin(const wchar_t* const protocols[], |
| 243 const base::Closure& on_finished_callback) { | 244 const base::Closure& on_finished_callback) { |
| 244 new OpenSystemSettingsHelper(protocols, on_finished_callback); | 245 new OpenSystemSettingsHelper(protocols, on_finished_callback); |
| 245 } | 246 } |
| 246 | 247 |
| 247 private: | 248 private: |
| 248 // The reason the settings interaction concluded. Do not modify the ordering | 249 // The reason the settings interaction concluded. Do not modify the ordering |
| 249 // because it is used for UMA. | 250 // because it is used for UMA. |
| 250 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; | 251 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; |
| 251 | 252 |
| 252 OpenSystemSettingsHelper(const wchar_t* const protocols[], | 253 OpenSystemSettingsHelper(const wchar_t* const protocols[], |
| 253 const base::Closure& on_finished_callback) | 254 const base::Closure& on_finished_callback) |
| 254 : on_finished_callback_(on_finished_callback), weak_ptr_factory_(this) { | 255 : scoped_user_protocol_entry_(protocols[0]), |
| 256 on_finished_callback_(on_finished_callback), |
| 257 weak_ptr_factory_(this) { |
| 255 static const wchar_t kUrlAssociationFormat[] = | 258 static const wchar_t kUrlAssociationFormat[] = |
| 256 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\" | 259 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\" |
| 257 L"%ls\\UserChoice"; | 260 L"%ls\\UserChoice"; |
| 258 | 261 |
| 259 // Remember the start time. | 262 // Remember the start time. |
| 260 start_time_ = base::TimeTicks::Now(); | 263 start_time_ = base::TimeTicks::Now(); |
| 261 | 264 |
| 262 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) { | 265 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) { |
| 263 AddRegistryKeyWatcher( | 266 AddRegistryKeyWatcher( |
| 264 base::StringPrintf(kUrlAssociationFormat, *scan).c_str()); | 267 base::StringPrintf(kUrlAssociationFormat, *scan).c_str()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 new base::win::RegKey(HKEY_CURRENT_USER, key_path, KEY_NOTIFY)); | 312 new base::win::RegKey(HKEY_CURRENT_USER, key_path, KEY_NOTIFY)); |
| 310 | 313 |
| 311 if (reg_key->Valid() && | 314 if (reg_key->Valid() && |
| 312 reg_key->StartWatching( | 315 reg_key->StartWatching( |
| 313 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, | 316 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, |
| 314 weak_ptr_factory_.GetWeakPtr()))) { | 317 weak_ptr_factory_.GetWeakPtr()))) { |
| 315 registry_key_watchers_.push_back(std::move(reg_key)); | 318 registry_key_watchers_.push_back(std::move(reg_key)); |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 | 321 |
| 322 // This is needed to make sure that Windows displays an entry for the protocol |
| 323 // inside the "Choose default apps by protocol" settings page. |
| 324 ScopedUserProtocolEntry scoped_user_protocol_entry_; |
| 325 |
| 319 // The function to call when the interaction with the system settings is | 326 // The function to call when the interaction with the system settings is |
| 320 // finished. | 327 // finished. |
| 321 base::Closure on_finished_callback_; | 328 base::Closure on_finished_callback_; |
| 322 | 329 |
| 323 // The number of time the registry key watchers must fire. | 330 // The number of time the registry key watchers must fire. |
| 324 int registry_watcher_count_ = 0; | 331 int registry_watcher_count_ = 0; |
| 325 | 332 |
| 326 // There can be multiple registry key watchers as some settings modify | 333 // There can be multiple registry key watchers as some settings modify |
| 327 // multiple protocol associations. e.g. Changing the default browser modifies | 334 // multiple protocol associations. e.g. Changing the default browser modifies |
| 328 // the http and https associations. | 335 // the http and https associations. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, | 510 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, |
| 504 wprotocol)) { | 511 wprotocol)) { |
| 505 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; | 512 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 506 return false; | 513 return false; |
| 507 } | 514 } |
| 508 | 515 |
| 509 VLOG(1) << "Set-default-client Windows UI completed."; | 516 VLOG(1) << "Set-default-client Windows UI completed."; |
| 510 return true; | 517 return true; |
| 511 } | 518 } |
| 512 | 519 |
| 520 void SetAsDefaultProtocolClientUsingSystemSettings( |
| 521 const std::string& protocol, |
| 522 const base::Closure& on_finished_callback) { |
| 523 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 524 |
| 525 base::FilePath chrome_exe; |
| 526 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 527 NOTREACHED() << "Error getting app exe path"; |
| 528 on_finished_callback.Run(); |
| 529 return; |
| 530 } |
| 531 |
| 532 // The helper manages its own lifetime. |
| 533 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
| 534 const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr}; |
| 535 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback); |
| 536 |
| 537 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 538 ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, |
| 539 wprotocol); |
| 540 } |
| 541 |
| 513 base::string16 GetAppModelIdForProfile(const base::string16& app_name, | 542 base::string16 GetAppModelIdForProfile(const base::string16& app_name, |
| 514 const base::FilePath& profile_path) { | 543 const base::FilePath& profile_path) { |
| 515 std::vector<base::string16> components; | 544 std::vector<base::string16> components; |
| 516 components.push_back(app_name); | 545 components.push_back(app_name); |
| 517 const base::string16 profile_id(GetProfileIdFromPath(profile_path)); | 546 const base::string16 profile_id(GetProfileIdFromPath(profile_path)); |
| 518 if (!profile_id.empty()) | 547 if (!profile_id.empty()) |
| 519 components.push_back(profile_id); | 548 components.push_back(profile_id); |
| 520 return ShellUtil::BuildAppModelId(components); | 549 return ShellUtil::BuildAppModelId(components); |
| 521 } | 550 } |
| 522 | 551 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 if (base::PathExists(shortcut)) | 715 if (base::PathExists(shortcut)) |
| 687 return shortcut; | 716 return shortcut; |
| 688 } | 717 } |
| 689 | 718 |
| 690 return base::FilePath(); | 719 return base::FilePath(); |
| 691 } | 720 } |
| 692 | 721 |
| 693 } // namespace win | 722 } // namespace win |
| 694 | 723 |
| 695 } // namespace shell_integration | 724 } // namespace shell_integration |
| OLD | NEW |