Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/shell_integration_win.cc

Issue 1896513002: Fix registerProtocolHandler implementation on Windows 8 and 10. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Round of comment #1 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 ScopedUserProtocolEntry scoped_user_protocol_entry_;
grt (UTC plus 2) 2016/04/18 19:00:56 nit: a comment here would be helpful to understand
grt (UTC plus 2) 2016/04/19 02:03:46 as per face-to-face discussion, i understand this
Patrick Monette 2016/04/19 14:36:13 I added a comment. I think shell util is due for a
322
318 // The function to call when the interaction with the system settings is 323 // The function to call when the interaction with the system settings is
319 // finished. 324 // finished.
320 base::Closure on_finished_callback_; 325 base::Closure on_finished_callback_;
321 326
322 // The number of time the registry key watchers must fire. 327 // The number of time the registry key watchers must fire.
323 int registry_watcher_count_ = 0; 328 int registry_watcher_count_ = 0;
324 329
325 // There can be multiple registry key watchers as some settings modify 330 // There can be multiple registry key watchers as some settings modify
326 // multiple protocol associations. e.g. Changing the default browser modifies 331 // multiple protocol associations. e.g. Changing the default browser modifies
327 // the http and https associations. 332 // the http and https associations.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe, 687 if (!ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
683 wprotocol)) { 688 wprotocol)) {
684 LOG(ERROR) << "Failed to launch the set-default-client Windows UI."; 689 LOG(ERROR) << "Failed to launch the set-default-client Windows UI.";
685 return false; 690 return false;
686 } 691 }
687 692
688 VLOG(1) << "Set-default-client Windows UI completed."; 693 VLOG(1) << "Set-default-client Windows UI completed.";
689 return true; 694 return true;
690 } 695 }
691 696
697 void SetAsDefaultProtocolClientUsingSystemSettings(
698 const std::string& protocol,
699 const base::Closure& on_finished_callback) {
700 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
701
702 base::FilePath chrome_exe;
703 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
704 NOTREACHED() << "Error getting app exe path";
705 on_finished_callback.Run();
706 return;
707 }
708
709 // The helper manages its own lifetime.
710 base::string16 wprotocol(base::UTF8ToUTF16(protocol));
711 static const wchar_t* const kProtocols[] = {wprotocol.c_str(), nullptr};
712 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback);
713
714 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
715 ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(dist, chrome_exe,
716 wprotocol);
717 }
718
692 } // namespace win 719 } // namespace win
693 720
694 } // namespace shell_integration 721 } // namespace shell_integration
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698