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 | |
216 // This class cannot open urls until startup has finished. The urls that cannot | 212 // This class cannot open urls until startup has finished. The urls that cannot |
217 // be opened are cached in |startupUrls_|. This method must be called exactly | 213 // be opened are cached in |startupUrls_|. This method must be called exactly |
218 // once after startup has completed. It opens the urls in |startupUrls_|, and | 214 // once after startup has completed. It opens the urls in |startupUrls_|, and |
219 // clears |startupUrls_|. | 215 // clears |startupUrls_|. |
220 - (void)openStartupUrls; | 216 - (void)openStartupUrls; |
221 | 217 |
222 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before | 218 // Opens a tab for each GURL in |urls|. If there is exactly one tab open before |
223 // this method is called, and that tab is the NTP, then this method closes the | 219 // this method is called, and that tab is the NTP, then this method closes the |
224 // NTP after all the |urls| have been opened. | 220 // NTP after all the |urls| have been opened. |
225 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; | 221 - (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 | 1268 |
1273 // Returns true if a browser window may be opened for the last active profile. | 1269 // Returns true if a browser window may be opened for the last active profile. |
1274 - (bool)canOpenNewBrowser { | 1270 - (bool)canOpenNewBrowser { |
1275 Profile* profile = [self safeLastProfileForNewWindows]; | 1271 Profile* profile = [self safeLastProfileForNewWindows]; |
1276 | 1272 |
1277 const PrefService* prefs = g_browser_process->local_state(); | 1273 const PrefService* prefs = g_browser_process->local_state(); |
1278 return !profile->IsGuestSession() || | 1274 return !profile->IsGuestSession() || |
1279 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); | 1275 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); |
1280 } | 1276 } |
1281 | 1277 |
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 | |
1292 // Various methods to open URLs that we get in a native fashion. We use | 1278 // Various methods to open URLs that we get in a native fashion. We use |
1293 // StartupBrowserCreator here because on the other platforms, URLs to open come | 1279 // StartupBrowserCreator here because on the other platforms, URLs to open come |
1294 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best | 1280 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
1295 // to bottleneck the openings through that for uniform handling. | 1281 // to bottleneck the openings through that for uniform handling. |
1296 - (void)openUrls:(const std::vector<GURL>&)urls { | 1282 - (void)openUrls:(const std::vector<GURL>&)urls { |
1297 if (!startupComplete_) { | 1283 if (!startupComplete_) { |
1298 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); | 1284 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
1299 return; | 1285 return; |
1300 } | 1286 } |
1301 | 1287 |
1302 Profile* profile = [self safeLastProfileForNewWindows]; | 1288 Browser* browser = chrome::GetLastActiveBrowser(); |
1303 SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref( | 1289 // if no browser window exists then create one with no tabs to be filled in |
1304 *base::CommandLine::ForCurrentProcess(), profile); | 1290 if (!browser) { |
| 1291 browser = new Browser( |
| 1292 Browser::CreateParams([self safeLastProfileForNewWindows], true)); |
| 1293 browser->window()->Show(); |
| 1294 } |
1305 | 1295 |
1306 if (pref.type == SessionStartupPref::LAST) { | 1296 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
1307 if (SessionRestore::IsRestoring(profile)) { | 1297 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
1308 // In case of session restore, remember |urls|, so they will be opened | 1298 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
1309 // after session is resored, in the tabs next to it. | 1299 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); |
1310 SessionRestore::AddURLsToOpen(profile, urls); | 1300 launch.OpenURLsInBrowser(browser, false, urls); |
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]; | |
1331 } | |
1332 } | 1301 } |
1333 | 1302 |
1334 - (void)getUrl:(NSAppleEventDescriptor*)event | 1303 - (void)getUrl:(NSAppleEventDescriptor*)event |
1335 withReply:(NSAppleEventDescriptor*)reply { | 1304 withReply:(NSAppleEventDescriptor*)reply { |
1336 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] | 1305 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] |
1337 stringValue]; | 1306 stringValue]; |
1338 | 1307 |
1339 GURL gurl(base::SysNSStringToUTF8(urlStr)); | 1308 GURL gurl(base::SysNSStringToUTF8(urlStr)); |
1340 std::vector<GURL> gurlVector; | 1309 std::vector<GURL> gurlVector; |
1341 gurlVector.push_back(gurl); | 1310 gurlVector.push_back(gurl); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 | 1612 |
1644 //--------------------------------------------------------------------------- | 1613 //--------------------------------------------------------------------------- |
1645 | 1614 |
1646 namespace app_controller_mac { | 1615 namespace app_controller_mac { |
1647 | 1616 |
1648 bool IsOpeningNewWindow() { | 1617 bool IsOpeningNewWindow() { |
1649 return g_is_opening_new_window; | 1618 return g_is_opening_new_window; |
1650 } | 1619 } |
1651 | 1620 |
1652 } // namespace app_controller_mac | 1621 } // namespace app_controller_mac |
OLD | NEW |