blob: adf019c4f888b0551690570b03e322973c4d0055 [file] [log] [blame]
[email protected]71c0eb92012-01-03 17:57:301// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1bcdb532009-01-16 17:47:572// 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
[email protected]eddcf7502012-02-09 22:43:488#if defined(__OBJC__)
9
[email protected]1bcdb532009-01-16 17:47:5710#import <Cocoa/Cocoa.h>
dcheng4af48582016-04-19 00:29:3511
12#include <memory>
[email protected]136140c2009-05-19 13:58:2513#include <vector>
[email protected]1bcdb532009-01-16 17:47:5714
bauerb773470002015-02-20 12:20:2015#include "base/files/file_path.h"
[email protected]a8522032013-06-24 22:51:4616#include "base/mac/scoped_nsobject.h"
[email protected]d4c811e72013-10-29 21:57:5517#include "base/time/time.h"
brettwb1fc1b82016-02-02 00:19:0818#include "components/prefs/pref_change_registrar.h"
[email protected]3111f08b2009-04-30 16:01:5219
[email protected]1c62b2f2013-06-28 00:15:0020class AppControllerProfileObserver;
[email protected]edb2d032013-08-30 09:03:1721@class AppShimMenuController;
[email protected]3f34599d2009-03-25 22:11:4322class BookmarkMenuBridge;
[email protected]88d74942009-01-21 22:04:4423class CommandUpdater;
[email protected]136140c2009-05-19 13:58:2524class GURL;
erikchen600f7962014-12-12 00:17:3825class HandoffActiveURLObserverBridge;
26@class HandoffManager;
[email protected]1c84c82c2009-07-27 15:37:2527class HistoryMenuBridge;
[email protected]3f34599d2009-03-25 22:11:4328class Profile;
[email protected]961a6932011-07-19 19:52:4629@class ProfileMenuController;
[email protected]425f7a02014-04-29 01:51:4430class QuitWithAppsController;
dgn02377782016-03-12 00:58:3831class ScopedKeepAlive;
Leonard Grey2bdd08f2017-10-03 18:40:5232@class ShareMenuController;
[email protected]425f7a02014-04-29 01:51:4433
[email protected]1bcdb532009-01-16 17:47:5734// 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.
[email protected]0cbfdaa2010-11-05 00:57:3437@interface AppController : NSObject<NSUserInterfaceValidations,
andresantoso04f7bab2015-01-15 19:19:1638 NSMenuDelegate,
[email protected]0cbfdaa2010-11-05 00:57:3439 NSApplicationDelegate> {
[email protected]3f34599d2009-03-25 22:11:4340 @private
[email protected]5c593702011-06-17 18:35:2441 // Manages the state of the command menu items.
dcheng4af48582016-04-19 00:29:3542 std::unique_ptr<CommandUpdater> menuState_;
[email protected]5c593702011-06-17 18:35:2443
44 // The profile last used by a Browser. It is this profile that was used to
45 // build the user-data specific main menu items.
46 Profile* lastProfile_;
47
lwchkg9c183942016-03-13 06:29:5448 // The ProfileObserver observes the ProfileAttrbutesStorage and gets notified
[email protected]1c62b2f2013-06-28 00:15:0049 // when a profile has been deleted.
dcheng4af48582016-04-19 00:29:3550 std::unique_ptr<AppControllerProfileObserver>
51 profileAttributesStorageObserver_;
[email protected]1c62b2f2013-06-28 00:15:0052
[email protected]3f34599d2009-03-25 22:11:4353 // Management of the bookmark menu which spans across all windows
lgarron9e6dee22014-11-18 01:03:3954 // (and Browser*s). |profileBookmarkMenuBridgeMap_| is a cache that owns one
55 // pointer to a BookmarkMenuBridge for each profile. |bookmarkMenuBridge_| is
56 // a weak pointer that is updated to match the corresponding cache entry
57 // during a profile switch.
58 BookmarkMenuBridge* bookmarkMenuBridge_;
avi82554752016-09-23 17:48:5059 std::map<base::FilePath, std::unique_ptr<BookmarkMenuBridge>>
60 profileBookmarkMenuBridgeMap_;
lgarron9e6dee22014-11-18 01:03:3961
dcheng4af48582016-04-19 00:29:3562 std::unique_ptr<HistoryMenuBridge> historyMenuBridge_;
[email protected]136140c2009-05-19 13:58:2563
[email protected]edb2d032013-08-30 09:03:1764 // Controller that manages main menu items for packaged apps.
65 base::scoped_nsobject<AppShimMenuController> appShimMenuController_;
66
[email protected]961a6932011-07-19 19:52:4667 // The profile menu, which appears right before the Help menu. It is only
68 // available when multiple profiles is enabled.
[email protected]a8522032013-06-24 22:51:4669 base::scoped_nsobject<ProfileMenuController> profileMenuController_;
[email protected]961a6932011-07-19 19:52:4670
Leonard Grey2bdd08f2017-10-03 18:40:5271 // Controller for the macOS system share menu.
72 base::scoped_nsobject<ShareMenuController> shareMenuController_;
73
[email protected]caadfca2010-01-22 21:51:2174 // If we're told to open URLs (in particular, via |-application:openFiles:| by
75 // Launch Services) before we've launched the browser, we queue them up in
[email protected]d630d7d52010-02-21 00:55:1176 // |startupUrls_| so that they can go in the first browser window/tab.
77 std::vector<GURL> startupUrls_;
[email protected]caadfca2010-01-22 21:51:2178 BOOL startupComplete_;
[email protected]1c84c82c2009-07-27 15:37:2579
[email protected]8cfbdbd2011-06-16 04:17:1780 // Outlets for the close tab/window menu items so that we can adjust the
81 // commmand-key equivalent depending on the kind of window and how many
82 // tabs it has.
83 IBOutlet NSMenuItem* closeTabMenuItem_;
84 IBOutlet NSMenuItem* closeWindowMenuItem_;
[email protected]8cfbdbd2011-06-16 04:17:1785
[email protected]f2c20fa2009-12-01 17:42:0286 // Outlet for the help menu so we can bless it so Cocoa adds the search item
87 // to it.
88 IBOutlet NSMenu* helpMenu_;
[email protected]c1d0d812010-07-27 20:21:5589
[email protected]d4c811e72013-10-29 21:57:5590 // If we are expecting a workspace change in response to a reopen
91 // event, the time we got the event. A null time otherwise.
92 base::TimeTicks reopenTime_;
93
dcheng4af48582016-04-19 00:29:3594 std::unique_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
[email protected]05454532013-01-22 21:09:0895 PrefChangeRegistrar localPrefRegistrar_;
[email protected]425f7a02014-04-29 01:51:4496
97 // Displays a notification when quitting while apps are running.
98 scoped_refptr<QuitWithAppsController> quitWithAppsController_;
erikchen600f7962014-12-12 00:17:3899
100 // Responsible for maintaining all state related to the Handoff feature.
101 base::scoped_nsobject<HandoffManager> handoffManager_;
102
103 // Observes changes to the active URL.
dcheng4af48582016-04-19 00:29:35104 std::unique_ptr<HandoffActiveURLObserverBridge>
erikchen600f7962014-12-12 00:17:38105 handoff_active_url_observer_bridge_;
jochenbf9420152015-01-13 14:12:57106
107 // This will be true after receiving a NSWorkspaceWillPowerOffNotification.
108 BOOL isPoweringOff_;
dgn02377782016-03-12 00:58:38109
110 // Request to keep the browser alive during that object's lifetime.
dcheng4af48582016-04-19 00:29:35111 std::unique_ptr<ScopedKeepAlive> keep_alive_;
[email protected]1bcdb532009-01-16 17:47:57112}
113
[email protected]caadfca2010-01-22 21:51:21114@property(readonly, nonatomic) BOOL startupComplete;
[email protected]a585a8db2011-06-20 18:58:35115@property(readonly, nonatomic) Profile* lastProfile;
[email protected]caadfca2010-01-22 21:51:21116
[email protected]3b6aa8b62009-09-15 21:36:11117- (void)didEndMainMessageLoop;
[email protected]1bcdb532009-01-16 17:47:57118
[email protected]7dc8c6b2010-04-09 17:02:50119// Try to close all browser windows, and if that succeeds then quit.
120- (BOOL)tryToTerminateApplication:(NSApplication*)app;
121
122// Stop trying to terminate the application. That is, prevent the final browser
123// window closure from causing the application to quit.
124- (void)stopTryingToTerminateApplication:(NSApplication*)app;
125
jochenbf9420152015-01-13 14:12:57126// Indicate that the system is powering off or logging out.
127- (void)willPowerOff:(NSNotification*)inNotification;
128
[email protected]05454532013-01-22 21:09:08129// Returns true if there is a modal window (either window- or application-
[email protected]f6c15fa2010-06-04 20:08:21130// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
131// sheets) will not count as blocking the browser. But things like open/save
132// dialogs that are window modal will block the browser.
[email protected]05454532013-01-22 21:09:08133- (BOOL)keyWindowIsModal;
[email protected]f6c15fa2010-06-04 20:08:21134
tapted676995d2016-04-18 11:32:29135// Called when the user picks a menu item when there are no key windows, or when
136// there is no foreground browser window. Calls through to the browser object to
137// execute the command. This assumes that the command is supported and doesn't
138// check, otherwise it should have been disabled in the UI in
139// |-validateUserInterfaceItem:|.
140- (void)commandDispatch:(id)sender;
141
[email protected]3111f08b2009-04-30 16:01:52142// Show the preferences window, or bring it to the front if it's already
143// visible.
144- (IBAction)showPreferences:(id)sender;
145
[email protected]bde3dda2009-05-20 22:13:07146// Redirect in the menu item from the expected target of "File's
[email protected]1c62b2f2013-06-28 00:15:00147// Owner" (NSApplication) for a Branded About Box
[email protected]bde3dda2009-05-20 22:13:07148- (IBAction)orderFrontStandardAboutPanel:(id)sender;
149
[email protected]a99fce0e2011-03-21 20:58:48150// Toggles the "Confirm to Quit" preference.
151- (IBAction)toggleConfirmToQuit:(id)sender;
152
[email protected]b01e7562009-09-15 23:18:07153// Delegate method to return the dock menu.
154- (NSMenu*)applicationDockMenu:(NSApplication*)sender;
155
[email protected]caadfca2010-01-22 21:51:21156// Get the URLs that Launch Services expects the browser to open at startup.
[email protected]d630d7d52010-02-21 00:55:11157- (const std::vector<GURL>&)startupUrls;
[email protected]caadfca2010-01-22 21:51:21158
[email protected]7e4c69d02011-05-11 22:16:47159- (BookmarkMenuBridge*)bookmarkMenuBridge;
mlerman8ae56aa2015-04-24 13:56:27160- (HistoryMenuBridge*)historyMenuBridge;
[email protected]7e4c69d02011-05-11 22:16:47161
[email protected]e7dc3992013-11-06 02:16:42162// Initializes the AppShimMenuController. This enables changing the menu bar for
163// apps.
164- (void)initAppShimMenuController;
165
nomsdd5b6a612014-09-23 15:20:16166// Called when the user has changed browser windows, meaning the backing profile
167// may have changed. This can cause a rebuild of the user-data menus. This is a
168// no-op if the new profile is the same as the current one. This will always be
169// the original profile and never incognito.
170- (void)windowChangedToProfile:(Profile*)profile;
171
[email protected]1bcdb532009-01-16 17:47:57172@end
173
[email protected]eddcf7502012-02-09 22:43:48174#endif // __OBJC__
175
176// Functions that may be accessed from non-Objective-C C/C++ code.
177
178namespace app_controller_mac {
179
180// True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
181// SessionService::Observe() to get around windows/linux and mac having
182// different models of application lifetime.
183bool IsOpeningNewWindow();
184
185} // namespace app_controller_mac
186
michaelpg33eea592017-01-19 01:34:56187#endif // CHROME_BROWSER_APP_CONTROLLER_MAC_H_