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 "apps/app_shim/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 - (void)initMenuState; | 210 - (void)initMenuState; |
211 - (void)initProfileMenu; | 211 - (void)initProfileMenu; |
212 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 212 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
213 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; | 213 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; |
214 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 214 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
215 - (void)openUrls:(const std::vector<GURL>&)urls; | 215 - (void)openUrls:(const std::vector<GURL>&)urls; |
216 - (void)getUrl:(NSAppleEventDescriptor*)event | 216 - (void)getUrl:(NSAppleEventDescriptor*)event |
217 withReply:(NSAppleEventDescriptor*)reply; | 217 withReply:(NSAppleEventDescriptor*)reply; |
218 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 218 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
219 - (void)activeSpaceDidChange:(NSNotification*)inNotification; | 219 - (void)activeSpaceDidChange:(NSNotification*)inNotification; |
220 - (void)windowChangedToProfile:(Profile*)profile; | |
221 - (void)checkForAnyKeyWindows; | 220 - (void)checkForAnyKeyWindows; |
222 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 221 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
223 - (BOOL)shouldQuitWithInProgressDownloads; | 222 - (BOOL)shouldQuitWithInProgressDownloads; |
224 - (void)executeApplication:(id)sender; | 223 - (void)executeApplication:(id)sender; |
225 - (void)profileWasRemoved:(const base::FilePath&)profilePath; | 224 - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
226 @end | 225 @end |
227 | 226 |
228 class AppControllerProfileObserver : public ProfileInfoCacheObserver { | 227 class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
229 public: | 228 public: |
230 AppControllerProfileObserver( | 229 AppControllerProfileObserver( |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 hasPopover_ = YES; | 631 hasPopover_ = YES; |
633 [self fixCloseMenuItemKeyEquivalents]; | 632 [self fixCloseMenuItemKeyEquivalents]; |
634 } | 633 } |
635 | 634 |
636 // Called on Lion and later when a popover (e.g. dictionary) is closed. | 635 // Called on Lion and later when a popover (e.g. dictionary) is closed. |
637 - (void)popoverDidClose:(NSNotification*)notify { | 636 - (void)popoverDidClose:(NSNotification*)notify { |
638 hasPopover_ = NO; | 637 hasPopover_ = NO; |
639 [self fixCloseMenuItemKeyEquivalents]; | 638 [self fixCloseMenuItemKeyEquivalents]; |
640 } | 639 } |
641 | 640 |
642 // Called when the user has changed browser windows, meaning the backing profile | |
643 // may have changed. This can cause a rebuild of the user-data menus. This is a | |
644 // no-op if the new profile is the same as the current one. This will always be | |
645 // the original profile and never incognito. | |
646 - (void)windowChangedToProfile:(Profile*)profile { | |
647 if (lastProfile_ == profile) | |
648 return; | |
649 | |
650 // Before tearing down the menu controller bridges, return the Cocoa menus to | |
651 // their initial state. | |
652 if (bookmarkMenuBridge_.get()) | |
653 bookmarkMenuBridge_->ResetMenu(); | |
654 if (historyMenuBridge_.get()) | |
655 historyMenuBridge_->ResetMenu(); | |
656 | |
657 // Rebuild the menus with the new profile. | |
658 lastProfile_ = profile; | |
659 | |
660 bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, | |
661 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); | |
662 // No need to |BuildMenu| here. It is done lazily upon menu access. | |
663 | |
664 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); | |
665 historyMenuBridge_->BuildMenu(); | |
666 | |
667 chrome::BrowserCommandController:: | |
668 UpdateSharedCommandsForIncognitoAvailability( | |
669 menuState_.get(), lastProfile_); | |
670 profilePrefRegistrar_.reset(new PrefChangeRegistrar()); | |
671 profilePrefRegistrar_->Init(lastProfile_->GetPrefs()); | |
672 profilePrefRegistrar_->Add( | |
673 prefs::kIncognitoModeAvailability, | |
674 base::Bind(&chrome::BrowserCommandController:: | |
675 UpdateSharedCommandsForIncognitoAvailability, | |
676 menuState_.get(), | |
677 lastProfile_)); | |
678 } | |
679 | |
680 - (void)checkForAnyKeyWindows { | 641 - (void)checkForAnyKeyWindows { |
681 if ([NSApp keyWindow]) | 642 if ([NSApp keyWindow]) |
682 return; | 643 return; |
683 | 644 |
684 content::NotificationService::current()->Notify( | 645 content::NotificationService::current()->Notify( |
685 chrome::NOTIFICATION_NO_KEY_WINDOW, | 646 chrome::NOTIFICATION_NO_KEY_WINDOW, |
686 content::NotificationService::AllSources(), | 647 content::NotificationService::AllSources(), |
687 content::NotificationService::NoDetails()); | 648 content::NotificationService::NoDetails()); |
688 } | 649 } |
689 | 650 |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 | 1487 |
1527 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { | 1488 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer { |
1528 workAreaChangeObservers_.RemoveObserver(observer); | 1489 workAreaChangeObservers_.RemoveObserver(observer); |
1529 } | 1490 } |
1530 | 1491 |
1531 - (void)initAppShimMenuController { | 1492 - (void)initAppShimMenuController { |
1532 if (!appShimMenuController_) | 1493 if (!appShimMenuController_) |
1533 appShimMenuController_.reset([[AppShimMenuController alloc] init]); | 1494 appShimMenuController_.reset([[AppShimMenuController alloc] init]); |
1534 } | 1495 } |
1535 | 1496 |
| 1497 - (void)windowChangedToProfile:(Profile*)profile { |
| 1498 if (lastProfile_ == profile) |
| 1499 return; |
| 1500 |
| 1501 // Before tearing down the menu controller bridges, return the Cocoa menus to |
| 1502 // their initial state. |
| 1503 if (bookmarkMenuBridge_.get()) |
| 1504 bookmarkMenuBridge_->ResetMenu(); |
| 1505 if (historyMenuBridge_.get()) |
| 1506 historyMenuBridge_->ResetMenu(); |
| 1507 |
| 1508 // Rebuild the menus with the new profile. |
| 1509 lastProfile_ = profile; |
| 1510 |
| 1511 bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, |
| 1512 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); |
| 1513 // No need to |BuildMenu| here. It is done lazily upon menu access. |
| 1514 |
| 1515 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
| 1516 historyMenuBridge_->BuildMenu(); |
| 1517 |
| 1518 chrome::BrowserCommandController:: |
| 1519 UpdateSharedCommandsForIncognitoAvailability( |
| 1520 menuState_.get(), lastProfile_); |
| 1521 profilePrefRegistrar_.reset(new PrefChangeRegistrar()); |
| 1522 profilePrefRegistrar_->Init(lastProfile_->GetPrefs()); |
| 1523 profilePrefRegistrar_->Add( |
| 1524 prefs::kIncognitoModeAvailability, |
| 1525 base::Bind(&chrome::BrowserCommandController:: |
| 1526 UpdateSharedCommandsForIncognitoAvailability, |
| 1527 menuState_.get(), |
| 1528 lastProfile_)); |
| 1529 } |
| 1530 |
1536 - (void)applicationDidChangeScreenParameters:(NSNotification*)notification { | 1531 - (void)applicationDidChangeScreenParameters:(NSNotification*)notification { |
1537 // During this callback the working area is not always already updated. Defer. | 1532 // During this callback the working area is not always already updated. Defer. |
1538 [self performSelector:@selector(delayedScreenParametersUpdate) | 1533 [self performSelector:@selector(delayedScreenParametersUpdate) |
1539 withObject:nil | 1534 withObject:nil |
1540 afterDelay:0]; | 1535 afterDelay:0]; |
1541 } | 1536 } |
1542 | 1537 |
1543 - (void)delayedScreenParametersUpdate { | 1538 - (void)delayedScreenParametersUpdate { |
1544 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_, | 1539 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_, |
1545 WorkAreaChanged()); | 1540 WorkAreaChanged()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 | 1574 |
1580 //--------------------------------------------------------------------------- | 1575 //--------------------------------------------------------------------------- |
1581 | 1576 |
1582 namespace app_controller_mac { | 1577 namespace app_controller_mac { |
1583 | 1578 |
1584 bool IsOpeningNewWindow() { | 1579 bool IsOpeningNewWindow() { |
1585 return g_is_opening_new_window; | 1580 return g_is_opening_new_window; |
1586 } | 1581 } |
1587 | 1582 |
1588 } // namespace app_controller_mac | 1583 } // namespace app_controller_mac |
OLD | NEW |