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

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Code style: disallow copy and assign. Created 3 years, 7 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 #import "chrome/browser/app_controller_mac.h" 5 #import "chrome/browser/app_controller_mac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 - (void)activeSpaceDidChange:(NSNotification*)inNotification; 202 - (void)activeSpaceDidChange:(NSNotification*)inNotification;
203 - (void)checkForAnyKeyWindows; 203 - (void)checkForAnyKeyWindows;
204 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 204 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
205 - (BOOL)shouldQuitWithInProgressDownloads; 205 - (BOOL)shouldQuitWithInProgressDownloads;
206 - (void)executeApplication:(id)sender; 206 - (void)executeApplication:(id)sender;
207 - (void)profileWasRemoved:(const base::FilePath&)profilePath; 207 - (void)profileWasRemoved:(const base::FilePath&)profilePath;
208 208
209 // Opens a tab for each GURL in |urls|. 209 // Opens a tab for each GURL in |urls|.
210 - (void)openUrls:(const std::vector<GURL>&)urls; 210 - (void)openUrls:(const std::vector<GURL>&)urls;
211 211
212 // Creates StartupBrowserCreator and opens |urls| with it.
213 - (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls
214 inBrowser:(Browser*)browser;
215
212 // This class cannot open urls until startup has finished. The urls that cannot 216 // This class cannot open urls until startup has finished. The urls that cannot
213 // be opened are cached in |startupUrls_|. This method must be called exactly 217 // be opened are cached in |startupUrls_|. This method must be called exactly
214 // once after startup has completed. It opens the urls in |startupUrls_|, and 218 // once after startup has completed. It opens the urls in |startupUrls_|, and
215 // clears |startupUrls_|. 219 // clears |startupUrls_|.
216 - (void)openStartupUrls; 220 - (void)openStartupUrls;
217 221
218 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before 222 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before
219 // this method is called, and that tab is the NTP, then this method closes the 223 // this method is called, and that tab is the NTP, then this method closes the
220 // NTP after all the |urls| have been opened. 224 // NTP after all the |urls| have been opened.
221 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; 225 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls;
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 1267
1264 // Returns true if a browser window may be opened for the last active profile. 1268 // Returns true if a browser window may be opened for the last active profile.
1265 - (bool)canOpenNewBrowser { 1269 - (bool)canOpenNewBrowser {
1266 Profile* profile = [self safeLastProfileForNewWindows]; 1270 Profile* profile = [self safeLastProfileForNewWindows];
1267 1271
1268 const PrefService* prefs = g_browser_process->local_state(); 1272 const PrefService* prefs = g_browser_process->local_state();
1269 return !profile->IsGuestSession() || 1273 return !profile->IsGuestSession() ||
1270 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); 1274 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled);
1271 } 1275 }
1272 1276
1277 - (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls
1278 inBrowser:(Browser*)browser {
1279 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1280 chrome::startup::IsFirstRun first_run =
1281 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
1282 : chrome::startup::IS_NOT_FIRST_RUN;
1283 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1284 launch.OpenURLsInBrowser(browser, false, urls);
1285 }
1286
1273 // Various methods to open URLs that we get in a native fashion. We use 1287 // Various methods to open URLs that we get in a native fashion. We use
1274 // StartupBrowserCreator here because on the other platforms, URLs to open come 1288 // StartupBrowserCreator here because on the other platforms, URLs to open come
1275 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best 1289 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best
1276 // to bottleneck the openings through that for uniform handling. 1290 // to bottleneck the openings through that for uniform handling.
1277 - (void)openUrls:(const std::vector<GURL>&)urls { 1291 - (void)openUrls:(const std::vector<GURL>&)urls {
1278 if (!startupComplete_) { 1292 if (!startupComplete_) {
1279 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); 1293 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end());
1280 return; 1294 return;
1281 } 1295 }
1282 1296
1283 Browser* browser = chrome::GetLastActiveBrowser(); 1297 Profile* profile = [self lastProfile];
Avi (use Gerrit) 2017/05/17 15:51:09 You've tested this with multiple profile setups?
1284 // if no browser window exists then create one with no tabs to be filled in 1298 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref(
1285 if (!browser) { 1299 *base::CommandLine::ForCurrentProcess(), profile);
1286 browser = new Browser(Browser::CreateParams([self lastProfile], true)); 1300
1287 browser->window()->Show(); 1301 if (pref.type == SessionStartupPref::LAST) {
1302 if (SessionRestore::IsRestoring(profile)) {
1303 // In case of session restore, remember |urls|, so they will be opened
1304 // after session is resored, in the tabs next to it.
1305 SessionRestore::AddURLsToOpen(profile, urls);
1306 } else {
1307 Browser* browser = chrome::GetLastActiveBrowser();
1308 if (!browser) {
1309 // This behavior is needed for the case when chromium app is launched,
1310 // but there are no open indows.
1311 browser = new Browser(Browser::CreateParams([self lastProfile], true));
1312 browser->window()->Show();
1313 SessionRestore::AddURLsToOpen(profile, urls);
1314 } else {
1315 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser];
1316 }
1317 }
1318 } else {
1319 Browser* browser = chrome::GetLastActiveBrowser();
1320 // If no browser window exists then create one with no tabs to be filled in.
1321 if (!browser) {
1322 browser = new Browser(Browser::CreateParams([self lastProfile], true));
1323 browser->window()->Show();
1324 }
1325 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser];
1288 } 1326 }
1289
1290 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1291 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
1292 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
1293 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1294 launch.OpenURLsInBrowser(browser, false, urls);
1295 } 1327 }
1296 1328
1297 - (void)getUrl:(NSAppleEventDescriptor*)event 1329 - (void)getUrl:(NSAppleEventDescriptor*)event
1298 withReply:(NSAppleEventDescriptor*)reply { 1330 withReply:(NSAppleEventDescriptor*)reply {
1299 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] 1331 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
1300 stringValue]; 1332 stringValue];
1301 1333
1302 GURL gurl(base::SysNSStringToUTF8(urlStr)); 1334 GURL gurl(base::SysNSStringToUTF8(urlStr));
1303 std::vector<GURL> gurlVector; 1335 std::vector<GURL> gurlVector;
1304 gurlVector.push_back(gurl); 1336 gurlVector.push_back(gurl);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 1640
1609 //--------------------------------------------------------------------------- 1641 //---------------------------------------------------------------------------
1610 1642
1611 namespace app_controller_mac { 1643 namespace app_controller_mac {
1612 1644
1613 bool IsOpeningNewWindow() { 1645 bool IsOpeningNewWindow() {
1614 return g_is_opening_new_window; 1646 return g_is_opening_new_window;
1615 } 1647 }
1616 1648
1617 } // namespace app_controller_mac 1649 } // namespace app_controller_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698