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