OLD | NEW |
---|---|
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 Loading... | |
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 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1268 | 1272 |
1269 // Returns true if a browser window may be opened for the last active profile. | 1273 // Returns true if a browser window may be opened for the last active profile. |
1270 - (bool)canOpenNewBrowser { | 1274 - (bool)canOpenNewBrowser { |
1271 Profile* profile = [self safeLastProfileForNewWindows]; | 1275 Profile* profile = [self safeLastProfileForNewWindows]; |
1272 | 1276 |
1273 const PrefService* prefs = g_browser_process->local_state(); | 1277 const PrefService* prefs = g_browser_process->local_state(); |
1274 return !profile->IsGuestSession() || | 1278 return !profile->IsGuestSession() || |
1275 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); | 1279 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); |
1276 } | 1280 } |
1277 | 1281 |
1282 - (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls | |
1283 inBrowser:(Browser*)browser { | |
1284 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
1285 chrome::startup::IsFirstRun first_run = | |
1286 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN | |
1287 : chrome::startup::IS_NOT_FIRST_RUN; | |
1288 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
1289 launch.OpenURLsInBrowser(browser, false, urls); | |
1290 } | |
1291 | |
1278 // Various methods to open URLs that we get in a native fashion. We use | 1292 // Various methods to open URLs that we get in a native fashion. We use |
1279 // StartupBrowserCreator here because on the other platforms, URLs to open come | 1293 // StartupBrowserCreator here because on the other platforms, URLs to open come |
1280 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best | 1294 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
1281 // to bottleneck the openings through that for uniform handling. | 1295 // to bottleneck the openings through that for uniform handling. |
1282 - (void)openUrls:(const std::vector<GURL>&)urls { | 1296 - (void)openUrls:(const std::vector<GURL>&)urls { |
1283 if (!startupComplete_) { | 1297 if (!startupComplete_) { |
1284 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); | 1298 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
1285 return; | 1299 return; |
1286 } | 1300 } |
1287 | 1301 |
1288 Browser* browser = chrome::GetLastActiveBrowser(); | 1302 Profile* profile = [self safeLastProfileForNewWindows]; |
1289 // if no browser window exists then create one with no tabs to be filled in | 1303 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref( |
1290 if (!browser) { | 1304 *base::CommandLine::ForCurrentProcess(), profile); |
1291 browser = new Browser( | 1305 |
1292 Browser::CreateParams([self safeLastProfileForNewWindows], true)); | 1306 if (pref.type == SessionStartupPref::LAST) { |
1293 browser->window()->Show(); | 1307 if (SessionRestore::IsRestoring(profile)) { |
1308 // In case of session restore, remember |urls|, so they will be opened | |
1309 // after session is resored, in the tabs next to it. | |
1310 SessionRestore::AddURLsToOpen(profile, urls); | |
gab
2017/06/09 16:59:19
Is this use case specific to Mac? Launching throug
eugenebng
2017/06/13 12:10:02
URLs to open come via apple events (see test code
| |
1311 } else { | |
1312 Browser* browser = chrome::GetLastActiveBrowser(); | |
1313 if (!browser) { | |
1314 // This behavior is needed for the case when chromium app is launched, | |
1315 // but there are no open indows. | |
1316 browser = new Browser(Browser::CreateParams(profile, true)); | |
1317 browser->window()->Show(); | |
1318 SessionRestore::AddURLsToOpen(profile, urls); | |
1319 } else { | |
1320 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser]; | |
1321 } | |
1322 } | |
1323 } else { | |
1324 Browser* browser = chrome::GetLastActiveBrowser(); | |
1325 // If no browser window exists then create one with no tabs to be filled in. | |
1326 if (!browser) { | |
1327 browser = new Browser(Browser::CreateParams(profile, true)); | |
1328 browser->window()->Show(); | |
1329 } | |
1330 [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser]; | |
1294 } | 1331 } |
1295 | |
1296 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
1297 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? | |
1298 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | |
1299 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
1300 launch.OpenURLsInBrowser(browser, false, urls); | |
1301 } | 1332 } |
1302 | 1333 |
1303 - (void)getUrl:(NSAppleEventDescriptor*)event | 1334 - (void)getUrl:(NSAppleEventDescriptor*)event |
1304 withReply:(NSAppleEventDescriptor*)reply { | 1335 withReply:(NSAppleEventDescriptor*)reply { |
1305 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] | 1336 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] |
1306 stringValue]; | 1337 stringValue]; |
1307 | 1338 |
1308 GURL gurl(base::SysNSStringToUTF8(urlStr)); | 1339 GURL gurl(base::SysNSStringToUTF8(urlStr)); |
1309 std::vector<GURL> gurlVector; | 1340 std::vector<GURL> gurlVector; |
1310 gurlVector.push_back(gurl); | 1341 gurlVector.push_back(gurl); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 | 1643 |
1613 //--------------------------------------------------------------------------- | 1644 //--------------------------------------------------------------------------- |
1614 | 1645 |
1615 namespace app_controller_mac { | 1646 namespace app_controller_mac { |
1616 | 1647 |
1617 bool IsOpeningNewWindow() { | 1648 bool IsOpeningNewWindow() { |
1618 return g_is_opening_new_window; | 1649 return g_is_opening_new_window; |
1619 } | 1650 } |
1620 | 1651 |
1621 } // namespace app_controller_mac | 1652 } // namespace app_controller_mac |
OLD | NEW |