15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_APP_CONTROLLER_MAC_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_APP_CONTROLLER_MAC_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__OBJC__)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_change_registrar.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/time/time.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/work_area_watcher_observer.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass AppControllerProfileObserver;
21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)@class AppShimMenuController;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BookmarkMenuBridge;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CommandUpdater;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HistoryMenuBridge;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class ProfileMenuController;
285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass QuitWithAppsController;
295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WorkAreaWatcherObserver;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The application controller object, created by loading the MainMenu nib.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This handles things like responding to menus when there are no windows
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// open, etc and acts as the NSApplication delegate.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface AppController : NSObject<NSUserInterfaceValidations,
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    NSApplicationDelegate> {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Manages the state of the command menu items.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<CommandUpdater> menuState_;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The profile last used by a Browser. It is this profile that was used to
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // build the user-data specific main menu items.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Profile* lastProfile_;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // The ProfileObserver observes the ProfileInfoCache and gets notified
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // when a profile has been deleted.
49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<AppControllerProfileObserver> profileInfoCacheObserver_;
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Management of the bookmark menu which spans across all windows
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (and Browser*s).
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<HistoryMenuBridge> historyMenuBridge_;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Controller that manages main menu items for packaged apps.
57424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  base::scoped_nsobject<AppShimMenuController> appShimMenuController_;
58424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The profile menu, which appears right before the Help menu. It is only
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // available when multiple profiles is enabled.
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<ProfileMenuController> profileMenuController_;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we're told to open URLs (in particular, via |-application:openFiles:| by
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Launch Services) before we've launched the browser, we queue them up in
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |startupUrls_| so that they can go in the first browser window/tab.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<GURL> startupUrls_;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL startupComplete_;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Outlets for the close tab/window menu items so that we can adjust the
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // commmand-key equivalent depending on the kind of window and how many
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // tabs it has.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IBOutlet NSMenuItem* closeTabMenuItem_;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IBOutlet NSMenuItem* closeWindowMenuItem_;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL fileMenuUpdatePending_;  // ensure we only do this once per notificaion.
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Outlet for the help menu so we can bless it so Cocoa adds the search item
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to it.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IBOutlet NSMenu* helpMenu_;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates wheter an NSPopover is currently being shown.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL hasPopover_;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // If we are expecting a workspace change in response to a reopen
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // event, the time we got the event. A null time otherwise.
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::TimeTicks reopenTime_;
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Observers that listen to the work area changes.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ObserverList<ui::WorkAreaWatcherObserver> workAreaChangeObservers_;
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<PrefChangeRegistrar> profilePrefRegistrar_;
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PrefChangeRegistrar localPrefRegistrar_;
925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Displays a notification when quitting while apps are running.
945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  scoped_refptr<QuitWithAppsController> quitWithAppsController_;
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@property(readonly, nonatomic) BOOL startupComplete;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@property(readonly, nonatomic) Profile* lastProfile;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)didEndMainMessageLoop;
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Try to close all browser windows, and if that succeeds then quit.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BOOL)tryToTerminateApplication:(NSApplication*)app;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Stop trying to terminate the application. That is, prevent the final browser
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// window closure from causing the application to quit.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)stopTryingToTerminateApplication:(NSApplication*)app;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns true if there is a modal window (either window- or application-
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// sheets) will not count as blocking the browser. But things like open/save
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// dialogs that are window modal will block the browser.
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)- (BOOL)keyWindowIsModal;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Show the preferences window, or bring it to the front if it's already
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// visible.
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (IBAction)showPreferences:(id)sender;
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Redirect in the menu item from the expected target of "File's
120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Owner" (NSApplication) for a Branded About Box
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (IBAction)orderFrontStandardAboutPanel:(id)sender;
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Toggles the "Confirm to Quit" preference.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (IBAction)toggleConfirmToQuit:(id)sender;
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Toggles the "Hide Notifications Icon" preference.
1275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu- (IBAction)toggleDisplayMessageCenter:(id)sender;
1285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Delegate method to return the dock menu.
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSMenu*)applicationDockMenu:(NSApplication*)sender;
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the URLs that Launch Services expects the browser to open at startup.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (const std::vector<GURL>&)startupUrls;
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BookmarkMenuBridge*)bookmarkMenuBridge;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Subscribes/unsubscribes from the work area change notification.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)addObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)removeObserverForWorkAreaChange:(ui::WorkAreaWatcherObserver*)observer;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Initializes the AppShimMenuController. This enables changing the menu bar for
142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// apps.
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)- (void)initAppShimMenuController;
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Called when the user has changed browser windows, meaning the backing profile
1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// may have changed. This can cause a rebuild of the user-data menus. This is a
1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// no-op if the new profile is the same as the current one. This will always be
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// the original profile and never incognito.
1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (void)windowChangedToProfile:(Profile*)profile;
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // __OBJC__
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Functions that may be accessed from non-Objective-C C/C++ code.
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace app_controller_mac {
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SessionService::Observe() to get around windows/linux and mac having
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// different models of application lifetime.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsOpeningNewWindow();
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace app_controller_mac
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
167