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

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: Test for default browser callback + comments 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 // static 445 // static
440 void StartupBrowserCreator::RegisterLocalStatePrefs( 446 void StartupBrowserCreator::RegisterLocalStatePrefs(
441 PrefRegistrySimple* registry) { 447 PrefRegistrySimple* registry) {
442 #if defined(OS_WIN) 448 #if defined(OS_WIN)
443 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string()); 449 registry->RegisterStringPref(prefs::kLastWelcomedOSVersion, std::string());
444 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true); 450 registry->RegisterBooleanPref(prefs::kWelcomePageOnOSUpgradeEnabled, true);
445 #endif 451 #endif
446 } 452 }
447 453
448 // static 454 // static
455 bool StartupBrowserCreator::SetDefaultBrowserCallback(
456 const base::Closure& callback) {
457 DCHECK_CURRENTLY_ON(BrowserThread::UI);
458 if (!g_default_browser_callback) {
459 g_default_browser_callback = new base::Closure(callback);
Peter Kasting 2015/09/25 20:52:27 Nit: I might add a comment here on why this can't
Patrick Monette 2015/09/28 23:46:38 Done.
460 return true;
461 }
462 return false;
463 }
464
465 // static
466 void StartupBrowserCreator::ClearDefaultBrowserCallback() {
467 DCHECK_CURRENTLY_ON(BrowserThread::UI);
468 if (g_default_browser_callback) {
grt (UTC plus 2) 2015/09/28 14:31:04 delete null is well-defined in C++, so you could r
Patrick Monette 2015/09/28 23:46:38 Done.
469 delete g_default_browser_callback;
470 g_default_browser_callback = nullptr;
471 }
472 }
473
474 // static
475 const wchar_t* StartupBrowserCreator::GetDefaultBrowserUrl() {
476 return kSetDefaultBrowserHelpUrl;
477 }
478
479 // static
449 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 480 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
450 const base::CommandLine& command_line, 481 const base::CommandLine& command_line,
451 const base::FilePath& cur_dir, 482 const base::FilePath& cur_dir,
452 Profile* profile) { 483 Profile* profile) {
453 std::vector<GURL> urls; 484 std::vector<GURL> urls;
454 485
455 const base::CommandLine::StringVector& params = command_line.GetArgs(); 486 const base::CommandLine::StringVector& params = command_line.GetArgs();
456 for (size_t i = 0; i < params.size(); ++i) { 487 for (size_t i = 0; i < params.size(); ++i) {
457 base::FilePath param = base::FilePath(params[i]); 488 base::FilePath param = base::FilePath(params[i]);
458 // Handle Vista way of searching - "? <search-term>" 489 // Handle Vista way of searching - "? <search-term>"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 535 }
505 536
506 // static 537 // static
507 bool StartupBrowserCreator::ProcessCmdLineImpl( 538 bool StartupBrowserCreator::ProcessCmdLineImpl(
508 const base::CommandLine& command_line, 539 const base::CommandLine& command_line,
509 const base::FilePath& cur_dir, 540 const base::FilePath& cur_dir,
510 bool process_startup, 541 bool process_startup,
511 Profile* last_used_profile, 542 Profile* last_used_profile,
512 const Profiles& last_opened_profiles, 543 const Profiles& last_opened_profiles,
513 StartupBrowserCreator* browser_creator) { 544 StartupBrowserCreator* browser_creator) {
545 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 546 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
515 547
516 DCHECK(last_used_profile); 548 DCHECK(last_used_profile);
517 if (process_startup) { 549 if (process_startup) {
518 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 550 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
519 content::NavigationController::DisablePromptOnRepost(); 551 content::NavigationController::DisablePromptOnRepost();
520 } 552 }
521 553
522 bool silent_launch = false; 554 bool silent_launch = false;
523 555
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // Return early here since we don't want to open a browser window. 675 // Return early here since we don't want to open a browser window.
644 // The exception is when there are no browser windows, since we don't want 676 // The exception is when there are no browser windows, since we don't want
645 // chrome to shut down. 677 // chrome to shut down.
646 // TODO(jackhou): Do this properly once keep-alive is handled by the 678 // TODO(jackhou): Do this properly once keep-alive is handled by the
647 // background page of apps. Tracked at http://crbug.com/175381 679 // background page of apps. Tracked at http://crbug.com/175381
648 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 680 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
649 return true; 681 return true;
650 } 682 }
651 683
652 #if defined(OS_WIN) 684 #if defined(OS_WIN)
685 // Intercept a specific url when setting the default browser asynchronously.
686 // This only happens on Windows 10+.
687 if (g_default_browser_callback) {
688 base::CommandLine::StringType default_browser_url_(
689 kSetDefaultBrowserHelpUrl);
690 for (const auto& arg : command_line.GetArgs()) {
691 if (arg == default_browser_url_) {
692 g_default_browser_callback->Run();
693 return true;
694 }
695 }
696 }
697
653 // Log whether this process was a result of an action in the Windows Jumplist. 698 // Log whether this process was a result of an action in the Windows Jumplist.
654 if (command_line.HasSwitch(switches::kWinJumplistAction)) { 699 if (command_line.HasSwitch(switches::kWinJumplistAction)) {
655 jumplist::LogJumplistActionFromSwitchValue( 700 jumplist::LogJumplistActionFromSwitchValue(
656 command_line.GetSwitchValueASCII(switches::kWinJumplistAction)); 701 command_line.GetSwitchValueASCII(switches::kWinJumplistAction));
657 } 702 }
658 #endif 703 #endif // defined(OS_WIN)
659 704
660 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 705 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
661 chrome::startup::IS_PROCESS_STARTUP : 706 chrome::startup::IS_PROCESS_STARTUP :
662 chrome::startup::IS_NOT_PROCESS_STARTUP; 707 chrome::startup::IS_NOT_PROCESS_STARTUP;
663 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 708 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
664 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 709 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
665 // |last_opened_profiles| will be empty in the following circumstances: 710 // |last_opened_profiles| will be empty in the following circumstances:
666 // - This is the first launch. |last_used_profile| is the initial profile. 711 // - This is the first launch. |last_used_profile| is the initial profile.
667 // - The user exited the browser by closing all windows for all 712 // - The user exited the browser by closing all windows for all
668 // profiles. |last_used_profile| is the profile which owned the last open 713 // profiles. |last_used_profile| is the profile which owned the last open
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // If we are showing the app list then chrome isn't shown so load the app 887 // If we are showing the app list then chrome isn't shown so load the app
843 // list's profile rather than chrome's. 888 // list's profile rather than chrome's.
844 if (command_line.HasSwitch(switches::kShowAppList)) { 889 if (command_line.HasSwitch(switches::kShowAppList)) {
845 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 890 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
846 GetProfilePath(user_data_dir); 891 GetProfilePath(user_data_dir);
847 } 892 }
848 893
849 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 894 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
850 user_data_dir); 895 user_data_dir);
851 } 896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698