blob: 35984ffeccb5fbaf372e5025dd660bdba4a603aa [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.
Robert Sesek705c3802018-10-24 20:58:4283 NSMenuItem* closeTabMenuItem_;
84 NSMenuItem* closeWindowMenuItem_;
[email protected]8cfbdbd2011-06-16 04:17:1785
[email protected]d4c811e72013-10-29 21:57:5586 // If we are expecting a workspace change in response to a reopen
87 // event, the time we got the event. A null time otherwise.
88 base::TimeTicks reopenTime_;
89
dcheng4af48582016-04-19 00:29:3590 std::unique_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
[email protected]05454532013-01-22 21:09:0891 PrefChangeRegistrar localPrefRegistrar_;
[email protected]425f7a02014-04-29 01:51:4492
93 // Displays a notification when quitting while apps are running.
94 scoped_refptr<QuitWithAppsController> quitWithAppsController_;
erikchen600f7962014-12-12 00:17:3895
96 // Responsible for maintaining all state related to the Handoff feature.
97 base::scoped_nsobject<HandoffManager> handoffManager_;
98
99 // Observes changes to the active URL.
dcheng4af48582016-04-19 00:29:35100 std::unique_ptr<HandoffActiveURLObserverBridge>
erikchen600f7962014-12-12 00:17:38101 handoff_active_url_observer_bridge_;
jochenbf9420152015-01-13 14:12:57102
103 // This will be true after receiving a NSWorkspaceWillPowerOffNotification.
104 BOOL isPoweringOff_;
dgn02377782016-03-12 00:58:38105
106 // Request to keep the browser alive during that object's lifetime.
dcheng4af48582016-04-19 00:29:35107 std::unique_ptr<ScopedKeepAlive> keep_alive_;
[email protected]1bcdb532009-01-16 17:47:57108}
109
[email protected]caadfca2010-01-22 21:51:21110@property(readonly, nonatomic) BOOL startupComplete;
[email protected]a585a8db2011-06-20 18:58:35111@property(readonly, nonatomic) Profile* lastProfile;
[email protected]caadfca2010-01-22 21:51:21112
Robert Sesek124f80f92018-07-24 20:31:29113// This method is called very early in application startup after the main menu
114// has been created.
115- (void)mainMenuCreated;
116
[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
Avi Drissmanf19bb472018-11-29 19:51:28126// Run the quit confirmation panel and return whether or not to continue
127// quitting.
128- (BOOL)runConfirmQuitPanel;
129
jochenbf9420152015-01-13 14:12:57130// Indicate that the system is powering off or logging out.
131- (void)willPowerOff:(NSNotification*)inNotification;
132
[email protected]05454532013-01-22 21:09:08133// Returns true if there is a modal window (either window- or application-
[email protected]f6c15fa2010-06-04 20:08:21134// 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.
[email protected]05454532013-01-22 21:09:08137- (BOOL)keyWindowIsModal;
[email protected]f6c15fa2010-06-04 20:08:21138
tapted676995d2016-04-18 11:32:29139// Called when the user picks a menu item when there are no key windows, or when
140// there is no foreground browser window. Calls through to the browser object to
141// execute the command. This assumes that the command is supported and doesn't
142// check, otherwise it should have been disabled in the UI in
143// |-validateUserInterfaceItem:|.
144- (void)commandDispatch:(id)sender;
145
[email protected]3111f08b2009-04-30 16:01:52146// Show the preferences window, or bring it to the front if it's already
147// visible.
148- (IBAction)showPreferences:(id)sender;
149
[email protected]bde3dda2009-05-20 22:13:07150// Redirect in the menu item from the expected target of "File's
[email protected]1c62b2f2013-06-28 00:15:00151// Owner" (NSApplication) for a Branded About Box
[email protected]bde3dda2009-05-20 22:13:07152- (IBAction)orderFrontStandardAboutPanel:(id)sender;
153
[email protected]a99fce0e2011-03-21 20:58:48154// Toggles the "Confirm to Quit" preference.
155- (IBAction)toggleConfirmToQuit:(id)sender;
156
[email protected]b01e7562009-09-15 23:18:07157// Delegate method to return the dock menu.
158- (NSMenu*)applicationDockMenu:(NSApplication*)sender;
159
[email protected]caadfca2010-01-22 21:51:21160// Get the URLs that Launch Services expects the browser to open at startup.
[email protected]d630d7d52010-02-21 00:55:11161- (const std::vector<GURL>&)startupUrls;
[email protected]caadfca2010-01-22 21:51:21162
[email protected]7e4c69d02011-05-11 22:16:47163- (BookmarkMenuBridge*)bookmarkMenuBridge;
mlerman8ae56aa2015-04-24 13:56:27164- (HistoryMenuBridge*)historyMenuBridge;
[email protected]7e4c69d02011-05-11 22:16:47165
[email protected]e7dc3992013-11-06 02:16:42166// Initializes the AppShimMenuController. This enables changing the menu bar for
167// apps.
168- (void)initAppShimMenuController;
169
nomsdd5b6a612014-09-23 15:20:16170// 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;
175
erikchen22be2092018-06-12 15:54:00176// Certain NSMenuItems [Close Tab and Close Window] have different
177// keyEquivalents depending on context. This must be invoked in two locations:
178// * In menuNeedsUpdate:, which is called prior to showing the NSMenu.
179// * In CommandDispatcher, which independently searches for a matching
180// keyEquivalent.
181- (void)updateMenuItemKeyEquivalents;
182
[email protected]1bcdb532009-01-16 17:47:57183@end
184
[email protected]eddcf7502012-02-09 22:43:48185#endif // __OBJC__
186
187// Functions that may be accessed from non-Objective-C C/C++ code.
188
189namespace app_controller_mac {
190
191// True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
192// SessionService::Observe() to get around windows/linux and mac having
193// different models of application lifetime.
194bool IsOpeningNewWindow();
195
Elly Fong-Jones68b85b82018-04-21 00:36:54196// Create a guest profile if one is needed. Afterwards, even if the profile
197// already existed, notify the AppController of the profile in use.
198void CreateGuestProfileIfNeeded();
199
Owen Min3bcf8d152018-07-16 16:50:39200// Called when Enterprise startup dialog is close and repost
201// applicationDidFinished notification.
202void EnterpriseStartupDialogClosed();
203
[email protected]eddcf7502012-02-09 22:43:48204} // namespace app_controller_mac
205
michaelpg33eea592017-01-19 01:34:56206#endif // CHROME_BROWSER_APP_CONTROLLER_MAC_H_