blob: 6c8a9f19d26fa63f443eb3be4b61c58bb9372f9d [file] [log] [blame]
[email protected]7dc8c6b2010-04-09 17:02:501// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]1bcdb532009-01-16 17:47:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]2c47bc12009-04-10 20:14:005#import "chrome/browser/app_controller_mac.h"
[email protected]1bcdb532009-01-16 17:47:576
[email protected]0ccf4612010-07-31 07:11:367#include "app/l10n_util.h"
[email protected]288bfcd32009-09-14 18:14:468#include "app/l10n_util_mac.h"
[email protected]d630d7d52010-02-21 00:55:119#include "base/auto_reset.h"
[email protected]57750f822009-04-21 21:43:0910#include "base/command_line.h"
[email protected]f805fe82010-08-03 22:47:1011#include "base/file_path.h"
[email protected]09729a552009-08-03 23:21:4112#include "base/mac_util.h"
[email protected]2c47bc12009-04-10 20:14:0013#include "base/message_loop.h"
[email protected]528c56d2010-07-30 19:28:4414#include "base/string_number_conversions.h"
[email protected]57750f822009-04-21 21:43:0915#include "base/sys_string_conversions.h"
[email protected]56fedfa2010-11-05 23:15:5816#import "base/worker_pool_mac.h"
[email protected]1a3aba82010-11-08 23:52:5417#include "chrome/app/chrome_command_ids.h"
[email protected]2c47bc12009-04-10 20:14:0018#include "chrome/browser/browser.h"
[email protected]57750f822009-04-21 21:43:0919#include "chrome/browser/browser_init.h"
[email protected]2c47bc12009-04-10 20:14:0020#include "chrome/browser/browser_list.h"
[email protected]5c238752009-06-13 10:29:0721#include "chrome/browser/browser_process.h"
[email protected]41741a962009-02-18 21:51:3922#include "chrome/browser/browser_shutdown.h"
[email protected]ed7e6dd2010-10-12 02:02:4523#include "chrome/browser/browser_thread.h"
[email protected]ce560f82009-06-03 09:39:4424#include "chrome/browser/browser_window.h"
[email protected]bde3dda2009-05-20 22:13:0725#import "chrome/browser/cocoa/about_window_controller.h"
[email protected]421fb792010-10-15 21:16:3126#import "chrome/browser/cocoa/bookmarks/bookmark_menu_bridge.h"
[email protected]a9e8afc2009-08-11 22:03:1727#import "chrome/browser/cocoa/browser_window_cocoa.h"
28#import "chrome/browser/cocoa/browser_window_controller.h"
[email protected]3896b182009-11-03 16:15:3229#import "chrome/browser/cocoa/bug_report_window_controller.h"
[email protected]93e181762009-05-29 14:30:3830#import "chrome/browser/cocoa/clear_browsing_data_controller.h"
[email protected]177aceb2010-11-03 16:17:4131#import "chrome/browser/cocoa/confirm_quit_panel_controller.h"
[email protected]2bcec612009-05-14 17:50:5332#import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h"
[email protected]4aee5652009-11-19 18:59:2133#import "chrome/browser/cocoa/history_menu_bridge.h"
34#import "chrome/browser/cocoa/import_settings_dialog.h"
[email protected]42404382009-04-30 17:59:2435#import "chrome/browser/cocoa/preferences_window_controller.h"
[email protected]449dd2f2009-05-27 13:04:0036#import "chrome/browser/cocoa/tab_strip_controller.h"
37#import "chrome/browser/cocoa/tab_window_controller.h"
[email protected]ceaaf1812010-01-20 22:13:0938#include "chrome/browser/cocoa/task_manager_mac.h"
[email protected]2c47bc12009-04-10 20:14:0039#include "chrome/browser/command_updater.h"
[email protected]09729a552009-08-03 23:21:4140#include "chrome/browser/download/download_manager.h"
[email protected]4aee5652009-11-19 18:59:2141#include "chrome/browser/metrics/user_metrics.h"
[email protected]60ad3e22009-09-18 21:07:1942#include "chrome/browser/options_window.h"
[email protected]37858e52010-08-26 00:22:0243#include "chrome/browser/prefs/pref_service.h"
[email protected]e7dd6d82010-10-07 23:21:1244#include "chrome/browser/printing/print_job_manager.h"
[email protected]052313b2010-02-19 09:43:0845#include "chrome/browser/profile_manager.h"
[email protected]fbc947b2009-06-19 13:28:2446#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f9bc9b92009-11-24 00:55:3547#include "chrome/browser/sync/profile_sync_service.h"
[email protected]40f047972009-11-25 03:54:4048#include "chrome/browser/sync/sync_ui_util.h"
49#include "chrome/browser/sync/sync_ui_util_mac.h"
[email protected]60ad3e22009-09-18 21:07:1950#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]646b9b92010-04-30 21:51:5851#include "chrome/common/app_mode_common_mac.h"
[email protected]12dc3d42010-02-22 23:37:1252#include "chrome/common/chrome_paths_internal.h"
[email protected]f4acfae82009-09-11 00:33:3853#include "chrome/common/chrome_switches.h"
[email protected]a96ec6a2009-11-04 17:27:0854#include "chrome/common/notification_service.h"
[email protected]cd63ef62009-05-06 19:41:3755#include "chrome/common/pref_names.h"
[email protected]024617a2010-08-20 05:08:0556#include "chrome/common/url_constants.h"
[email protected]9dcb59662009-09-23 01:15:5057#include "grit/chromium_strings.h"
[email protected]09729a552009-08-03 23:21:4158#include "grit/generated_resources.h"
[email protected]caadfca2010-01-22 21:51:2159#include "net/base/net_util.h"
[email protected]88d74942009-01-21 22:04:4460
[email protected]f2c20fa2009-12-01 17:42:0261// 10.6 adds a public API for the Spotlight-backed search menu item in the Help
62// menu. Provide the declaration so it can be called below when building with
63// the 10.5 SDK.
64#if !defined(MAC_OS_X_VERSION_10_6) || \
65 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
66@interface NSApplication (SnowLeopardSDKDeclarations)
[email protected]caadfca2010-01-22 21:51:2167- (void)setHelpMenu:(NSMenu*)helpMenu;
[email protected]f2c20fa2009-12-01 17:42:0268@end
69#endif
70
[email protected]d630d7d52010-02-21 00:55:1171namespace {
72
73// True while AppController is calling Browser::OpenEmptyWindow(). We need a
74// global flag here, analogue to BrowserInit::InProcessStartup() because
75// otherwise the SessionService will try to restore sessions when we make a new
76// window while there are no other active windows.
77bool g_is_opening_new_window = false;
78
79// Activates a browser window having the given profile (the last one active) if
80// possible and returns a pointer to the activate |Browser| or NULL if this was
81// not possible. If the last active browser is minimized (in particular, if
82// there are only minimized windows), it will unminimize it.
83Browser* ActivateBrowser(Profile* profile) {
84 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
85 if (browser)
86 browser->window()->Activate();
87 return browser;
88}
89
90// Creates an empty browser window with the given profile and returns a pointer
91// to the new |Browser|.
92Browser* CreateBrowser(Profile* profile) {
93 {
[email protected]0fbd70332010-06-01 19:28:3494 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
[email protected]d630d7d52010-02-21 00:55:1195 Browser::OpenEmptyWindow(profile);
96 }
97
98 Browser* browser = BrowserList::GetLastActive();
99 CHECK(browser);
100 return browser;
101}
102
103// Activates a browser window having the given profile (the last one active) if
104// possible or creates an empty one if necessary. Returns a pointer to the
105// activated/new |Browser|.
106Browser* ActivateOrCreateBrowser(Profile* profile) {
107 if (Browser* browser = ActivateBrowser(profile))
108 return browser;
109 return CreateBrowser(profile);
110}
111
[email protected]12dc3d42010-02-22 23:37:12112// This task synchronizes preferences (under "org.chromium.Chromium" or
113// "com.google.Chrome"), in particular, writes them out to disk.
114class PrefsSyncTask : public Task {
115 public:
116 PrefsSyncTask() {}
117 virtual ~PrefsSyncTask() {}
118 virtual void Run() {
119 if (!CFPreferencesAppSynchronize(app_mode::kAppPrefsID))
120 LOG(WARNING) << "Error recording application bundle path.";
121 }
122};
123
124// Record the location of the application bundle (containing the main framework)
125// from which Chromium was loaded. This is used by app mode shims to find
126// Chromium.
127void RecordLastRunAppBundlePath() {
128 // Going up three levels from |chrome::GetVersionedDirectory()| gives the
129 // real, user-visible app bundle directory. (The alternatives give either the
130 // framework's path or the initial app's path, which may be an app mode shim
131 // or a unit test.)
132 FilePath appBundlePath =
133 chrome::GetVersionedDirectory().DirName().DirName().DirName();
134 CFPreferencesSetAppValue(app_mode::kLastRunAppBundlePathPrefsKey,
135 base::SysUTF8ToCFStringRef(appBundlePath.value()),
136 app_mode::kAppPrefsID);
137
138 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty.
[email protected]d04e7662010-10-10 22:24:48139 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
140 new PrefsSyncTask(), 1500);
[email protected]12dc3d42010-02-22 23:37:12141}
142
[email protected]d630d7d52010-02-21 00:55:11143} // anonymous namespace
144
145@interface AppController(Private)
[email protected]88d74942009-01-21 22:04:44146- (void)initMenuState;
[email protected]eef99c22010-08-17 05:55:16147- (void)registerServicesMenuTypesTo:(NSApplication*)app;
[email protected]d630d7d52010-02-21 00:55:11148- (void)openUrls:(const std::vector<GURL>&)urls;
[email protected]57750f822009-04-21 21:43:09149- (void)getUrl:(NSAppleEventDescriptor*)event
150 withReply:(NSAppleEventDescriptor*)reply;
[email protected]449dd2f2009-05-27 13:04:00151- (void)windowLayeringDidChange:(NSNotification*)inNotification;
[email protected]dd6ab1282010-07-20 01:07:32152- (void)checkForAnyKeyWindows;
[email protected]73f5b362009-08-10 23:58:21153- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
[email protected]09729a552009-08-03 23:21:41154- (BOOL)shouldQuitWithInProgressDownloads;
[email protected]d989f07c2009-11-14 00:35:46155- (void)showPreferencesWindow:(id)sender
156 page:(OptionsPage)page
157 profile:(Profile*)profile;
[email protected]88d74942009-01-21 22:04:44158@end
[email protected]1bcdb532009-01-16 17:47:57159
160@implementation AppController
161
[email protected]caadfca2010-01-22 21:51:21162@synthesize startupComplete = startupComplete_;
163
[email protected]cd63ef62009-05-06 19:41:37164// This method is called very early in application startup (ie, before
165// the profile is loaded or any preferences have been registered). Defer any
166// user-data initialization until -applicationDidFinishLaunching:.
[email protected]88d74942009-01-21 22:04:44167- (void)awakeFromNib {
[email protected]136140c2009-05-19 13:58:25168 // We need to register the handlers early to catch events fired on launch.
[email protected]57750f822009-04-21 21:43:09169 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
170 [em setEventHandler:self
171 andSelector:@selector(getUrl:withReply:)
172 forEventClass:kInternetEventClass
173 andEventID:kAEGetURL];
174 [em setEventHandler:self
175 andSelector:@selector(getUrl:withReply:)
176 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates
177 andEventID:'OURL']; // back to the Spyglass days.
[email protected]cd63ef62009-05-06 19:41:37178
[email protected]449dd2f2009-05-27 13:04:00179 // Register for various window layering changes. We use these to update
180 // various UI elements (command-key equivalents, etc) when the frontmost
181 // window changes.
182 NSNotificationCenter* notificationCenter =
183 [NSNotificationCenter defaultCenter];
[email protected]ce560f82009-06-03 09:39:44184 [notificationCenter
[email protected]449dd2f2009-05-27 13:04:00185 addObserver:self
186 selector:@selector(windowLayeringDidChange:)
187 name:NSWindowDidBecomeKeyNotification
188 object:nil];
189 [notificationCenter
190 addObserver:self
191 selector:@selector(windowLayeringDidChange:)
192 name:NSWindowDidResignKeyNotification
193 object:nil];
194 [notificationCenter
195 addObserver:self
196 selector:@selector(windowLayeringDidChange:)
197 name:NSWindowDidBecomeMainNotification
198 object:nil];
199 [notificationCenter
200 addObserver:self
201 selector:@selector(windowLayeringDidChange:)
202 name:NSWindowDidResignMainNotification
203 object:nil];
204
205 // Register for a notification that the number of tabs changes in windows
206 // so we can adjust the close tab/window command keys.
207 [notificationCenter
208 addObserver:self
209 selector:@selector(tabsChanged:)
210 name:kTabStripNumberOfTabsChanged
211 object:nil];
212
[email protected]136140c2009-05-19 13:58:25213 // Set up the command updater for when there are no windows open
214 [self initMenuState];
[email protected]f4acfae82009-09-11 00:33:38215
216 // Activate (bring to foreground) if asked to do so. On
217 // Windows this logic isn't necessary since
218 // BrowserWindow::Activate() calls ::SetForegroundWindow() which is
219 // adequate. On Mac, BrowserWindow::Activate() calls -[NSWindow
220 // makeKeyAndOrderFront:] which does not activate the application
221 // itself.
222 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
223 if (parsed_command_line.HasSwitch(switches::kActivateOnLaunch)) {
224 [NSApp activateIgnoringOtherApps:YES];
225 }
[email protected]56fedfa2010-11-05 23:15:58226
227 // Temporary flag to revert to the old WorkerPool implementation.
228 // This will be removed once we either fix the Mac WorkerPool
229 // implementation, or completely switch to the shared (with Linux)
230 // implementation.
231 // http://crbug.com/44392
232 if (parsed_command_line.HasSwitch(switches::kDisableLinuxWorkerPool)) {
233 worker_pool_mac::SetUseLinuxWorkerPool(false);
234 }
[email protected]136140c2009-05-19 13:58:25235}
236
[email protected]7dc8c6b2010-04-09 17:02:50237// (NSApplicationDelegate protocol) This is the Apple-approved place to override
238// the default handlers.
239- (void)applicationWillFinishLaunching:(NSNotification*)notification {
[email protected]58877932010-05-25 05:43:11240 // Nothing here right now.
[email protected]7dc8c6b2010-04-09 17:02:50241}
242
243- (BOOL)tryToTerminateApplication:(NSApplication*)app {
[email protected]3076fad2010-04-28 18:11:45244 // Check for in-process downloads, and prompt the user if they really want
245 // to quit (and thus cancel downloads). Only check if we're not already
246 // shutting down, else the user might be prompted multiple times if the
247 // download isn't stopped before terminate is called again.
248 if (!browser_shutdown::IsTryingToQuit() &&
249 ![self shouldQuitWithInProgressDownloads])
250 return NO;
251
[email protected]7dc8c6b2010-04-09 17:02:50252 // TODO(viettrungluu): Remove Apple Event handlers here? (It's safe to leave
253 // them in, but I'm not sure about UX; we'd also want to disable other things
254 // though.) http://crbug.com/40861
255
[email protected]177aceb2010-11-03 16:17:41256 // Check if the user really wants to quit by employing the confirm-to-quit
257 // mechanism.
258 if (!browser_shutdown::IsTryingToQuit() &&
259 [self applicationShouldTerminate:app] != NSTerminateNow)
260 return NO;
261
[email protected]c984d9f2010-07-20 20:52:20262 size_t num_browsers = BrowserList::size();
[email protected]7dc8c6b2010-04-09 17:02:50263
[email protected]e7dd6d82010-10-07 23:21:12264 // Give any print jobs in progress time to finish.
265 if (!browser_shutdown::IsTryingToQuit())
266 g_browser_process->print_job_manager()->StopJobs(true);
267
[email protected]c984d9f2010-07-20 20:52:20268 // Initiate a shutdown (via BrowserList::CloseAllBrowsers()) if we aren't
269 // already shutting down.
270 if (!browser_shutdown::IsTryingToQuit())
[email protected]c6032e82010-09-13 20:06:05271 BrowserList::CloseAllBrowsers();
[email protected]7dc8c6b2010-04-09 17:02:50272
[email protected]c984d9f2010-07-20 20:52:20273 return num_browsers == 0 ? YES : NO;
[email protected]7dc8c6b2010-04-09 17:02:50274}
275
276- (void)stopTryingToTerminateApplication:(NSApplication*)app {
277 if (browser_shutdown::IsTryingToQuit()) {
278 // Reset the "trying to quit" state, so that closing all browser windows
279 // will no longer lead to termination.
280 browser_shutdown::SetTryingToQuit(false);
281
282 // TODO(viettrungluu): Were we to remove Apple Event handlers above, we
283 // would have to reinstall them here. http://crbug.com/40861
284 }
[email protected]a9e8afc2009-08-11 22:03:17285}
286
[email protected]177aceb2010-11-03 16:17:41287- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
288 // Check if the experiment is enabled.
289 const CommandLine* commandLine(CommandLine::ForCurrentProcess());
290 if (!commandLine->HasSwitch(switches::kEnableConfirmToQuit))
291 return NSTerminateNow;
292
293 // If the application is going to terminate as the result of a Cmd+Q
294 // invocation, use the special sauce to prevent accidental quitting.
295 // http://dev.chromium.org/developers/design-documents/confirm-to-quit-experiment
296 NSEvent* currentEvent = [app currentEvent];
297 if ([currentEvent type] == NSKeyDown) {
298 ConfirmQuitPanelController* quitPanel =
299 [[ConfirmQuitPanelController alloc] init]; // Releases self.
300 // Show the info panel that explains what the user must to do confirm quit.
301 [quitPanel showWindow:self];
302
303 // How long the user must hold down Cmd+Q to confirm the quit.
304 const NSTimeInterval kTimeToConfirmQuit = 1.5;
305 // Leeway between the |targetDate| and the current time that will confirm a
306 // quit.
307 const NSTimeInterval kTimeDeltaFuzzFactor = 1.0;
308 // Duration of the window fade out animation.
309 const NSTimeInterval kWindowFadeAnimationDuration = 0.2;
310
311 // Spin a nested run loop until the |targetDate| is reached or a KeyUp event
312 // is sent.
313 NSDate* targetDate =
314 [NSDate dateWithTimeIntervalSinceNow:kTimeToConfirmQuit];
315 BOOL willQuit = NO;
316 NSEvent* nextEvent = nil;
317 do {
318 // Dequeue events until a key up is received.
319 nextEvent = [app nextEventMatchingMask:NSKeyUpMask
320 untilDate:nil
321 inMode:NSEventTrackingRunLoopMode
322 dequeue:YES];
323
324 // Wait for the time expiry to happen. Once past the hold threshold,
325 // commit to quitting and hide all the open windows.
326 if (!willQuit) {
327 NSDate* now = [NSDate date];
328 NSTimeInterval difference = [targetDate timeIntervalSinceDate:now];
329 if (difference < kTimeDeltaFuzzFactor) {
330 willQuit = YES;
331
332 // At this point, the quit has been confirmed and windows should all
333 // fade out to convince the user to release the key combo to finalize
334 // the quit.
335 [NSAnimationContext beginGrouping];
336 [[NSAnimationContext currentContext] setDuration:
337 kWindowFadeAnimationDuration];
338 for (NSWindow* aWindow in [app windows]) {
339 // Windows that are set to animate and have a delegate do not
340 // expect to be animated by other things and could result in an
341 // invalid state. If a window is set up like so, just force the
342 // alpha value to 0. Otherwise, animate all pretty and stuff.
343 if (![[aWindow animationForKey:@"alphaValue"] delegate]) {
344 [[aWindow animator] setAlphaValue:0.0];
345 } else {
346 [aWindow setAlphaValue:0.0];
347 }
348 }
349 [NSAnimationContext endGrouping];
350 }
351 }
352 } while (!nextEvent);
353
354 // The user has released the key combo. Discard any events (i.e. the
355 // repeated KeyDown Cmd+Q).
356 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent];
357 if (willQuit) {
358 // The user held down the combination long enough that quitting should
359 // happen.
360 return NSTerminateNow;
361 } else {
362 // Slowly fade the confirm window out in case the user doesn't
363 // understand what they have to do to quit.
364 [quitPanel dismissPanel];
365 return NSTerminateCancel;
366 }
367 } // if event type is KeyDown
368
369 // Default case: terminate.
370 return NSTerminateNow;
371}
372
[email protected]449dd2f2009-05-27 13:04:00373// Called when the app is shutting down. Clean-up as appropriate.
[email protected]7dc8c6b2010-04-09 17:02:50374- (void)applicationWillTerminate:(NSNotification*)aNotification {
[email protected]3b6aa8b62009-09-15 21:36:11375 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
376 [em removeEventHandlerForEventClass:kInternetEventClass
377 andEventID:kAEGetURL];
378 [em removeEventHandlerForEventClass:'WWW!'
379 andEventID:'OURL'];
[email protected]3b6aa8b62009-09-15 21:36:11380
[email protected]7dc8c6b2010-04-09 17:02:50381 // There better be no browser windows left at this point.
382 CHECK_EQ(BrowserList::size(), 0u);
[email protected]3b6aa8b62009-09-15 21:36:11383
[email protected]c984d9f2010-07-20 20:52:20384 // Tell BrowserList not to keep the browser process alive. Once all the
385 // browsers get dealloc'd, it will stop the RunLoop and fall back into main().
386 BrowserList::EndKeepAlive();
[email protected]fbc947b2009-06-19 13:28:24387
[email protected]d4e18652009-11-19 21:52:16388 // Close these off if they have open windows.
389 [prefsController_ close];
390 [aboutController_ close];
391
[email protected]449dd2f2009-05-27 13:04:00392 [[NSNotificationCenter defaultCenter] removeObserver:self];
393}
394
[email protected]3b6aa8b62009-09-15 21:36:11395- (void)didEndMainMessageLoop {
396 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile]));
397 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) {
398 // As we're shutting down, we need to nuke the TabRestoreService, which
399 // will start the shutdown of the NavigationControllers and allow for
400 // proper shutdown. If we don't do this, Chrome won't shut down cleanly,
401 // and may end up crashing when some thread tries to use the IO thread (or
402 // another thread) that is no longer valid.
403 [self defaultProfile]->ResetTabRestoreService();
404 }
405}
406
[email protected]449dd2f2009-05-27 13:04:00407// Helper routine to get the window controller if the key window is a tabbed
408// window, or nil if not. Examples of non-tabbed windows are "about" or
409// "preferences".
410- (TabWindowController*)keyWindowTabController {
411 NSWindowController* keyWindowController =
[email protected]5dbabd02009-09-17 20:44:13412 [[NSApp keyWindow] windowController];
[email protected]449dd2f2009-05-27 13:04:00413 if ([keyWindowController isKindOfClass:[TabWindowController class]])
414 return (TabWindowController*)keyWindowController;
415
416 return nil;
417}
418
[email protected]74c0c642009-09-22 21:25:50419// Helper routine to get the window controller if the main window is a tabbed
420// window, or nil if not. Examples of non-tabbed windows are "about" or
421// "preferences".
422- (TabWindowController*)mainWindowTabController {
423 NSWindowController* mainWindowController =
424 [[NSApp mainWindow] windowController];
425 if ([mainWindowController isKindOfClass:[TabWindowController class]])
426 return (TabWindowController*)mainWindowController;
427
428 return nil;
429}
430
[email protected]449dd2f2009-05-27 13:04:00431// If the window has tabs, make "close window" be cmd-shift-w, otherwise leave
432// it as the normal cmd-w. Capitalization of the key equivalent affects whether
433// the shift modifer is used.
434- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs {
435 [closeWindowMenuItem_ setKeyEquivalent:(inHaveTabs ? @"W" : @"w")];
[email protected]74c0c642009-09-22 21:25:50436 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
[email protected]449dd2f2009-05-27 13:04:00437}
438
439// If the window has tabs, make "close tab" take over cmd-w, otherwise it
440// shouldn't have any key-equivalent because it should be disabled.
441- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)hasTabs {
442 if (hasTabs) {
443 [closeTabMenuItem_ setKeyEquivalent:@"w"];
444 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
445 } else {
446 [closeTabMenuItem_ setKeyEquivalent:@""];
447 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
448 }
449}
450
[email protected]74c0c642009-09-22 21:25:50451// Explicitly remove any command-key equivalents from the close tab/window
452// menus so that nothing can go haywire if we get a user action during pending
453// updates.
454- (void)clearCloseMenuItemKeyEquivalents {
455 [closeTabMenuItem_ setKeyEquivalent:@""];
456 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
457 [closeWindowMenuItem_ setKeyEquivalent:@""];
458 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0];
459}
460
[email protected]449dd2f2009-05-27 13:04:00461// See if we have a window with tabs open, and adjust the key equivalents for
[email protected]668c911c2010-03-08 17:05:25462// Close Tab/Close Window accordingly.
[email protected]449dd2f2009-05-27 13:04:00463- (void)fixCloseMenuItemKeyEquivalents {
[email protected]668c911c2010-03-08 17:05:25464 fileMenuUpdatePending_ = NO;
[email protected]449dd2f2009-05-27 13:04:00465 TabWindowController* tabController = [self keyWindowTabController];
[email protected]74c0c642009-09-22 21:25:50466 if (!tabController && ![NSApp keyWindow]) {
467 // There might be a small amount of time where there is no key window,
468 // so just use our main browser window if there is one.
469 tabController = [self mainWindowTabController];
470 }
[email protected]449dd2f2009-05-27 13:04:00471 BOOL windowWithMultipleTabs =
472 (tabController && [tabController numberOfTabs] > 1);
473 [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs];
474 [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs];
[email protected]449dd2f2009-05-27 13:04:00475}
476
477// Fix up the "close tab/close window" command-key equivalents. We do this
478// after a delay to ensure that window layer state has been set by the time
[email protected]f2a5c342010-01-21 17:00:29479// we do the enabling. This should only be called on the main thread, code that
480// calls this (even as a side-effect) from other threads needs to be fixed.
[email protected]449dd2f2009-05-27 13:04:00481- (void)delayedFixCloseMenuItemKeyEquivalents {
[email protected]f2a5c342010-01-21 17:00:29482 DCHECK([NSThread isMainThread]);
[email protected]449dd2f2009-05-27 13:04:00483 if (!fileMenuUpdatePending_) {
[email protected]74c0c642009-09-22 21:25:50484 // The OS prefers keypresses to timers, so it's possible that a cmd-w
485 // can sneak in before this timer fires. In order to prevent that from
486 // having any bad consequences, just clear the keys combos altogether. They
487 // will be reset when the timer eventually fires.
[email protected]668c911c2010-03-08 17:05:25488 if ([NSThread isMainThread]) {
489 fileMenuUpdatePending_ = YES;
490 [self clearCloseMenuItemKeyEquivalents];
491 [self performSelector:@selector(fixCloseMenuItemKeyEquivalents)
492 withObject:nil
493 afterDelay:0];
494 } else {
495 // This shouldn't be happening, but if it does, force it to the main
496 // thread to avoid dropping the update. Don't mess with
497 // |fileMenuUpdatePending_| as it's not expected to be threadsafe and
498 // there could be a race between the selector finishing and setting the
499 // flag.
500 [self
501 performSelectorOnMainThread:@selector(fixCloseMenuItemKeyEquivalents)
[email protected]f2a5c342010-01-21 17:00:29502 withObject:nil
503 waitUntilDone:NO];
[email protected]668c911c2010-03-08 17:05:25504 }
[email protected]449dd2f2009-05-27 13:04:00505 }
506}
507
508// Called when we get a notification about the window layering changing to
509// update the UI based on the new main window.
510- (void)windowLayeringDidChange:(NSNotification*)notify {
511 [self delayedFixCloseMenuItemKeyEquivalents];
[email protected]dd6ab1282010-07-20 01:07:32512
513 if ([notify name] == NSWindowDidResignKeyNotification) {
514 // If a window is closed, this notification is fired but |[NSApp keyWindow]|
515 // returns nil regardless of whether any suitable candidates for the key
516 // window remain. It seems that the new key window for the app is not set
517 // until after this notification is fired, so a check is performed after the
518 // run loop is allowed to spin.
519 [self performSelector:@selector(checkForAnyKeyWindows)
520 withObject:nil
521 afterDelay:0.0];
522 }
523}
524
525- (void)checkForAnyKeyWindows {
526 if ([NSApp keyWindow])
527 return;
528
529 NotificationService::current()->Notify(
530 NotificationType::NO_KEY_WINDOW,
531 NotificationService::AllSources(),
532 NotificationService::NoDetails());
[email protected]449dd2f2009-05-27 13:04:00533}
534
535// Called when the number of tabs changes in one of the browser windows. The
536// object is the tab strip controller, but we don't currently care.
537- (void)tabsChanged:(NSNotification*)notify {
[email protected]e72746b12009-10-19 14:11:51538 // We don't need to do this on a delay, as in the method above, because the
539 // window layering isn't changing. As a result, there's no chance that a
540 // different window will sneak in as the key window and cause the problems
541 // we hacked around above by clearing the key equivalents.
542 [self fixCloseMenuItemKeyEquivalents];
[email protected]449dd2f2009-05-27 13:04:00543}
544
[email protected]414fde592009-05-21 16:14:43545// If the auto-update interval is not set, make it 5 hours.
546// This code is specific to Mac Chrome Dev Channel.
547// Placed here for 2 reasons:
548// 1) Same spot as other Pref stuff
549// 2) Try and be friendly by keeping this after app launch
550// TODO(jrg): remove once we go Beta.
551- (void)setUpdateCheckInterval {
552#if defined(GOOGLE_CHROME_BUILD)
553 CFStringRef app = (CFStringRef)@"com.google.Keystone.Agent";
554 CFStringRef checkInterval = (CFStringRef)@"checkInterval";
555 CFPropertyListRef plist = CFPreferencesCopyAppValue(checkInterval, app);
556 if (!plist) {
557 const float fiveHoursInSeconds = 5.0 * 60.0 * 60.0;
[email protected]7dc8c6b2010-04-09 17:02:50558 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds];
[email protected]414fde592009-05-21 16:14:43559 CFPreferencesSetAppValue(checkInterval, value, app);
560 CFPreferencesAppSynchronize(app);
561 }
562#endif
563}
564
[email protected]136140c2009-05-19 13:58:25565// This is called after profiles have been loaded and preferences registered.
566// It is safe to access the default profile here.
567- (void)applicationDidFinishLaunching:(NSNotification*)notify {
[email protected]c984d9f2010-07-20 20:52:20568 // Notify BrowserList to keep the application running so it doesn't go away
569 // when all the browser windows get closed.
570 BrowserList::StartKeepAlive();
[email protected]136140c2009-05-19 13:58:25571
[email protected]e5575022009-08-22 00:31:22572 bookmarkMenuBridge_.reset(new BookmarkMenuBridge([self defaultProfile]));
[email protected]1c84c82c2009-07-27 15:37:25573 historyMenuBridge_.reset(new HistoryMenuBridge([self defaultProfile]));
[email protected]cd63ef62009-05-06 19:41:37574
[email protected]414fde592009-05-21 16:14:43575 [self setUpdateCheckInterval];
[email protected]2bcec612009-05-14 17:50:53576
577 // Build up the encoding menu, the order of the items differs based on the
578 // current locale (see http://crbug.com/7647 for details).
579 // We need a valid g_browser_process to get the profile which is why we can't
580 // call this from awakeFromNib.
[email protected]fc349322009-09-23 22:28:23581 NSMenu* view_menu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu];
582 NSMenuItem* encoding_menu_item = [view_menu itemWithTag:IDC_ENCODING_MENU];
[email protected]7dc8c6b2010-04-09 17:02:50583 NSMenu* encoding_menu = [encoding_menu_item submenu];
[email protected]fc349322009-09-23 22:28:23584 EncodingMenuControllerDelegate::BuildEncodingMenu([self defaultProfile],
585 encoding_menu);
[email protected]2bcec612009-05-14 17:50:53586
[email protected]f2c20fa2009-12-01 17:42:02587 // Since Chrome is localized to more languages than the OS, tell Cocoa which
588 // menu is the Help so it can add the search item to it.
[email protected]caadfca2010-01-22 21:51:21589 if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)])
[email protected]f2c20fa2009-12-01 17:42:02590 [NSApp setHelpMenu:helpMenu_];
[email protected]f2c20fa2009-12-01 17:42:02591
[email protected]12dc3d42010-02-22 23:37:12592 // Record the path to the (browser) app bundle; this is used by the app mode
593 // shim.
594 RecordLastRunAppBundlePath();
595
[email protected]eef99c22010-08-17 05:55:16596 // Makes "Services" menu items available.
597 [self registerServicesMenuTypesTo:[notify object]];
598
[email protected]caadfca2010-01-22 21:51:21599 startupComplete_ = YES;
600
601 // TODO(viettrungluu): This is very temporary, since this should be done "in"
602 // |BrowserMain()|, i.e., this list of startup URLs should be appended to the
603 // (probably-empty) list of URLs from the command line.
[email protected]d630d7d52010-02-21 00:55:11604 if (startupUrls_.size()) {
605 [self openUrls:startupUrls_];
606 [self clearStartupUrls];
[email protected]caadfca2010-01-22 21:51:21607 }
[email protected]ad2a3ded2010-08-27 13:19:05608
609 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
610 if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) {
611 [tabposeMenuItem_ setHidden:YES];
612 }
[email protected]7c321082009-02-09 15:35:47613}
614
[email protected]a96ec6a2009-11-04 17:27:08615// This is called after profiles have been loaded and preferences registered.
616// It is safe to access the default profile here.
617- (void)applicationDidBecomeActive:(NSNotification*)notify {
618 NotificationService::current()->Notify(NotificationType::APP_ACTIVATED,
619 NotificationService::AllSources(),
620 NotificationService::NoDetails());
621}
622
[email protected]73f5b362009-08-10 23:58:21623// Helper function for populating and displaying the in progress downloads at
624// exit alert panel.
625- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount {
[email protected]e8b5f7882009-09-14 20:59:13626 NSString* warningText = nil;
627 NSString* explanationText = nil;
[email protected]73f5b362009-08-10 23:58:21628 NSString* waitTitle = nil;
629 NSString* exitTitle = nil;
630
[email protected]757127052010-04-27 14:42:26631 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
[email protected]9dcb59662009-09-23 01:15:50632
[email protected]73f5b362009-08-10 23:58:21633 // Set the dialog text based on whether or not there are multiple downloads.
634 if (downloadCount == 1) {
[email protected]e8b5f7882009-09-14 20:59:13635 // Dialog text: warning and explanation.
[email protected]757127052010-04-27 14:42:26636 warningText = l10n_util::GetNSStringF(
637 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING, product_name);
638 explanationText = l10n_util::GetNSStringF(
639 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION, product_name);
[email protected]73f5b362009-08-10 23:58:21640
641 // Cancel download and exit button text.
[email protected]757127052010-04-27 14:42:26642 exitTitle = l10n_util::GetNSString(
643 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21644
645 // Wait for download button text.
[email protected]757127052010-04-27 14:42:26646 waitTitle = l10n_util::GetNSString(
647 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21648 } else {
[email protected]e8b5f7882009-09-14 20:59:13649 // Dialog text: warning and explanation.
[email protected]757127052010-04-27 14:42:26650 warningText = l10n_util::GetNSStringF(
651 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING, product_name,
[email protected]528c56d2010-07-30 19:28:44652 base::IntToString16(downloadCount));
[email protected]757127052010-04-27 14:42:26653 explanationText = l10n_util::GetNSStringF(
654 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION, product_name);
[email protected]73f5b362009-08-10 23:58:21655
656 // Cancel downloads and exit button text.
[email protected]757127052010-04-27 14:42:26657 exitTitle = l10n_util::GetNSString(
658 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21659
660 // Wait for downloads button text.
[email protected]757127052010-04-27 14:42:26661 waitTitle = l10n_util::GetNSString(
662 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21663 }
664
665 // 'waitButton' is the default choice.
[email protected]e8b5f7882009-09-14 20:59:13666 int choice = NSRunAlertPanel(warningText, explanationText,
667 waitTitle, exitTitle, nil);
[email protected]73f5b362009-08-10 23:58:21668 return choice == NSAlertDefaultReturn ? YES : NO;
669}
670
671// Check all profiles for in progress downloads, and if we find any, prompt the
[email protected]09729a552009-08-03 23:21:41672// user to see if we should continue to exit (and thus cancel the downloads), or
673// if we should wait.
674- (BOOL)shouldQuitWithInProgressDownloads {
[email protected]73f5b362009-08-10 23:58:21675 ProfileManager* profile_manager = g_browser_process->profile_manager();
676 if (!profile_manager)
677 return YES;
[email protected]09729a552009-08-03 23:21:41678
[email protected]73f5b362009-08-10 23:58:21679 ProfileManager::const_iterator it = profile_manager->begin();
680 for (; it != profile_manager->end(); ++it) {
681 Profile* profile = *it;
[email protected]09729a552009-08-03 23:21:41682 DownloadManager* download_manager = profile->GetDownloadManager();
[email protected]73f5b362009-08-10 23:58:21683 if (download_manager && download_manager->in_progress_count() > 0) {
684 int downloadCount = download_manager->in_progress_count();
685 if ([self userWillWaitForInProgressDownloads:downloadCount]) {
686 // Create a new browser window (if necessary) and navigate to the
687 // downloads page if the user chooses to wait.
688 Browser* browser = BrowserList::FindBrowserWithProfile(profile);
689 if (!browser) {
690 browser = Browser::Create(profile);
691 browser->window()->Show();
692 }
693 DCHECK(browser);
694 browser->ShowDownloadsTab();
695 return NO;
696 }
[email protected]09729a552009-08-03 23:21:41697
[email protected]73f5b362009-08-10 23:58:21698 // User wants to exit.
699 return YES;
[email protected]09729a552009-08-03 23:21:41700 }
[email protected]09729a552009-08-03 23:21:41701 }
702
[email protected]73f5b362009-08-10 23:58:21703 // No profiles or active downloads found, okay to exit.
[email protected]09729a552009-08-03 23:21:41704 return YES;
705}
706
[email protected]fbc947b2009-06-19 13:28:24707// Called to determine if we should enable the "restore tab" menu item.
708// Checks with the TabRestoreService to see if there's anything there to
709// restore and returns YES if so.
710- (BOOL)canRestoreTab {
711 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService();
712 return service && !service->entries().empty();
713}
714
[email protected]f6c15fa2010-06-04 20:08:21715// Returns true if there is not a modal window (either window- or application-
716// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
717// sheets) will not count as blocking the browser. But things like open/save
718// dialogs that are window modal will block the browser.
719- (BOOL)keyWindowIsNotModal {
[email protected]6a281332009-10-13 17:41:06720 Browser* browser = BrowserList::GetLastActive();
[email protected]dc76e8362010-06-11 16:29:52721 return [NSApp modalWindow] == nil && (!browser ||
[email protected]6a281332009-10-13 17:41:06722 ![[browser->window()->GetNativeHandle() attachedSheet]
[email protected]f6c15fa2010-06-04 20:08:21723 isKindOfClass:[NSWindow class]]);
[email protected]6a281332009-10-13 17:41:06724}
725
[email protected]88d74942009-01-21 22:04:44726// Called to validate menu items when there are no key windows. All the
727// items we care about have been set with the |commandDispatch:| action and
728// a target of FirstResponder in IB. If it's not one of those, let it
729// continue up the responder chain to be handled elsewhere. We pull out the
730// tag as the cross-platform constant to differentiate and dispatch the
731// various commands.
732- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
733 SEL action = [item action];
734 BOOL enable = NO;
735 if (action == @selector(commandDispatch:)) {
736 NSInteger tag = [item tag];
[email protected]fbc947b2009-06-19 13:28:24737 if (menuState_->SupportsCommand(tag)) {
738 switch (tag) {
[email protected]419eb2a2009-11-11 16:26:26739 // The File Menu commands are not automatically disabled by Cocoa when a
740 // dialog sheet obscures the browser window, so we disable several of
741 // them here. We don't need to include IDC_CLOSE_WINDOW, because
742 // app_controller is only activated when there are no key windows (see
743 // function comment).
[email protected]fbc947b2009-06-19 13:28:24744 case IDC_RESTORE_TAB:
[email protected]f6c15fa2010-06-04 20:08:21745 enable = [self keyWindowIsNotModal] && [self canRestoreTab];
[email protected]6a281332009-10-13 17:41:06746 break;
[email protected]f6c15fa2010-06-04 20:08:21747 // Browser-level items that open in new tabs should not open if there's
748 // a window- or app-modal dialog.
[email protected]6a281332009-10-13 17:41:06749 case IDC_OPEN_FILE:
[email protected]6a281332009-10-13 17:41:06750 case IDC_NEW_TAB:
[email protected]f6c15fa2010-06-04 20:08:21751 case IDC_SHOW_HISTORY:
752 case IDC_SHOW_BOOKMARK_MANAGER:
753 enable = [self keyWindowIsNotModal];
754 break;
755 // Browser-level items that open in new windows.
756 case IDC_NEW_WINDOW:
757 case IDC_TASK_MANAGER:
758 // Allow the user to open a new window if there's a window-modal
759 // dialog.
760 enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil);
[email protected]fbc947b2009-06-19 13:28:24761 break;
[email protected]446e16a2010-05-03 21:23:58762 case IDC_SYNC_BOOKMARKS: {
763 Profile* defaultProfile = [self defaultProfile];
764 // The profile may be NULL during shutdown -- see
765 // http://code.google.com/p/chromium/issues/detail?id=43048 .
766 //
767 // TODO(akalin,viettrungluu): Figure out whether this method
768 // can be prevented from being called if defaultProfile is
769 // NULL.
770 if (!defaultProfile) {
771 LOG(WARNING)
772 << "NULL defaultProfile detected -- not doing anything";
773 break;
774 }
[email protected]d3b98c82010-07-14 07:45:59775 enable = defaultProfile->IsSyncAccessible() &&
776 [self keyWindowIsNotModal];
[email protected]446e16a2010-05-03 21:23:58777 sync_ui_util::UpdateSyncItem(item, enable, defaultProfile);
[email protected]f9bc9b92009-11-24 00:55:35778 break;
[email protected]446e16a2010-05-03 21:23:58779 }
[email protected]fbc947b2009-06-19 13:28:24780 default:
[email protected]f6c15fa2010-06-04 20:08:21781 enable = menuState_->IsCommandEnabled(tag) ?
782 [self keyWindowIsNotModal] : NO;
[email protected]fbc947b2009-06-19 13:28:24783 }
784 }
[email protected]3b6aa8b62009-09-15 21:36:11785 } else if (action == @selector(terminate:)) {
[email protected]88d74942009-01-21 22:04:44786 enable = YES;
[email protected]3111f08b2009-04-30 16:01:52787 } else if (action == @selector(showPreferences:)) {
788 enable = YES;
[email protected]bde3dda2009-05-20 22:13:07789 } else if (action == @selector(orderFrontStandardAboutPanel:)) {
790 enable = YES;
[email protected]3d4bd23f2009-10-06 03:58:38791 } else if (action == @selector(newWindowFromDock:)) {
792 enable = YES;
[email protected]88d74942009-01-21 22:04:44793 }
794 return enable;
795}
796
[email protected]947fc0d2010-01-14 22:33:05797// Called when the user picks a menu item when there are no key windows, or when
798// there is no foreground browser window. Calls through to the browser object to
799// execute the command. This assumes that the command is supported and doesn't
[email protected]d630d7d52010-02-21 00:55:11800// check, otherwise it should have been disabled in the UI in
801// |-validateUserInterfaceItem:|.
[email protected]88d74942009-01-21 22:04:44802- (void)commandDispatch:(id)sender {
[email protected]93e181762009-05-29 14:30:38803 Profile* defaultProfile = [self defaultProfile];
[email protected]f0a51fb52009-03-05 12:46:38804
[email protected]947fc0d2010-01-14 22:33:05805 // Handle the case where we're dispatching a command from a sender that's in a
806 // browser window. This means that the command came from a background window
807 // and is getting here because the foreground window is not a browser window.
808 if ([sender respondsToSelector:@selector(window)]) {
809 id delegate = [[sender window] windowController];
810 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
811 [delegate commandDispatch:sender];
812 return;
813 }
814 }
815
[email protected]88d74942009-01-21 22:04:44816 NSInteger tag = [sender tag];
817 switch (tag) {
[email protected]fbc947b2009-06-19 13:28:24818 case IDC_NEW_TAB:
[email protected]d630d7d52010-02-21 00:55:11819 // Create a new tab in an existing browser window (which we activate) if
820 // possible.
821 if (Browser* browser = ActivateBrowser(defaultProfile)) {
822 browser->ExecuteCommand(IDC_NEW_TAB);
823 break;
824 }
825 // Else fall through to create new window.
[email protected]88d74942009-01-21 22:04:44826 case IDC_NEW_WINDOW:
[email protected]d630d7d52010-02-21 00:55:11827 CreateBrowser(defaultProfile);
828 break;
[email protected]91a5b3e2009-10-30 19:32:22829 case IDC_FOCUS_LOCATION:
[email protected]d630d7d52010-02-21 00:55:11830 ActivateOrCreateBrowser(defaultProfile)->
831 ExecuteCommand(IDC_FOCUS_LOCATION);
[email protected]88d74942009-01-21 22:04:44832 break;
[email protected]cddc5242009-12-07 18:54:33833 case IDC_FOCUS_SEARCH:
[email protected]d630d7d52010-02-21 00:55:11834 ActivateOrCreateBrowser(defaultProfile)->ExecuteCommand(IDC_FOCUS_SEARCH);
[email protected]cddc5242009-12-07 18:54:33835 break;
[email protected]863ff662009-01-26 20:18:18836 case IDC_NEW_INCOGNITO_WINDOW:
[email protected]e9e211272009-09-22 16:39:11837 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile());
[email protected]863ff662009-01-26 20:18:18838 break;
[email protected]fbc947b2009-06-19 13:28:24839 case IDC_RESTORE_TAB:
840 Browser::OpenWindowWithRestoredTabs(defaultProfile);
841 break;
[email protected]e19516d2009-04-28 17:15:19842 case IDC_OPEN_FILE:
[email protected]d630d7d52010-02-21 00:55:11843 CreateBrowser(defaultProfile)->ExecuteCommand(IDC_OPEN_FILE);
[email protected]e19516d2009-04-28 17:15:19844 break;
[email protected]1fdff702009-10-22 00:36:18845 case IDC_CLEAR_BROWSING_DATA: {
[email protected]93e181762009-05-29 14:30:38846 // There may not be a browser open, so use the default profile.
[email protected]049ac832009-12-15 16:26:54847 [ClearBrowsingDataController
848 showClearBrowsingDialogForProfile:defaultProfile];
[email protected]93e181762009-05-29 14:30:38849 break;
[email protected]1fdff702009-10-22 00:36:18850 }
[email protected]4aee5652009-11-19 18:59:21851 case IDC_IMPORT_SETTINGS: {
[email protected]896220042010-03-23 18:14:28852 UserMetrics::RecordAction(UserMetricsAction("Import_ShowDlg"),
853 defaultProfile);
[email protected]2989cce12010-02-01 10:56:53854 [ImportSettingsDialogController
855 showImportSettingsDialogForProfile:defaultProfile];
[email protected]4aee5652009-11-19 18:59:21856 break;
857 }
[email protected]af7c25e2010-01-23 05:46:45858 case IDC_SHOW_BOOKMARK_MANAGER:
[email protected]896220042010-03-23 18:14:28859 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"),
860 defaultProfile);
[email protected]90a8bf252010-03-12 00:09:47861 if (Browser* browser = ActivateBrowser(defaultProfile)) {
[email protected]47e532b2010-04-23 17:46:40862 // Open a bookmark manager tab.
[email protected]90a8bf252010-03-12 00:09:47863 browser->OpenBookmarkManager();
864 } else {
[email protected]47e532b2010-04-23 17:46:40865 // No browser window, so create one for the bookmark manager tab.
866 Browser::OpenBookmarkManagerWindow(defaultProfile);
[email protected]90a8bf252010-03-12 00:09:47867 }
[email protected]af7c25e2010-01-23 05:46:45868 break;
[email protected]91a5b3e2009-10-30 19:32:22869 case IDC_SHOW_HISTORY:
[email protected]d630d7d52010-02-21 00:55:11870 if (Browser* browser = ActivateBrowser(defaultProfile))
871 browser->ShowHistoryTab();
872 else
873 Browser::OpenHistoryWindow(defaultProfile);
[email protected]91a5b3e2009-10-30 19:32:22874 break;
875 case IDC_SHOW_DOWNLOADS:
[email protected]d630d7d52010-02-21 00:55:11876 if (Browser* browser = ActivateBrowser(defaultProfile))
877 browser->ShowDownloadsTab();
878 else
879 Browser::OpenDownloadsWindow(defaultProfile);
[email protected]91a5b3e2009-10-30 19:32:22880 break;
[email protected]bb37e6ec2009-11-18 17:59:36881 case IDC_MANAGE_EXTENSIONS:
[email protected]d630d7d52010-02-21 00:55:11882 if (Browser* browser = ActivateBrowser(defaultProfile))
883 browser->ShowExtensionsTab();
884 else
885 Browser::OpenExtensionsWindow(defaultProfile);
[email protected]bb37e6ec2009-11-18 17:59:36886 break;
[email protected]1fdff702009-10-22 00:36:18887 case IDC_HELP_PAGE:
[email protected]d630d7d52010-02-21 00:55:11888 if (Browser* browser = ActivateBrowser(defaultProfile))
889 browser->OpenHelpTab();
890 else
891 Browser::OpenHelpWindow(defaultProfile);
[email protected]1fdff702009-10-22 00:36:18892 break;
[email protected]3896b182009-11-03 16:15:32893 case IDC_REPORT_BUG: {
894 Browser* browser = BrowserList::GetLastActive();
[email protected]d630d7d52010-02-21 00:55:11895 TabContents* currentTab =
896 browser ? browser->GetSelectedTabContents() : NULL;
[email protected]3896b182009-11-03 16:15:32897 BugReportWindowController* controller =
898 [[BugReportWindowController alloc]
[email protected]d630d7d52010-02-21 00:55:11899 initWithTabContents:currentTab
900 profile:[self defaultProfile]];
[email protected]3896b182009-11-03 16:15:32901 [controller runModalDialog];
902 break;
903 }
[email protected]f9bc9b92009-11-24 00:55:35904 case IDC_SYNC_BOOKMARKS:
[email protected]446e16a2010-05-03 21:23:58905 // The profile may be NULL during shutdown -- see
906 // http://code.google.com/p/chromium/issues/detail?id=43048 .
907 //
908 // TODO(akalin,viettrungluu): Figure out whether this method can
909 // be prevented from being called if defaultProfile is NULL.
910 if (!defaultProfile) {
911 LOG(WARNING) << "NULL defaultProfile detected -- not doing anything";
912 break;
913 }
[email protected]f9bc9b92009-11-24 00:55:35914 // TODO(akalin): Add a constant to denote starting sync from the
915 // main menu and use that instead of START_FROM_WRENCH.
[email protected]40f047972009-11-25 03:54:40916 sync_ui_util::OpenSyncMyBookmarksDialog(
[email protected]f9bc9b92009-11-24 00:55:35917 defaultProfile, ProfileSyncService::START_FROM_WRENCH);
918 break;
[email protected]ceaaf1812010-01-20 22:13:09919 case IDC_TASK_MANAGER:
[email protected]896220042010-03-23 18:14:28920 UserMetrics::RecordAction(UserMetricsAction("TaskManager"),
921 defaultProfile);
[email protected]ceaaf1812010-01-20 22:13:09922 TaskManagerMac::Show();
923 break;
[email protected]4a42d272010-06-18 01:29:42924 case IDC_OPTIONS:
925 [self showPreferences:sender];
926 break;
[email protected]d630d7d52010-02-21 00:55:11927 }
[email protected]88d74942009-01-21 22:04:44928}
929
[email protected]947fc0d2010-01-14 22:33:05930// Same as |-commandDispatch:|, but executes commands using a disposition
931// determined by the key flags. This will get called in the case where the
932// frontmost window is not a browser window, and the user has command-clicked
933// a button in a background browser window whose action is
934// |-commandDispatchUsingKeyModifiers:|
935- (void)commandDispatchUsingKeyModifiers:(id)sender {
936 DCHECK(sender);
937 if ([sender respondsToSelector:@selector(window)]) {
938 id delegate = [[sender window] windowController];
939 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
940 [delegate commandDispatchUsingKeyModifiers:sender];
941 }
942 }
943}
944
[email protected]ff81e0a2009-04-13 14:58:54945// NSApplication delegate method called when someone clicks on the
946// dock icon and there are no open windows. To match standard mac
947// behavior, we should open a new window.
948- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
949 hasVisibleWindows:(BOOL)flag {
[email protected]70631402010-04-26 20:16:54950 // If the browser is currently trying to quit, don't do anything and return NO
951 // to prevent AppKit from doing anything.
952 // TODO(rohitrao): Remove this code when http://crbug.com/40861 is resolved.
953 if (browser_shutdown::IsTryingToQuit())
954 return NO;
955
[email protected]ff81e0a2009-04-13 14:58:54956 // Don't do anything if there are visible windows. This will cause
957 // AppKit to unminimize the most recently minimized window.
958 if (flag)
959 return YES;
960
[email protected]0d1210d62010-09-07 17:31:38961 // If launched as a hidden login item (due to installation of a persistent app
962 // or by the user, for example in System Preferenecs->Accounts->Login Items),
963 // allow session to be restored first time the user clicks on a Dock icon.
964 // Normally, it'd just open a new empty page.
965 {
966 static BOOL doneOnce = NO;
967 if (!doneOnce) {
968 doneOnce = YES;
969 if (mac_util::WasLaunchedAsHiddenLoginItem()) {
970 SessionService* sessionService =
971 [self defaultProfile]->GetSessionService();
972 if (sessionService &&
973 sessionService->RestoreIfNecessary(std::vector<GURL>()))
974 return NO;
975 }
976 }
977 }
[email protected]ff81e0a2009-04-13 14:58:54978 // Otherwise open a new window.
[email protected]d630d7d52010-02-21 00:55:11979 {
[email protected]0fbd70332010-06-01 19:28:34980 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
[email protected]d630d7d52010-02-21 00:55:11981 Browser::OpenEmptyWindow([self defaultProfile]);
982 }
[email protected]ff81e0a2009-04-13 14:58:54983
984 // We've handled the reopen event, so return NO to tell AppKit not
985 // to do anything.
986 return NO;
987}
988
[email protected]88d74942009-01-21 22:04:44989- (void)initMenuState {
[email protected]3111f08b2009-04-30 16:01:52990 menuState_.reset(new CommandUpdater(NULL));
[email protected]fbc947b2009-06-19 13:28:24991 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true);
[email protected]88d74942009-01-21 22:04:44992 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true);
[email protected]863ff662009-01-26 20:18:18993 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true);
[email protected]e19516d2009-04-28 17:15:19994 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true);
[email protected]93e181762009-05-29 14:30:38995 menuState_->UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true);
[email protected]fbc947b2009-06-19 13:28:24996 menuState_->UpdateCommandEnabled(IDC_RESTORE_TAB, false);
[email protected]91a5b3e2009-10-30 19:32:22997 menuState_->UpdateCommandEnabled(IDC_FOCUS_LOCATION, true);
[email protected]cddc5242009-12-07 18:54:33998 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true);
[email protected]af7c25e2010-01-23 05:46:45999 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true);
[email protected]91a5b3e2009-10-30 19:32:221000 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true);
1001 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]bb37e6ec2009-11-18 17:59:361002 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true);
[email protected]1fdff702009-10-22 00:36:181003 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE, true);
[email protected]4aee5652009-11-19 18:59:211004 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true);
[email protected]3896b182009-11-03 16:15:321005 menuState_->UpdateCommandEnabled(IDC_REPORT_BUG, true);
[email protected]d3b98c82010-07-14 07:45:591006 menuState_->UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, true);
[email protected]ceaaf1812010-01-20 22:13:091007 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true);
[email protected]88d74942009-01-21 22:04:441008}
[email protected]1bcdb532009-01-16 17:47:571009
[email protected]eef99c22010-08-17 05:55:161010- (void)registerServicesMenuTypesTo:(NSApplication*)app {
[email protected]09ea24c2010-08-23 19:05:411011 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which
1012 // handles requests from services.
1013 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
1014 [app registerServicesMenuSendTypes:types returnTypes:types];
[email protected]eef99c22010-08-17 05:55:161015}
1016
[email protected]3f34599d2009-03-25 22:11:431017- (Profile*)defaultProfile {
[email protected]3f34599d2009-03-25 22:11:431018 // TODO(jrg): Find a better way to get the "default" profile.
1019 if (g_browser_process->profile_manager())
[email protected]065566b2010-01-20 20:38:261020 return *g_browser_process->profile_manager()->begin();
[email protected]3f34599d2009-03-25 22:11:431021
[email protected]f6314002009-04-23 01:18:131022 return NULL;
[email protected]3f34599d2009-03-25 22:11:431023}
1024
[email protected]57750f822009-04-21 21:43:091025// Various methods to open URLs that we get in a native fashion. We use
1026// BrowserInit here because on the other platforms, URLs to open come through
1027// the ProcessSingleton, and it calls BrowserInit. It's best to bottleneck the
1028// openings through that for uniform handling.
1029
[email protected]d630d7d52010-02-21 00:55:111030- (void)openUrls:(const std::vector<GURL>&)urls {
[email protected]caadfca2010-01-22 21:51:211031 // If the browser hasn't started yet, just queue up the URLs.
1032 if (!startupComplete_) {
[email protected]d630d7d52010-02-21 00:55:111033 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end());
[email protected]136140c2009-05-19 13:58:251034 return;
1035 }
[email protected]57750f822009-04-21 21:43:091036
[email protected]0e863512009-05-28 19:45:071037 Browser* browser = BrowserList::GetLastActive();
1038 // if no browser window exists then create one with no tabs to be filled in
1039 if (!browser) {
1040 browser = Browser::Create([self defaultProfile]);
[email protected]ce560f82009-06-03 09:39:441041 browser->window()->Show();
[email protected]0e863512009-05-28 19:45:071042 }
1043
[email protected]947446b2010-10-21 03:36:311044 CommandLine dummy(CommandLine::NO_PROGRAM);
[email protected]f805fe82010-08-03 22:47:101045 BrowserInit::LaunchWithProfile launch(FilePath(), dummy);
[email protected]0e863512009-05-28 19:45:071046 launch.OpenURLsInBrowser(browser, false, urls);
[email protected]57750f822009-04-21 21:43:091047}
1048
[email protected]57750f822009-04-21 21:43:091049- (void)getUrl:(NSAppleEventDescriptor*)event
1050 withReply:(NSAppleEventDescriptor*)reply {
1051 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
1052 stringValue];
1053
1054 GURL gurl(base::SysNSStringToUTF8(urlStr));
1055 std::vector<GURL> gurlVector;
1056 gurlVector.push_back(gurl);
1057
[email protected]d630d7d52010-02-21 00:55:111058 [self openUrls:gurlVector];
[email protected]57750f822009-04-21 21:43:091059}
1060
[email protected]caadfca2010-01-22 21:51:211061- (void)application:(NSApplication*)sender
1062 openFiles:(NSArray*)filenames {
[email protected]57750f822009-04-21 21:43:091063 std::vector<GURL> gurlVector;
[email protected]caadfca2010-01-22 21:51:211064 for (NSString* file in filenames) {
1065 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file)));
[email protected]57750f822009-04-21 21:43:091066 gurlVector.push_back(gurl);
1067 }
[email protected]caadfca2010-01-22 21:51:211068 if (!gurlVector.empty())
[email protected]d630d7d52010-02-21 00:55:111069 [self openUrls:gurlVector];
[email protected]caadfca2010-01-22 21:51:211070 else
1071 NOTREACHED() << "Nothing to open!";
[email protected]57750f822009-04-21 21:43:091072
[email protected]caadfca2010-01-22 21:51:211073 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
[email protected]57750f822009-04-21 21:43:091074}
[email protected]3f34599d2009-03-25 22:11:431075
[email protected]767543d2009-04-30 19:23:581076// Called when the preferences window is closed. We use this to release the
1077// window controller.
[email protected]d4e18652009-11-19 21:52:161078- (void)prefsWindowClosed:(NSNotification*)notification {
1079 NSWindow* window = [prefsController_ window];
1080 DCHECK([notification object] == window);
1081 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
1082 [defaultCenter removeObserver:self
1083 name:NSWindowWillCloseNotification
1084 object:window];
1085 // PreferencesWindowControllers are autoreleased in
1086 // -[PreferencesWindowController windowWillClose:].
1087 prefsController_ = nil;
[email protected]767543d2009-04-30 19:23:581088}
1089
[email protected]3111f08b2009-04-30 16:01:521090// Show the preferences window, or bring it to the front if it's already
1091// visible.
1092- (IBAction)showPreferences:(id)sender {
[email protected]4a42d272010-06-18 01:29:421093 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
1094 if (parsed_command_line.HasSwitch(switches::kEnableTabbedOptions)) {
1095 if (Browser* browser = ActivateBrowser([self defaultProfile])) {
1096 // Show options tab in the active browser window.
[email protected]024617a2010-08-20 05:08:051097 browser->ShowOptionsTab(chrome::kDefaultOptionsSubPage);
[email protected]4a42d272010-06-18 01:29:421098 } else {
1099 // No browser window, so create one for the options tab.
1100 Browser::OpenOptionsWindow([self defaultProfile]);
1101 }
1102 } else {
1103 [self showPreferencesWindow:sender
1104 page:OPTIONS_PAGE_DEFAULT
1105 profile:[self defaultProfile]];
1106 }
[email protected]d989f07c2009-11-14 00:35:461107}
1108
1109- (void)showPreferencesWindow:(id)sender
1110 page:(OptionsPage)page
1111 profile:(Profile*)profile {
[email protected]d4e18652009-11-19 21:52:161112 if (prefsController_) {
[email protected]d989f07c2009-11-14 00:35:461113 [prefsController_ switchToPage:page animate:YES];
1114 } else {
[email protected]d4e18652009-11-19 21:52:161115 prefsController_ =
1116 [[PreferencesWindowController alloc] initWithProfile:profile
1117 initialPage:page];
[email protected]767543d2009-04-30 19:23:581118 // Watch for a notification of when it goes away so that we can destroy
1119 // the controller.
1120 [[NSNotificationCenter defaultCenter]
1121 addObserver:self
1122 selector:@selector(prefsWindowClosed:)
[email protected]d4e18652009-11-19 21:52:161123 name:NSWindowWillCloseNotification
1124 object:[prefsController_ window]];
[email protected]42404382009-04-30 17:59:241125 }
1126 [prefsController_ showPreferences:sender];
[email protected]3111f08b2009-04-30 16:01:521127}
1128
[email protected]bde3dda2009-05-20 22:13:071129// Called when the about window is closed. We use this to release the
1130// window controller.
[email protected]d4e18652009-11-19 21:52:161131- (void)aboutWindowClosed:(NSNotification*)notification {
1132 NSWindow* window = [aboutController_ window];
1133 DCHECK(window == [notification object]);
[email protected]bde3dda2009-05-20 22:13:071134 [[NSNotificationCenter defaultCenter]
[email protected]49aeee52009-10-26 19:58:131135 removeObserver:self
[email protected]d4e18652009-11-19 21:52:161136 name:NSWindowWillCloseNotification
1137 object:window];
1138 // AboutWindowControllers are autoreleased in
1139 // -[AboutWindowController windowWillClose:].
1140 aboutController_ = nil;
[email protected]bde3dda2009-05-20 22:13:071141}
1142
1143- (IBAction)orderFrontStandardAboutPanel:(id)sender {
[email protected]bde3dda2009-05-20 22:13:071144 if (!aboutController_) {
[email protected]d4e18652009-11-19 21:52:161145 aboutController_ =
1146 [[AboutWindowController alloc] initWithProfile:[self defaultProfile]];
[email protected]49aeee52009-10-26 19:58:131147
[email protected]bde3dda2009-05-20 22:13:071148 // Watch for a notification of when it goes away so that we can destroy
1149 // the controller.
1150 [[NSNotificationCenter defaultCenter]
1151 addObserver:self
1152 selector:@selector(aboutWindowClosed:)
[email protected]d4e18652009-11-19 21:52:161153 name:NSWindowWillCloseNotification
1154 object:[aboutController_ window]];
[email protected]bde3dda2009-05-20 22:13:071155 }
[email protected]49aeee52009-10-26 19:58:131156
[email protected]bde3dda2009-05-20 22:13:071157 [aboutController_ showWindow:self];
[email protected]bde3dda2009-05-20 22:13:071158}
1159
[email protected]3d4bd23f2009-10-06 03:58:381160// Explicitly bring to the foreground when creating new windows from the dock.
1161- (void)newWindowFromDock:(id)sender {
1162 [NSApp activateIgnoringOtherApps:YES];
1163 [self commandDispatch:sender];
1164}
1165
[email protected]227fcee2010-06-11 19:19:371166- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
[email protected]018a3962009-09-17 22:23:441167 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
1168 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC);
1169 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc]
1170 initWithTitle:titleStr
[email protected]3d4bd23f2009-10-06 03:58:381171 action:@selector(newWindowFromDock:)
[email protected]018a3962009-09-17 22:23:441172 keyEquivalent:@""]);
[email protected]288bfcd32009-09-14 18:14:461173 [item setTarget:self];
1174 [item setTag:IDC_NEW_WINDOW];
[email protected]018a3962009-09-17 22:23:441175 [dockMenu addItem:item];
[email protected]288bfcd32009-09-14 18:14:461176
1177 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC);
[email protected]018a3962009-09-17 22:23:441178 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
[email protected]3d4bd23f2009-10-06 03:58:381179 action:@selector(newWindowFromDock:)
[email protected]018a3962009-09-17 22:23:441180 keyEquivalent:@""]);
[email protected]288bfcd32009-09-14 18:14:461181 [item setTarget:self];
1182 [item setTag:IDC_NEW_INCOGNITO_WINDOW];
[email protected]018a3962009-09-17 22:23:441183 [dockMenu addItem:item];
[email protected]288bfcd32009-09-14 18:14:461184
[email protected]018a3962009-09-17 22:23:441185 return dockMenu;
[email protected]288bfcd32009-09-14 18:14:461186}
1187
[email protected]d630d7d52010-02-21 00:55:111188- (const std::vector<GURL>&)startupUrls {
1189 return startupUrls_;
[email protected]caadfca2010-01-22 21:51:211190}
1191
[email protected]d630d7d52010-02-21 00:55:111192- (void)clearStartupUrls {
1193 startupUrls_.clear();
[email protected]caadfca2010-01-22 21:51:211194}
1195
[email protected]d630d7d52010-02-21 00:55:111196@end // @implementation AppController
[email protected]60ad3e22009-09-18 21:07:191197
1198//---------------------------------------------------------------------------
1199
[email protected]60ad3e22009-09-18 21:07:191200void ShowOptionsWindow(OptionsPage page,
1201 OptionsGroup highlight_group,
1202 Profile* profile) {
[email protected]d989f07c2009-11-14 00:35:461203 // TODO(akalin): Use highlight_group.
1204 AppController* appController = [NSApp delegate];
1205 [appController showPreferencesWindow:nil page:page profile:profile];
[email protected]60ad3e22009-09-18 21:07:191206}
[email protected]216e9042009-10-29 17:05:231207
1208namespace app_controller_mac {
1209
1210bool IsOpeningNewWindow() {
1211 return g_is_opening_new_window;
1212}
1213
1214} // namespace app_controller_mac