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

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

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Added new files for added tests. Created 3 years, 6 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 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1275
1272 // Returns true if a browser window may be opened for the last active profile. 1276 // Returns true if a browser window may be opened for the last active profile.
1273 - (bool)canOpenNewBrowser { 1277 - (bool)canOpenNewBrowser {
1274 Profile* profile = [self safeLastProfileForNewWindows]; 1278 Profile* profile = [self safeLastProfileForNewWindows];
1275 1279
1276 const PrefService* prefs = g_browser_process->local_state(); 1280 const PrefService* prefs = g_browser_process->local_state();
1277 return !profile->IsGuestSession() || 1281 return !profile->IsGuestSession() ||
1278 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); 1282 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled);
1279 } 1283 }
1280 1284
1285 - (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls
1286 inBrowser:(Browser*)browser {
1287 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1288 chrome::startup::IsFirstRun first_run =
1289 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
1290 : chrome::startup::IS_NOT_FIRST_RUN;
1291 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1292 launch.OpenURLsInBrowser(browser, false, urls);
1293 }
1294
1281 // Various methods to open URLs that we get in a native fashion. We use 1295 // Various methods to open URLs that we get in a native fashion. We use
1282 // StartupBrowserCreator here because on the other platforms, URLs to open come 1296 // StartupBrowserCreator here because on the other platforms, URLs to open come
1283 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best 1297 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best
1284 // to bottleneck the openings through that for uniform handling. 1298 // to bottleneck the openings through that for uniform handling.
1285 - (void)openUrls:(const std::vector<GURL>&)urls { 1299 - (void)openUrls:(const std::vector<GURL>&)urls {
1286 if (!startupComplete_) { 1300 if (!startupComplete_) {
1287 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); 1301 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end());
1288 return; 1302 return;
1289 } 1303 }
1290 1304
1291 Browser* browser = chrome::GetLastActiveBrowser(); 1305 Profile* profile = [self lastProfile];
1292 // if no browser window exists then create one with no tabs to be filled in 1306 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref(
1293 if (!browser) { 1307 *base::CommandLine::ForCurrentProcess(), profile);
1294 browser = new Browser(Browser::CreateParams([self lastProfile], true)); 1308
1295 browser->window()->Show(); 1309 if (pref.type == SessionStartupPref::LAST) {
1310 if (SessionRestore::IsRestoring(profile)) {
1311 // In case of session restore, remember |urls|, so they will be opened
1312 // after session is resored, in the tabs next to it.
1313 SessionRestore::AddURLsToOpen(profile, urls);
1314 } else {
1315 Browser* browser = chrome::GetLastActiveBrowser();
1316 if (!browser) {
1317 // This behavior is needed for the case when chromium app is launched,
1318 // but there are no open indows.
1319 browser = new Browser(Browser::CreateParams([self lastProfile], true));
Avi (use Gerrit) 2017/06/01 19:54:31 I just learned this, but you need to use [self saf
eugenebng 2017/06/07 10:42:11 Done. Thank you for sharing that!
1320 browser->window()->Show();
1321 SessionRestore::AddURLsToOpen(profile, urls);
1322 } else {
1323 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser];
1324 }
1325 }
1326 } else {
1327 Browser* browser = chrome::GetLastActiveBrowser();
1328 // If no browser window exists then create one with no tabs to be filled in.
1329 if (!browser) {
1330 browser = new Browser(Browser::CreateParams([self lastProfile], true));
Avi (use Gerrit) 2017/06/01 19:54:31 Same here.
eugenebng 2017/06/07 10:42:11 Done
1331 browser->window()->Show();
1332 }
1333 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser];
1296 } 1334 }
1297
1298 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1299 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
1300 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
1301 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1302 launch.OpenURLsInBrowser(browser, false, urls);
1303 } 1335 }
1304 1336
1305 - (void)getUrl:(NSAppleEventDescriptor*)event 1337 - (void)getUrl:(NSAppleEventDescriptor*)event
1306 withReply:(NSAppleEventDescriptor*)reply { 1338 withReply:(NSAppleEventDescriptor*)reply {
1307 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] 1339 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
1308 stringValue]; 1340 stringValue];
1309 1341
1310 GURL gurl(base::SysNSStringToUTF8(urlStr)); 1342 GURL gurl(base::SysNSStringToUTF8(urlStr));
1311 std::vector<GURL> gurlVector; 1343 std::vector<GURL> gurlVector;
1312 gurlVector.push_back(gurl); 1344 gurlVector.push_back(gurl);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 1648
1617 //--------------------------------------------------------------------------- 1649 //---------------------------------------------------------------------------
1618 1650
1619 namespace app_controller_mac { 1651 namespace app_controller_mac {
1620 1652
1621 bool IsOpeningNewWindow() { 1653 bool IsOpeningNewWindow() {
1622 return g_is_opening_new_window; 1654 return g_is_opening_new_window;
1623 } 1655 }
1624 1656
1625 } // namespace app_controller_mac 1657 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/app_controller_mac_browsertest.mm » ('j') | chrome/browser/app_controller_mac_browsertest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698