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

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

Issue 1575163002: New experiment without registry deletion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add experiment Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/browser/shell_integration.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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 case ShellUtil::NOT_DEFAULT: 246 case ShellUtil::NOT_DEFAULT:
247 return ShellIntegration::NOT_DEFAULT; 247 return ShellIntegration::NOT_DEFAULT;
248 case ShellUtil::IS_DEFAULT: 248 case ShellUtil::IS_DEFAULT:
249 return ShellIntegration::IS_DEFAULT; 249 return ShellIntegration::IS_DEFAULT;
250 default: 250 default:
251 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state); 251 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state);
252 return ShellIntegration::UNKNOWN_DEFAULT; 252 return ShellIntegration::UNKNOWN_DEFAULT;
253 } 253 }
254 } 254 }
255 255
256 // Resets the default browser choice for the current user.
257 void ResetDefaultBrowser() {
258 static const wchar_t* const kUrlAssociationKeyFormats[] = {
259 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
260 L"%ls\\UserChoice",
261 L"SOFTWARE\\Microsoft\\Windows\\Roaming\\OpenWith\\UrlAssociations\\"
262 L"%ls\\UserChoice"};
263 static const wchar_t* const kProtocols[] = {L"http", L"https"};
264
265 for (const wchar_t* format : kUrlAssociationKeyFormats) {
266 for (const wchar_t* protocol : kProtocols) {
267 base::win::RegKey registry_key(
268 HKEY_CURRENT_USER, base::StringPrintf(format, protocol).c_str(),
269 KEY_SET_VALUE);
270 registry_key.DeleteValue(L"Hash");
271 }
272 }
273 }
274
275 // Returns true if the AsyncSetAsDefault field trial is activated. 256 // Returns true if the AsyncSetAsDefault field trial is activated.
276 bool IsAsyncSetAsDefaultEnabled() { 257 bool IsAsyncSetAsDefaultEnabled() {
277 using base::CommandLine; 258 using base::CommandLine;
278 259
279 // Note: It's important to query the field trial state first, to ensure that 260 // Note: It's important to query the field trial state first, to ensure that
280 // UMA reports the correct group. 261 // UMA reports the correct group.
281 const std::string group_name = 262 const std::string group_name =
282 base::FieldTrialList::FindFullName("AsyncSetAsDefault"); 263 base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName);
283 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) 264 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault))
284 return false; 265 return false;
285 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) 266 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault))
286 return true; 267 return true;
287 268
288 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); 269 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
289 } 270 }
290 271
291 bool RegisterBrowser() { 272 bool RegisterBrowser() {
292 base::FilePath chrome_exe; 273 base::FilePath chrome_exe;
293 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 274 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
294 NOTREACHED() << "Error getting app exe path"; 275 NOTREACHED() << "Error getting app exe path";
295 return false; 276 return false;
296 } 277 }
297 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 278 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
298 279
299 return ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), 280 return ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(),
300 true); 281 true);
301 } 282 }
302 283
284 // Returns true if the default browser choice should be reset for the current
285 // user.
286 bool ShouldResetDefaultBrowser() {
287 return base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName) !=
288 "EnabledNoRegistry";
gab 2016/01/11 23:41:00 Use StartsWith() instead of == for comparing group
Patrick Monette 2016/01/12 00:07:27 Done.
289 }
290
291 // Resets the default browser choice for the current user.
292 void ResetDefaultBrowser() {
gab 2016/01/11 23:41:00 What's the reason to move the method? It appears u
Patrick Monette 2016/01/12 00:07:27 Just to make order of definition = order of use.
293 static const wchar_t* const kUrlAssociationKeyFormats[] = {
294 L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
295 L"%ls\\UserChoice",
296 L"SOFTWARE\\Microsoft\\Windows\\Roaming\\OpenWith\\UrlAssociations\\"
297 L"%ls\\UserChoice"};
298 static const wchar_t* const kProtocols[] = {L"http", L"https"};
299
300 for (const wchar_t* format : kUrlAssociationKeyFormats) {
301 for (const wchar_t* protocol : kProtocols) {
302 base::win::RegKey registry_key(
303 HKEY_CURRENT_USER, base::StringPrintf(format, protocol).c_str(),
304 KEY_SET_VALUE);
305 registry_key.DeleteValue(L"Hash");
306 }
307 }
308 }
309
303 } // namespace 310 } // namespace
304 311
305 // static 312 // static
306 bool ShellIntegration::IsSetAsDefaultAsynchronous() { 313 bool ShellIntegration::IsSetAsDefaultAsynchronous() {
307 return base::win::GetVersion() >= base::win::VERSION_WIN10 && 314 return base::win::GetVersion() >= base::win::VERSION_WIN10 &&
308 IsAsyncSetAsDefaultEnabled(); 315 IsAsyncSetAsDefaultEnabled();
309 } 316 }
310 317
311 bool ShellIntegration::SetAsDefaultBrowser() { 318 bool ShellIntegration::SetAsDefaultBrowser() {
312 base::FilePath chrome_exe; 319 base::FilePath chrome_exe;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 712
706 void ShellIntegration::DefaultBrowserWorker::FinalizeSetAsDefault() { 713 void ShellIntegration::DefaultBrowserWorker::FinalizeSetAsDefault() {
707 DCHECK_CURRENTLY_ON(BrowserThread::UI); 714 DCHECK_CURRENTLY_ON(BrowserThread::UI);
708 DCHECK(set_as_default_initialized()); 715 DCHECK(set_as_default_initialized());
709 716
710 async_timer_.reset(); 717 async_timer_.reset();
711 StartupBrowserCreator::ClearDefaultBrowserCallback(); 718 StartupBrowserCreator::ClearDefaultBrowserCallback();
712 } 719 }
713 720
714 // static 721 // static
715 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { 722 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() {
gab 2016/01/11 23:43:28 It's weird to have a group ("EnablednoRegistry") t
Patrick Monette 2016/01/12 00:07:27 This won't change the fact that there is 2 meaning
716 DCHECK(IsSetAsDefaultAsynchronous()); 723 DCHECK(IsSetAsDefaultAsynchronous());
717 724
718 // Registers chrome.exe as a browser on Windows to make sure it will be shown 725 // Registers chrome.exe as a browser on Windows to make sure it will be shown
719 // in the "How would you like to open this?" prompt. 726 // in the "How would you like to open this?" prompt.
720 if (!RegisterBrowser()) 727 if (!RegisterBrowser())
721 return false; 728 return false;
722 729
723 ResetDefaultBrowser(); 730 if (ShouldResetDefaultBrowser())
731 ResetDefaultBrowser();
724 732
725 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); 733 base::CommandLine cmdline(base::FilePath(L"openwith.exe"));
726 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); 734 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl());
727 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); 735 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid();
728 } 736 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698