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

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: grt comments #1 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";
grt (UTC plus 2) 2015/09/24 18:47:06 PK: it seems like this should be brand-specific. d
Peter Kasting 2015/09/24 20:34:10 Do we have any support pages for Chromium (not Chr
111
112 // Not thread-safe. Always use or modify this callback on the UI thread.
113 base::CancelableClosure async_set_as_default_filter_callback;
Peter Kasting 2015/09/23 23:01:39 The Google style guide bans the use of global or s
grt (UTC plus 2) 2015/09/24 18:24:12 i think CancelableClosure is overkill here since y
Peter Kasting 2015/09/24 20:34:10 One downside to this is it's prone to leaks. It's
grt (UTC plus 2) 2015/09/24 20:39:24 On the flipside, it means that there's a risk that
Patrick Monette 2015/09/25 20:06:25 Done.
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 void StartupBrowserCreator::SetAsyncSetAsDefaultFilter(base::Closure callback) {
456 DCHECK_CURRENTLY_ON(BrowserThread::UI);
457 async_set_as_default_filter_callback.Reset(callback);
458 }
459
460 // static
461 void StartupBrowserCreator::ClearAsyncSetAsDefaultFilter() {
462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
463 async_set_as_default_filter_callback.Cancel();
464 }
465
466 // static
467 const wchar_t* StartupBrowserCreator::GetAsyncSetAsDefaultUrl() {
468 return kSetDefaultBrowserHelpUrl;
469 }
470
471 // static
449 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine( 472 std::vector<GURL> StartupBrowserCreator::GetURLsFromCommandLine(
450 const base::CommandLine& command_line, 473 const base::CommandLine& command_line,
451 const base::FilePath& cur_dir, 474 const base::FilePath& cur_dir,
452 Profile* profile) { 475 Profile* profile) {
453 std::vector<GURL> urls; 476 std::vector<GURL> urls;
454 477
455 const base::CommandLine::StringVector& params = command_line.GetArgs(); 478 const base::CommandLine::StringVector& params = command_line.GetArgs();
456 for (size_t i = 0; i < params.size(); ++i) { 479 for (size_t i = 0; i < params.size(); ++i) {
457 base::FilePath param = base::FilePath(params[i]); 480 base::FilePath param = base::FilePath(params[i]);
458 // Handle Vista way of searching - "? <search-term>" 481 // Handle Vista way of searching - "? <search-term>"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 527 }
505 528
506 // static 529 // static
507 bool StartupBrowserCreator::ProcessCmdLineImpl( 530 bool StartupBrowserCreator::ProcessCmdLineImpl(
508 const base::CommandLine& command_line, 531 const base::CommandLine& command_line,
509 const base::FilePath& cur_dir, 532 const base::FilePath& cur_dir,
510 bool process_startup, 533 bool process_startup,
511 Profile* last_used_profile, 534 Profile* last_used_profile,
512 const Profiles& last_opened_profiles, 535 const Profiles& last_opened_profiles,
513 StartupBrowserCreator* browser_creator) { 536 StartupBrowserCreator* browser_creator) {
537 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl"); 538 TRACE_EVENT0("startup", "StartupBrowserCreator::ProcessCmdLineImpl");
515 539
516 DCHECK(last_used_profile); 540 DCHECK(last_used_profile);
517 if (process_startup) { 541 if (process_startup) {
518 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) 542 if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
519 content::NavigationController::DisablePromptOnRepost(); 543 content::NavigationController::DisablePromptOnRepost();
520 } 544 }
521 545
522 bool silent_launch = false; 546 bool silent_launch = false;
523 547
(...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. 667 // 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 668 // The exception is when there are no browser windows, since we don't want
645 // chrome to shut down. 669 // chrome to shut down.
646 // TODO(jackhou): Do this properly once keep-alive is handled by the 670 // TODO(jackhou): Do this properly once keep-alive is handled by the
647 // background page of apps. Tracked at http://crbug.com/175381 671 // background page of apps. Tracked at http://crbug.com/175381
648 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0) 672 if (chrome::GetTotalBrowserCountForProfile(last_used_profile) != 0)
649 return true; 673 return true;
650 } 674 }
651 675
652 #if defined(OS_WIN) 676 #if defined(OS_WIN)
677 // Intercept a specific url when setting the default browser asynchronously.
678 // This only happens on Windows 10+.
679 if (!async_set_as_default_filter_callback.IsCancelled()) {
680 for (const auto& arg : command_line.GetArgs()) {
681 GURL url(arg);
Peter Kasting 2015/09/23 23:01:39 Nit: I wonder if it wouldn't be simpler to just st
Patrick Monette 2015/09/25 20:06:25 Done.
682 if (url.is_valid() &&
683 url == GURL(L"https://support.google.com/chrome?p=default_browser")) {
Peter Kasting 2015/09/23 23:01:39 Why are you not using the constant here?
Patrick Monette 2015/09/25 20:06:25 Using it now.
684 async_set_as_default_filter_callback.callback().Run();
685 return true;
686 }
687 }
688 }
689
653 // Log whether this process was a result of an action in the Windows Jumplist. 690 // Log whether this process was a result of an action in the Windows Jumplist.
654 if (command_line.HasSwitch(switches::kWinJumplistAction)) { 691 if (command_line.HasSwitch(switches::kWinJumplistAction)) {
655 jumplist::LogJumplistActionFromSwitchValue( 692 jumplist::LogJumplistActionFromSwitchValue(
656 command_line.GetSwitchValueASCII(switches::kWinJumplistAction)); 693 command_line.GetSwitchValueASCII(switches::kWinJumplistAction));
657 } 694 }
658 #endif 695 #endif // defined(OS_WIN)
659 696
660 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 697 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
661 chrome::startup::IS_PROCESS_STARTUP : 698 chrome::startup::IS_PROCESS_STARTUP :
662 chrome::startup::IS_NOT_PROCESS_STARTUP; 699 chrome::startup::IS_NOT_PROCESS_STARTUP;
663 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? 700 chrome::startup::IsFirstRun is_first_run = first_run::IsChromeFirstRun() ?
664 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 701 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
665 // |last_opened_profiles| will be empty in the following circumstances: 702 // |last_opened_profiles| will be empty in the following circumstances:
666 // - This is the first launch. |last_used_profile| is the initial profile. 703 // - This is the first launch. |last_used_profile| is the initial profile.
667 // - The user exited the browser by closing all windows for all 704 // - The user exited the browser by closing all windows for all
668 // profiles. |last_used_profile| is the profile which owned the last open 705 // 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 879 // If we are showing the app list then chrome isn't shown so load the app
843 // list's profile rather than chrome's. 880 // list's profile rather than chrome's.
844 if (command_line.HasSwitch(switches::kShowAppList)) { 881 if (command_line.HasSwitch(switches::kShowAppList)) {
845 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> 882 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)->
846 GetProfilePath(user_data_dir); 883 GetProfilePath(user_data_dir);
847 } 884 }
848 885
849 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 886 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
850 user_data_dir); 887 user_data_dir);
851 } 888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698