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

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

Issue 1428833002: Register chrome as a browser when setting the default browser in Win 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 const std::string group_name = 278 const std::string group_name =
279 base::FieldTrialList::FindFullName("AsyncSetAsDefault"); 279 base::FieldTrialList::FindFullName("AsyncSetAsDefault");
280 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) 280 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault))
281 return false; 281 return false;
282 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) 282 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault))
283 return true; 283 return true;
284 284
285 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); 285 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
286 } 286 }
287 287
288 bool RegisterBrowser() {
289 base::FilePath chrome_exe;
290 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
291 NOTREACHED() << "Error getting app exe path";
292 return false;
293 }
294 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
295
296 return ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(),
297 true);
298 }
299
288 } // namespace 300 } // namespace
289 301
290 // static 302 // static
291 bool ShellIntegration::IsSetAsDefaultAsynchronous() { 303 bool ShellIntegration::IsSetAsDefaultAsynchronous() {
292 return base::win::GetVersion() >= base::win::VERSION_WIN10 && 304 return base::win::GetVersion() >= base::win::VERSION_WIN10 &&
293 IsAsyncSetAsDefaultEnabled(); 305 IsAsyncSetAsDefaultEnabled();
294 } 306 }
295 307
296 bool ShellIntegration::SetAsDefaultBrowser() { 308 bool ShellIntegration::SetAsDefaultBrowser() {
297 base::FilePath chrome_exe; 309 base::FilePath chrome_exe;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 bool ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() { 660 bool ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() {
649 DCHECK_CURRENTLY_ON(BrowserThread::UI); 661 DCHECK_CURRENTLY_ON(BrowserThread::UI);
650 662
651 if (!IsSetAsDefaultAsynchronous()) 663 if (!IsSetAsDefaultAsynchronous())
652 return false; 664 return false;
653 665
654 // On Windows 10+, there is no official way to prompt the user to set a 666 // On Windows 10+, there is no official way to prompt the user to set a
655 // default browser. This is the workaround: 667 // default browser. This is the workaround:
656 // 1. Unregister the default browser. 668 // 1. Unregister the default browser.
657 // 2. Open "How to make Chrome my default browser" link with openwith.exe. 669 // 2. Open "How to make Chrome my default browser" link with openwith.exe.
658 // 3. Windows will prompt the user with "How would you link to open this?". 670 // 3. Windows will prompt the user with "How would you like to open this?".
659 // 4. If Chrome is selected, we intercept the attempt to open the URL and 671 // 4. If Chrome is selected, we intercept the attempt to open the URL and
660 // instead call OnSetAsDefaultAttemptComplete(), passing true to indicate 672 // instead call OnSetAsDefaultAttemptComplete(), passing true to indicate
661 // success. 673 // success.
662 // 5. If Chrome is not selected, the url is opened in the selected browser. 674 // 5. If Chrome is not selected, the url is opened in the selected browser.
663 // After a certain amount of time, we notify the observer that the 675 // After a certain amount of time, we notify the observer that the
664 // process failed. 676 // process failed.
665 677
666 if (!StartupBrowserCreator::SetDefaultBrowserCallback( 678 if (!StartupBrowserCreator::SetDefaultBrowserCallback(
667 base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this, 679 base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this,
668 AttemptResult::SUCCESS))) { 680 AttemptResult::SUCCESS))) {
(...skipping 29 matching lines...) Expand all
698 DCHECK(set_as_default_initialized()); 710 DCHECK(set_as_default_initialized());
699 711
700 async_timer_.reset(); 712 async_timer_.reset();
701 StartupBrowserCreator::ClearDefaultBrowserCallback(); 713 StartupBrowserCreator::ClearDefaultBrowserCallback();
702 } 714 }
703 715
704 // static 716 // static
705 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { 717 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() {
706 DCHECK(IsSetAsDefaultAsynchronous()); 718 DCHECK(IsSetAsDefaultAsynchronous());
707 719
720 // Registers chrome.exe as a browser on Windows to make sure it will be shown
721 // in the "How would you like to open this?" prompt.
722 if (!RegisterBrowser())
723 return false;
724
708 ResetDefaultBrowser(); 725 ResetDefaultBrowser();
709 726
710 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); 727 base::CommandLine cmdline(base::FilePath(L"openwith.exe"));
711 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); 728 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl());
712 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); 729 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid();
713 } 730 }
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