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_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 25 matching lines...) Expand all Loading... | |
| 36 #include "chrome/browser/policy/policy_path_parser.h" | 36 #include "chrome/browser/policy/policy_path_parser.h" |
| 37 #include "chrome/browser/shell_integration.h" | 37 #include "chrome/browser/shell_integration.h" |
| 38 #include "chrome/browser/web_applications/web_app.h" | 38 #include "chrome/browser/web_applications/web_app.h" |
| 39 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
| 40 #include "chrome/common/chrome_paths_internal.h" | 40 #include "chrome/common/chrome_paths_internal.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/installer/setup/setup_util.h" | 42 #include "chrome/installer/setup/setup_util.h" |
| 43 #include "chrome/installer/util/browser_distribution.h" | 43 #include "chrome/installer/util/browser_distribution.h" |
| 44 #include "chrome/installer/util/create_reg_key_work_item.h" | 44 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 45 #include "chrome/installer/util/install_util.h" | 45 #include "chrome/installer/util/install_util.h" |
| 46 #include "chrome/installer/util/scoped_user_protocol_entry.h" | |
| 46 #include "chrome/installer/util/set_reg_value_work_item.h" | 47 #include "chrome/installer/util/set_reg_value_work_item.h" |
| 47 #include "chrome/installer/util/shell_util.h" | 48 #include "chrome/installer/util/shell_util.h" |
| 48 #include "chrome/installer/util/util_constants.h" | 49 #include "chrome/installer/util/util_constants.h" |
| 49 #include "chrome/installer/util/work_item.h" | 50 #include "chrome/installer/util/work_item.h" |
| 50 #include "chrome/installer/util/work_item_list.h" | 51 #include "chrome/installer/util/work_item_list.h" |
| 51 #include "components/variations/variations_associated_data.h" | 52 #include "components/variations/variations_associated_data.h" |
| 52 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| 53 | 54 |
| 54 using content::BrowserThread; | 55 using content::BrowserThread; |
| 55 | 56 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 // interaction early when it is clear that the user made a choice (e.g. http | 231 // interaction early when it is clear that the user made a choice (e.g. http |
| 231 // and https for default browser). | 232 // and https for default browser). |
| 232 // | 233 // |
| 233 // This helper class manages both the timer and the registry watchers and makes | 234 // This helper class manages both the timer and the registry watchers and makes |
| 234 // sure the callback for the end of the settings interaction is only run once. | 235 // sure the callback for the end of the settings interaction is only run once. |
| 235 // This class also manages its own lifetime. | 236 // This class also manages its own lifetime. |
| 236 class OpenSystemSettingsHelper { | 237 class OpenSystemSettingsHelper { |
| 237 public: | 238 public: |
| 238 // Begin the monitoring and will call |on_finished_callback| when done. | 239 // Begin the monitoring and will call |on_finished_callback| when done. |
| 239 // Takes in a null-terminated array of |protocols| whose registry keys must be | 240 // Takes in a null-terminated array of |protocols| whose registry keys must be |
| 240 // watched. | 241 // watched. The array must contain at least one element. |
| 241 static void Begin(const wchar_t* const protocols[], | 242 static void Begin(const wchar_t* const protocols[], |
| 242 const base::Closure& on_finished_callback) { | 243 const base::Closure& on_finished_callback) { |
| 243 new OpenSystemSettingsHelper(protocols, on_finished_callback); | 244 new OpenSystemSettingsHelper(protocols, on_finished_callback); |
| 244 } | 245 } |
| 245 | 246 |
| 246 private: | 247 private: |
| 247 // The reason the settings interaction concluded. Do not modify the ordering | 248 // The reason the settings interaction concluded. Do not modify the ordering |
| 248 // because it is used for UMA. | 249 // because it is used for UMA. |
| 249 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; | 250 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; |
| 250 | 251 |
| 251 OpenSystemSettingsHelper(const wchar_t* const protocols[], | 252 OpenSystemSettingsHelper(const wchar_t* const protocols[], |
| 252 const base::Closure& on_finished_callback) | 253 const base::Closure& on_finished_callback) |
| 253 : on_finished_callback_(on_finished_callback), weak_ptr_factory_(this) { | 254 : scoped_user_protocol_entry_(protocols[0]), |
| 255 on_finished_callback_(on_finished_callback), | |
| 256 weak_ptr_factory_(this) { | |
| 254 static const wchar_t kUrlAssociationFormat[] = | 257 static const wchar_t kUrlAssociationFormat[] = |
| 255 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\" | 258 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\" |
| 256 L"%ls\\UserChoice"; | 259 L"%ls\\UserChoice"; |
| 257 | 260 |
| 258 // Remember the start time. | 261 // Remember the start time. |
| 259 start_time_ = base::TimeTicks::Now(); | 262 start_time_ = base::TimeTicks::Now(); |
| 260 | 263 |
| 261 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) { | 264 for (const wchar_t* const* scan = &protocols[0]; *scan != nullptr; ++scan) { |
| 262 AddRegistryKeyWatcher( | 265 AddRegistryKeyWatcher( |
| 263 base::StringPrintf(kUrlAssociationFormat, *scan).c_str()); | 266 base::StringPrintf(kUrlAssociationFormat, *scan).c_str()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 new base::win::RegKey(HKEY_CURRENT_USER, key_path, KEY_NOTIFY)); | 311 new base::win::RegKey(HKEY_CURRENT_USER, key_path, KEY_NOTIFY)); |
| 309 | 312 |
| 310 if (reg_key->Valid() && | 313 if (reg_key->Valid() && |
| 311 reg_key->StartWatching( | 314 reg_key->StartWatching( |
| 312 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, | 315 base::Bind(&OpenSystemSettingsHelper::OnRegistryKeyChanged, |
| 313 weak_ptr_factory_.GetWeakPtr()))) { | 316 weak_ptr_factory_.GetWeakPtr()))) { |
| 314 registry_key_watchers_.push_back(std::move(reg_key)); | 317 registry_key_watchers_.push_back(std::move(reg_key)); |
| 315 } | 318 } |
| 316 } | 319 } |
| 317 | 320 |
| 321 // This is needed to make sure that Windows display an entry for the protocol | |
|
grt (UTC plus 2)
2016/04/20 12:37:52
nit: "displays"
Patrick Monette
2016/04/20 16:08:30
Done.
| |
| 322 // inside the "Choose default apps by protocol" settings page. | |
| 323 ScopedUserProtocolEntry scoped_user_protocol_entry_; | |
| 324 | |
| 318 // The function to call when the interaction with the system settings is | 325 // The function to call when the interaction with the system settings is |
| 319 // finished. | 326 // finished. |
| 320 base::Closure on_finished_callback_; | 327 base::Closure on_finished_callback_; |
| 321 | 328 |
| 322 // The number of time the registry key watchers must fire. | 329 // The number of time the registry key watchers must fire. |
| 323 int registry_watcher_count_ = 0; | 330 int registry_watcher_count_ = 0; |
| 324 | 331 |
| 325 // There can be multiple registry key watchers as some settings modify | 332 // There can be multiple registry key watchers as some settings modify |
| 326 // multiple protocol associations. e.g. Changing the default browser modifies | 333 // multiple protocol associations. e.g. Changing the default browser modifies |
| 327 // the http and https associations. | 334 // the http and https associations. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, | 689 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, |
| 683 wprotocol)) { | 690 wprotocol)) { |
| 684 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; | 691 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; |
| 685 return false; | 692 return false; |
| 686 } | 693 } |
| 687 | 694 |
| 688 VLOG(1) << "Set-default-client Windows UI completed."; | 695 VLOG(1) << "Set-default-client Windows UI completed."; |
| 689 return true; | 696 return true; |
| 690 } | 697 } |
| 691 | 698 |
| 699 void SetAsDefaultProtocolClientUsingSystemSettings( | |
| 700 const std::string& protocol, | |
| 701 const base::Closure& on_finished_callback) { | |
| 702 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 703 | |
| 704 base::FilePath chrome_exe; | |
| 705 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | |
| 706 NOTREACHED() << "Error getting app exe path"; | |
| 707 on_finished_callback.Run(); | |
| 708 return; | |
| 709 } | |
| 710 | |
| 711 // The helper manages its own lifetime. | |
| 712 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); | |
| 713 const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr}; | |
| 714 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback); | |
| 715 | |
| 716 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 717 ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, | |
| 718 wprotocol); | |
| 719 } | |
| 720 | |
| 692 } // namespace win | 721 } // namespace win |
| 693 | 722 |
| 694 } // namespace shell_integration | 723 } // namespace shell_integration |
| OLD | NEW |