[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / app_controller_mac.h
blob7707f10b936e3a5f715ccf289fc74da009bd76c1
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_
6 #define CHROME_BROWSER_APP_CONTROLLER_MAC_H_
8 #if defined(__OBJC__)
10 #import <Cocoa/Cocoa.h>
11 #include <vector>
13 #include "base/mac/scoped_nsobject.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/prefs/pref_change_registrar.h"
17 #include "base/time/time.h"
18 #include "ui/base/work_area_watcher_observer.h"
20 class AppControllerProfileObserver;
21 @class AppShimMenuController;
22 class BookmarkMenuBridge;
23 class CommandUpdater;
24 class GURL;
25 class HistoryMenuBridge;
26 class Profile;
27 @class ProfileMenuController;
28 class QuitWithAppsController;
30 namespace ui {
31 class WorkAreaWatcherObserver;
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.
37 @interface AppController : NSObject<NSUserInterfaceValidations,
38 NSApplicationDelegate> {
39 @private
40 // Manages the state of the command menu items.
41 scoped_ptr<CommandUpdater> menuState_;
43 // The profile last used by a Browser. It is this profile that was used to
44 // build the user-data specific main menu items.
45 Profile* lastProfile_;
47 // The ProfileObserver observes the ProfileInfoCache and gets notified
48 // when a profile has been deleted.
49 scoped_ptr<AppControllerProfileObserver> profileInfoCacheObserver_;
51 // Management of the bookmark menu which spans across all windows
52 // (and Browser*s).
53 scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_;
54 scoped_ptr<HistoryMenuBridge> historyMenuBridge_;
56 // Controller that manages main menu items for packaged apps.
57 base::scoped_nsobject<AppShimMenuController> appShimMenuController_;
59 // The profile menu, which appears right before the Help menu. It is only
60 // available when multiple profiles is enabled.
61 base::scoped_nsobject<ProfileMenuController> profileMenuController_;
63 // If we're told to open URLs (in particular, via |-application:openFiles:| by
64 // Launch Services) before we've launched the browser, we queue them up in
65 // |startupUrls_| so that they can go in the first browser window/tab.
66 std::vector<GURL> startupUrls_;
67 BOOL startupComplete_;
69 // Outlets for the close tab/window menu items so that we can adjust the
70 // commmand-key equivalent depending on the kind of window and how many
71 // tabs it has.
72 IBOutlet NSMenuItem* closeTabMenuItem_;
73 IBOutlet NSMenuItem* closeWindowMenuItem_;
74 BOOL fileMenuUpdatePending_; // ensure we only do this once per notificaion.
76 // Outlet for the help menu so we can bless it so Cocoa adds the search item
77 // to it.
78 IBOutlet NSMenu* helpMenu_;
80 // Indicates wheter an NSPopover is currently being shown.
81 BOOL hasPopover_;
83 // If we are expecting a workspace change in response to a reopen
84 // event, the time we got the event. A null time otherwise.
85 base::TimeTicks reopenTime_;
87 // Observers that listen to the work area changes.
88 ObserverList<ui::WorkAreaWatcherObserver> workAreaChangeObservers_;
90 scoped_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
91 PrefChangeRegistrar localPrefRegistrar_;
93 // Displays a notification when quitting while apps are running.
94 scoped_refptr<QuitWithAppsController> quitWithAppsController_;
97 @property(readonly, nonatomic) BOOL startupComplete;
98 @property(readonly, nonatomic) Profile* lastProfile;
100 - (void)didEndMainMessageLoop;
102 // Try to close all browser windows, and if that succeeds then quit.
103 - (BOOL)tryToTerminateApplication:(NSApplication*)app;
105 // Stop trying to terminate the application. That is, prevent the final browser
106 // window closure from causing the application to quit.
107 - (void)stopTryingToTerminateApplication:(NSApplication*)app;
109 // Returns true if there is a modal window (either window- or application-
110 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
111 // sheets) will not count as blocking the browser. But things like open/save
112 // dialogs that are window modal will block the browser.
113 - (BOOL)keyWindowIsModal;
115 // Show the preferences window, or bring it to the front if it's already
116 // visible.
117 - (IBAction)showPreferences:(id)sender;
119 // Redirect in the menu item from the expected target of "File's
120 // Owner" (NSApplication) for a Branded About Box
121 - (IBAction)orderFrontStandardAboutPanel:(id)sender;
123 // Toggles the "Confirm to Quit" preference.
124 - (IBAction)toggleConfirmToQuit:(id)sender;
126 // Toggles the "Hide Notifications Icon" preference.
127 - (IBAction)toggleDisplayMessageCenter:(id)sender;
129 // Delegate method to return the dock menu.
130 - (NSMenu*)applicationDockMenu:(NSApplication*)sender;
132 // Get the URLs that Launch Services expects the browser to open at startup.
133 - (const std::vector<GURL>&)startupUrls;
135 - (BookmarkMenuBridge*)bookmarkMenuBridge;
137 // Subscribes/unsubscribes from the work area change notification.
138 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
139 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
141 // Initializes the AppShimMenuController. This enables changing the menu bar for
142 // apps.
143 - (void)initAppShimMenuController;
145 @end
147 #endif // __OBJC__
149 // Functions that may be accessed from non-Objective-C C/C++ code.
151 namespace app_controller_mac {
153 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
154 // SessionService::Observe() to get around windows/linux and mac having
155 // different models of application lifetime.
156 bool IsOpeningNewWindow();
158 } // namespace app_controller_mac
160 #endif