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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 1349163008: Setting chrome as the default browser is now fixed on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 5 years, 2 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/ui/startup/startup_browser_creator.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 #include <set> 8 #include <set>
9 9
10 #include "apps/app_load_service.h" 10 #include "apps/app_load_service.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 99 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
100 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 100 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
101 #include "chrome/browser/printing/print_dialog_cloud.h" 101 #include "chrome/browser/printing/print_dialog_cloud.h"
102 #endif 102 #endif
103 103
104 using content::BrowserThread; 104 using content::BrowserThread;
105 using content::ChildProcessSecurityPolicy; 105 using content::ChildProcessSecurityPolicy;
106 106
107 namespace { 107 namespace {
108 108
109 const wchar_t kSetDefaultBrowserHelpUrl[] =
110 L"https://support.google.com/chrome?p=default_browser";
111
112 // Not thread-safe. Always use or modify this callback on the UI thread.
113 base::Closure* g_default_browser_callback = nullptr;
114
109 // Keeps track on which profiles have been launched. 115 // Keeps track on which profiles have been launched.
110 class ProfileLaunchObserver : public content::NotificationObserver { 116 class ProfileLaunchObserver : public content::NotificationObserver {
111 public: 117 public:
112 ProfileLaunchObserver() 118 ProfileLaunchObserver()
113 : profile_to_activate_(NULL), 119 : profile_to_activate_(NULL),
114 activated_profile_(false) { 120 activated_profile_(false) {
115 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 121 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
116 content::NotificationService::AllSources()); 122 content::NotificationService::AllSources());
117 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 123 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
118 content::NotificationService::AllSources()); 124 content::NotificationService::AllSources());
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // static 484 // static
479 void StartupBrowserCreator::RegisterLocalStatePrefs( 485 void StartupBrowserCreator::RegisterLocalStatePrefs(
480 PrefRegistrySimple* registry) { 486 PrefRegistrySimple* registry) {
481 #if defined(OS_WIN) 487 #if defined(OS_WIN)
482 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string()); 488 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string());
483 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true); 489 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true);
484 #endif 490 #endif
485 } 491 }
486 492
487 // static 493 // static
494 bool StartupBrowserCreator::SetDefaultBrowserCallback(
495 const base::Closure& callback) {
496 DCHECK_CURRENTLY_ON(BrowserThread::UI);
497 if (!g_default_browser_callback) {
498 // This won't leak because the worker class invoking this function always
499 // calls ClearDefaultBrowserCallback() in its destructor.
500 g_default_browser_callback = new base::Closure(callback);
501 return true;
502 }
503 return false;
504 }
505
506 // static
507 void StartupBrowserCreator::ClearDefaultBrowserCallback() {
508 DCHECK_CURRENTLY_ON(BrowserThread::UI);
509 delete g_default_browser_callback;
510 g_default_browser_callback = nullptr;
511 }
512
513 // static
514 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() {
515 return kSetDefaultBrowserHelpUrl;
516 }
517
518 // static
488 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 519 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
489 const base::CommandLine& command_line, 520 const base::CommandLine& command_line,
490 const base::FilePath& cur_dir, 521 const base::FilePath& cur_dir,
491 Profile* profile) { 522 Profile* profile) {
492 std::vector<GURL> urls; 523 std::vector<GURL> urls;
493 524
494 const base::CommandLine::StringVector& params = command_line.GetArgs(); 525 const base::CommandLine::StringVector& params = command_line.GetArgs();
495 for (size_t i = 0; i < params.size(); ++i) { 526 for (size_t i = 0; i < params.size(); ++i) {
496 base::FilePath param = base::FilePath(params[i]); 527 base::FilePath param = base::FilePath(params[i]);
497 // Handle Vista way of searching - "? <search-term>" 528 // Handle Vista way of searching - "? <search-term>"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 574 }
544 575
545 // static 576 // static
546 bool StartupBrowserCreator::ProcessCmdLineImpl( 577 bool StartupBrowserCreator::ProcessCmdLineImpl(
547 const base::CommandLine& command_line, 578 const base::CommandLine& command_line,
548 const base::FilePath& cur_dir, 579 const base::FilePath& cur_dir,
549 bool process_startup, 580 bool process_startup,
550 Profile* last_used_profile, 581 Profile* last_used_profile,
551 const Profiles& last_opened_profiles, 582 const Profiles& last_opened_profiles,
552 StartupBrowserCreator* browser_creator) { 583 StartupBrowserCreator* browser_creator) {
584 DCHECK_CURRENTLY_ON(BrowserThread::UI);
553 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 585 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
554 586
555 DCHECK(last_used_profile); 587 DCHECK(last_used_profile);
556 if (process_startup) { 588 if (process_startup) {
557 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 589 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
558 content::NavigationController::DisablePromptOnRepost(); 590 content::NavigationController::DisablePromptOnRepost();
559 } 591 }
560 592
561 bool silent_launch = false; 593 bool silent_launch = false;
562 594
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // Return early here since we don't want to open a browser window. 714 // Return early here since we don't want to open a browser window.
683 // The exception is when there are no browser windows, since we don't want 715 // The exception is when there are no browser windows, since we don't want
684 // chrome to shut down. 716 // chrome to shut down.
685 // TODO(jackhou): Do this properly once keep-alive is handled by the 717 // TODO(jackhou): Do this properly once keep-alive is handled by the
686 // background page of apps. Tracked at http://crbug.com/175381 718 // background page of apps. Tracked at http://crbug.com/175381
687 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 719 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
688 return true; 720 return true;
689 } 721 }
690 722
691 #if defined(OS_WIN) 723 #if defined(OS_WIN)
724 // Intercept a specific url when setting the default browser asynchronously.
725 // This only happens on Windows 10+.
726 if (g_default_browser_callback) {
727 base::CommandLine::StringType default_browser_url_(
728 kSetDefaultBrowserHelpUrl);
729 for (const auto& arg : command_line.GetArgs()) {
730 if (arg == default_browser_url_) {
731 g_default_browser_callback->Run();
732 return true;
733 }
734 }
735 }
736
692 // Log whether this process was a result of an action in the Windows Jumplist. 737 // Log whether this process was a result of an action in the Windows Jumplist.
693 if (command_line.HasSwitch(switches::kWinJumplistAction)) { 738 if (command_line.HasSwitch(switches::kWinJumplistAction)) {
694 jumplist::LogJumplistActionFromSwitchValue( 739 jumplist::LogJumplistActionFromSwitchValue(
695 command_line.GetSwitchValueASCII(switches::kWinJumplistAction)); 740 command_line.GetSwitchValueASCII(switches::kWinJumplistAction));
696 } 741 }
697 #endif 742 #endif // defined(OS_WIN)
698 743
699 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 744 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
700 chrome::startup::IS_PROCESS_STARTUP : 745 chrome::startup::IS_PROCESS_STARTUP :
701 chrome::startup::IS_NOT_PROCESS_STARTUP; 746 chrome::startup::IS_NOT_PROCESS_STARTUP;
702 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 747 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
703 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 748 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
704 // |last_opened_profiles| will be empty in the following circumstances: 749 // |last_opened_profiles| will be empty in the following circumstances:
705 // - This is the first launch. |last_used_profile| is the initial profile. 750 // - This is the first launch. |last_used_profile| is the initial profile.
706 // - The user exited the browser by closing all windows for all 751 // - The user exited the browser by closing all windows for all
707 // profiles. |last_used_profile| is the profile which owned the last open 752 // profiles. |last_used_profile| is the profile which owned the last open
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // If we are showing the app list then chrome isn't shown so load the app 902 // If we are showing the app list then chrome isn't shown so load the app
858 // list's profile rather than chrome's. 903 // list's profile rather than chrome's.
859 if (command_line.HasSwitch(switches::kShowAppList)) { 904 if (command_line.HasSwitch(switches::kShowAppList)) {
860 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 905 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
861 GetProfilePath(user_data_dir); 906 GetProfilePath(user_data_dir);
862 } 907 }
863 908
864 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 909 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
865 user_data_dir); 910 user_data_dir);
866 } 911 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698