| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 - (void)openPendingURLs; | 46 - (void)openPendingURLs; |
| 47 - (void)getUrl:(NSAppleEventDescriptor*)event | 47 - (void)getUrl:(NSAppleEventDescriptor*)event |
| 48 withReply:(NSAppleEventDescriptor*)reply; | 48 withReply:(NSAppleEventDescriptor*)reply; |
| 49 - (void)openFiles:(NSAppleEventDescriptor*)event | 49 - (void)openFiles:(NSAppleEventDescriptor*)event |
| 50 withReply:(NSAppleEventDescriptor*)reply; | 50 withReply:(NSAppleEventDescriptor*)reply; |
| 51 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 51 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
| 52 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 52 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
| 53 - (BOOL)shouldQuitWithInProgressDownloads; | 53 - (BOOL)shouldQuitWithInProgressDownloads; |
| 54 @end | 54 @end |
| 55 | 55 |
| 56 // True while AppController is calling Browser::OpenEmptyWindow(). We need a |
| 57 // global flag here, analogue to BrowserInit::InProcessStartup() because |
| 58 // otherwise the SessionService will try to restore sessions when we make a new |
| 59 // window while there are no other active windows. |
| 60 static bool g_is_opening_new_window = false; |
| 61 |
| 56 @implementation AppController | 62 @implementation AppController |
| 57 | 63 |
| 58 // This method is called very early in application startup (ie, before | 64 // This method is called very early in application startup (ie, before |
| 59 // the profile is loaded or any preferences have been registered). Defer any | 65 // the profile is loaded or any preferences have been registered). Defer any |
| 60 // user-data initialization until -applicationDidFinishLaunching:. | 66 // user-data initialization until -applicationDidFinishLaunching:. |
| 61 - (void)awakeFromNib { | 67 - (void)awakeFromNib { |
| 62 pendingURLs_.reset(new std::vector<GURL>()); | 68 pendingURLs_.reset(new std::vector<GURL>()); |
| 63 | 69 |
| 64 // We need to register the handlers early to catch events fired on launch. | 70 // We need to register the handlers early to catch events fired on launch. |
| 65 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 71 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 // through to the browser object to execute the command. This assumes that the | 488 // through to the browser object to execute the command. This assumes that the |
| 483 // command is supported and doesn't check, otherwise it would have been disabled | 489 // command is supported and doesn't check, otherwise it would have been disabled |
| 484 // in the UI in validateUserInterfaceItem:. | 490 // in the UI in validateUserInterfaceItem:. |
| 485 - (void)commandDispatch:(id)sender { | 491 - (void)commandDispatch:(id)sender { |
| 486 Profile* defaultProfile = [self defaultProfile]; | 492 Profile* defaultProfile = [self defaultProfile]; |
| 487 | 493 |
| 488 NSInteger tag = [sender tag]; | 494 NSInteger tag = [sender tag]; |
| 489 switch (tag) { | 495 switch (tag) { |
| 490 case IDC_NEW_TAB: | 496 case IDC_NEW_TAB: |
| 491 case IDC_NEW_WINDOW: | 497 case IDC_NEW_WINDOW: |
| 498 g_is_opening_new_window = true; |
| 492 Browser::OpenEmptyWindow(defaultProfile); | 499 Browser::OpenEmptyWindow(defaultProfile); |
| 500 g_is_opening_new_window = false; |
| 493 break; | 501 break; |
| 494 case IDC_NEW_INCOGNITO_WINDOW: | 502 case IDC_NEW_INCOGNITO_WINDOW: |
| 495 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile()); | 503 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile()); |
| 496 break; | 504 break; |
| 497 case IDC_RESTORE_TAB: | 505 case IDC_RESTORE_TAB: |
| 498 Browser::OpenWindowWithRestoredTabs(defaultProfile); | 506 Browser::OpenWindowWithRestoredTabs(defaultProfile); |
| 499 break; | 507 break; |
| 500 case IDC_OPEN_FILE: | 508 case IDC_OPEN_FILE: |
| 501 Browser::OpenEmptyWindow(defaultProfile); | 509 Browser::OpenEmptyWindow(defaultProfile); |
| 502 BrowserList::GetLastActive()-> | 510 BrowserList::GetLastActive()-> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 520 // dock icon and there are no open windows. To match standard mac | 528 // dock icon and there are no open windows. To match standard mac |
| 521 // behavior, we should open a new window. | 529 // behavior, we should open a new window. |
| 522 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication | 530 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication |
| 523 hasVisibleWindows:(BOOL)flag { | 531 hasVisibleWindows:(BOOL)flag { |
| 524 // Don't do anything if there are visible windows. This will cause | 532 // Don't do anything if there are visible windows. This will cause |
| 525 // AppKit to unminimize the most recently minimized window. | 533 // AppKit to unminimize the most recently minimized window. |
| 526 if (flag) | 534 if (flag) |
| 527 return YES; | 535 return YES; |
| 528 | 536 |
| 529 // Otherwise open a new window. | 537 // Otherwise open a new window. |
| 538 g_is_opening_new_window = true; |
| 530 Browser::OpenEmptyWindow([self defaultProfile]); | 539 Browser::OpenEmptyWindow([self defaultProfile]); |
| 540 g_is_opening_new_window = false; |
| 531 | 541 |
| 532 // We've handled the reopen event, so return NO to tell AppKit not | 542 // We've handled the reopen event, so return NO to tell AppKit not |
| 533 // to do anything. | 543 // to do anything. |
| 534 return NO; | 544 return NO; |
| 535 } | 545 } |
| 536 | 546 |
| 537 - (void)initMenuState { | 547 - (void)initMenuState { |
| 538 menuState_.reset(new CommandUpdater(NULL)); | 548 menuState_.reset(new CommandUpdater(NULL)); |
| 539 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); | 549 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 540 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 550 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 @end | 732 @end |
| 723 | 733 |
| 724 //--------------------------------------------------------------------------- | 734 //--------------------------------------------------------------------------- |
| 725 | 735 |
| 726 // Stub for cross-platform method that isn't called on Mac OS X. | 736 // Stub for cross-platform method that isn't called on Mac OS X. |
| 727 void ShowOptionsWindow(OptionsPage page, | 737 void ShowOptionsWindow(OptionsPage page, |
| 728 OptionsGroup highlight_group, | 738 OptionsGroup highlight_group, |
| 729 Profile* profile) { | 739 Profile* profile) { |
| 730 NOTIMPLEMENTED(); | 740 NOTIMPLEMENTED(); |
| 731 } | 741 } |
| 742 |
| 743 namespace app_controller_mac { |
| 744 |
| 745 bool IsOpeningNewWindow() { |
| 746 return g_is_opening_new_window; |
| 747 } |
| 748 |
| 749 } // namespace app_controller_mac |
| OLD | NEW |