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

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

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Fixed opening local file with Chromium on mac while restore session is enabled. File opens in the t… 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;
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 // static
441 void StartupBrowserCreatorImpl::OpenURLsAfterSessionRestore(
442 const std::vector<GURL>& urls) {
443 // Save URLs for deferred opening
444 if (!g_startup_urls)
445 g_startup_urls = new std::vector<GURL>();
446 *g_startup_urls = urls;
447 }
448
449 void StartupBrowserCreatorImpl::OpenDeferredURLs(Browser* browser) {
450 if (g_startup_urls && !g_startup_urls->empty()) {
451 StartupBrowserCreator::in_synchronous_profile_launch_ = true;
452 OpenURLsInBrowser(browser, false, *g_startup_urls);
453 StartupBrowserCreator::in_synchronous_profile_launch_ = false;
454 delete g_startup_urls;
455 g_startup_urls = nullptr;
456 }
457 }
458
438 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser, 459 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser,
439 bool process_startup, 460 bool process_startup,
440 const StartupTabs& tabs) { 461 const StartupTabs& tabs) {
441 DCHECK(!tabs.empty()); 462 DCHECK(!tabs.empty());
442 463
443 // If we don't yet have a profile, try to use the one we're given from 464 // 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 465 // |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. 466 // could be a popup window), we can at least use the profile.
446 if (!profile_ && browser) 467 if (!profile_ && browser)
447 profile_ = browser->profile(); 468 profile_ = browser->profile();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 Browser* StartupBrowserCreatorImpl::RestoreOrCreateBrowser( 776 Browser* StartupBrowserCreatorImpl::RestoreOrCreateBrowser(
756 const StartupTabs& tabs, 777 const StartupTabs& tabs,
757 BrowserOpenBehavior behavior, 778 BrowserOpenBehavior behavior,
758 SessionRestore::BehaviorBitmask restore_options, 779 SessionRestore::BehaviorBitmask restore_options,
759 bool process_startup, 780 bool process_startup,
760 bool is_post_crash_launch) { 781 bool is_post_crash_launch) {
761 Browser* browser = nullptr; 782 Browser* browser = nullptr;
762 if (behavior == BrowserOpenBehavior::SYNCHRONOUS_RESTORE) { 783 if (behavior == BrowserOpenBehavior::SYNCHRONOUS_RESTORE) {
763 browser = SessionRestore::RestoreSession(profile_, nullptr, restore_options, 784 browser = SessionRestore::RestoreSession(profile_, nullptr, restore_options,
764 TabsToUrls(tabs)); 785 TabsToUrls(tabs));
765 if (browser) 786 if (browser) {
787 OpenDeferredURLs(browser);
766 return browser; 788 return browser;
789 }
767 } else if (behavior == BrowserOpenBehavior::USE_EXISTING) { 790 } else if (behavior == BrowserOpenBehavior::USE_EXISTING) {
768 browser = chrome::FindTabbedBrowser(profile_, process_startup); 791 browser = chrome::FindTabbedBrowser(profile_, process_startup);
769 } 792 }
770 793
771 base::AutoReset<bool> synchronous_launch_resetter( 794 base::AutoReset<bool> synchronous_launch_resetter(
772 &StartupBrowserCreator::in_synchronous_profile_launch_, true); 795 &StartupBrowserCreator::in_synchronous_profile_launch_, true);
773 796
774 // OpenTabsInBrowser requires at least one tab be passed. As a fallback to 797 // 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 798 // 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. 799 // 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 } 1043 }
1021 #endif 1044 #endif
1022 1045
1023 std::vector<GURL> adjusted_urls(urls_to_open); 1046 std::vector<GURL> adjusted_urls(urls_to_open);
1024 AddSpecialURLs(&adjusted_urls); 1047 AddSpecialURLs(&adjusted_urls);
1025 1048
1026 // The startup code only executes for browsers launched in desktop mode. Ash 1049 // The startup code only executes for browsers launched in desktop mode. Ash
1027 // should never get here. 1050 // should never get here.
1028 Browser* browser = SessionRestore::RestoreSession( 1051 Browser* browser = SessionRestore::RestoreSession(
1029 profile_, NULL, restore_behavior, adjusted_urls); 1052 profile_, NULL, restore_behavior, adjusted_urls);
1030 1053 OpenDeferredURLs(browser);
1031 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 1054 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
1032 return true; 1055 return true;
1033 } 1056 }
1034 1057
1035 Browser* browser = ProcessSpecifiedURLs(urls_to_open); 1058 Browser* browser = ProcessSpecifiedURLs(urls_to_open);
1059 if (pref.type == SessionStartupPref::URLS) {
1060 OpenDeferredURLs(browser);
1061 }
1036 if (!browser) 1062 if (!browser)
1037 return false; 1063 return false;
1038 1064
1039 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 1065 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
1040 1066
1041 // Session restore may occur if the startup preference is "last" or if the 1067 // Session restore may occur if the startup preference is "last" or if the
1042 // crash infobar is displayed. Otherwise, it's safe for the DOM storage system 1068 // crash infobar is displayed. Otherwise, it's safe for the DOM storage system
1043 // to start deleting leftover data. 1069 // to start deleting leftover data.
1044 if (pref.type != SessionStartupPref::LAST && 1070 if (pref.type != SessionStartupPref::LAST &&
1045 !HasPendingUncleanExit(profile_)) { 1071 !HasPendingUncleanExit(profile_)) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 #if defined(OS_WIN) 1283 #if defined(OS_WIN)
1258 TriggeredProfileResetter* triggered_profile_resetter = 1284 TriggeredProfileResetter* triggered_profile_resetter =
1259 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); 1285 TriggeredProfileResetterFactory::GetForBrowserContext(profile_);
1260 // TriggeredProfileResetter instance will be nullptr for incognito profiles. 1286 // TriggeredProfileResetter instance will be nullptr for incognito profiles.
1261 if (triggered_profile_resetter) { 1287 if (triggered_profile_resetter) {
1262 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); 1288 has_reset_trigger = triggered_profile_resetter->HasResetTrigger();
1263 } 1289 }
1264 #endif // defined(OS_WIN) 1290 #endif // defined(OS_WIN)
1265 return has_reset_trigger; 1291 return has_reset_trigger;
1266 } 1292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698