[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / app_controller_mac.h
1 // Copyright 2012 The Chromium Authors
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
8 #include "base/memory/raw_ptr.h"
9 #include "base/scoped_observation.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/sessions/core/session_id.h"
12 #include "components/sessions/core/tab_restore_service.h"
13 #include "components/sessions/core/tab_restore_service_observer.h"
14
15 #if defined(__OBJC__)
16
17 #import <AuthenticationServices/AuthenticationServices.h>
18 #import <Cocoa/Cocoa.h>
19
20 #include <memory>
21 #include <vector>
22
23 #include "base/files/file_path.h"
24 #include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
25 #include "components/prefs/pref_change_registrar.h"
26
27 class BookmarkMenuBridge;
28 class GURL;
29 class HistoryMenuBridge;
30 class Profile;
31 class TabMenuBridge;
32
33 namespace ui {
34 class ColorProvider;
35 }  // namespace ui
36
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
41     : NSObject <NSUserInterfaceValidations,
42                 NSMenuDelegate,
43                 NSApplicationDelegate,
44                 ASWebAuthenticationSessionWebBrowserSessionHandling>
45
46 // The app-wide singleton AppController. Guaranteed to be the delegate of NSApp
47 // inside of Chromium (not inside of app shims; see AppShimDelegate). Guaranteed
48 // to not be nil.
49 @property(readonly, nonatomic, class) AppController* sharedController;
50
51 @property(readonly, nonatomic) BOOL startupComplete;
52 @property(readonly, nonatomic) Profile* lastProfileIfLoaded;
53
54 // DEPRECATED: use lastProfileIfLoaded instead.
55 // TODO(https://crbug.com/1176734): May be blocking, migrate all callers to
56 // |-lastProfileIfLoaded|.
57 @property(readonly, nonatomic) Profile* lastProfile;
58
59 // Do not create new instances of AppController; use the `sharedController`
60 // property so that the invariants of there always being exactly one
61 // AppController and that that instance is the NSApp delegate always hold true.
62 - (instancetype)init NS_UNAVAILABLE;
63
64 // This method is called very early in application startup after the main menu
65 // has been created.
66 - (void)mainMenuCreated;
67
68 - (void)didEndMainMessageLoop;
69
70 // Try to close all browser windows, and if that succeeds then quit.
71 - (BOOL)tryToTerminateApplication:(NSApplication*)app;
72
73 // Stop trying to terminate the application. That is, prevent the final browser
74 // window closure from causing the application to quit.
75 - (void)stopTryingToTerminateApplication:(NSApplication*)app;
76
77 // Run the quit confirmation panel and return whether or not to continue
78 // quitting.
79 - (BOOL)runConfirmQuitPanel;
80
81 // Indicate that the system is powering off or logging out.
82 - (void)willPowerOff:(NSNotification*)inNotification;
83
84 // Returns true if there is a modal window (either window- or application-
85 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
86 // sheets) will not count as blocking the browser. But things like open/save
87 // dialogs that are window modal will block the browser.
88 - (BOOL)keyWindowIsModal;
89
90 // Called when the user picks a menu item when there are no key windows, or when
91 // there is no foreground browser window. Calls through to the browser object to
92 // execute the command. This assumes that the command is supported and doesn't
93 // check, otherwise it should have been disabled in the UI in
94 // |-validateUserInterfaceItem:|.
95 - (void)commandDispatch:(id)sender;
96
97 // Helper function called by -commandDispatch:, to actually execute the command.
98 // This runs after -commandDispatch: has obtained a pointer to the last Profile
99 // (which possibly requires an async Profile load).
100 - (void)executeCommand:(id)sender withProfile:(Profile*)profile;
101
102 // Show the preferences window, or bring it to the front if it's already
103 // visible.
104 - (IBAction)showPreferences:(id)sender;
105 - (IBAction)showPreferencesForProfile:(Profile*)profile;
106
107 // Redirect in the menu item from the expected target of "File's
108 // Owner" (NSApplication) for a Branded About Box
109 - (IBAction)orderFrontStandardAboutPanel:(id)sender;
110 - (IBAction)orderFrontStandardAboutPanelForProfile:(Profile*)profile;
111
112 // Toggles the "Confirm to Quit" preference.
113 - (IBAction)toggleConfirmToQuit:(id)sender;
114
115 // Delegate method to return the dock menu.
116 - (NSMenu*)applicationDockMenu:(NSApplication*)sender;
117
118 // Get the URLs that Launch Services expects the browser to open at startup.
119 - (const std::vector<GURL>&)startupUrls;
120
121 - (BookmarkMenuBridge*)bookmarkMenuBridge;
122 - (HistoryMenuBridge*)historyMenuBridge;
123 - (TabMenuBridge*)tabMenuBridge;
124
125 // Initializes the AppShimMenuController. This enables changing the menu bar for
126 // apps.
127 - (void)initAppShimMenuController;
128
129 // Called when the user has changed browser windows, meaning the backing profile
130 // may have changed. This can cause a rebuild of the user-data menus. This is a
131 // no-op if the new profile is the same as the current one. This can be either
132 // the original or the incognito profile.
133 - (void)setLastProfile:(Profile*)profile;
134
135 // Returns the last active ColorProvider.
136 - (const ui::ColorProvider&)lastActiveColorProvider;
137
138 // This is called when the system wide light or dark mode changes.
139 - (void)nativeThemeDidChange;
140
141 // Certain NSMenuItems [Close Tab and Close Window] have different
142 // keyEquivalents depending on context. This must be invoked in two locations:
143 //   * In menuNeedsUpdate:, which is called prior to showing the NSMenu.
144 //   * In CommandDispatcher, which independently searches for a matching
145 //     keyEquivalent.
146 - (void)updateMenuItemKeyEquivalents;
147
148 // Returns YES if `window` is a normal, tabbed, non-app browser window.
149 // Serves as a swizzle point for unit tests to avoid creating Browser
150 // instances.
151 - (BOOL)windowHasBrowserTabs:(NSWindow*)window;
152
153 // Testing API.
154 - (void)setCloseWindowMenuItemForTesting:(NSMenuItem*)menuItem;
155 - (void)setCloseTabMenuItemForTesting:(NSMenuItem*)menuItem;
156 - (void)setLastProfileForTesting:(Profile*)profile;
157
158 @end
159
160 #endif  // __OBJC__
161
162 // Functions that may be accessed from non-Objective-C C/C++ code.
163
164 namespace app_controller_mac {
165
166 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
167 // SessionService::Observe() to get around windows/linux and mac having
168 // different models of application lifetime.
169 bool IsOpeningNewWindow();
170
171 // Create a guest profile if one is needed. Afterwards, even if the profile
172 // already existed, notify the AppController of the profile in use.
173 void CreateGuestProfileIfNeeded();
174
175 // Called when Enterprise startup dialog is close and repost
176 // applicationDidFinished notification.
177 void EnterpriseStartupDialogClosed();
178
179 // Tells RunInSafeProfile() or RunInSpecificSafeProfile() what to do if the
180 // profile cannot be loaded from disk.
181 enum ProfileLoadFailureBehavior {
182   // Silently fail, and run |callback| with nullptr.
183   kIgnoreOnFailure,
184   // Show the profile picker, and run |callback| with nullptr.
185   kShowProfilePickerOnFailure,
186 };
187
188 // Tries to load the profile returned by |-safeProfileForNewWindows:|. If it
189 // succeeds, calls |callback| with it.
190 //
191 // |callback| must be valid.
192 void RunInLastProfileSafely(base::OnceCallback<void(Profile*)> callback,
193                             ProfileLoadFailureBehavior on_failure);
194
195 // Tries to load the profile in |profile_dir|. If it succeeds, calls
196 // |callback| with it. If the profile was already loaded, |callback| runs
197 // immediately.
198 //
199 // |callback| must be valid.
200 void RunInProfileSafely(const base::FilePath& profile_dir,
201                         base::OnceCallback<void(Profile*)> callback,
202                         ProfileLoadFailureBehavior on_failure);
203
204 // Waits for the TabRestoreService to have loaded its entries, then calls
205 // OpenWindowWithRestoredTabs().
206 //
207 // Owned by itself.
208 class TabRestorer : public sessions::TabRestoreServiceObserver {
209  public:
210   // Restore the most recent tab in |profile|, e.g. for Cmd+Shift+T.
211   static void RestoreMostRecent(Profile* profile);
212
213   // Restore a specific tab in |profile|, e.g. for a History menu item.
214   // |session_id| can be a |TabRestoreService::Entry::id|, or a
215   // |TabRestoreEntryService::Entry::original_id|.
216   static void RestoreByID(Profile* profile, SessionID session_id);
217
218   ~TabRestorer() override;
219
220   // sessions::TabRestoreServiceObserver:
221   void TabRestoreServiceDestroyed(
222       sessions::TabRestoreService* service) override;
223   void TabRestoreServiceLoaded(sessions::TabRestoreService* service) override;
224
225  private:
226   TabRestorer(Profile* profile, SessionID session_id);
227
228   // Performs the tab restore. Called either in TabRestoreServiceLoaded(), or
229   // directly from RestoreMostRecent()/RestoreByID() if the service was already
230   // loaded.
231   static void DoRestoreTab(Profile* profile, SessionID session_id);
232
233   base::ScopedObservation<sessions::TabRestoreService,
234                           sessions::TabRestoreServiceObserver>
235       observation_{this};
236   raw_ptr<Profile> profile_;
237   SessionID session_id_;
238 };
239
240 }  // namespace app_controller_mac
241
242 #endif  // CHROME_BROWSER_APP_CONTROLLER_MAC_H_