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
;
29 class WorkAreaWatcherObserver
;
32 // The application controller object, created by loading the MainMenu nib.
33 // This handles things like responding to menus when there are no windows
34 // open, etc and acts as the NSApplication delegate.
35 @interface AppController
: NSObject
<NSUserInterfaceValidations
,
36 NSApplicationDelegate
> {
38 // Manages the state of the command menu items.
39 scoped_ptr
<CommandUpdater
> menuState_
;
41 // The profile last used by a Browser. It is this profile that was used to
42 // build the user-data specific main menu items.
43 Profile
* lastProfile_
;
45 // The ProfileObserver observes the ProfileInfoCache and gets notified
46 // when a profile has been deleted.
47 scoped_ptr
<AppControllerProfileObserver
> profileInfoCacheObserver_
;
49 // Management of the bookmark menu which spans across all windows
51 scoped_ptr
<BookmarkMenuBridge
> bookmarkMenuBridge_
;
52 scoped_ptr
<HistoryMenuBridge
> historyMenuBridge_
;
54 // Controller that manages main menu items for packaged apps.
55 base::scoped_nsobject
<AppShimMenuController
> appShimMenuController_
;
57 // The profile menu, which appears right before the Help menu. It is only
58 // available when multiple profiles is enabled.
59 base::scoped_nsobject
<ProfileMenuController
> profileMenuController_
;
61 // If we're told to open URLs (in particular, via |-application:openFiles:| by
62 // Launch Services) before we've launched the browser, we queue them up in
63 // |startupUrls_| so that they can go in the first browser window/tab.
64 std::vector
<GURL
> startupUrls_
;
65 BOOL startupComplete_
;
67 // Outlets for the close tab/window menu items so that we can adjust the
68 // commmand-key equivalent depending on the kind of window and how many
70 IBOutlet NSMenuItem
* closeTabMenuItem_
;
71 IBOutlet NSMenuItem
* closeWindowMenuItem_
;
72 BOOL fileMenuUpdatePending_
; // ensure we only do this once per notificaion.
74 // Outlet for the help menu so we can bless it so Cocoa adds the search item
76 IBOutlet NSMenu
* helpMenu_
;
78 // Outlet for the tabpose menu item so we can hide it.
79 IBOutlet NSMenuItem
* tabposeMenuItem_
;
81 // Indicates wheter an NSPopover is currently being shown.
84 // If we are expecting a workspace change in response to a reopen
85 // event, the time we got the event. A null time otherwise.
86 base::TimeTicks reopenTime_
;
88 // Observers that listen to the work area changes.
89 ObserverList
<ui::WorkAreaWatcherObserver
> workAreaChangeObservers_
;
91 scoped_ptr
<PrefChangeRegistrar
> profilePrefRegistrar_
;
92 PrefChangeRegistrar localPrefRegistrar_
;
95 @
property(readonly
, nonatomic
) BOOL startupComplete
;
96 @
property(readonly
, nonatomic
) Profile
* lastProfile
;
98 - (void)didEndMainMessageLoop
;
100 // Try to close all browser windows, and if that succeeds then quit.
101 - (BOOL
)tryToTerminateApplication
:(NSApplication
*)app
;
103 // Stop trying to terminate the application. That is, prevent the final browser
104 // window closure from causing the application to quit.
105 - (void)stopTryingToTerminateApplication
:(NSApplication
*)app
;
107 // Returns true if there is a modal window (either window- or application-
108 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
109 // sheets) will not count as blocking the browser. But things like open/save
110 // dialogs that are window modal will block the browser.
111 - (BOOL
)keyWindowIsModal
;
113 // Show the preferences window, or bring it to the front if it's already
115 - (IBAction
)showPreferences
:(id
)sender
;
117 // Redirect in the menu item from the expected target of "File's
118 // Owner" (NSApplication) for a Branded About Box
119 - (IBAction
)orderFrontStandardAboutPanel
:(id
)sender
;
121 // Toggles the "Confirm to Quit" preference.
122 - (IBAction
)toggleConfirmToQuit
:(id
)sender
;
124 // Delegate method to return the dock menu.
125 - (NSMenu
*)applicationDockMenu
:(NSApplication
*)sender
;
127 // Get the URLs that Launch Services expects the browser to open at startup.
128 - (const std::vector
<GURL
>&)startupUrls
;
130 // Clear the list of startup URLs.
131 - (void)clearStartupUrls
;
133 - (BookmarkMenuBridge
*)bookmarkMenuBridge
;
135 // Subscribes/unsubscribes from the work area change notification.
136 - (void)addObserverForWorkAreaChange
:(ui::WorkAreaWatcherObserver
*)observer
;
137 - (void)removeObserverForWorkAreaChange
:(ui::WorkAreaWatcherObserver
*)observer
;
139 // Initializes the AppShimMenuController. This enables changing the menu bar for
141 - (void)initAppShimMenuController
;
147 // Functions that may be accessed from non-Objective-C C/C++ code.
149 namespace app_controller_mac
{
151 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
152 // SessionService::Observe() to get around windows/linux and mac having
153 // different models of application lifetime.
154 bool IsOpeningNewWindow();
156 } // namespace app_controller_mac