Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / app_controller_mac.h
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.
4
5 #ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_
6 #define CHROME_BROWSER_APP_CONTROLLER_MAC_H_
7
8 #if defined(__OBJC__)
9
10 #import <Cocoa/Cocoa.h>
11 #include <vector>
12
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"
19
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;
29
30 namespace ui {
31 class WorkAreaWatcherObserver;
32 }
33
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_;
42
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_;
46
47   // The ProfileObserver observes the ProfileInfoCache and gets notified
48   // when a profile has been deleted.
49   scoped_ptr<AppControllerProfileObserver> profileInfoCacheObserver_;
50
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_;
55
56   // Controller that manages main menu items for packaged apps.
57   base::scoped_nsobject<AppShimMenuController> appShimMenuController_;
58
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_;
62
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_;
68
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.
75
76   // Outlet for the help menu so we can bless it so Cocoa adds the search item
77   // to it.
78   IBOutlet NSMenu* helpMenu_;
79
80   // Indicates wheter an NSPopover is currently being shown.
81   BOOL hasPopover_;
82
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_;
86
87   // Observers that listen to the work area changes.
88   ObserverList<ui::WorkAreaWatcherObserver> workAreaChangeObservers_;
89
90   scoped_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
91   PrefChangeRegistrar localPrefRegistrar_;
92
93   // Displays a notification when quitting while apps are running.
94   scoped_refptr<QuitWithAppsController> quitWithAppsController_;
95 }
96
97 @property(readonly, nonatomic) BOOL startupComplete;
98 @property(readonly, nonatomic) Profile* lastProfile;
99
100 - (void)didEndMainMessageLoop;
101
102 // Try to close all browser windows, and if that succeeds then quit.
103 - (BOOL)tryToTerminateApplication:(NSApplication*)app;
104
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;
108
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;
114
115 // Show the preferences window, or bring it to the front if it's already
116 // visible.
117 - (IBAction)showPreferences:(id)sender;
118
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;
122
123 // Toggles the "Confirm to Quit" preference.
124 - (IBAction)toggleConfirmToQuit:(id)sender;
125
126 // Toggles the "Hide Notifications Icon" preference.
127 - (IBAction)toggleDisplayMessageCenter:(id)sender;
128
129 // Delegate method to return the dock menu.
130 - (NSMenu*)applicationDockMenu:(NSApplication*)sender;
131
132 // Get the URLs that Launch Services expects the browser to open at startup.
133 - (const std::vector<GURL>&)startupUrls;
134
135 - (BookmarkMenuBridge*)bookmarkMenuBridge;
136
137 // Subscribes/unsubscribes from the work area change notification.
138 - (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
139 - (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
140
141 // Initializes the AppShimMenuController. This enables changing the menu bar for
142 // apps.
143 - (void)initAppShimMenuController;
144
145 // Called when the user has changed browser windows, meaning the backing profile
146 // may have changed. This can cause a rebuild of the user-data menus. This is a
147 // no-op if the new profile is the same as the current one. This will always be
148 // the original profile and never incognito.
149 - (void)windowChangedToProfile:(Profile*)profile;
150
151 @end
152
153 #endif  // __OBJC__
154
155 // Functions that may be accessed from non-Objective-C C/C++ code.
156
157 namespace app_controller_mac {
158
159 // True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
160 // SessionService::Observe() to get around windows/linux and mac having
161 // different models of application lifetime.
162 bool IsOpeningNewWindow();
163
164 }  // namespace app_controller_mac
165
166 #endif