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

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

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Created 3 years, 8 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_impl.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #if BUILDFLAG(ENABLE_RLZ) 123 #if BUILDFLAG(ENABLE_RLZ)
124 #include "components/rlz/rlz_tracker.h" // nogncheck 124 #include "components/rlz/rlz_tracker.h" // nogncheck
125 #endif 125 #endif
126 126
127 using content::ChildProcessSecurityPolicy; 127 using content::ChildProcessSecurityPolicy;
128 using content::WebContents; 128 using content::WebContents;
129 using extensions::Extension; 129 using extensions::Extension;
130 130
131 namespace { 131 namespace {
132 132
133 std::vector<GURL>* g_startup_urls = nullptr;
Avi (use Gerrit) 2017/04/06 15:54:42 Why would this need to be global? Can't it be an i
eugenebng 2017/04/10 11:54:08 This cannot be an instance variable, because diffe
134
133 // Utility functions ---------------------------------------------------------- 135 // Utility functions ----------------------------------------------------------
134 136
135 enum LaunchMode { 137 enum LaunchMode {
136 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. 138 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut.
137 LM_AS_WEBAPP, // Launched as a installed web application. 139 LM_AS_WEBAPP, // Launched as a installed web application.
138 LM_WITH_URLS, // Launched with urls in the cmd line. 140 LM_WITH_URLS, // Launched with urls in the cmd line.
139 LM_SHORTCUT_NONE, // Not launched from a shortcut. 141 LM_SHORTCUT_NONE, // Not launched from a shortcut.
140 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available. 142 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available.
141 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut. 143 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut.
142 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar. 144 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 430
429 Browser* StartupBrowserCreatorImpl::OpenURLsInBrowser( 431 Browser* StartupBrowserCreatorImpl::OpenURLsInBrowser(
430 Browser* browser, 432 Browser* browser,
431 bool process_startup, 433 bool process_startup,
432 const std::vector<GURL>& urls) { 434 const std::vector<GURL>& urls) {
433 StartupTabs tabs; 435 StartupTabs tabs;
434 UrlsToTabs(urls, &tabs); 436 UrlsToTabs(urls, &tabs);
435 return OpenTabsInBrowser(browser, process_startup, tabs); 437 return OpenTabsInBrowser(browser, process_startup, tabs);
436 } 438 }
437 439
440 void StartupBrowserCreatorImpl::OpenURLsAfterSessionRestore(
441 Browser* browser,
442 bool process_startup,
443 const std::vector<GURL>& urls) {
444 // Save URLs for deferred opening
445 if (!g_startup_urls)
446 g_startup_urls = new std::vector<GURL>();
447 *g_startup_urls = urls;
448 }
449
450 bool StartupBrowserCreatorImpl::WillRestoreSession(
Avi (use Gerrit) 2017/04/06 15:54:42 This seems like a bunch of logic that must already
gab 2017/04/06 16:02:21 That's probably true and if you can avoid touching
gab 2017/04/06 16:02:21 That's probably true and if you can avoid touching
eugenebng 2017/04/10 11:54:08 True, this logic was taken from conditions for cal
451 Browser* browser,
452 Profile* profile,
453 bool process_startup,
454 const std::vector<GURL>& urls) {
455 // First condition.
456 BrowserOpenBehaviorOptions behavior_options = 0;
457 bool is_post_crash_launch = HasPendingUncleanExit(profile);
458 if (process_startup)
459 behavior_options |= PROCESS_STARTUP;
460 if (is_post_crash_launch)
461 behavior_options |= IS_POST_CRASH_LAUNCH;
462 if (command_line_.HasSwitch(switches::kRestoreLastSession))
463 behavior_options |= HAS_RESTORE_SWITCH;
464 if (command_line_.HasSwitch(switches::kOpenInNewWindow))
465 behavior_options |= HAS_NEW_WINDOW_SWITCH;
466 if (!urls.empty())
467 behavior_options |= HAS_CMD_LINE_TABS;
468 BrowserOpenBehavior behavior = DetermineBrowserOpenBehavior(
469 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile),
470 behavior_options);
471 if (behavior == BrowserOpenBehavior::SYNCHRONOUS_RESTORE)
472 return true;
473 // Second contition.
474 SessionStartupPref pref =
475 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile);
476 if (pref.type == SessionStartupPref::LAST && !is_first_run_&&
477 (!(profile->GetLastSessionExitType() == Profile::EXIT_CRASHED) ||
478 command_line_.HasSwitch(switches::kRestoreLastSession)))
479 return true;
480 return false;
481 }
482
483 void StartupBrowserCreatorImpl::OpenDeferredURLs(Browser* browser) {
484 if (g_startup_urls && !g_startup_urls->empty()) {
485 StartupBrowserCreator::in_synchronous_profile_launch_ = true;
486 OpenURLsInBrowser(browser, false, *g_startup_urls);
487 StartupBrowserCreator::in_synchronous_profile_launch_ = false;
488 delete g_startup_urls;
489 g_startup_urls = nullptr;
490 }
491 }
492
438 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser, 493 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser,
439 bool process_startup, 494 bool process_startup,
440 const StartupTabs& tabs) { 495 const StartupTabs& tabs) {
441 DCHECK(!tabs.empty()); 496 DCHECK(!tabs.empty());
442 497
443 // If we don't yet have a profile, try to use the one we're given from 498 // If we don't yet have a profile, try to use the one we're given from
444 // |browser|. While we may not end up actually using |browser| (since it 499 // |browser|. While we may not end up actually using |browser| (since it
445 // could be a popup window), we can at least use the profile. 500 // could be a popup window), we can at least use the profile.
446 if (!profile_ && browser) 501 if (!profile_ && browser)
447 profile_ = browser->profile(); 502 profile_ = browser->profile();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 Browser* StartupBrowserCreatorImpl::RestoreOrCreateBrowser( 810 Browser* StartupBrowserCreatorImpl::RestoreOrCreateBrowser(
756 const StartupTabs& tabs, 811 const StartupTabs& tabs,
757 BrowserOpenBehavior behavior, 812 BrowserOpenBehavior behavior,
758 SessionRestore::BehaviorBitmask restore_options, 813 SessionRestore::BehaviorBitmask restore_options,
759 bool process_startup, 814 bool process_startup,
760 bool is_post_crash_launch) { 815 bool is_post_crash_launch) {
761 Browser* browser = nullptr; 816 Browser* browser = nullptr;
762 if (behavior == BrowserOpenBehavior::SYNCHRONOUS_RESTORE) { 817 if (behavior == BrowserOpenBehavior::SYNCHRONOUS_RESTORE) {
763 browser = SessionRestore::RestoreSession(profile_, nullptr, restore_options, 818 browser = SessionRestore::RestoreSession(profile_, nullptr, restore_options,
764 TabsToUrls(tabs)); 819 TabsToUrls(tabs));
765 if (browser) 820 if (browser) {
821 OpenDeferredURLs(browser);
766 return browser; 822 return browser;
823 }
767 } else if (behavior == BrowserOpenBehavior::USE_EXISTING) { 824 } else if (behavior == BrowserOpenBehavior::USE_EXISTING) {
768 browser = chrome::FindTabbedBrowser(profile_, process_startup); 825 browser = chrome::FindTabbedBrowser(profile_, process_startup);
769 } 826 }
770 827
771 base::AutoReset<bool> synchronous_launch_resetter( 828 base::AutoReset<bool> synchronous_launch_resetter(
772 &StartupBrowserCreator::in_synchronous_profile_launch_, true); 829 &StartupBrowserCreator::in_synchronous_profile_launch_, true);
773 830
774 // OpenTabsInBrowser requires at least one tab be passed. As a fallback to 831 // OpenTabsInBrowser requires at least one tab be passed. As a fallback to
775 // prevent a crash, use the NTP if |tabs| is empty. This could happen if 832 // prevent a crash, use the NTP if |tabs| is empty. This could happen if
776 // we expected a session restore to happen but it did not occur/succeed. 833 // we expected a session restore to happen but it did not occur/succeed.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1077 }
1021 #endif 1078 #endif
1022 1079
1023 std::vector<GURL> adjusted_urls(urls_to_open); 1080 std::vector<GURL> adjusted_urls(urls_to_open);
1024 AddSpecialURLs(&adjusted_urls); 1081 AddSpecialURLs(&adjusted_urls);
1025 1082
1026 // The startup code only executes for browsers launched in desktop mode. Ash 1083 // The startup code only executes for browsers launched in desktop mode. Ash
1027 // should never get here. 1084 // should never get here.
1028 Browser* browser = SessionRestore::RestoreSession( 1085 Browser* browser = SessionRestore::RestoreSession(
1029 profile_, NULL, restore_behavior, adjusted_urls); 1086 profile_, NULL, restore_behavior, adjusted_urls);
1030 1087 OpenDeferredURLs(browser);
1031 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 1088 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
1032 return true; 1089 return true;
1033 } 1090 }
1034 1091
1035 Browser* browser = ProcessSpecifiedURLs(urls_to_open); 1092 Browser* browser = ProcessSpecifiedURLs(urls_to_open);
1036 if (!browser) 1093 if (!browser)
1037 return false; 1094 return false;
1038 1095
1039 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 1096 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
1040 1097
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 #if defined(OS_WIN) 1314 #if defined(OS_WIN)
1258 TriggeredProfileResetter* triggered_profile_resetter = 1315 TriggeredProfileResetter* triggered_profile_resetter =
1259 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); 1316 TriggeredProfileResetterFactory::GetForBrowserContext(profile_);
1260 // TriggeredProfileResetter instance will be nullptr for incognito profiles. 1317 // TriggeredProfileResetter instance will be nullptr for incognito profiles.
1261 if (triggered_profile_resetter) { 1318 if (triggered_profile_resetter) {
1262 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); 1319 has_reset_trigger = triggered_profile_resetter->HasResetTrigger();
1263 } 1320 }
1264 #endif // defined(OS_WIN) 1321 #endif // defined(OS_WIN)
1265 return has_reset_trigger; 1322 return has_reset_trigger;
1266 } 1323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698