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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_ 6 #define CHROME_BROWSER_APP_CONTROLLER_MAC_H_ 7 8 #if defined(__OBJC__) 9 10 #import <Cocoa/Cocoa.h> 11 #include <vector> 12 13 #include "base/mac/scoped_nsobject.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/observer_list.h" 16 #include "base/prefs/pref_change_registrar.h" 17 #include "ui/base/work_area_watcher_observer.h" 18 19 class AppControllerProfileObserver; 20 class BookmarkMenuBridge; 21 class CommandUpdater; 22 class GURL; 23 class HistoryMenuBridge; 24 class Profile; 25 @class ProfileMenuController; 26 namespace ui { 27 class WorkAreaWatcherObserver; 28 } 29 30 // The application controller object, created by loading the MainMenu nib. 31 // This handles things like responding to menus when there are no windows 32 // open, etc and acts as the NSApplication delegate. 33 @interface AppController : NSObject<NSUserInterfaceValidations, 34 NSApplicationDelegate> { 35 @private 36 // Manages the state of the command menu items. 37 scoped_ptr<CommandUpdater> menuState_; 38 39 // The profile last used by a Browser. It is this profile that was used to 40 // build the user-data specific main menu items. 41 Profile* lastProfile_; 42 43 // The ProfileObserver observes the ProfileInfoCache and gets notified 44 // when a profile has been deleted. 45 scoped_ptr<AppControllerProfileObserver> profileInfoCacheObserver_; 46 47 // Management of the bookmark menu which spans across all windows 48 // (and Browser*s). 49 scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_; 50 scoped_ptr<HistoryMenuBridge> historyMenuBridge_; 51 52 // The profile menu, which appears right before the Help menu. It is only 53 // available when multiple profiles is enabled. 54 base::scoped_nsobject<ProfileMenuController> profileMenuController_; 55 56 // If we're told to open URLs (in particular, via |-application:openFiles:| by 57 // Launch Services) before we've launched the browser, we queue them up in 58 // |startupUrls_| so that they can go in the first browser window/tab. 59 std::vector<GURL> startupUrls_; 60 BOOL startupComplete_; 61 62 // Outlets for the close tab/window menu items so that we can adjust the 63 // commmand-key equivalent depending on the kind of window and how many 64 // tabs it has. 65 IBOutlet NSMenuItem* closeTabMenuItem_; 66 IBOutlet NSMenuItem* closeWindowMenuItem_; 67 BOOL fileMenuUpdatePending_; // ensure we only do this once per notificaion. 68 69 // Outlet for the help menu so we can bless it so Cocoa adds the search item 70 // to it. 71 IBOutlet NSMenu* helpMenu_; 72 73 // Outlet for the tabpose menu item so we can hide it. 74 IBOutlet NSMenuItem* tabposeMenuItem_; 75 76 // Indicates wheter an NSPopover is currently being shown. 77 BOOL hasPopover_; 78 79 // Observers that listen to the work area changes. 80 ObserverList<ui::WorkAreaWatcherObserver> workAreaChangeObservers_; 81 82 scoped_ptr<PrefChangeRegistrar> profilePrefRegistrar_; 83 PrefChangeRegistrar localPrefRegistrar_; 84 } 85 86 @property(readonly, nonatomic) BOOL startupComplete; 87 @property(readonly, nonatomic) Profile* lastProfile; 88 89 - (void)didEndMainMessageLoop; 90 91 // Try to close all browser windows, and if that succeeds then quit. 92 - (BOOL)tryToTerminateApplication:(NSApplication*)app; 93 94 // Stop trying to terminate the application. That is, prevent the final browser 95 // window closure from causing the application to quit. 96 - (void)stopTryingToTerminateApplication:(NSApplication*)app; 97 98 // Returns true if there is a modal window (either window- or application- 99 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth 100 // sheets) will not count as blocking the browser. But things like open/save 101 // dialogs that are window modal will block the browser. 102 - (BOOL)keyWindowIsModal; 103 104 // Show the preferences window, or bring it to the front if it's already 105 // visible. 106 - (IBAction)showPreferences:(id)sender; 107 108 // Redirect in the menu item from the expected target of "File's 109 // Owner" (NSApplication) for a Branded About Box 110 - (IBAction)orderFrontStandardAboutPanel:(id)sender; 111 112 // Toggles the "Confirm to Quit" preference. 113 - (IBAction)toggleConfirmToQuit:(id)sender; 114 115 // Delegate method to return the dock menu. 116 - (NSMenu*)applicationDockMenu:(NSApplication*)sender; 117 118 // Get the URLs that Launch Services expects the browser to open at startup. 119 - (const std::vector<GURL>&)startupUrls; 120 121 // Clear the list of startup URLs. 122 - (void)clearStartupUrls; 123 124 - (BookmarkMenuBridge*)bookmarkMenuBridge; 125 126 // Subscribes/unsubscribes from the work area change notification. 127 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer; 128 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer; 129 130 @end 131 132 #endif // __OBJC__ 133 134 // Functions that may be accessed from non-Objective-C C/C++ code. 135 136 namespace app_controller_mac { 137 138 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in 139 // SessionService::Observe() to get around windows/linux and mac having 140 // different models of application lifetime. 141 bool IsOpeningNewWindow(); 142 143 } // namespace app_controller_mac 144 145 #endif 146