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

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: Fix compilation again 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 #if defined(OS_WIN)
110 const wchar_t kSetDefaultBrowserHelpUrl[] =
111 L"https://support.google.com/chrome?p=default_browser";
112
113 // Not thread-safe. Always use or modify this callback on the UI thread.
114 base::Closure* g_default_browser_callback = nullptr;
115 #endif // defined(OS_WIN)
116
109 // Keeps track on which profiles have been launched. 117 // Keeps track on which profiles have been launched.
110 class ProfileLaunchObserver : public content::NotificationObserver { 118 class ProfileLaunchObserver : public content::NotificationObserver {
111 public: 119 public:
112 ProfileLaunchObserver() 120 ProfileLaunchObserver()
113 : profile_to_activate_(NULL), 121 : profile_to_activate_(NULL),
114 activated_profile_(false) { 122 activated_profile_(false) {
115 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 123 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
116 content::NotificationService::AllSources()); 124 content::NotificationService::AllSources());
117 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 125 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
118 content::NotificationService::AllSources()); 126 content::NotificationService::AllSources());
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 485
478 // static 486 // static
479 void StartupBrowserCreator::RegisterLocalStatePrefs( 487 void StartupBrowserCreator::RegisterLocalStatePrefs(
480 PrefRegistrySimple* registry) { 488 PrefRegistrySimple* registry) {
481 #if defined(OS_WIN) 489 #if defined(OS_WIN)
482 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string()); 490 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string());
483 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true); 491 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true);
484 #endif 492 #endif
485 } 493 }
486 494
495
496 #if defined(OS_WIN)
497 // static
498 bool StartupBrowserCreator::SetDefaultBrowserCallback(
499 const base::Closure& callback) {
500 DCHECK_CURRENTLY_ON(BrowserThread::UI);
501 if (!g_default_browser_callback) {
502 // This won't leak because the worker class invoking this function always
503 // calls ClearDefaultBrowserCallback() in its destructor.
504 g_default_browser_callback = new base::Closure(callback);
505 return true;
506 }
507 return false;
508 }
509
510 // static
511 void StartupBrowserCreator::ClearDefaultBrowserCallback() {
512 DCHECK_CURRENTLY_ON(BrowserThread::UI);
513 delete g_default_browser_callback;
514 g_default_browser_callback = nullptr;
515 }
516
517 // static
518 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() {
519 return kSetDefaultBrowserHelpUrl;
520 }
521 #endif // defined(OS_WIN)
522
487 // static 523 // static
488 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 524 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
489 const base::CommandLine& command_line, 525 const base::CommandLine& command_line,
490 const base::FilePath& cur_dir, 526 const base::FilePath& cur_dir,
491 Profile* profile) { 527 Profile* profile) {
492 std::vector<GURL> urls; 528 std::vector<GURL> urls;
493 529
494 const base::CommandLine::StringVector& params = command_line.GetArgs(); 530 const base::CommandLine::StringVector& params = command_line.GetArgs();
495 for (size_t i = 0; i < params.size(); ++i) { 531 for (size_t i = 0; i < params.size(); ++i) {
496 base::FilePath param = base::FilePath(params[i]); 532 base::FilePath param = base::FilePath(params[i]);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 579 }
544 580
545 // static 581 // static
546 bool StartupBrowserCreator::ProcessCmdLineImpl( 582 bool StartupBrowserCreator::ProcessCmdLineImpl(
547 const base::CommandLine& command_line, 583 const base::CommandLine& command_line,
548 const base::FilePath& cur_dir, 584 const base::FilePath& cur_dir,
549 bool process_startup, 585 bool process_startup,
550 Profile* last_used_profile, 586 Profile* last_used_profile,
551 const Profiles& last_opened_profiles, 587 const Profiles& last_opened_profiles,
552 StartupBrowserCreator* browser_creator) { 588 StartupBrowserCreator* browser_creator) {
589 DCHECK_CURRENTLY_ON(BrowserThread::UI);
553 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 590 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
554 591
555 DCHECK(last_used_profile); 592 DCHECK(last_used_profile);
556 if (process_startup) { 593 if (process_startup) {
557 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 594 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
558 content::NavigationController::DisablePromptOnRepost(); 595 content::NavigationController::DisablePromptOnRepost();
559 } 596 }
560 597
561 bool silent_launch = false; 598 bool silent_launch = false;
562 599
(...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. 719 // 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 720 // The exception is when there are no browser windows, since we don't want
684 // chrome to shut down. 721 // chrome to shut down.
685 // TODO(jackhou): Do this properly once keep-alive is handled by the 722 // TODO(jackhou): Do this properly once keep-alive is handled by the
686 // background page of apps. Tracked at http://crbug.com/175381 723 // background page of apps. Tracked at http://crbug.com/175381
687 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 724 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
688 return true; 725 return true;
689 } 726 }
690 727
691 #if defined(OS_WIN) 728 #if defined(OS_WIN)
729 // Intercept a specific url when setting the default browser asynchronously.
730 // This only happens on Windows 10+.
731 if (g_default_browser_callback) {
732 base::CommandLine::StringType default_browser_url_(
733 kSetDefaultBrowserHelpUrl);
734 for (const auto& arg : command_line.GetArgs()) {
735 if (arg == default_browser_url_) {
736 g_default_browser_callback->Run();
737 return true;
738 }
739 }
740 }
741
692 // Log whether this process was a result of an action in the Windows Jumplist. 742 // Log whether this process was a result of an action in the Windows Jumplist.
693 if (command_line.HasSwitch(switches::kWinJumplistAction)) { 743 if (command_line.HasSwitch(switches::kWinJumplistAction)) {
694 jumplist::LogJumplistActionFromSwitchValue( 744 jumplist::LogJumplistActionFromSwitchValue(
695 command_line.GetSwitchValueASCII(switches::kWinJumplistAction)); 745 command_line.GetSwitchValueASCII(switches::kWinJumplistAction));
696 } 746 }
697 #endif 747 #endif // defined(OS_WIN)
698 748
699 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 749 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
700 chrome::startup::IS_PROCESS_STARTUP : 750 chrome::startup::IS_PROCESS_STARTUP :
701 chrome::startup::IS_NOT_PROCESS_STARTUP; 751 chrome::startup::IS_NOT_PROCESS_STARTUP;
702 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 752 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
703 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 753 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
704 // |last_opened_profiles| will be empty in the following circumstances: 754 // |last_opened_profiles| will be empty in the following circumstances:
705 // - This is the first launch. |last_used_profile| is the initial profile. 755 // - This is the first launch. |last_used_profile| is the initial profile.
706 // - The user exited the browser by closing all windows for all 756 // - The user exited the browser by closing all windows for all
707 // profiles. |last_used_profile| is the profile which owned the last open 757 // 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 907 // If we are showing the app list then chrome isn't shown so load the app
858 // list's profile rather than chrome's. 908 // list's profile rather than chrome's.
859 if (command_line.HasSwitch(switches::kShowAppList)) { 909 if (command_line.HasSwitch(switches::kShowAppList)) {
860 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 910 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
861 GetProfilePath(user_data_dir); 911 GetProfilePath(user_data_dir);
862 } 912 }
863 913
864 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 914 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
865 user_data_dir); 915 user_data_dir);
866 } 916 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698