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.
5 #ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_
6 #define CHROME_BROWSER_APP_CONTROLLER_MAC_H_
10 #import <Cocoa/Cocoa.h>
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 "base/time/time.h"
18 #include "ui/base/work_area_watcher_observer.h"
20 class AppControllerProfileObserver
;
21 @
class AppShimMenuController
;
22 class BookmarkMenuBridge
;
25 class HistoryMenuBridge
;
27 @
class ProfileMenuController
;
28 class QuitWithAppsController
;
31 class WorkAreaWatcherObserver
;
34 // The application controller object, created by loading the MainMenu nib.
35 // This handles things like responding to menus when there are no windows
36 // open, etc and acts as the NSApplication delegate.
37 @interface AppController
: NSObject
<NSUserInterfaceValidations
,
38 NSApplicationDelegate
> {
40 // Manages the state of the command menu items.
41 scoped_ptr
<CommandUpdater
> menuState_
;
43 // The profile last used by a Browser. It is this profile that was used to
44 // build the user-data specific main menu items.
45 Profile
* lastProfile_
;
47 // The ProfileObserver observes the ProfileInfoCache and gets notified
48 // when a profile has been deleted.
49 scoped_ptr
<AppControllerProfileObserver
> profileInfoCacheObserver_
;
51 // Management of the bookmark menu which spans across all windows
52 // (and Browser*s). |profileBookmarkMenuBridgeMap_| is a cache that owns one
53 // pointer to a BookmarkMenuBridge for each profile. |bookmarkMenuBridge_| is
54 // a weak pointer that is updated to match the corresponding cache entry
55 // during a profile switch.
56 BookmarkMenuBridge
* bookmarkMenuBridge_
;
57 std::map
<Profile
*, BookmarkMenuBridge
*> profileBookmarkMenuBridgeMap_
;
59 scoped_ptr
<HistoryMenuBridge
> historyMenuBridge_
;
61 // Controller that manages main menu items for packaged apps.
62 base::scoped_nsobject
<AppShimMenuController
> appShimMenuController_
;
64 // The profile menu, which appears right before the Help menu. It is only
65 // available when multiple profiles is enabled.
66 base::scoped_nsobject
<ProfileMenuController
> profileMenuController_
;
68 // If we're told to open URLs (in particular, via |-application:openFiles:| by
69 // Launch Services) before we've launched the browser, we queue them up in
70 // |startupUrls_| so that they can go in the first browser window/tab.
71 std::vector
<GURL
> startupUrls_
;
72 BOOL startupComplete_
;
74 // Outlets for the close tab/window menu items so that we can adjust the
75 // commmand-key equivalent depending on the kind of window and how many
77 IBOutlet NSMenuItem
* closeTabMenuItem_
;
78 IBOutlet NSMenuItem
* closeWindowMenuItem_
;
79 BOOL fileMenuUpdatePending_
; // ensure we only do this once per notificaion.
81 // Outlet for the help menu so we can bless it so Cocoa adds the search item
83 IBOutlet NSMenu
* helpMenu_
;
85 // Indicates wheter an NSPopover is currently being shown.
88 // If we are expecting a workspace change in response to a reopen
89 // event, the time we got the event. A null time otherwise.
90 base::TimeTicks reopenTime_
;
92 // Observers that listen to the work area changes.
93 ObserverList
<ui::WorkAreaWatcherObserver
> workAreaChangeObservers_
;
95 scoped_ptr
<PrefChangeRegistrar
> profilePrefRegistrar_
;
96 PrefChangeRegistrar localPrefRegistrar_
;
98 // Displays a notification when quitting while apps are running.
99 scoped_refptr
<QuitWithAppsController
> quitWithAppsController_
;
102 @
property(readonly
, nonatomic
) BOOL startupComplete
;
103 @
property(readonly
, nonatomic
) Profile
* lastProfile
;
105 - (void)didEndMainMessageLoop
;
107 // Try to close all browser windows, and if that succeeds then quit.
108 - (BOOL
)tryToTerminateApplication
:(NSApplication
*)app
;
110 // Stop trying to terminate the application. That is, prevent the final browser
111 // window closure from causing the application to quit.
112 - (void)stopTryingToTerminateApplication
:(NSApplication
*)app
;
114 // Returns true if there is a modal window (either window- or application-
115 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
116 // sheets) will not count as blocking the browser. But things like open/save
117 // dialogs that are window modal will block the browser.
118 - (BOOL
)keyWindowIsModal
;
120 // Show the preferences window, or bring it to the front if it's already
122 - (IBAction
)showPreferences
:(id
)sender
;
124 // Redirect in the menu item from the expected target of "File's
125 // Owner" (NSApplication) for a Branded About Box
126 - (IBAction
)orderFrontStandardAboutPanel
:(id
)sender
;
128 // Toggles the "Confirm to Quit" preference.
129 - (IBAction
)toggleConfirmToQuit
:(id
)sender
;
131 // Toggles the "Hide Notifications Icon" preference.
132 - (IBAction
)toggleDisplayMessageCenter
:(id
)sender
;
134 // Delegate method to return the dock menu.
135 - (NSMenu
*)applicationDockMenu
:(NSApplication
*)sender
;
137 // Get the URLs that Launch Services expects the browser to open at startup.
138 - (const std::vector
<GURL
>&)startupUrls
;
140 - (BookmarkMenuBridge
*)bookmarkMenuBridge
;
142 // Subscribes/unsubscribes from the work area change notification.
143 - (void)addObserverForWorkAreaChange
:(ui::WorkAreaWatcherObserver
*)observer
;
144 - (void)removeObserverForWorkAreaChange
:(ui::WorkAreaWatcherObserver
*)observer
;
146 // Initializes the AppShimMenuController. This enables changing the menu bar for
148 - (void)initAppShimMenuController
;
150 // Called when the user has changed browser windows, meaning the backing profile
151 // may have changed. This can cause a rebuild of the user-data menus. This is a
152 // no-op if the new profile is the same as the current one. This will always be
153 // the original profile and never incognito.
154 - (void)windowChangedToProfile
:(Profile
*)profile
;
160 // Functions that may be accessed from non-Objective-C C/C++ code.
162 namespace app_controller_mac
{
164 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
165 // SessionService::Observe() to get around windows/linux and mac having
166 // different models of application lifetime.
167 bool IsOpeningNewWindow();
169 } // namespace app_controller_mac