blob: 464d3c8c5ac4bc18c7d8cfbc6edc0f06af2aba7b [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]5c238752009-06-13 10:29:0718#include "chrome/browser/browser_process.h"
[email protected]41741a962009-02-18 21:51:3919#include "chrome/browser/browser_shutdown.h"
[email protected]ed7e6dd2010-10-12 02:02:4520#include "chrome/browser/browser_thread.h"
[email protected]2c47bc12009-04-10 20:14:0021#include "chrome/browser/command_updater.h"
[email protected]09729a552009-08-03 23:21:4122#include "chrome/browser/download/download_manager.h"
[email protected]4aee5652009-11-19 18:59:2123#include "chrome/browser/metrics/user_metrics.h"
[email protected]60ad3e22009-09-18 21:07:1924#include "chrome/browser/options_window.h"
[email protected]37858e52010-08-26 00:22:0225#include "chrome/browser/prefs/pref_service.h"
[email protected]e7dd6d82010-10-07 23:21:1226#include "chrome/browser/printing/print_job_manager.h"
[email protected]052313b2010-02-19 09:43:0827#include "chrome/browser/profile_manager.h"
[email protected]fbc947b2009-06-19 13:28:2428#include "chrome/browser/sessions/tab_restore_service.h"
[email protected]f9bc9b92009-11-24 00:55:3529#include "chrome/browser/sync/profile_sync_service.h"
[email protected]40f047972009-11-25 03:54:4030#include "chrome/browser/sync/sync_ui_util.h"
31#include "chrome/browser/sync/sync_ui_util_mac.h"
[email protected]60ad3e22009-09-18 21:07:1932#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]ae04f592010-11-18 20:41:3533#include "chrome/browser/ui/browser.h"
[email protected]f7002802010-11-12 19:50:2834#include "chrome/browser/ui/browser_init.h"
[email protected]ae04f592010-11-18 20:41:3535#include "chrome/browser/ui/browser_list.h"
36#include "chrome/browser/ui/browser_window.h"
[email protected]7d791652010-12-01 16:34:4937#import "chrome/browser/ui/cocoa/about_window_controller.h"
38#import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
39#import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
40#import "chrome/browser/ui/cocoa/browser_window_controller.h"
41#import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
42#import "chrome/browser/ui/cocoa/clear_browsing_data_controller.h"
43#import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
44#import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h"
45#import "chrome/browser/ui/cocoa/history_menu_bridge.h"
46#import "chrome/browser/ui/cocoa/import_settings_dialog.h"
47#import "chrome/browser/ui/cocoa/preferences_window_controller.h"
48#import "chrome/browser/ui/cocoa/tab_strip_controller.h"
49#import "chrome/browser/ui/cocoa/tab_window_controller.h"
50#include "chrome/browser/ui/cocoa/task_manager_mac.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) {
[email protected]177aceb2010-11-03 16:17:41298 // Show the info panel that explains what the user must to do confirm quit.
[email protected]8ecce342010-11-22 21:13:51299 [[ConfirmQuitPanelController sharedController] showWindow:self];
[email protected]177aceb2010-11-03 16:17:41300
301 // How long the user must hold down Cmd+Q to confirm the quit.
302 const NSTimeInterval kTimeToConfirmQuit = 1.5;
303 // Leeway between the |targetDate| and the current time that will confirm a
304 // quit.
305 const NSTimeInterval kTimeDeltaFuzzFactor = 1.0;
306 // Duration of the window fade out animation.
307 const NSTimeInterval kWindowFadeAnimationDuration = 0.2;
308
309 // Spin a nested run loop until the |targetDate| is reached or a KeyUp event
310 // is sent.
311 NSDate* targetDate =
312 [NSDate dateWithTimeIntervalSinceNow:kTimeToConfirmQuit];
313 BOOL willQuit = NO;
314 NSEvent* nextEvent = nil;
315 do {
316 // Dequeue events until a key up is received.
317 nextEvent = [app nextEventMatchingMask:NSKeyUpMask
318 untilDate:nil
319 inMode:NSEventTrackingRunLoopMode
320 dequeue:YES];
321
322 // Wait for the time expiry to happen. Once past the hold threshold,
323 // commit to quitting and hide all the open windows.
324 if (!willQuit) {
325 NSDate* now = [NSDate date];
326 NSTimeInterval difference = [targetDate timeIntervalSinceDate:now];
327 if (difference < kTimeDeltaFuzzFactor) {
328 willQuit = YES;
329
330 // At this point, the quit has been confirmed and windows should all
331 // fade out to convince the user to release the key combo to finalize
332 // the quit.
333 [NSAnimationContext beginGrouping];
334 [[NSAnimationContext currentContext] setDuration:
335 kWindowFadeAnimationDuration];
336 for (NSWindow* aWindow in [app windows]) {
337 // Windows that are set to animate and have a delegate do not
338 // expect to be animated by other things and could result in an
339 // invalid state. If a window is set up like so, just force the
340 // alpha value to 0. Otherwise, animate all pretty and stuff.
341 if (![[aWindow animationForKey:@"alphaValue"] delegate]) {
342 [[aWindow animator] setAlphaValue:0.0];
343 } else {
344 [aWindow setAlphaValue:0.0];
345 }
346 }
347 [NSAnimationContext endGrouping];
348 }
349 }
350 } while (!nextEvent);
351
352 // The user has released the key combo. Discard any events (i.e. the
353 // repeated KeyDown Cmd+Q).
354 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent];
355 if (willQuit) {
356 // The user held down the combination long enough that quitting should
357 // happen.
358 return NSTerminateNow;
359 } else {
360 // Slowly fade the confirm window out in case the user doesn't
361 // understand what they have to do to quit.
[email protected]8ecce342010-11-22 21:13:51362 [[ConfirmQuitPanelController sharedController] dismissPanel];
[email protected]177aceb2010-11-03 16:17:41363 return NSTerminateCancel;
364 }
365 } // if event type is KeyDown
366
367 // Default case: terminate.
368 return NSTerminateNow;
369}
370
[email protected]449dd2f2009-05-27 13:04:00371// Called when the app is shutting down. Clean-up as appropriate.
[email protected]7dc8c6b2010-04-09 17:02:50372- (void)applicationWillTerminate:(NSNotification*)aNotification {
[email protected]3b6aa8b62009-09-15 21:36:11373 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
374 [em removeEventHandlerForEventClass:kInternetEventClass
375 andEventID:kAEGetURL];
376 [em removeEventHandlerForEventClass:'WWW!'
377 andEventID:'OURL'];
[email protected]3b6aa8b62009-09-15 21:36:11378
[email protected]7dc8c6b2010-04-09 17:02:50379 // There better be no browser windows left at this point.
380 CHECK_EQ(BrowserList::size(), 0u);
[email protected]3b6aa8b62009-09-15 21:36:11381
[email protected]c984d9f2010-07-20 20:52:20382 // Tell BrowserList not to keep the browser process alive. Once all the
383 // browsers get dealloc'd, it will stop the RunLoop and fall back into main().
384 BrowserList::EndKeepAlive();
[email protected]fbc947b2009-06-19 13:28:24385
[email protected]d4e18652009-11-19 21:52:16386 // Close these off if they have open windows.
387 [prefsController_ close];
388 [aboutController_ close];
389
[email protected]449dd2f2009-05-27 13:04:00390 [[NSNotificationCenter defaultCenter] removeObserver:self];
391}
392
[email protected]3b6aa8b62009-09-15 21:36:11393- (void)didEndMainMessageLoop {
394 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile]));
395 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) {
396 // As we're shutting down, we need to nuke the TabRestoreService, which
397 // will start the shutdown of the NavigationControllers and allow for
398 // proper shutdown. If we don't do this, Chrome won't shut down cleanly,
399 // and may end up crashing when some thread tries to use the IO thread (or
400 // another thread) that is no longer valid.
401 [self defaultProfile]->ResetTabRestoreService();
402 }
403}
404
[email protected]449dd2f2009-05-27 13:04:00405// Helper routine to get the window controller if the key window is a tabbed
406// window, or nil if not. Examples of non-tabbed windows are "about" or
407// "preferences".
408- (TabWindowController*)keyWindowTabController {
409 NSWindowController* keyWindowController =
[email protected]5dbabd02009-09-17 20:44:13410 [[NSApp keyWindow] windowController];
[email protected]449dd2f2009-05-27 13:04:00411 if ([keyWindowController isKindOfClass:[TabWindowController class]])
412 return (TabWindowController*)keyWindowController;
413
414 return nil;
415}
416
[email protected]74c0c642009-09-22 21:25:50417// Helper routine to get the window controller if the main window is a tabbed
418// window, or nil if not. Examples of non-tabbed windows are "about" or
419// "preferences".
420- (TabWindowController*)mainWindowTabController {
421 NSWindowController* mainWindowController =
422 [[NSApp mainWindow] windowController];
423 if ([mainWindowController isKindOfClass:[TabWindowController class]])
424 return (TabWindowController*)mainWindowController;
425
426 return nil;
427}
428
[email protected]449dd2f2009-05-27 13:04:00429// If the window has tabs, make "close window" be cmd-shift-w, otherwise leave
430// it as the normal cmd-w. Capitalization of the key equivalent affects whether
431// the shift modifer is used.
432- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs {
433 [closeWindowMenuItem_ setKeyEquivalent:(inHaveTabs ? @"W" : @"w")];
[email protected]74c0c642009-09-22 21:25:50434 [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
[email protected]449dd2f2009-05-27 13:04:00435}
436
437// If the window has tabs, make "close tab" take over cmd-w, otherwise it
438// shouldn't have any key-equivalent because it should be disabled.
439- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)hasTabs {
440 if (hasTabs) {
441 [closeTabMenuItem_ setKeyEquivalent:@"w"];
442 [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask];
443 } else {
444 [closeTabMenuItem_ setKeyEquivalent:@""];
445 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
446 }
447}
448
[email protected]74c0c642009-09-22 21:25:50449// Explicitly remove any command-key equivalents from the close tab/window
450// menus so that nothing can go haywire if we get a user action during pending
451// updates.
452- (void)clearCloseMenuItemKeyEquivalents {
453 [closeTabMenuItem_ setKeyEquivalent:@""];
454 [closeTabMenuItem_ setKeyEquivalentModifierMask:0];
455 [closeWindowMenuItem_ setKeyEquivalent:@""];
456 [closeWindowMenuItem_ setKeyEquivalentModifierMask:0];
457}
458
[email protected]449dd2f2009-05-27 13:04:00459// See if we have a window with tabs open, and adjust the key equivalents for
[email protected]668c911c2010-03-08 17:05:25460// Close Tab/Close Window accordingly.
[email protected]449dd2f2009-05-27 13:04:00461- (void)fixCloseMenuItemKeyEquivalents {
[email protected]668c911c2010-03-08 17:05:25462 fileMenuUpdatePending_ = NO;
[email protected]449dd2f2009-05-27 13:04:00463 TabWindowController* tabController = [self keyWindowTabController];
[email protected]74c0c642009-09-22 21:25:50464 if (!tabController && ![NSApp keyWindow]) {
465 // There might be a small amount of time where there is no key window,
466 // so just use our main browser window if there is one.
467 tabController = [self mainWindowTabController];
468 }
[email protected]449dd2f2009-05-27 13:04:00469 BOOL windowWithMultipleTabs =
470 (tabController && [tabController numberOfTabs] > 1);
471 [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs];
472 [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs];
[email protected]449dd2f2009-05-27 13:04:00473}
474
475// Fix up the "close tab/close window" command-key equivalents. We do this
476// after a delay to ensure that window layer state has been set by the time
[email protected]f2a5c342010-01-21 17:00:29477// we do the enabling. This should only be called on the main thread, code that
478// calls this (even as a side-effect) from other threads needs to be fixed.
[email protected]449dd2f2009-05-27 13:04:00479- (void)delayedFixCloseMenuItemKeyEquivalents {
[email protected]f2a5c342010-01-21 17:00:29480 DCHECK([NSThread isMainThread]);
[email protected]449dd2f2009-05-27 13:04:00481 if (!fileMenuUpdatePending_) {
[email protected]74c0c642009-09-22 21:25:50482 // The OS prefers keypresses to timers, so it's possible that a cmd-w
483 // can sneak in before this timer fires. In order to prevent that from
484 // having any bad consequences, just clear the keys combos altogether. They
485 // will be reset when the timer eventually fires.
[email protected]668c911c2010-03-08 17:05:25486 if ([NSThread isMainThread]) {
487 fileMenuUpdatePending_ = YES;
488 [self clearCloseMenuItemKeyEquivalents];
489 [self performSelector:@selector(fixCloseMenuItemKeyEquivalents)
490 withObject:nil
491 afterDelay:0];
492 } else {
493 // This shouldn't be happening, but if it does, force it to the main
494 // thread to avoid dropping the update. Don't mess with
495 // |fileMenuUpdatePending_| as it's not expected to be threadsafe and
496 // there could be a race between the selector finishing and setting the
497 // flag.
498 [self
499 performSelectorOnMainThread:@selector(fixCloseMenuItemKeyEquivalents)
[email protected]f2a5c342010-01-21 17:00:29500 withObject:nil
501 waitUntilDone:NO];
[email protected]668c911c2010-03-08 17:05:25502 }
[email protected]449dd2f2009-05-27 13:04:00503 }
504}
505
506// Called when we get a notification about the window layering changing to
507// update the UI based on the new main window.
508- (void)windowLayeringDidChange:(NSNotification*)notify {
509 [self delayedFixCloseMenuItemKeyEquivalents];
[email protected]dd6ab1282010-07-20 01:07:32510
511 if ([notify name] == NSWindowDidResignKeyNotification) {
512 // If a window is closed, this notification is fired but |[NSApp keyWindow]|
513 // returns nil regardless of whether any suitable candidates for the key
514 // window remain. It seems that the new key window for the app is not set
515 // until after this notification is fired, so a check is performed after the
516 // run loop is allowed to spin.
517 [self performSelector:@selector(checkForAnyKeyWindows)
518 withObject:nil
519 afterDelay:0.0];
520 }
521}
522
523- (void)checkForAnyKeyWindows {
524 if ([NSApp keyWindow])
525 return;
526
527 NotificationService::current()->Notify(
528 NotificationType::NO_KEY_WINDOW,
529 NotificationService::AllSources(),
530 NotificationService::NoDetails());
[email protected]449dd2f2009-05-27 13:04:00531}
532
533// Called when the number of tabs changes in one of the browser windows. The
534// object is the tab strip controller, but we don't currently care.
535- (void)tabsChanged:(NSNotification*)notify {
[email protected]e72746b12009-10-19 14:11:51536 // We don't need to do this on a delay, as in the method above, because the
537 // window layering isn't changing. As a result, there's no chance that a
538 // different window will sneak in as the key window and cause the problems
539 // we hacked around above by clearing the key equivalents.
540 [self fixCloseMenuItemKeyEquivalents];
[email protected]449dd2f2009-05-27 13:04:00541}
542
[email protected]414fde592009-05-21 16:14:43543// If the auto-update interval is not set, make it 5 hours.
544// This code is specific to Mac Chrome Dev Channel.
545// Placed here for 2 reasons:
546// 1) Same spot as other Pref stuff
547// 2) Try and be friendly by keeping this after app launch
548// TODO(jrg): remove once we go Beta.
549- (void)setUpdateCheckInterval {
550#if defined(GOOGLE_CHROME_BUILD)
551 CFStringRef app = (CFStringRef)@"com.google.Keystone.Agent";
552 CFStringRef checkInterval = (CFStringRef)@"checkInterval";
553 CFPropertyListRef plist = CFPreferencesCopyAppValue(checkInterval, app);
554 if (!plist) {
555 const float fiveHoursInSeconds = 5.0 * 60.0 * 60.0;
[email protected]7dc8c6b2010-04-09 17:02:50556 NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds];
[email protected]414fde592009-05-21 16:14:43557 CFPreferencesSetAppValue(checkInterval, value, app);
558 CFPreferencesAppSynchronize(app);
559 }
560#endif
561}
562
[email protected]136140c2009-05-19 13:58:25563// This is called after profiles have been loaded and preferences registered.
564// It is safe to access the default profile here.
565- (void)applicationDidFinishLaunching:(NSNotification*)notify {
[email protected]c984d9f2010-07-20 20:52:20566 // Notify BrowserList to keep the application running so it doesn't go away
567 // when all the browser windows get closed.
568 BrowserList::StartKeepAlive();
[email protected]136140c2009-05-19 13:58:25569
[email protected]e5575022009-08-22 00:31:22570 bookmarkMenuBridge_.reset(new BookmarkMenuBridge([self defaultProfile]));
[email protected]1c84c82c2009-07-27 15:37:25571 historyMenuBridge_.reset(new HistoryMenuBridge([self defaultProfile]));
[email protected]cd63ef62009-05-06 19:41:37572
[email protected]414fde592009-05-21 16:14:43573 [self setUpdateCheckInterval];
[email protected]2bcec612009-05-14 17:50:53574
575 // Build up the encoding menu, the order of the items differs based on the
576 // current locale (see http://crbug.com/7647 for details).
577 // We need a valid g_browser_process to get the profile which is why we can't
578 // call this from awakeFromNib.
[email protected]fc349322009-09-23 22:28:23579 NSMenu* view_menu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu];
580 NSMenuItem* encoding_menu_item = [view_menu itemWithTag:IDC_ENCODING_MENU];
[email protected]7dc8c6b2010-04-09 17:02:50581 NSMenu* encoding_menu = [encoding_menu_item submenu];
[email protected]fc349322009-09-23 22:28:23582 EncodingMenuControllerDelegate::BuildEncodingMenu([self defaultProfile],
583 encoding_menu);
[email protected]2bcec612009-05-14 17:50:53584
[email protected]f2c20fa2009-12-01 17:42:02585 // Since Chrome is localized to more languages than the OS, tell Cocoa which
586 // menu is the Help so it can add the search item to it.
[email protected]caadfca2010-01-22 21:51:21587 if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)])
[email protected]f2c20fa2009-12-01 17:42:02588 [NSApp setHelpMenu:helpMenu_];
[email protected]f2c20fa2009-12-01 17:42:02589
[email protected]12dc3d42010-02-22 23:37:12590 // Record the path to the (browser) app bundle; this is used by the app mode
591 // shim.
592 RecordLastRunAppBundlePath();
593
[email protected]eef99c22010-08-17 05:55:16594 // Makes "Services" menu items available.
595 [self registerServicesMenuTypesTo:[notify object]];
596
[email protected]caadfca2010-01-22 21:51:21597 startupComplete_ = YES;
598
599 // TODO(viettrungluu): This is very temporary, since this should be done "in"
600 // |BrowserMain()|, i.e., this list of startup URLs should be appended to the
601 // (probably-empty) list of URLs from the command line.
[email protected]d630d7d52010-02-21 00:55:11602 if (startupUrls_.size()) {
603 [self openUrls:startupUrls_];
604 [self clearStartupUrls];
[email protected]caadfca2010-01-22 21:51:21605 }
[email protected]ad2a3ded2010-08-27 13:19:05606
607 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
608 if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) {
609 [tabposeMenuItem_ setHidden:YES];
610 }
[email protected]7c321082009-02-09 15:35:47611}
612
[email protected]a96ec6a2009-11-04 17:27:08613// This is called after profiles have been loaded and preferences registered.
614// It is safe to access the default profile here.
615- (void)applicationDidBecomeActive:(NSNotification*)notify {
616 NotificationService::current()->Notify(NotificationType::APP_ACTIVATED,
617 NotificationService::AllSources(),
618 NotificationService::NoDetails());
619}
620
[email protected]73f5b362009-08-10 23:58:21621// Helper function for populating and displaying the in progress downloads at
622// exit alert panel.
623- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount {
[email protected]e8b5f7882009-09-14 20:59:13624 NSString* warningText = nil;
625 NSString* explanationText = nil;
[email protected]73f5b362009-08-10 23:58:21626 NSString* waitTitle = nil;
627 NSString* exitTitle = nil;
628
[email protected]757127052010-04-27 14:42:26629 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
[email protected]9dcb59662009-09-23 01:15:50630
[email protected]73f5b362009-08-10 23:58:21631 // Set the dialog text based on whether or not there are multiple downloads.
632 if (downloadCount == 1) {
[email protected]e8b5f7882009-09-14 20:59:13633 // Dialog text: warning and explanation.
[email protected]757127052010-04-27 14:42:26634 warningText = l10n_util::GetNSStringF(
635 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING, product_name);
636 explanationText = l10n_util::GetNSStringF(
637 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION, product_name);
[email protected]73f5b362009-08-10 23:58:21638
639 // Cancel download and exit button text.
[email protected]757127052010-04-27 14:42:26640 exitTitle = l10n_util::GetNSString(
641 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21642
643 // Wait for download button text.
[email protected]757127052010-04-27 14:42:26644 waitTitle = l10n_util::GetNSString(
645 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21646 } else {
[email protected]e8b5f7882009-09-14 20:59:13647 // Dialog text: warning and explanation.
[email protected]757127052010-04-27 14:42:26648 warningText = l10n_util::GetNSStringF(
649 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING, product_name,
[email protected]528c56d2010-07-30 19:28:44650 base::IntToString16(downloadCount));
[email protected]757127052010-04-27 14:42:26651 explanationText = l10n_util::GetNSStringF(
652 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION, product_name);
[email protected]73f5b362009-08-10 23:58:21653
654 // Cancel downloads and exit button text.
[email protected]757127052010-04-27 14:42:26655 exitTitle = l10n_util::GetNSString(
656 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21657
658 // Wait for downloads button text.
[email protected]757127052010-04-27 14:42:26659 waitTitle = l10n_util::GetNSString(
660 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
[email protected]73f5b362009-08-10 23:58:21661 }
662
663 // 'waitButton' is the default choice.
[email protected]e8b5f7882009-09-14 20:59:13664 int choice = NSRunAlertPanel(warningText, explanationText,
665 waitTitle, exitTitle, nil);
[email protected]73f5b362009-08-10 23:58:21666 return choice == NSAlertDefaultReturn ? YES : NO;
667}
668
669// Check all profiles for in progress downloads, and if we find any, prompt the
[email protected]09729a552009-08-03 23:21:41670// user to see if we should continue to exit (and thus cancel the downloads), or
671// if we should wait.
672- (BOOL)shouldQuitWithInProgressDownloads {
[email protected]73f5b362009-08-10 23:58:21673 ProfileManager* profile_manager = g_browser_process->profile_manager();
674 if (!profile_manager)
675 return YES;
[email protected]09729a552009-08-03 23:21:41676
[email protected]73f5b362009-08-10 23:58:21677 ProfileManager::const_iterator it = profile_manager->begin();
678 for (; it != profile_manager->end(); ++it) {
679 Profile* profile = *it;
[email protected]09729a552009-08-03 23:21:41680 DownloadManager* download_manager = profile->GetDownloadManager();
[email protected]73f5b362009-08-10 23:58:21681 if (download_manager && download_manager->in_progress_count() > 0) {
682 int downloadCount = download_manager->in_progress_count();
683 if ([self userWillWaitForInProgressDownloads:downloadCount]) {
684 // Create a new browser window (if necessary) and navigate to the
685 // downloads page if the user chooses to wait.
686 Browser* browser = BrowserList::FindBrowserWithProfile(profile);
687 if (!browser) {
688 browser = Browser::Create(profile);
689 browser->window()->Show();
690 }
691 DCHECK(browser);
692 browser->ShowDownloadsTab();
693 return NO;
694 }
[email protected]09729a552009-08-03 23:21:41695
[email protected]73f5b362009-08-10 23:58:21696 // User wants to exit.
697 return YES;
[email protected]09729a552009-08-03 23:21:41698 }
[email protected]09729a552009-08-03 23:21:41699 }
700
[email protected]73f5b362009-08-10 23:58:21701 // No profiles or active downloads found, okay to exit.
[email protected]09729a552009-08-03 23:21:41702 return YES;
703}
704
[email protected]fbc947b2009-06-19 13:28:24705// Called to determine if we should enable the "restore tab" menu item.
706// Checks with the TabRestoreService to see if there's anything there to
707// restore and returns YES if so.
708- (BOOL)canRestoreTab {
709 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService();
710 return service && !service->entries().empty();
711}
712
[email protected]f6c15fa2010-06-04 20:08:21713// Returns true if there is not a modal window (either window- or application-
714// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
715// sheets) will not count as blocking the browser. But things like open/save
716// dialogs that are window modal will block the browser.
717- (BOOL)keyWindowIsNotModal {
[email protected]6a281332009-10-13 17:41:06718 Browser* browser = BrowserList::GetLastActive();
[email protected]dc76e8362010-06-11 16:29:52719 return [NSApp modalWindow] == nil && (!browser ||
[email protected]6a281332009-10-13 17:41:06720 ![[browser->window()->GetNativeHandle() attachedSheet]
[email protected]f6c15fa2010-06-04 20:08:21721 isKindOfClass:[NSWindow class]]);
[email protected]6a281332009-10-13 17:41:06722}
723
[email protected]88d74942009-01-21 22:04:44724// Called to validate menu items when there are no key windows. All the
725// items we care about have been set with the |commandDispatch:| action and
726// a target of FirstResponder in IB. If it's not one of those, let it
727// continue up the responder chain to be handled elsewhere. We pull out the
728// tag as the cross-platform constant to differentiate and dispatch the
729// various commands.
730- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
731 SEL action = [item action];
732 BOOL enable = NO;
733 if (action == @selector(commandDispatch:)) {
734 NSInteger tag = [item tag];
[email protected]fbc947b2009-06-19 13:28:24735 if (menuState_->SupportsCommand(tag)) {
736 switch (tag) {
[email protected]419eb2a2009-11-11 16:26:26737 // The File Menu commands are not automatically disabled by Cocoa when a
738 // dialog sheet obscures the browser window, so we disable several of
739 // them here. We don't need to include IDC_CLOSE_WINDOW, because
740 // app_controller is only activated when there are no key windows (see
741 // function comment).
[email protected]fbc947b2009-06-19 13:28:24742 case IDC_RESTORE_TAB:
[email protected]f6c15fa2010-06-04 20:08:21743 enable = [self keyWindowIsNotModal] && [self canRestoreTab];
[email protected]6a281332009-10-13 17:41:06744 break;
[email protected]f6c15fa2010-06-04 20:08:21745 // Browser-level items that open in new tabs should not open if there's
746 // a window- or app-modal dialog.
[email protected]6a281332009-10-13 17:41:06747 case IDC_OPEN_FILE:
[email protected]6a281332009-10-13 17:41:06748 case IDC_NEW_TAB:
[email protected]f6c15fa2010-06-04 20:08:21749 case IDC_SHOW_HISTORY:
750 case IDC_SHOW_BOOKMARK_MANAGER:
751 enable = [self keyWindowIsNotModal];
752 break;
753 // Browser-level items that open in new windows.
754 case IDC_NEW_WINDOW:
755 case IDC_TASK_MANAGER:
756 // Allow the user to open a new window if there's a window-modal
757 // dialog.
758 enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil);
[email protected]fbc947b2009-06-19 13:28:24759 break;
[email protected]446e16a2010-05-03 21:23:58760 case IDC_SYNC_BOOKMARKS: {
761 Profile* defaultProfile = [self defaultProfile];
762 // The profile may be NULL during shutdown -- see
763 // http://code.google.com/p/chromium/issues/detail?id=43048 .
764 //
765 // TODO(akalin,viettrungluu): Figure out whether this method
766 // can be prevented from being called if defaultProfile is
767 // NULL.
768 if (!defaultProfile) {
769 LOG(WARNING)
770 << "NULL defaultProfile detected -- not doing anything";
771 break;
772 }
[email protected]d3b98c82010-07-14 07:45:59773 enable = defaultProfile->IsSyncAccessible() &&
774 [self keyWindowIsNotModal];
[email protected]446e16a2010-05-03 21:23:58775 sync_ui_util::UpdateSyncItem(item, enable, defaultProfile);
[email protected]f9bc9b92009-11-24 00:55:35776 break;
[email protected]446e16a2010-05-03 21:23:58777 }
[email protected]fbc947b2009-06-19 13:28:24778 default:
[email protected]f6c15fa2010-06-04 20:08:21779 enable = menuState_->IsCommandEnabled(tag) ?
780 [self keyWindowIsNotModal] : NO;
[email protected]fbc947b2009-06-19 13:28:24781 }
782 }
[email protected]3b6aa8b62009-09-15 21:36:11783 } else if (action == @selector(terminate:)) {
[email protected]88d74942009-01-21 22:04:44784 enable = YES;
[email protected]3111f08b2009-04-30 16:01:52785 } else if (action == @selector(showPreferences:)) {
786 enable = YES;
[email protected]bde3dda2009-05-20 22:13:07787 } else if (action == @selector(orderFrontStandardAboutPanel:)) {
788 enable = YES;
[email protected]3d4bd23f2009-10-06 03:58:38789 } else if (action == @selector(newWindowFromDock:)) {
790 enable = YES;
[email protected]88d74942009-01-21 22:04:44791 }
792 return enable;
793}
794
[email protected]947fc0d2010-01-14 22:33:05795// Called when the user picks a menu item when there are no key windows, or when
796// there is no foreground browser window. Calls through to the browser object to
797// execute the command. This assumes that the command is supported and doesn't
[email protected]d630d7d52010-02-21 00:55:11798// check, otherwise it should have been disabled in the UI in
799// |-validateUserInterfaceItem:|.
[email protected]88d74942009-01-21 22:04:44800- (void)commandDispatch:(id)sender {
[email protected]93e181762009-05-29 14:30:38801 Profile* defaultProfile = [self defaultProfile];
[email protected]f0a51fb52009-03-05 12:46:38802
[email protected]947fc0d2010-01-14 22:33:05803 // Handle the case where we're dispatching a command from a sender that's in a
804 // browser window. This means that the command came from a background window
805 // and is getting here because the foreground window is not a browser window.
806 if ([sender respondsToSelector:@selector(window)]) {
807 id delegate = [[sender window] windowController];
808 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
809 [delegate commandDispatch:sender];
810 return;
811 }
812 }
813
[email protected]88d74942009-01-21 22:04:44814 NSInteger tag = [sender tag];
815 switch (tag) {
[email protected]fbc947b2009-06-19 13:28:24816 case IDC_NEW_TAB:
[email protected]d630d7d52010-02-21 00:55:11817 // Create a new tab in an existing browser window (which we activate) if
818 // possible.
819 if (Browser* browser = ActivateBrowser(defaultProfile)) {
820 browser->ExecuteCommand(IDC_NEW_TAB);
821 break;
822 }
823 // Else fall through to create new window.
[email protected]88d74942009-01-21 22:04:44824 case IDC_NEW_WINDOW:
[email protected]d630d7d52010-02-21 00:55:11825 CreateBrowser(defaultProfile);
826 break;
[email protected]91a5b3e2009-10-30 19:32:22827 case IDC_FOCUS_LOCATION:
[email protected]d630d7d52010-02-21 00:55:11828 ActivateOrCreateBrowser(defaultProfile)->
829 ExecuteCommand(IDC_FOCUS_LOCATION);
[email protected]88d74942009-01-21 22:04:44830 break;
[email protected]cddc5242009-12-07 18:54:33831 case IDC_FOCUS_SEARCH:
[email protected]d630d7d52010-02-21 00:55:11832 ActivateOrCreateBrowser(defaultProfile)->ExecuteCommand(IDC_FOCUS_SEARCH);
[email protected]cddc5242009-12-07 18:54:33833 break;
[email protected]863ff662009-01-26 20:18:18834 case IDC_NEW_INCOGNITO_WINDOW:
[email protected]e9e211272009-09-22 16:39:11835 Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile());
[email protected]863ff662009-01-26 20:18:18836 break;
[email protected]fbc947b2009-06-19 13:28:24837 case IDC_RESTORE_TAB:
838 Browser::OpenWindowWithRestoredTabs(defaultProfile);
839 break;
[email protected]e19516d2009-04-28 17:15:19840 case IDC_OPEN_FILE:
[email protected]d630d7d52010-02-21 00:55:11841 CreateBrowser(defaultProfile)->ExecuteCommand(IDC_OPEN_FILE);
[email protected]e19516d2009-04-28 17:15:19842 break;
[email protected]1fdff702009-10-22 00:36:18843 case IDC_CLEAR_BROWSING_DATA: {
[email protected]93e181762009-05-29 14:30:38844 // There may not be a browser open, so use the default profile.
[email protected]049ac832009-12-15 16:26:54845 [ClearBrowsingDataController
846 showClearBrowsingDialogForProfile:defaultProfile];
[email protected]93e181762009-05-29 14:30:38847 break;
[email protected]1fdff702009-10-22 00:36:18848 }
[email protected]4aee5652009-11-19 18:59:21849 case IDC_IMPORT_SETTINGS: {
[email protected]896220042010-03-23 18:14:28850 UserMetrics::RecordAction(UserMetricsAction("Import_ShowDlg"),
851 defaultProfile);
[email protected]2989cce12010-02-01 10:56:53852 [ImportSettingsDialogController
853 showImportSettingsDialogForProfile:defaultProfile];
[email protected]4aee5652009-11-19 18:59:21854 break;
855 }
[email protected]af7c25e2010-01-23 05:46:45856 case IDC_SHOW_BOOKMARK_MANAGER:
[email protected]896220042010-03-23 18:14:28857 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarkManager"),
858 defaultProfile);
[email protected]90a8bf252010-03-12 00:09:47859 if (Browser* browser = ActivateBrowser(defaultProfile)) {
[email protected]47e532b2010-04-23 17:46:40860 // Open a bookmark manager tab.
[email protected]90a8bf252010-03-12 00:09:47861 browser->OpenBookmarkManager();
862 } else {
[email protected]47e532b2010-04-23 17:46:40863 // No browser window, so create one for the bookmark manager tab.
864 Browser::OpenBookmarkManagerWindow(defaultProfile);
[email protected]90a8bf252010-03-12 00:09:47865 }
[email protected]af7c25e2010-01-23 05:46:45866 break;
[email protected]91a5b3e2009-10-30 19:32:22867 case IDC_SHOW_HISTORY:
[email protected]d630d7d52010-02-21 00:55:11868 if (Browser* browser = ActivateBrowser(defaultProfile))
869 browser->ShowHistoryTab();
870 else
871 Browser::OpenHistoryWindow(defaultProfile);
[email protected]91a5b3e2009-10-30 19:32:22872 break;
873 case IDC_SHOW_DOWNLOADS:
[email protected]d630d7d52010-02-21 00:55:11874 if (Browser* browser = ActivateBrowser(defaultProfile))
875 browser->ShowDownloadsTab();
876 else
877 Browser::OpenDownloadsWindow(defaultProfile);
[email protected]91a5b3e2009-10-30 19:32:22878 break;
[email protected]bb37e6ec2009-11-18 17:59:36879 case IDC_MANAGE_EXTENSIONS:
[email protected]d630d7d52010-02-21 00:55:11880 if (Browser* browser = ActivateBrowser(defaultProfile))
881 browser->ShowExtensionsTab();
882 else
883 Browser::OpenExtensionsWindow(defaultProfile);
[email protected]bb37e6ec2009-11-18 17:59:36884 break;
[email protected]1fdff702009-10-22 00:36:18885 case IDC_HELP_PAGE:
[email protected]d630d7d52010-02-21 00:55:11886 if (Browser* browser = ActivateBrowser(defaultProfile))
887 browser->OpenHelpTab();
888 else
889 Browser::OpenHelpWindow(defaultProfile);
[email protected]1fdff702009-10-22 00:36:18890 break;
[email protected]1c41a932010-11-22 23:41:23891 case IDC_FEEDBACK: {
[email protected]3896b182009-11-03 16:15:32892 Browser* browser = BrowserList::GetLastActive();
[email protected]d630d7d52010-02-21 00:55:11893 TabContents* currentTab =
894 browser ? browser->GetSelectedTabContents() : NULL;
[email protected]3896b182009-11-03 16:15:32895 BugReportWindowController* controller =
896 [[BugReportWindowController alloc]
[email protected]d630d7d52010-02-21 00:55:11897 initWithTabContents:currentTab
898 profile:[self defaultProfile]];
[email protected]3896b182009-11-03 16:15:32899 [controller runModalDialog];
900 break;
901 }
[email protected]f9bc9b92009-11-24 00:55:35902 case IDC_SYNC_BOOKMARKS:
[email protected]446e16a2010-05-03 21:23:58903 // The profile may be NULL during shutdown -- see
904 // http://code.google.com/p/chromium/issues/detail?id=43048 .
905 //
906 // TODO(akalin,viettrungluu): Figure out whether this method can
907 // be prevented from being called if defaultProfile is NULL.
908 if (!defaultProfile) {
909 LOG(WARNING) << "NULL defaultProfile detected -- not doing anything";
910 break;
911 }
[email protected]f9bc9b92009-11-24 00:55:35912 // TODO(akalin): Add a constant to denote starting sync from the
913 // main menu and use that instead of START_FROM_WRENCH.
[email protected]40f047972009-11-25 03:54:40914 sync_ui_util::OpenSyncMyBookmarksDialog(
[email protected]f9bc9b92009-11-24 00:55:35915 defaultProfile, ProfileSyncService::START_FROM_WRENCH);
916 break;
[email protected]ceaaf1812010-01-20 22:13:09917 case IDC_TASK_MANAGER:
[email protected]896220042010-03-23 18:14:28918 UserMetrics::RecordAction(UserMetricsAction("TaskManager"),
919 defaultProfile);
[email protected]ceaaf1812010-01-20 22:13:09920 TaskManagerMac::Show();
921 break;
[email protected]4a42d272010-06-18 01:29:42922 case IDC_OPTIONS:
923 [self showPreferences:sender];
924 break;
[email protected]d630d7d52010-02-21 00:55:11925 }
[email protected]88d74942009-01-21 22:04:44926}
927
[email protected]947fc0d2010-01-14 22:33:05928// Same as |-commandDispatch:|, but executes commands using a disposition
929// determined by the key flags. This will get called in the case where the
930// frontmost window is not a browser window, and the user has command-clicked
931// a button in a background browser window whose action is
932// |-commandDispatchUsingKeyModifiers:|
933- (void)commandDispatchUsingKeyModifiers:(id)sender {
934 DCHECK(sender);
935 if ([sender respondsToSelector:@selector(window)]) {
936 id delegate = [[sender window] windowController];
937 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
938 [delegate commandDispatchUsingKeyModifiers:sender];
939 }
940 }
941}
942
[email protected]ff81e0a2009-04-13 14:58:54943// NSApplication delegate method called when someone clicks on the
944// dock icon and there are no open windows. To match standard mac
945// behavior, we should open a new window.
946- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
947 hasVisibleWindows:(BOOL)flag {
[email protected]70631402010-04-26 20:16:54948 // If the browser is currently trying to quit, don't do anything and return NO
949 // to prevent AppKit from doing anything.
950 // TODO(rohitrao): Remove this code when http://crbug.com/40861 is resolved.
951 if (browser_shutdown::IsTryingToQuit())
952 return NO;
953
[email protected]ff81e0a2009-04-13 14:58:54954 // Don't do anything if there are visible windows. This will cause
955 // AppKit to unminimize the most recently minimized window.
956 if (flag)
957 return YES;
958
[email protected]0d1210d62010-09-07 17:31:38959 // If launched as a hidden login item (due to installation of a persistent app
960 // or by the user, for example in System Preferenecs->Accounts->Login Items),
961 // allow session to be restored first time the user clicks on a Dock icon.
962 // Normally, it'd just open a new empty page.
963 {
964 static BOOL doneOnce = NO;
965 if (!doneOnce) {
966 doneOnce = YES;
967 if (mac_util::WasLaunchedAsHiddenLoginItem()) {
968 SessionService* sessionService =
969 [self defaultProfile]->GetSessionService();
970 if (sessionService &&
971 sessionService->RestoreIfNecessary(std::vector<GURL>()))
972 return NO;
973 }
974 }
975 }
[email protected]ff81e0a2009-04-13 14:58:54976 // Otherwise open a new window.
[email protected]d630d7d52010-02-21 00:55:11977 {
[email protected]0fbd70332010-06-01 19:28:34978 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
[email protected]d630d7d52010-02-21 00:55:11979 Browser::OpenEmptyWindow([self defaultProfile]);
980 }
[email protected]ff81e0a2009-04-13 14:58:54981
982 // We've handled the reopen event, so return NO to tell AppKit not
983 // to do anything.
984 return NO;
985}
986
[email protected]88d74942009-01-21 22:04:44987- (void)initMenuState {
[email protected]3111f08b2009-04-30 16:01:52988 menuState_.reset(new CommandUpdater(NULL));
[email protected]fbc947b2009-06-19 13:28:24989 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true);
[email protected]88d74942009-01-21 22:04:44990 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true);
[email protected]863ff662009-01-26 20:18:18991 menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true);
[email protected]e19516d2009-04-28 17:15:19992 menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true);
[email protected]93e181762009-05-29 14:30:38993 menuState_->UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true);
[email protected]fbc947b2009-06-19 13:28:24994 menuState_->UpdateCommandEnabled(IDC_RESTORE_TAB, false);
[email protected]91a5b3e2009-10-30 19:32:22995 menuState_->UpdateCommandEnabled(IDC_FOCUS_LOCATION, true);
[email protected]cddc5242009-12-07 18:54:33996 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true);
[email protected]af7c25e2010-01-23 05:46:45997 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true);
[email protected]91a5b3e2009-10-30 19:32:22998 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true);
999 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]bb37e6ec2009-11-18 17:59:361000 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true);
[email protected]1fdff702009-10-22 00:36:181001 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE, true);
[email protected]4aee5652009-11-19 18:59:211002 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true);
[email protected]1c41a932010-11-22 23:41:231003 menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true);
[email protected]d3b98c82010-07-14 07:45:591004 menuState_->UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, true);
[email protected]ceaaf1812010-01-20 22:13:091005 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true);
[email protected]88d74942009-01-21 22:04:441006}
[email protected]1bcdb532009-01-16 17:47:571007
[email protected]eef99c22010-08-17 05:55:161008- (void)registerServicesMenuTypesTo:(NSApplication*)app {
[email protected]09ea24c2010-08-23 19:05:411009 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which
1010 // handles requests from services.
1011 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil];
1012 [app registerServicesMenuSendTypes:types returnTypes:types];
[email protected]eef99c22010-08-17 05:55:161013}
1014
[email protected]3f34599d2009-03-25 22:11:431015- (Profile*)defaultProfile {
[email protected]3f34599d2009-03-25 22:11:431016 // TODO(jrg): Find a better way to get the "default" profile.
1017 if (g_browser_process->profile_manager())
[email protected]065566b2010-01-20 20:38:261018 return *g_browser_process->profile_manager()->begin();
[email protected]3f34599d2009-03-25 22:11:431019
[email protected]f6314002009-04-23 01:18:131020 return NULL;
[email protected]3f34599d2009-03-25 22:11:431021}
1022
[email protected]57750f822009-04-21 21:43:091023// Various methods to open URLs that we get in a native fashion. We use
1024// BrowserInit here because on the other platforms, URLs to open come through
1025// the ProcessSingleton, and it calls BrowserInit. It's best to bottleneck the
1026// openings through that for uniform handling.
1027
[email protected]d630d7d52010-02-21 00:55:111028- (void)openUrls:(const std::vector<GURL>&)urls {
[email protected]caadfca2010-01-22 21:51:211029 // If the browser hasn't started yet, just queue up the URLs.
1030 if (!startupComplete_) {
[email protected]d630d7d52010-02-21 00:55:111031 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end());
[email protected]136140c2009-05-19 13:58:251032 return;
1033 }
[email protected]57750f822009-04-21 21:43:091034
[email protected]0e863512009-05-28 19:45:071035 Browser* browser = BrowserList::GetLastActive();
1036 // if no browser window exists then create one with no tabs to be filled in
1037 if (!browser) {
1038 browser = Browser::Create([self defaultProfile]);
[email protected]ce560f82009-06-03 09:39:441039 browser->window()->Show();
[email protected]0e863512009-05-28 19:45:071040 }
1041
[email protected]947446b2010-10-21 03:36:311042 CommandLine dummy(CommandLine::NO_PROGRAM);
[email protected]f805fe82010-08-03 22:47:101043 BrowserInit::LaunchWithProfile launch(FilePath(), dummy);
[email protected]0e863512009-05-28 19:45:071044 launch.OpenURLsInBrowser(browser, false, urls);
[email protected]57750f822009-04-21 21:43:091045}
1046
[email protected]57750f822009-04-21 21:43:091047- (void)getUrl:(NSAppleEventDescriptor*)event
1048 withReply:(NSAppleEventDescriptor*)reply {
1049 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
1050 stringValue];
1051
1052 GURL gurl(base::SysNSStringToUTF8(urlStr));
1053 std::vector<GURL> gurlVector;
1054 gurlVector.push_back(gurl);
1055
[email protected]d630d7d52010-02-21 00:55:111056 [self openUrls:gurlVector];
[email protected]57750f822009-04-21 21:43:091057}
1058
[email protected]caadfca2010-01-22 21:51:211059- (void)application:(NSApplication*)sender
1060 openFiles:(NSArray*)filenames {
[email protected]57750f822009-04-21 21:43:091061 std::vector<GURL> gurlVector;
[email protected]caadfca2010-01-22 21:51:211062 for (NSString* file in filenames) {
1063 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file)));
[email protected]57750f822009-04-21 21:43:091064 gurlVector.push_back(gurl);
1065 }
[email protected]caadfca2010-01-22 21:51:211066 if (!gurlVector.empty())
[email protected]d630d7d52010-02-21 00:55:111067 [self openUrls:gurlVector];
[email protected]caadfca2010-01-22 21:51:211068 else
1069 NOTREACHED() << "Nothing to open!";
[email protected]57750f822009-04-21 21:43:091070
[email protected]caadfca2010-01-22 21:51:211071 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
[email protected]57750f822009-04-21 21:43:091072}
[email protected]3f34599d2009-03-25 22:11:431073
[email protected]767543d2009-04-30 19:23:581074// Called when the preferences window is closed. We use this to release the
1075// window controller.
[email protected]d4e18652009-11-19 21:52:161076- (void)prefsWindowClosed:(NSNotification*)notification {
1077 NSWindow* window = [prefsController_ window];
1078 DCHECK([notification object] == window);
1079 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
1080 [defaultCenter removeObserver:self
1081 name:NSWindowWillCloseNotification
1082 object:window];
1083 // PreferencesWindowControllers are autoreleased in
1084 // -[PreferencesWindowController windowWillClose:].
1085 prefsController_ = nil;
[email protected]767543d2009-04-30 19:23:581086}
1087
[email protected]3111f08b2009-04-30 16:01:521088// Show the preferences window, or bring it to the front if it's already
1089// visible.
1090- (IBAction)showPreferences:(id)sender {
[email protected]4a42d272010-06-18 01:29:421091 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
1092 if (parsed_command_line.HasSwitch(switches::kEnableTabbedOptions)) {
1093 if (Browser* browser = ActivateBrowser([self defaultProfile])) {
1094 // Show options tab in the active browser window.
[email protected]024617a2010-08-20 05:08:051095 browser->ShowOptionsTab(chrome::kDefaultOptionsSubPage);
[email protected]4a42d272010-06-18 01:29:421096 } else {
1097 // No browser window, so create one for the options tab.
1098 Browser::OpenOptionsWindow([self defaultProfile]);
1099 }
1100 } else {
1101 [self showPreferencesWindow:sender
1102 page:OPTIONS_PAGE_DEFAULT
1103 profile:[self defaultProfile]];
1104 }
[email protected]d989f07c2009-11-14 00:35:461105}
1106
1107- (void)showPreferencesWindow:(id)sender
1108 page:(OptionsPage)page
1109 profile:(Profile*)profile {
[email protected]d4e18652009-11-19 21:52:161110 if (prefsController_) {
[email protected]d989f07c2009-11-14 00:35:461111 [prefsController_ switchToPage:page animate:YES];
1112 } else {
[email protected]d4e18652009-11-19 21:52:161113 prefsController_ =
1114 [[PreferencesWindowController alloc] initWithProfile:profile
1115 initialPage:page];
[email protected]767543d2009-04-30 19:23:581116 // Watch for a notification of when it goes away so that we can destroy
1117 // the controller.
1118 [[NSNotificationCenter defaultCenter]
1119 addObserver:self
1120 selector:@selector(prefsWindowClosed:)
[email protected]d4e18652009-11-19 21:52:161121 name:NSWindowWillCloseNotification
1122 object:[prefsController_ window]];
[email protected]42404382009-04-30 17:59:241123 }
1124 [prefsController_ showPreferences:sender];
[email protected]3111f08b2009-04-30 16:01:521125}
1126
[email protected]bde3dda2009-05-20 22:13:071127// Called when the about window is closed. We use this to release the
1128// window controller.
[email protected]d4e18652009-11-19 21:52:161129- (void)aboutWindowClosed:(NSNotification*)notification {
1130 NSWindow* window = [aboutController_ window];
1131 DCHECK(window == [notification object]);
[email protected]bde3dda2009-05-20 22:13:071132 [[NSNotificationCenter defaultCenter]
[email protected]49aeee52009-10-26 19:58:131133 removeObserver:self
[email protected]d4e18652009-11-19 21:52:161134 name:NSWindowWillCloseNotification
1135 object:window];
1136 // AboutWindowControllers are autoreleased in
1137 // -[AboutWindowController windowWillClose:].
1138 aboutController_ = nil;
[email protected]bde3dda2009-05-20 22:13:071139}
1140
1141- (IBAction)orderFrontStandardAboutPanel:(id)sender {
[email protected]bde3dda2009-05-20 22:13:071142 if (!aboutController_) {
[email protected]d4e18652009-11-19 21:52:161143 aboutController_ =
1144 [[AboutWindowController alloc] initWithProfile:[self defaultProfile]];
[email protected]49aeee52009-10-26 19:58:131145
[email protected]bde3dda2009-05-20 22:13:071146 // Watch for a notification of when it goes away so that we can destroy
1147 // the controller.
1148 [[NSNotificationCenter defaultCenter]
1149 addObserver:self
1150 selector:@selector(aboutWindowClosed:)
[email protected]d4e18652009-11-19 21:52:161151 name:NSWindowWillCloseNotification
1152 object:[aboutController_ window]];
[email protected]bde3dda2009-05-20 22:13:071153 }
[email protected]49aeee52009-10-26 19:58:131154
[email protected]bde3dda2009-05-20 22:13:071155 [aboutController_ showWindow:self];
[email protected]bde3dda2009-05-20 22:13:071156}
1157
[email protected]3d4bd23f2009-10-06 03:58:381158// Explicitly bring to the foreground when creating new windows from the dock.
1159- (void)newWindowFromDock:(id)sender {
1160 [NSApp activateIgnoringOtherApps:YES];
1161 [self commandDispatch:sender];
1162}
1163
[email protected]227fcee2010-06-11 19:19:371164- (NSMenu*)applicationDockMenu:(NSApplication*)sender {
[email protected]018a3962009-09-17 22:23:441165 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
1166 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC);
1167 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc]
1168 initWithTitle:titleStr
[email protected]3d4bd23f2009-10-06 03:58:381169 action:@selector(newWindowFromDock:)
[email protected]018a3962009-09-17 22:23:441170 keyEquivalent:@""]);
[email protected]288bfcd32009-09-14 18:14:461171 [item setTarget:self];
1172 [item setTag:IDC_NEW_WINDOW];
[email protected]018a3962009-09-17 22:23:441173 [dockMenu addItem:item];
[email protected]288bfcd32009-09-14 18:14:461174
1175 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC);
[email protected]018a3962009-09-17 22:23:441176 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
[email protected]3d4bd23f2009-10-06 03:58:381177 action:@selector(newWindowFromDock:)
[email protected]018a3962009-09-17 22:23:441178 keyEquivalent:@""]);
[email protected]288bfcd32009-09-14 18:14:461179 [item setTarget:self];
1180 [item setTag:IDC_NEW_INCOGNITO_WINDOW];
[email protected]018a3962009-09-17 22:23:441181 [dockMenu addItem:item];
[email protected]288bfcd32009-09-14 18:14:461182
[email protected]018a3962009-09-17 22:23:441183 return dockMenu;
[email protected]288bfcd32009-09-14 18:14:461184}
1185
[email protected]d630d7d52010-02-21 00:55:111186- (const std::vector<GURL>&)startupUrls {
1187 return startupUrls_;
[email protected]caadfca2010-01-22 21:51:211188}
1189
[email protected]d630d7d52010-02-21 00:55:111190- (void)clearStartupUrls {
1191 startupUrls_.clear();
[email protected]caadfca2010-01-22 21:51:211192}
1193
[email protected]d630d7d52010-02-21 00:55:111194@end // @implementation AppController
[email protected]60ad3e22009-09-18 21:07:191195
1196//---------------------------------------------------------------------------
1197
[email protected]60ad3e22009-09-18 21:07:191198void ShowOptionsWindow(OptionsPage page,
1199 OptionsGroup highlight_group,
1200 Profile* profile) {
[email protected]d989f07c2009-11-14 00:35:461201 // TODO(akalin): Use highlight_group.
1202 AppController* appController = [NSApp delegate];
1203 [appController showPreferencesWindow:nil page:page profile:profile];
[email protected]60ad3e22009-09-18 21:07:191204}
[email protected]216e9042009-10-29 17:05:231205
1206namespace app_controller_mac {
1207
1208bool IsOpeningNewWindow() {
1209 return g_is_opening_new_window;
1210}
1211
1212} // namespace app_controller_mac