QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / app_controller_mac.h
blob9b640f2980b43c5663432e1105eb7f8157a15f81
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_
8 #if defined(__OBJC__)
10 #import <Cocoa/Cocoa.h>
11 #include <vector>
13 #include "base/files/file_path.h"
14 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/prefs/pref_change_registrar.h"
18 #include "base/time/time.h"
19 #include "ui/base/work_area_watcher_observer.h"
21 class AppControllerProfileObserver;
22 @class AppShimMenuController;
23 class BookmarkMenuBridge;
24 class CommandUpdater;
25 class GURL;
26 class HandoffActiveURLObserverBridge;
27 @class HandoffManager;
28 class HistoryMenuBridge;
29 class Profile;
30 @class ProfileMenuController;
31 class QuitWithAppsController;
33 namespace ui {
34 class WorkAreaWatcherObserver;
37 // The application controller object, created by loading the MainMenu nib.
38 // This handles things like responding to menus when there are no windows
39 // open, etc and acts as the NSApplication delegate.
40 @interface AppController : NSObject<NSUserInterfaceValidations,
41 NSMenuDelegate,
42 NSApplicationDelegate> {
43 @private
44 // Manages the state of the command menu items.
45 scoped_ptr<CommandUpdater> menuState_;
47 // The profile last used by a Browser. It is this profile that was used to
48 // build the user-data specific main menu items.
49 Profile* lastProfile_;
51 // The ProfileObserver observes the ProfileInfoCache and gets notified
52 // when a profile has been deleted.
53 scoped_ptr<AppControllerProfileObserver> profileInfoCacheObserver_;
55 // Management of the bookmark menu which spans across all windows
56 // (and Browser*s). |profileBookmarkMenuBridgeMap_| is a cache that owns one
57 // pointer to a BookmarkMenuBridge for each profile. |bookmarkMenuBridge_| is
58 // a weak pointer that is updated to match the corresponding cache entry
59 // during a profile switch.
60 BookmarkMenuBridge* bookmarkMenuBridge_;
61 std::map<base::FilePath, BookmarkMenuBridge*> profileBookmarkMenuBridgeMap_;
63 scoped_ptr<HistoryMenuBridge> historyMenuBridge_;
65 // Controller that manages main menu items for packaged apps.
66 base::scoped_nsobject<AppShimMenuController> appShimMenuController_;
68 // The profile menu, which appears right before the Help menu. It is only
69 // available when multiple profiles is enabled.
70 base::scoped_nsobject<ProfileMenuController> profileMenuController_;
72 // If we're told to open URLs (in particular, via |-application:openFiles:| by
73 // Launch Services) before we've launched the browser, we queue them up in
74 // |startupUrls_| so that they can go in the first browser window/tab.
75 std::vector<GURL> startupUrls_;
76 BOOL startupComplete_;
78 // Outlets for the close tab/window menu items so that we can adjust the
79 // commmand-key equivalent depending on the kind of window and how many
80 // tabs it has.
81 IBOutlet NSMenuItem* closeTabMenuItem_;
82 IBOutlet NSMenuItem* closeWindowMenuItem_;
84 // Outlet for the help menu so we can bless it so Cocoa adds the search item
85 // to it.
86 IBOutlet NSMenu* helpMenu_;
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 base::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_;
101 // Responsible for maintaining all state related to the Handoff feature.
102 base::scoped_nsobject<HandoffManager> handoffManager_;
104 // Observes changes to the active URL.
105 scoped_ptr<HandoffActiveURLObserverBridge>
106 handoff_active_url_observer_bridge_;
108 // This will be true after receiving a NSWorkspaceWillPowerOffNotification.
109 BOOL isPoweringOff_;
112 @property(readonly, nonatomic) BOOL startupComplete;
113 @property(readonly, nonatomic) Profile* lastProfile;
115 // Helper method used to update the "Signin" menu item in the main menu and the
116 // wrench menu to reflect the current signed in state.
117 + (void)updateSigninItem:(id)signinItem
118 shouldShow:(BOOL)showSigninMenuItem
119 currentProfile:(Profile*)profile;
121 - (void)didEndMainMessageLoop;
123 // Try to close all browser windows, and if that succeeds then quit.
124 - (BOOL)tryToTerminateApplication:(NSApplication*)app;
126 // Stop trying to terminate the application. That is, prevent the final browser
127 // window closure from causing the application to quit.
128 - (void)stopTryingToTerminateApplication:(NSApplication*)app;
130 // Indicate that the system is powering off or logging out.
131 - (void)willPowerOff:(NSNotification*)inNotification;
133 // Returns true if there is a modal window (either window- or application-
134 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
135 // sheets) will not count as blocking the browser. But things like open/save
136 // dialogs that are window modal will block the browser.
137 - (BOOL)keyWindowIsModal;
139 // Show the preferences window, or bring it to the front if it's already
140 // visible.
141 - (IBAction)showPreferences:(id)sender;
143 // Redirect in the menu item from the expected target of "File's
144 // Owner" (NSApplication) for a Branded About Box
145 - (IBAction)orderFrontStandardAboutPanel:(id)sender;
147 // Toggles the "Confirm to Quit" preference.
148 - (IBAction)toggleConfirmToQuit:(id)sender;
150 // Toggles the "Hide Notifications Icon" preference.
151 - (IBAction)toggleDisplayMessageCenter:(id)sender;
153 // Delegate method to return the dock menu.
154 - (NSMenu*)applicationDockMenu:(NSApplication*)sender;
156 // Get the URLs that Launch Services expects the browser to open at startup.
157 - (const std::vector<GURL>&)startupUrls;
159 - (BookmarkMenuBridge*)bookmarkMenuBridge;
160 - (HistoryMenuBridge*)historyMenuBridge;
162 // Subscribes/unsubscribes from the work area change notification.
163 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
164 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
166 // Initializes the AppShimMenuController. This enables changing the menu bar for
167 // apps.
168 - (void)initAppShimMenuController;
170 // Called when the user has changed browser windows, meaning the backing profile
171 // may have changed. This can cause a rebuild of the user-data menus. This is a
172 // no-op if the new profile is the same as the current one. This will always be
173 // the original profile and never incognito.
174 - (void)windowChangedToProfile:(Profile*)profile;
176 @end
178 #endif // __OBJC__
180 // Functions that may be accessed from non-Objective-C C/C++ code.
182 namespace app_controller_mac {
184 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
185 // SessionService::Observe() to get around windows/linux and mac having
186 // different models of application lifetime.
187 bool IsOpeningNewWindow();
189 } // namespace app_controller_mac
191 #endif