[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 2 | // 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] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 8 | #if defined(__OBJC__) |
| 9 | |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 10 | #import <Cocoa/Cocoa.h> |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 11 | |
| 12 | #include <memory> |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 13 | #include <vector> |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 14 | |
bauerb | 77347000 | 2015-02-20 12:20:20 | [diff] [blame] | 15 | #include "base/files/file_path.h" |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 16 | #include "base/mac/scoped_nsobject.h" |
[email protected] | d4c811e7 | 2013-10-29 21:57:55 | [diff] [blame] | 17 | #include "base/time/time.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 18 | #include "components/prefs/pref_change_registrar.h" |
[email protected] | 3111f08b | 2009-04-30 16:01:52 | [diff] [blame] | 19 | |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 20 | class AppControllerProfileObserver; |
[email protected] | edb2d03 | 2013-08-30 09:03:17 | [diff] [blame] | 21 | @class AppShimMenuController; |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 22 | class BookmarkMenuBridge; |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 23 | class CommandUpdater; |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 24 | class GURL; |
erikchen | 600f796 | 2014-12-12 00:17:38 | [diff] [blame] | 25 | class HandoffActiveURLObserverBridge; |
| 26 | @class HandoffManager; |
[email protected] | 1c84c82c | 2009-07-27 15:37:25 | [diff] [blame] | 27 | class HistoryMenuBridge; |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 28 | class Profile; |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 29 | @class ProfileMenuController; |
[email protected] | 425f7a0 | 2014-04-29 01:51:44 | [diff] [blame] | 30 | class QuitWithAppsController; |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 31 | class ScopedKeepAlive; |
Leonard Grey | 2bdd08f | 2017-10-03 18:40:52 | [diff] [blame] | 32 | @class ShareMenuController; |
[email protected] | 425f7a0 | 2014-04-29 01:51:44 | [diff] [blame] | 33 | |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 34 | // 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] | 0cbfdaa | 2010-11-05 00:57:34 | [diff] [blame] | 37 | @interface AppController : NSObject<NSUserInterfaceValidations, |
andresantoso | 04f7bab | 2015-01-15 19:19:16 | [diff] [blame] | 38 | NSMenuDelegate, |
[email protected] | 0cbfdaa | 2010-11-05 00:57:34 | [diff] [blame] | 39 | NSApplicationDelegate> { |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 40 | @private |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 41 | // Manages the state of the command menu items. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 42 | std::unique_ptr<CommandUpdater> menuState_; |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 43 | |
| 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 | |
lwchkg | 9c18394 | 2016-03-13 06:29:54 | [diff] [blame] | 48 | // The ProfileObserver observes the ProfileAttrbutesStorage and gets notified |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 49 | // when a profile has been deleted. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 50 | std::unique_ptr<AppControllerProfileObserver> |
| 51 | profileAttributesStorageObserver_; |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 52 | |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 53 | // Management of the bookmark menu which spans across all windows |
lgarron | 9e6dee2 | 2014-11-18 01:03:39 | [diff] [blame] | 54 | // (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_; |
avi | 8255475 | 2016-09-23 17:48:50 | [diff] [blame] | 59 | std::map<base::FilePath, std::unique_ptr<BookmarkMenuBridge>> |
| 60 | profileBookmarkMenuBridgeMap_; |
lgarron | 9e6dee2 | 2014-11-18 01:03:39 | [diff] [blame] | 61 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 62 | std::unique_ptr<HistoryMenuBridge> historyMenuBridge_; |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 63 | |
[email protected] | edb2d03 | 2013-08-30 09:03:17 | [diff] [blame] | 64 | // Controller that manages main menu items for packaged apps. |
| 65 | base::scoped_nsobject<AppShimMenuController> appShimMenuController_; |
| 66 | |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 67 | // The profile menu, which appears right before the Help menu. It is only |
| 68 | // available when multiple profiles is enabled. |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 69 | base::scoped_nsobject<ProfileMenuController> profileMenuController_; |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 70 | |
Leonard Grey | 2bdd08f | 2017-10-03 18:40:52 | [diff] [blame] | 71 | // Controller for the macOS system share menu. |
| 72 | base::scoped_nsobject<ShareMenuController> shareMenuController_; |
| 73 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 74 | // 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] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 76 | // |startupUrls_| so that they can go in the first browser window/tab. |
| 77 | std::vector<GURL> startupUrls_; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 78 | BOOL startupComplete_; |
[email protected] | 1c84c82c | 2009-07-27 15:37:25 | [diff] [blame] | 79 | |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 80 | // 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 Sesek | 705c380 | 2018-10-24 20:58:42 | [diff] [blame] | 83 | NSMenuItem* closeTabMenuItem_; |
| 84 | NSMenuItem* closeWindowMenuItem_; |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 85 | |
[email protected] | d4c811e7 | 2013-10-29 21:57:55 | [diff] [blame] | 86 | // 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 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 90 | std::unique_ptr<PrefChangeRegistrar> profilePrefRegistrar_; |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 91 | PrefChangeRegistrar localPrefRegistrar_; |
[email protected] | 425f7a0 | 2014-04-29 01:51:44 | [diff] [blame] | 92 | |
| 93 | // Displays a notification when quitting while apps are running. |
| 94 | scoped_refptr<QuitWithAppsController> quitWithAppsController_; |
erikchen | 600f796 | 2014-12-12 00:17:38 | [diff] [blame] | 95 | |
| 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. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 100 | std::unique_ptr<HandoffActiveURLObserverBridge> |
erikchen | 600f796 | 2014-12-12 00:17:38 | [diff] [blame] | 101 | handoff_active_url_observer_bridge_; |
jochen | bf942015 | 2015-01-13 14:12:57 | [diff] [blame] | 102 | |
| 103 | // This will be true after receiving a NSWorkspaceWillPowerOffNotification. |
| 104 | BOOL isPoweringOff_; |
dgn | 0237778 | 2016-03-12 00:58:38 | [diff] [blame] | 105 | |
| 106 | // Request to keep the browser alive during that object's lifetime. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 107 | std::unique_ptr<ScopedKeepAlive> keep_alive_; |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 110 | @property(readonly, nonatomic) BOOL startupComplete; |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 111 | @property(readonly, nonatomic) Profile* lastProfile; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 112 | |
Robert Sesek | 124f80f9 | 2018-07-24 20:31:29 | [diff] [blame] | 113 | // This method is called very early in application startup after the main menu |
| 114 | // has been created. |
| 115 | - (void)mainMenuCreated; |
| 116 | |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 117 | - (void)didEndMainMessageLoop; |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 118 | |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 119 | // 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 Drissman | f19bb47 | 2018-11-29 19:51:28 | [diff] [blame] | 126 | // Run the quit confirmation panel and return whether or not to continue |
| 127 | // quitting. |
| 128 | - (BOOL)runConfirmQuitPanel; |
| 129 | |
jochen | bf942015 | 2015-01-13 14:12:57 | [diff] [blame] | 130 | // Indicate that the system is powering off or logging out. |
| 131 | - (void)willPowerOff:(NSNotification*)inNotification; |
| 132 | |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 133 | // Returns true if there is a modal window (either window- or application- |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 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. |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 137 | - (BOOL)keyWindowIsModal; |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 138 | |
tapted | 676995d | 2016-04-18 11:32:29 | [diff] [blame] | 139 | // 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] | 3111f08b | 2009-04-30 16:01:52 | [diff] [blame] | 146 | // Show the preferences window, or bring it to the front if it's already |
| 147 | // visible. |
| 148 | - (IBAction)showPreferences:(id)sender; |
| 149 | |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 150 | // Redirect in the menu item from the expected target of "File's |
[email protected] | 1c62b2f | 2013-06-28 00:15:00 | [diff] [blame] | 151 | // Owner" (NSApplication) for a Branded About Box |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 152 | - (IBAction)orderFrontStandardAboutPanel:(id)sender; |
| 153 | |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 154 | // Toggles the "Confirm to Quit" preference. |
| 155 | - (IBAction)toggleConfirmToQuit:(id)sender; |
| 156 | |
[email protected] | b01e756 | 2009-09-15 23:18:07 | [diff] [blame] | 157 | // Delegate method to return the dock menu. |
| 158 | - (NSMenu*)applicationDockMenu:(NSApplication*)sender; |
| 159 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 160 | // Get the URLs that Launch Services expects the browser to open at startup. |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 161 | - (const std::vector<GURL>&)startupUrls; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 162 | |
[email protected] | 7e4c69d0 | 2011-05-11 22:16:47 | [diff] [blame] | 163 | - (BookmarkMenuBridge*)bookmarkMenuBridge; |
mlerman | 8ae56aa | 2015-04-24 13:56:27 | [diff] [blame] | 164 | - (HistoryMenuBridge*)historyMenuBridge; |
[email protected] | 7e4c69d0 | 2011-05-11 22:16:47 | [diff] [blame] | 165 | |
[email protected] | e7dc399 | 2013-11-06 02:16:42 | [diff] [blame] | 166 | // Initializes the AppShimMenuController. This enables changing the menu bar for |
| 167 | // apps. |
| 168 | - (void)initAppShimMenuController; |
| 169 | |
noms | dd5b6a61 | 2014-09-23 15:20:16 | [diff] [blame] | 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; |
| 175 | |
erikchen | 22be209 | 2018-06-12 15:54:00 | [diff] [blame] | 176 | // 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] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 183 | @end |
| 184 | |
[email protected] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 185 | #endif // __OBJC__ |
| 186 | |
| 187 | // Functions that may be accessed from non-Objective-C C/C++ code. |
| 188 | |
| 189 | namespace 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. |
| 194 | bool IsOpeningNewWindow(); |
| 195 | |
Elly Fong-Jones | 68b85b8 | 2018-04-21 00:36:54 | [diff] [blame] | 196 | // Create a guest profile if one is needed. Afterwards, even if the profile |
| 197 | // already existed, notify the AppController of the profile in use. |
| 198 | void CreateGuestProfileIfNeeded(); |
| 199 | |
Owen Min | 3bcf8d15 | 2018-07-16 16:50:39 | [diff] [blame] | 200 | // Called when Enterprise startup dialog is close and repost |
| 201 | // applicationDidFinished notification. |
| 202 | void EnterpriseStartupDialogClosed(); |
| 203 | |
[email protected] | eddcf750 | 2012-02-09 22:43:48 | [diff] [blame] | 204 | } // namespace app_controller_mac |
| 205 | |
michaelpg | 33eea59 | 2017-01-19 01:34:56 | [diff] [blame] | 206 | #endif // CHROME_BROWSER_APP_CONTROLLER_MAC_H_ |