[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 2c47bc1 | 2009-04-10 20:14:00 | [diff] [blame] | 5 | #import "chrome/browser/app_controller_mac.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 6 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
[email protected] | 0b8caad | 2011-11-28 23:33:27 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | f805fe8 | 2010-08-03 22:47:10 | [diff] [blame] | 10 | #include "base/file_path.h" |
[email protected] | 151c4a6 | 2011-04-22 04:15:13 | [diff] [blame] | 11 | #include "base/mac/foundation_util.h" |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 12 | #include "base/mac/mac_util.h" |
[email protected] | 2c47bc1 | 2009-04-10 20:14:00 | [diff] [blame] | 13 | #include "base/message_loop.h" |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 15 | #include "base/sys_string_conversions.h" |
[email protected] | 061a5ea8 | 2011-08-03 10:11:50 | [diff] [blame] | 16 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 17 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 18 | #include "chrome/browser/background/background_application_list_model.h" |
[email protected] | 78d78a6 | 2011-09-29 18:24:33 | [diff] [blame] | 19 | #include "chrome/browser/background/background_mode_manager.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 20 | #include "chrome/browser/browser_process.h" |
[email protected] | 41741a96 | 2009-02-18 21:51:39 | [diff] [blame] | 21 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 2c47bc1 | 2009-04-10 20:14:00 | [diff] [blame] | 22 | #include "chrome/browser/command_updater.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 23 | #include "chrome/browser/download/download_service.h" |
| 24 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | e4a377cf | 2011-10-05 02:51:49 | [diff] [blame] | 25 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | 0934de8 | 2011-03-09 18:42:16 | [diff] [blame] | 26 | #include "chrome/browser/instant/instant_confirm_dialog.h" |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 27 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 28 | #include "chrome/browser/printing/cloud_print/virtual_driver_install_helper.h" |
| 29 | #include "chrome/browser/printing/print_dialog_cloud.h" |
[email protected] | e7dd6d8 | 2010-10-07 23:21:12 | [diff] [blame] | 30 | #include "chrome/browser/printing/print_job_manager.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 31 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 32 | #include "chrome/browser/service/service_process_control.h" |
[email protected] | d2912a2 | 2011-03-15 15:20:50 | [diff] [blame] | 33 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 34 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 35 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 36 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | f9bc9b9 | 2009-11-24 00:55:35 | [diff] [blame] | 37 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 38 | #include "chrome/browser/sync/sync_ui_util.h" |
| 39 | #include "chrome/browser/sync/sync_ui_util_mac.h" |
[email protected] | ae04f59 | 2010-11-18 20:41:35 | [diff] [blame] | 40 | #include "chrome/browser/ui/browser.h" |
[email protected] | f700280 | 2010-11-12 19:50:28 | [diff] [blame] | 41 | #include "chrome/browser/ui/browser_init.h" |
[email protected] | ae04f59 | 2010-11-18 20:41:35 | [diff] [blame] | 42 | #include "chrome/browser/ui/browser_list.h" |
| 43 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 44 | #import "chrome/browser/ui/cocoa/about_window_controller.h" |
| 45 | #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
| 46 | #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 47 | #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 48 | #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
| 49 | #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
| 50 | #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 51 | #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
[email protected] | cfe1d61 | 2011-01-19 20:06:47 | [diff] [blame] | 52 | #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 53 | #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 54 | #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
[email protected] | 6a45507 | 2011-11-02 01:32:28 | [diff] [blame] | 55 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | 14fb7d3 | 2011-07-10 17:53:32 | [diff] [blame] | 56 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 57 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | f4acfae8 | 2009-09-11 00:33:38 | [diff] [blame] | 58 | #include "chrome/common/chrome_switches.h" |
[email protected] | 13aec6c4 | 2011-10-27 21:22:08 | [diff] [blame] | 59 | #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
[email protected] | 6c583d3 | 2011-08-19 14:46:22 | [diff] [blame] | 60 | #include "chrome/common/mac/app_mode_common.h" |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 61 | #include "chrome/common/pref_names.h" |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 62 | #include "chrome/common/service_messages.h" |
[email protected] | 024617a | 2010-08-20 05:08:05 | [diff] [blame] | 63 | #include "chrome/common/url_constants.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 64 | #include "content/public/browser/browser_thread.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 65 | #include "content/public/browser/download_manager.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 66 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 67 | #include "content/public/browser/notification_types.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 68 | #include "content/public/browser/user_metrics.h" |
[email protected] | 9dcb5966 | 2009-09-23 01:15:50 | [diff] [blame] | 69 | #include "grit/chromium_strings.h" |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 70 | #include "grit/generated_resources.h" |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 71 | #include "net/base/net_util.h" |
[email protected] | 2b68f81 | 2011-11-25 15:02:11 | [diff] [blame] | 72 | #include "ui/base/accelerators/accelerator_cocoa.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 73 | #include "ui/base/l10n/l10n_util.h" |
| 74 | #include "ui/base/l10n/l10n_util_mac.h" |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 75 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 76 | using content::BrowserThread; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 77 | using content::DownloadManager; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 78 | using content::UserMetricsAction; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 79 | |
[email protected] | f2c20fa | 2009-12-01 17:42:02 | [diff] [blame] | 80 | // 10.6 adds a public API for the Spotlight-backed search menu item in the Help |
| 81 | // menu. Provide the declaration so it can be called below when building with |
| 82 | // the 10.5 SDK. |
| 83 | #if !defined(MAC_OS_X_VERSION_10_6) || \ |
| 84 | MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
| 85 | @interface NSApplication (SnowLeopardSDKDeclarations) |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 86 | - (void)setHelpMenu:(NSMenu*)helpMenu; |
[email protected] | f2c20fa | 2009-12-01 17:42:02 | [diff] [blame] | 87 | @end |
| 88 | #endif |
| 89 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 90 | namespace { |
| 91 | |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 92 | // Declare notification names from the 10.7 SDK. |
| 93 | #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 94 | MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 95 | NSString* NSPopoverDidShowNotification = @"NSPopoverDidShowNotification"; |
| 96 | NSString* NSPopoverDidCloseNotification = @"NSPopoverDidCloseNotification"; |
| 97 | #endif |
| 98 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 99 | // True while AppController is calling Browser::OpenEmptyWindow(). We need a |
| 100 | // global flag here, analogue to BrowserInit::InProcessStartup() because |
| 101 | // otherwise the SessionService will try to restore sessions when we make a new |
| 102 | // window while there are no other active windows. |
| 103 | bool g_is_opening_new_window = false; |
| 104 | |
| 105 | // Activates a browser window having the given profile (the last one active) if |
| 106 | // possible and returns a pointer to the activate |Browser| or NULL if this was |
| 107 | // not possible. If the last active browser is minimized (in particular, if |
| 108 | // there are only minimized windows), it will unminimize it. |
| 109 | Browser* ActivateBrowser(Profile* profile) { |
| 110 | Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 111 | if (browser) |
| 112 | browser->window()->Activate(); |
| 113 | return browser; |
| 114 | } |
| 115 | |
| 116 | // Creates an empty browser window with the given profile and returns a pointer |
| 117 | // to the new |Browser|. |
| 118 | Browser* CreateBrowser(Profile* profile) { |
| 119 | { |
[email protected] | 0fbd7033 | 2010-06-01 19:28:34 | [diff] [blame] | 120 | AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 121 | Browser::OpenEmptyWindow(profile); |
| 122 | } |
| 123 | |
| 124 | Browser* browser = BrowserList::GetLastActive(); |
| 125 | CHECK(browser); |
| 126 | return browser; |
| 127 | } |
| 128 | |
| 129 | // Activates a browser window having the given profile (the last one active) if |
| 130 | // possible or creates an empty one if necessary. Returns a pointer to the |
| 131 | // activated/new |Browser|. |
| 132 | Browser* ActivateOrCreateBrowser(Profile* profile) { |
| 133 | if (Browser* browser = ActivateBrowser(profile)) |
| 134 | return browser; |
| 135 | return CreateBrowser(profile); |
| 136 | } |
| 137 | |
[email protected] | 151c4a6 | 2011-04-22 04:15:13 | [diff] [blame] | 138 | CFStringRef BaseBundleID_CFString() { |
| 139 | NSString* base_bundle_id = |
| 140 | [NSString stringWithUTF8String:base::mac::BaseBundleID()]; |
| 141 | return base::mac::NSToCFCast(base_bundle_id); |
| 142 | } |
| 143 | |
[email protected] | 0b8caad | 2011-11-28 23:33:27 | [diff] [blame] | 144 | // This callback synchronizes preferences (under "org.chromium.Chromium" or |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 145 | // "com.google.Chrome"), in particular, writes them out to disk. |
[email protected] | 0b8caad | 2011-11-28 23:33:27 | [diff] [blame] | 146 | void PrefsSyncCallback() { |
| 147 | if (!CFPreferencesAppSynchronize(BaseBundleID_CFString())) |
| 148 | LOG(WARNING) << "Error recording application bundle path."; |
| 149 | } |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 150 | |
| 151 | // Record the location of the application bundle (containing the main framework) |
| 152 | // from which Chromium was loaded. This is used by app mode shims to find |
| 153 | // Chromium. |
| 154 | void RecordLastRunAppBundlePath() { |
| 155 | // Going up three levels from |chrome::GetVersionedDirectory()| gives the |
| 156 | // real, user-visible app bundle directory. (The alternatives give either the |
| 157 | // framework's path or the initial app's path, which may be an app mode shim |
| 158 | // or a unit test.) |
| 159 | FilePath appBundlePath = |
| 160 | chrome::GetVersionedDirectory().DirName().DirName().DirName(); |
| 161 | CFPreferencesSetAppValue(app_mode::kLastRunAppBundlePathPrefsKey, |
| 162 | base::SysUTF8ToCFStringRef(appBundlePath.value()), |
[email protected] | 151c4a6 | 2011-04-22 04:15:13 | [diff] [blame] | 163 | BaseBundleID_CFString()); |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 164 | |
| 165 | // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 166 | BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, |
[email protected] | 0b8caad | 2011-11-28 23:33:27 | [diff] [blame] | 167 | base::Bind(&PrefsSyncCallback), 1500); |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 170 | } // anonymous namespace |
| 171 | |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 172 | const AEEventClass kAECloudPrintInstallClass = 'GCPi'; |
| 173 | const AEEventClass kAECloudPrintUninstallClass = 'GCPu'; |
| 174 | |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 175 | @interface AppController (Private) |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 176 | - (void)initMenuState; |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 177 | - (void)initProfileMenu; |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 178 | - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 179 | - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 180 | - (void)openUrls:(const std::vector<GURL>&)urls; |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 181 | - (void)getUrl:(NSAppleEventDescriptor*)event |
| 182 | withReply:(NSAppleEventDescriptor*)reply; |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 183 | - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; |
| 184 | - (void)installCloudPrint:(NSAppleEventDescriptor*)event; |
| 185 | - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event; |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 186 | - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 187 | - (void)windowChangedToProfile:(Profile*)profile; |
[email protected] | dd6ab128 | 2010-07-20 01:07:32 | [diff] [blame] | 188 | - (void)checkForAnyKeyWindows; |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 189 | - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 190 | - (BOOL)shouldQuitWithInProgressDownloads; |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 191 | - (void)executeApplication:(id)sender; |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 192 | @end |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 193 | |
| 194 | @implementation AppController |
| 195 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 196 | @synthesize startupComplete = startupComplete_; |
| 197 | |
[email protected] | cd63ef6 | 2009-05-06 19:41:37 | [diff] [blame] | 198 | // This method is called very early in application startup (ie, before |
| 199 | // the profile is loaded or any preferences have been registered). Defer any |
| 200 | // user-data initialization until -applicationDidFinishLaunching:. |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 201 | - (void)awakeFromNib { |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 202 | // We need to register the handlers early to catch events fired on launch. |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 203 | NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
| 204 | [em setEventHandler:self |
| 205 | andSelector:@selector(getUrl:withReply:) |
| 206 | forEventClass:kInternetEventClass |
| 207 | andEventID:kAEGetURL]; |
| 208 | [em setEventHandler:self |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 209 | andSelector:@selector(submitCloudPrintJob:) |
[email protected] | 13aec6c4 | 2011-10-27 21:22:08 | [diff] [blame] | 210 | forEventClass:cloud_print::kAECloudPrintClass |
| 211 | andEventID:cloud_print::kAECloudPrintClass]; |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 212 | // Install and uninstall handlers for virtual drivers. |
| 213 | [em setEventHandler:self |
| 214 | andSelector:@selector(installCloudPrint:) |
| 215 | forEventClass:kAECloudPrintInstallClass |
| 216 | andEventID:kAECloudPrintInstallClass]; |
| 217 | [em setEventHandler:self |
| 218 | andSelector:@selector(uninstallCloudPrint:) |
| 219 | forEventClass:kAECloudPrintUninstallClass |
| 220 | andEventID:kAECloudPrintUninstallClass]; |
| 221 | [em setEventHandler:self |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 222 | andSelector:@selector(getUrl:withReply:) |
| 223 | forEventClass:'WWW!' // A particularly ancient AppleEvent that dates |
| 224 | andEventID:'OURL']; // back to the Spyglass days. |
[email protected] | cd63ef6 | 2009-05-06 19:41:37 | [diff] [blame] | 225 | |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 226 | // Register for various window layering changes. We use these to update |
| 227 | // various UI elements (command-key equivalents, etc) when the frontmost |
| 228 | // window changes. |
| 229 | NSNotificationCenter* notificationCenter = |
| 230 | [NSNotificationCenter defaultCenter]; |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 231 | [notificationCenter |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 232 | addObserver:self |
| 233 | selector:@selector(windowLayeringDidChange:) |
| 234 | name:NSWindowDidBecomeKeyNotification |
| 235 | object:nil]; |
| 236 | [notificationCenter |
| 237 | addObserver:self |
| 238 | selector:@selector(windowLayeringDidChange:) |
| 239 | name:NSWindowDidResignKeyNotification |
| 240 | object:nil]; |
| 241 | [notificationCenter |
| 242 | addObserver:self |
| 243 | selector:@selector(windowLayeringDidChange:) |
| 244 | name:NSWindowDidBecomeMainNotification |
| 245 | object:nil]; |
| 246 | [notificationCenter |
| 247 | addObserver:self |
| 248 | selector:@selector(windowLayeringDidChange:) |
| 249 | name:NSWindowDidResignMainNotification |
| 250 | object:nil]; |
| 251 | |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 252 | if (base::mac::IsOSLionOrLater()) { |
| 253 | [notificationCenter |
| 254 | addObserver:self |
| 255 | selector:@selector(popoverDidShow:) |
| 256 | name:NSPopoverDidShowNotification |
| 257 | object:nil]; |
| 258 | [notificationCenter |
| 259 | addObserver:self |
| 260 | selector:@selector(popoverDidClose:) |
| 261 | name:NSPopoverDidCloseNotification |
| 262 | object:nil]; |
| 263 | } |
| 264 | |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 265 | // Set up the command updater for when there are no windows open |
| 266 | [self initMenuState]; |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 267 | |
| 268 | // Initialize the Profile menu. |
| 269 | [self initProfileMenu]; |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 270 | } |
| 271 | |
[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 272 | - (void)unregisterEventHandlers { |
| 273 | NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
| 274 | [em removeEventHandlerForEventClass:kInternetEventClass |
| 275 | andEventID:kAEGetURL]; |
| 276 | [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass |
| 277 | andEventID:cloud_print::kAECloudPrintClass]; |
| 278 | [em removeEventHandlerForEventClass:kAECloudPrintInstallClass |
| 279 | andEventID:kAECloudPrintInstallClass]; |
| 280 | [em removeEventHandlerForEventClass:kAECloudPrintUninstallClass |
| 281 | andEventID:kAECloudPrintUninstallClass]; |
| 282 | [em removeEventHandlerForEventClass:'WWW!' |
| 283 | andEventID:'OURL']; |
| 284 | [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 285 | } |
| 286 | |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 287 | // (NSApplicationDelegate protocol) This is the Apple-approved place to override |
| 288 | // the default handlers. |
| 289 | - (void)applicationWillFinishLaunching:(NSNotification*)notification { |
[email protected] | 5887793 | 2010-05-25 05:43:11 | [diff] [blame] | 290 | // Nothing here right now. |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | - (BOOL)tryToTerminateApplication:(NSApplication*)app { |
[email protected] | 3076fad | 2010-04-28 18:11:45 | [diff] [blame] | 294 | // Check for in-process downloads, and prompt the user if they really want |
| 295 | // to quit (and thus cancel downloads). Only check if we're not already |
| 296 | // shutting down, else the user might be prompted multiple times if the |
| 297 | // download isn't stopped before terminate is called again. |
| 298 | if (!browser_shutdown::IsTryingToQuit() && |
| 299 | ![self shouldQuitWithInProgressDownloads]) |
| 300 | return NO; |
| 301 | |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 302 | // TODO(viettrungluu): Remove Apple Event handlers here? (It's safe to leave |
| 303 | // them in, but I'm not sure about UX; we'd also want to disable other things |
| 304 | // though.) http://crbug.com/40861 |
| 305 | |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 306 | // Check if the user really wants to quit by employing the confirm-to-quit |
| 307 | // mechanism. |
| 308 | if (!browser_shutdown::IsTryingToQuit() && |
| 309 | [self applicationShouldTerminate:app] != NSTerminateNow) |
| 310 | return NO; |
| 311 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 312 | size_t num_browsers = BrowserList::size(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 313 | |
[email protected] | e7dd6d8 | 2010-10-07 23:21:12 | [diff] [blame] | 314 | // Give any print jobs in progress time to finish. |
| 315 | if (!browser_shutdown::IsTryingToQuit()) |
| 316 | g_browser_process->print_job_manager()->StopJobs(true); |
| 317 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 318 | // Initiate a shutdown (via BrowserList::CloseAllBrowsers()) if we aren't |
| 319 | // already shutting down. |
| 320 | if (!browser_shutdown::IsTryingToQuit()) |
[email protected] | c6032e8 | 2010-09-13 20:06:05 | [diff] [blame] | 321 | BrowserList::CloseAllBrowsers(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 322 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 323 | return num_browsers == 0 ? YES : NO; |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | - (void)stopTryingToTerminateApplication:(NSApplication*)app { |
| 327 | if (browser_shutdown::IsTryingToQuit()) { |
| 328 | // Reset the "trying to quit" state, so that closing all browser windows |
| 329 | // will no longer lead to termination. |
| 330 | browser_shutdown::SetTryingToQuit(false); |
| 331 | |
| 332 | // TODO(viettrungluu): Were we to remove Apple Event handlers above, we |
| 333 | // would have to reinstall them here. http://crbug.com/40861 |
| 334 | } |
[email protected] | a9e8afc | 2009-08-11 22:03:17 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 337 | - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app { |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 338 | // Check if the preference is turned on. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 339 | const PrefService* prefs = [self lastProfile]->GetPrefs(); |
[email protected] | 1eaddf3 | 2011-04-05 15:09:23 | [diff] [blame] | 340 | if (!prefs->GetBoolean(prefs::kConfirmToQuitEnabled)) { |
| 341 | confirm_quit::RecordHistogram(confirm_quit::kNoConfirm); |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 342 | return NSTerminateNow; |
[email protected] | 1eaddf3 | 2011-04-05 15:09:23 | [diff] [blame] | 343 | } |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 344 | |
| 345 | // If the application is going to terminate as the result of a Cmd+Q |
| 346 | // invocation, use the special sauce to prevent accidental quitting. |
| 347 | // http://dev.chromium.org/developers/design-documents/confirm-to-quit-experiment |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 348 | |
[email protected] | 2020fd0b | 2010-12-10 01:16:50 | [diff] [blame] | 349 | // This logic is only for keyboard-initiated quits. |
[email protected] | 5df54fb | 2011-03-07 18:15:26 | [diff] [blame] | 350 | if (![ConfirmQuitPanelController eventTriggersFeature:[app currentEvent]]) |
[email protected] | 2020fd0b | 2010-12-10 01:16:50 | [diff] [blame] | 351 | return NSTerminateNow; |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 352 | |
[email protected] | 5df54fb | 2011-03-07 18:15:26 | [diff] [blame] | 353 | return [[ConfirmQuitPanelController sharedController] |
| 354 | runModalLoopForApplication:app]; |
[email protected] | 177aceb | 2010-11-03 16:17:41 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 357 | // Called when the app is shutting down. Clean-up as appropriate. |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 358 | - (void)applicationWillTerminate:(NSNotification*)aNotification { |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 359 | // There better be no browser windows left at this point. |
[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 360 | CHECK_EQ(0u, BrowserList::size()); |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 361 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 362 | // Tell BrowserList not to keep the browser process alive. Once all the |
| 363 | // browsers get dealloc'd, it will stop the RunLoop and fall back into main(). |
| 364 | BrowserList::EndKeepAlive(); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 365 | |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 366 | // Close these off if they have open windows. |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 367 | [aboutController_ close]; |
| 368 | |
[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 369 | [self unregisterEventHandlers]; |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 372 | - (void)didEndMainMessageLoop { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 373 | DCHECK(!BrowserList::HasBrowserWithProfile([self lastProfile])); |
| 374 | if (!BrowserList::HasBrowserWithProfile([self lastProfile])) { |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 375 | // As we're shutting down, we need to nuke the TabRestoreService, which |
| 376 | // will start the shutdown of the NavigationControllers and allow for |
| 377 | // proper shutdown. If we don't do this, Chrome won't shut down cleanly, |
| 378 | // and may end up crashing when some thread tries to use the IO thread (or |
| 379 | // another thread) that is no longer valid. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 380 | TabRestoreServiceFactory::ResetForProfile([self lastProfile]); |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 384 | // If the window has a tab controller, make "close window" be cmd-shift-w, |
| 385 | // otherwise leave it as the normal cmd-w. Capitalization of the key equivalent |
| 386 | // affects whether the shift modifer is used. |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 387 | - (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)enableCloseTabShortcut { |
| 388 | [closeWindowMenuItem_ setKeyEquivalent:(enableCloseTabShortcut ? @"W" : |
| 389 | @"w")]; |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 390 | [closeWindowMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; |
| 391 | } |
| 392 | |
| 393 | // If the window has a tab controller, make "close tab" take over cmd-w, |
| 394 | // otherwise it shouldn't have any key-equivalent because it should be disabled. |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 395 | - (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)enableCloseTabShortcut { |
| 396 | if (enableCloseTabShortcut) { |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 397 | [closeTabMenuItem_ setKeyEquivalent:@"w"]; |
| 398 | [closeTabMenuItem_ setKeyEquivalentModifierMask:NSCommandKeyMask]; |
| 399 | } else { |
| 400 | [closeTabMenuItem_ setKeyEquivalent:@""]; |
| 401 | [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // Explicitly remove any command-key equivalents from the close tab/window |
| 406 | // menus so that nothing can go haywire if we get a user action during pending |
| 407 | // updates. |
| 408 | - (void)clearCloseMenuItemKeyEquivalents { |
| 409 | [closeTabMenuItem_ setKeyEquivalent:@""]; |
| 410 | [closeTabMenuItem_ setKeyEquivalentModifierMask:0]; |
| 411 | [closeWindowMenuItem_ setKeyEquivalent:@""]; |
| 412 | [closeWindowMenuItem_ setKeyEquivalentModifierMask:0]; |
| 413 | } |
| 414 | |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 415 | // See if the focused window window has tabs, and adjust the key equivalents for |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 416 | // Close Tab/Close Window accordingly. |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 417 | - (void)fixCloseMenuItemKeyEquivalents { |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 418 | fileMenuUpdatePending_ = NO; |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 419 | |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 420 | NSWindow* window = [NSApp keyWindow]; |
| 421 | NSWindow* mainWindow = [NSApp mainWindow]; |
| 422 | if (!window || ([window parentWindow] == mainWindow)) { |
| 423 | // If the key window is a child of the main window (e.g. a bubble), the main |
| 424 | // window should be the one that handles the close menu item action. |
| 425 | // Also, there might be a small amount of time where there is no key window; |
| 426 | // in that case as well, just use our main browser window if there is one. |
| 427 | // You might think that we should just always use the main window, but the |
| 428 | // "About Chrome" window serves as a counterexample. |
| 429 | window = mainWindow; |
| 430 | } |
| 431 | |
| 432 | BOOL hasTabs = |
| 433 | [[window windowController] isKindOfClass:[TabWindowController class]]; |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 434 | BOOL enableCloseTabShortcut = hasTabs && !hasPopover_; |
| 435 | [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut]; |
| 436 | [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut]; |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // Fix up the "close tab/close window" command-key equivalents. We do this |
| 440 | // after a delay to ensure that window layer state has been set by the time |
| 441 | // we do the enabling. This should only be called on the main thread, code that |
| 442 | // calls this (even as a side-effect) from other threads needs to be fixed. |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 443 | - (void)delayedFixCloseMenuItemKeyEquivalents { |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 444 | DCHECK([NSThread isMainThread]); |
| 445 | if (!fileMenuUpdatePending_) { |
| 446 | // The OS prefers keypresses to timers, so it's possible that a cmd-w |
| 447 | // can sneak in before this timer fires. In order to prevent that from |
| 448 | // having any bad consequences, just clear the keys combos altogether. They |
| 449 | // will be reset when the timer eventually fires. |
| 450 | if ([NSThread isMainThread]) { |
| 451 | fileMenuUpdatePending_ = YES; |
| 452 | [self clearCloseMenuItemKeyEquivalents]; |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 453 | [self performSelector:@selector(fixCloseMenuItemKeyEquivalents) |
| 454 | withObject:nil |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 455 | afterDelay:0]; |
| 456 | } else { |
| 457 | // This shouldn't be happening, but if it does, force it to the main |
| 458 | // thread to avoid dropping the update. Don't mess with |
| 459 | // |fileMenuUpdatePending_| as it's not expected to be threadsafe and |
| 460 | // there could be a race between the selector finishing and setting the |
| 461 | // flag. |
| 462 | [self |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 463 | performSelectorOnMainThread:@selector(fixCloseMenuItemKeyEquivalents) |
| 464 | withObject:nil |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 465 | waitUntilDone:NO]; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 470 | // Called when we get a notification about the window layering changing to |
| 471 | // update the UI based on the new main window. |
| 472 | - (void)windowLayeringDidChange:(NSNotification*)notify { |
[email protected] | 9f5f79b6 | 2011-10-28 00:43:45 | [diff] [blame] | 473 | [self delayedFixCloseMenuItemKeyEquivalents]; |
[email protected] | 8cfbdbd | 2011-06-16 04:17:17 | [diff] [blame] | 474 | |
[email protected] | dd6ab128 | 2010-07-20 01:07:32 | [diff] [blame] | 475 | if ([notify name] == NSWindowDidResignKeyNotification) { |
| 476 | // If a window is closed, this notification is fired but |[NSApp keyWindow]| |
| 477 | // returns nil regardless of whether any suitable candidates for the key |
| 478 | // window remain. It seems that the new key window for the app is not set |
| 479 | // until after this notification is fired, so a check is performed after the |
| 480 | // run loop is allowed to spin. |
| 481 | [self performSelector:@selector(checkForAnyKeyWindows) |
| 482 | withObject:nil |
| 483 | afterDelay:0.0]; |
| 484 | } |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 485 | |
| 486 | // If the window changed to a new BrowserWindowController, update the profile. |
| 487 | id windowController = [[notify object] windowController]; |
[email protected] | dc25148 | 2012-01-03 18:55:21 | [diff] [blame] | 488 | if ([notify name] == NSWindowDidBecomeMainNotification && |
| 489 | [windowController isKindOfClass:[BrowserWindowController class]]) { |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 490 | // If the profile is incognito, use the original profile. |
| 491 | Profile* newProfile = [windowController profile]->GetOriginalProfile(); |
| 492 | [self windowChangedToProfile:newProfile]; |
[email protected] | cae68b3a | 2011-11-21 23:29:49 | [diff] [blame] | 493 | } else if (BrowserList::empty()) { |
| 494 | [self windowChangedToProfile: |
| 495 | g_browser_process->profile_manager()->GetLastUsedProfile()]; |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 499 | // Called on Lion and later when a popover (e.g. dictionary) is shown. |
| 500 | - (void)popoverDidShow:(NSNotification*)notify { |
| 501 | hasPopover_ = YES; |
| 502 | [self fixCloseMenuItemKeyEquivalents]; |
| 503 | } |
| 504 | |
| 505 | // Called on Lion and later when a popover (e.g. dictionary) is closed. |
| 506 | - (void)popoverDidClose:(NSNotification*)notify { |
| 507 | hasPopover_ = NO; |
| 508 | [self fixCloseMenuItemKeyEquivalents]; |
| 509 | } |
| 510 | |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 511 | // Called when the user has changed browser windows, meaning the backing profile |
| 512 | // may have changed. This can cause a rebuild of the user-data menus. This is a |
| 513 | // no-op if the new profile is the same as the current one. This will always be |
| 514 | // the original profile and never incognito. |
| 515 | - (void)windowChangedToProfile:(Profile*)profile { |
| 516 | if (lastProfile_ == profile) |
| 517 | return; |
| 518 | |
| 519 | // Before tearing down the menu controller bridges, return the Cocoa menus to |
| 520 | // their initial state. |
| 521 | if (bookmarkMenuBridge_.get()) |
| 522 | bookmarkMenuBridge_->ResetMenu(); |
| 523 | if (historyMenuBridge_.get()) |
| 524 | historyMenuBridge_->ResetMenu(); |
| 525 | |
| 526 | // Rebuild the menus with the new profile. |
| 527 | lastProfile_ = profile; |
| 528 | |
[email protected] | 0c165cf | 2011-07-09 03:56:50 | [diff] [blame] | 529 | bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, |
| 530 | [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); |
[email protected] | dc25148 | 2012-01-03 18:55:21 | [diff] [blame] | 531 | // No need to |BuildMenu| here. It is done lazily upon menu access. |
[email protected] | 5c59370 | 2011-06-17 18:35:24 | [diff] [blame] | 532 | |
| 533 | historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
| 534 | historyMenuBridge_->BuildMenu(); |
[email protected] | dd6ab128 | 2010-07-20 01:07:32 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | - (void)checkForAnyKeyWindows { |
| 538 | if ([NSApp keyWindow]) |
| 539 | return; |
| 540 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 541 | content::NotificationService::current()->Notify( |
[email protected] | 666641df | 2011-07-10 18:24:38 | [diff] [blame] | 542 | content::NOTIFICATION_NO_KEY_WINDOW, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 543 | content::NotificationService::AllSources(), |
| 544 | content::NotificationService::NoDetails()); |
[email protected] | 449dd2f | 2009-05-27 13:04:00 | [diff] [blame] | 545 | } |
| 546 | |
[email protected] | 414fde59 | 2009-05-21 16:14:43 | [diff] [blame] | 547 | // If the auto-update interval is not set, make it 5 hours. |
| 548 | // This code is specific to Mac Chrome Dev Channel. |
| 549 | // Placed here for 2 reasons: |
| 550 | // 1) Same spot as other Pref stuff |
| 551 | // 2) Try and be friendly by keeping this after app launch |
| 552 | // TODO(jrg): remove once we go Beta. |
| 553 | - (void)setUpdateCheckInterval { |
| 554 | #if defined(GOOGLE_CHROME_BUILD) |
| 555 | CFStringRef app = (CFStringRef)@"com.google.Keystone.Agent"; |
| 556 | CFStringRef checkInterval = (CFStringRef)@"checkInterval"; |
| 557 | CFPropertyListRef plist = CFPreferencesCopyAppValue(checkInterval, app); |
| 558 | if (!plist) { |
| 559 | const float fiveHoursInSeconds = 5.0 * 60.0 * 60.0; |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 560 | NSNumber* value = [NSNumber numberWithFloat:fiveHoursInSeconds]; |
[email protected] | 414fde59 | 2009-05-21 16:14:43 | [diff] [blame] | 561 | CFPreferencesSetAppValue(checkInterval, value, app); |
| 562 | CFPreferencesAppSynchronize(app); |
| 563 | } |
| 564 | #endif |
| 565 | } |
| 566 | |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 567 | // This is called after profiles have been loaded and preferences registered. |
| 568 | // It is safe to access the default profile here. |
| 569 | - (void)applicationDidFinishLaunching:(NSNotification*)notify { |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 570 | // Notify BrowserList to keep the application running so it doesn't go away |
| 571 | // when all the browser windows get closed. |
| 572 | BrowserList::StartKeepAlive(); |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 573 | |
[email protected] | 414fde59 | 2009-05-21 16:14:43 | [diff] [blame] | 574 | [self setUpdateCheckInterval]; |
[email protected] | 2bcec61 | 2009-05-14 17:50:53 | [diff] [blame] | 575 | |
| 576 | // Build up the encoding menu, the order of the items differs based on the |
| 577 | // current locale (see http://crbug.com/7647 for details). |
| 578 | // We need a valid g_browser_process to get the profile which is why we can't |
| 579 | // call this from awakeFromNib. |
[email protected] | 6f91e5ae | 2011-03-21 19:53:14 | [diff] [blame] | 580 | NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; |
| 581 | NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; |
| 582 | NSMenu* encodingMenu = [encodingMenuItem submenu]; |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 583 | EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], |
[email protected] | 6f91e5ae | 2011-03-21 19:53:14 | [diff] [blame] | 584 | encodingMenu); |
[email protected] | 2bcec61 | 2009-05-14 17:50:53 | [diff] [blame] | 585 | |
[email protected] | f2c20fa | 2009-12-01 17:42:02 | [diff] [blame] | 586 | // Since Chrome is localized to more languages than the OS, tell Cocoa which |
| 587 | // menu is the Help so it can add the search item to it. |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 588 | if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)]) |
[email protected] | f2c20fa | 2009-12-01 17:42:02 | [diff] [blame] | 589 | [NSApp setHelpMenu:helpMenu_]; |
[email protected] | f2c20fa | 2009-12-01 17:42:02 | [diff] [blame] | 590 | |
[email protected] | 12dc3d4 | 2010-02-22 23:37:12 | [diff] [blame] | 591 | // Record the path to the (browser) app bundle; this is used by the app mode |
| 592 | // shim. |
| 593 | RecordLastRunAppBundlePath(); |
| 594 | |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 595 | // Makes "Services" menu items available. |
| 596 | [self registerServicesMenuTypesTo:[notify object]]; |
| 597 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 598 | startupComplete_ = YES; |
| 599 | |
| 600 | // TODO(viettrungluu): This is very temporary, since this should be done "in" |
| 601 | // |BrowserMain()|, i.e., this list of startup URLs should be appended to the |
| 602 | // (probably-empty) list of URLs from the command line. |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 603 | if (startupUrls_.size()) { |
| 604 | [self openUrls:startupUrls_]; |
| 605 | [self clearStartupUrls]; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 606 | } |
[email protected] | aac169d | 2011-03-18 19:53:03 | [diff] [blame] | 607 | |
| 608 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 609 | if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) { |
| 610 | [tabposeMenuItem_ setHidden:YES]; |
| 611 | } |
[email protected] | 7c32108 | 2009-02-09 15:35:47 | [diff] [blame] | 612 | } |
| 613 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 614 | // This is called after profiles have been loaded and preferences registered. |
| 615 | // It is safe to access the default profile here. |
| 616 | - (void)applicationDidBecomeActive:(NSNotification*)notify { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 617 | content::NotificationService::current()->Notify( |
| 618 | content::NOTIFICATION_APP_ACTIVATED, |
| 619 | content::NotificationService::AllSources(), |
| 620 | content::NotificationService::NoDetails()); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 623 | // Helper function for populating and displaying the in progress downloads at |
| 624 | // exit alert panel. |
| 625 | - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount { |
[email protected] | e8b5f788 | 2009-09-14 20:59:13 | [diff] [blame] | 626 | NSString* warningText = nil; |
| 627 | NSString* explanationText = nil; |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 628 | NSString* waitTitle = nil; |
| 629 | NSString* exitTitle = nil; |
| 630 | |
| 631 | // Set the dialog text based on whether or not there are multiple downloads. |
| 632 | if (downloadCount == 1) { |
[email protected] | e8b5f788 | 2009-09-14 20:59:13 | [diff] [blame] | 633 | // Dialog text: warning and explanation. |
[email protected] | ab3b1c11 | 2012-01-13 22:04:16 | [diff] [blame] | 634 | warningText = l10n_util::GetNSString( |
| 635 | IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING); |
| 636 | explanationText = l10n_util::GetNSString( |
| 637 | IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 638 | |
| 639 | // Cancel download and exit button text. |
[email protected] | 75712705 | 2010-04-27 14:42:26 | [diff] [blame] | 640 | exitTitle = l10n_util::GetNSString( |
| 641 | IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 642 | |
| 643 | // Wait for download button text. |
[email protected] | 75712705 | 2010-04-27 14:42:26 | [diff] [blame] | 644 | waitTitle = l10n_util::GetNSString( |
| 645 | IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 646 | } else { |
[email protected] | e8b5f788 | 2009-09-14 20:59:13 | [diff] [blame] | 647 | // Dialog text: warning and explanation. |
[email protected] | 75712705 | 2010-04-27 14:42:26 | [diff] [blame] | 648 | warningText = l10n_util::GetNSStringF( |
[email protected] | ab3b1c11 | 2012-01-13 22:04:16 | [diff] [blame] | 649 | IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING, |
[email protected] | 528c56d | 2010-07-30 19:28:44 | [diff] [blame] | 650 | base::IntToString16(downloadCount)); |
[email protected] | ab3b1c11 | 2012-01-13 22:04:16 | [diff] [blame] | 651 | explanationText = l10n_util::GetNSString( |
| 652 | IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 653 | |
| 654 | // Cancel downloads and exit button text. |
[email protected] | 75712705 | 2010-04-27 14:42:26 | [diff] [blame] | 655 | exitTitle = l10n_util::GetNSString( |
| 656 | IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 657 | |
| 658 | // Wait for downloads button text. |
[email protected] | 75712705 | 2010-04-27 14:42:26 | [diff] [blame] | 659 | waitTitle = l10n_util::GetNSString( |
| 660 | IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | // 'waitButton' is the default choice. |
[email protected] | e8b5f788 | 2009-09-14 20:59:13 | [diff] [blame] | 664 | int choice = NSRunAlertPanel(warningText, explanationText, |
| 665 | waitTitle, exitTitle, nil); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 666 | return choice == NSAlertDefaultReturn ? YES : NO; |
| 667 | } |
| 668 | |
| 669 | // Check all profiles for in progress downloads, and if we find any, prompt the |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 670 | // 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] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 673 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 674 | if (!profile_manager) |
| 675 | return YES; |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 676 | |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 677 | std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
| 678 | for (size_t i = 0; i < profiles.size(); ++i) { |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 679 | DownloadService* download_service = |
| 680 | DownloadServiceFactory::GetForProfile(profiles[i]); |
| 681 | DownloadManager* download_manager = |
| 682 | (download_service->HasCreatedDownloadManager() ? |
| 683 | download_service->GetDownloadManager() : NULL); |
[email protected] | 5656f8a | 2011-11-17 16:12:58 | [diff] [blame] | 684 | if (download_manager && download_manager->InProgressCount() > 0) { |
| 685 | int downloadCount = download_manager->InProgressCount(); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 686 | if ([self userWillWaitForInProgressDownloads:downloadCount]) { |
| 687 | // Create a new browser window (if necessary) and navigate to the |
| 688 | // downloads page if the user chooses to wait. |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 689 | Browser* browser = BrowserList::FindBrowserWithProfile(profiles[i]); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 690 | if (!browser) { |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 691 | browser = Browser::Create(profiles[i]); |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 692 | browser->window()->Show(); |
| 693 | } |
| 694 | DCHECK(browser); |
| 695 | browser->ShowDownloadsTab(); |
| 696 | return NO; |
| 697 | } |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 698 | |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 699 | // User wants to exit. |
| 700 | return YES; |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 701 | } |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 702 | } |
| 703 | |
[email protected] | 73f5b36 | 2009-08-10 23:58:21 | [diff] [blame] | 704 | // No profiles or active downloads found, okay to exit. |
[email protected] | 09729a55 | 2009-08-03 23:21:41 | [diff] [blame] | 705 | return YES; |
| 706 | } |
| 707 | |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 708 | // Called to determine if we should enable the "restore tab" menu item. |
| 709 | // Checks with the TabRestoreService to see if there's anything there to |
| 710 | // restore and returns YES if so. |
| 711 | - (BOOL)canRestoreTab { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 712 | TabRestoreService* service = |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 713 | TabRestoreServiceFactory::GetForProfile([self lastProfile]); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 714 | return service && !service->entries().empty(); |
| 715 | } |
| 716 | |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 717 | // Returns true if there is not a modal window (either window- or application- |
| 718 | // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
| 719 | // sheets) will not count as blocking the browser. But things like open/save |
| 720 | // dialogs that are window modal will block the browser. |
| 721 | - (BOOL)keyWindowIsNotModal { |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 722 | Browser* browser = BrowserList::GetLastActive(); |
[email protected] | dc76e836 | 2010-06-11 16:29:52 | [diff] [blame] | 723 | return [NSApp modalWindow] == nil && (!browser || |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 724 | ![[browser->window()->GetNativeHandle() attachedSheet] |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 725 | isKindOfClass:[NSWindow class]]); |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 728 | // Called to validate menu items when there are no key windows. All the |
| 729 | // items we care about have been set with the |commandDispatch:| action and |
| 730 | // a target of FirstResponder in IB. If it's not one of those, let it |
| 731 | // continue up the responder chain to be handled elsewhere. We pull out the |
| 732 | // tag as the cross-platform constant to differentiate and dispatch the |
| 733 | // various commands. |
| 734 | - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 735 | SEL action = [item action]; |
| 736 | BOOL enable = NO; |
| 737 | if (action == @selector(commandDispatch:)) { |
| 738 | NSInteger tag = [item tag]; |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 739 | if (menuState_->SupportsCommand(tag)) { |
| 740 | switch (tag) { |
[email protected] | 419eb2a | 2009-11-11 16:26:26 | [diff] [blame] | 741 | // The File Menu commands are not automatically disabled by Cocoa when a |
| 742 | // dialog sheet obscures the browser window, so we disable several of |
| 743 | // them here. We don't need to include IDC_CLOSE_WINDOW, because |
| 744 | // app_controller is only activated when there are no key windows (see |
| 745 | // function comment). |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 746 | case IDC_RESTORE_TAB: |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 747 | enable = [self keyWindowIsNotModal] && [self canRestoreTab]; |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 748 | break; |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 749 | // Browser-level items that open in new tabs should not open if there's |
| 750 | // a window- or app-modal dialog. |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 751 | case IDC_OPEN_FILE: |
[email protected] | 6a28133 | 2009-10-13 17:41:06 | [diff] [blame] | 752 | case IDC_NEW_TAB: |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 753 | case IDC_SHOW_HISTORY: |
| 754 | case IDC_SHOW_BOOKMARK_MANAGER: |
| 755 | enable = [self keyWindowIsNotModal]; |
| 756 | break; |
| 757 | // Browser-level items that open in new windows. |
| 758 | case IDC_NEW_WINDOW: |
| 759 | case IDC_TASK_MANAGER: |
| 760 | // Allow the user to open a new window if there's a window-modal |
| 761 | // dialog. |
| 762 | enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 763 | break; |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 764 | case IDC_SYNC_BOOKMARKS: { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 765 | Profile* lastProfile = [self lastProfile]; |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 766 | // The profile may be NULL during shutdown -- see |
| 767 | // http://code.google.com/p/chromium/issues/detail?id=43048 . |
| 768 | // |
| 769 | // TODO(akalin,viettrungluu): Figure out whether this method |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 770 | // can be prevented from being called if lastProfile is |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 771 | // NULL. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 772 | if (!lastProfile) { |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 773 | LOG(WARNING) |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 774 | << "NULL lastProfile detected -- not doing anything"; |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 775 | break; |
| 776 | } |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 777 | enable = lastProfile->IsSyncAccessible() && |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 778 | [self keyWindowIsNotModal]; |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 779 | sync_ui_util::UpdateSyncItem(item, enable, lastProfile); |
[email protected] | f9bc9b9 | 2009-11-24 00:55:35 | [diff] [blame] | 780 | break; |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 781 | } |
[email protected] | acaa37b | 2011-08-31 07:19:11 | [diff] [blame] | 782 | case IDC_FEEDBACK: |
| 783 | enable = NO; |
| 784 | break; |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 785 | default: |
[email protected] | f6c15fa | 2010-06-04 20:08:21 | [diff] [blame] | 786 | enable = menuState_->IsCommandEnabled(tag) ? |
| 787 | [self keyWindowIsNotModal] : NO; |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 788 | } |
| 789 | } |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 790 | } else if (action == @selector(terminate:)) { |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 791 | enable = YES; |
[email protected] | 3111f08b | 2009-04-30 16:01:52 | [diff] [blame] | 792 | } else if (action == @selector(showPreferences:)) { |
| 793 | enable = YES; |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 794 | } else if (action == @selector(orderFrontStandardAboutPanel:)) { |
| 795 | enable = YES; |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 796 | } else if (action == @selector(commandFromDock:)) { |
[email protected] | 3d4bd23f | 2009-10-06 03:58:38 | [diff] [blame] | 797 | enable = YES; |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 798 | } else if (action == @selector(toggleConfirmToQuit:)) { |
| 799 | [self updateConfirmToQuitPrefMenuItem:static_cast<NSMenuItem*>(item)]; |
| 800 | enable = YES; |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 801 | } |
| 802 | return enable; |
| 803 | } |
| 804 | |
[email protected] | 947fc0d | 2010-01-14 22:33:05 | [diff] [blame] | 805 | // Called when the user picks a menu item when there are no key windows, or when |
| 806 | // there is no foreground browser window. Calls through to the browser object to |
| 807 | // execute the command. This assumes that the command is supported and doesn't |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 808 | // check, otherwise it should have been disabled in the UI in |
| 809 | // |-validateUserInterfaceItem:|. |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 810 | - (void)commandDispatch:(id)sender { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 811 | Profile* lastProfile = [self lastProfile]; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 812 | |
[email protected] | 947fc0d | 2010-01-14 22:33:05 | [diff] [blame] | 813 | // Handle the case where we're dispatching a command from a sender that's in a |
| 814 | // browser window. This means that the command came from a background window |
| 815 | // and is getting here because the foreground window is not a browser window. |
| 816 | if ([sender respondsToSelector:@selector(window)]) { |
| 817 | id delegate = [[sender window] windowController]; |
| 818 | if ([delegate isKindOfClass:[BrowserWindowController class]]) { |
| 819 | [delegate commandDispatch:sender]; |
| 820 | return; |
| 821 | } |
| 822 | } |
| 823 | |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 824 | NSInteger tag = [sender tag]; |
| 825 | switch (tag) { |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 826 | case IDC_NEW_TAB: |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 827 | // Create a new tab in an existing browser window (which we activate) if |
| 828 | // possible. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 829 | if (Browser* browser = ActivateBrowser(lastProfile)) { |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 830 | browser->ExecuteCommand(IDC_NEW_TAB); |
| 831 | break; |
| 832 | } |
| 833 | // Else fall through to create new window. |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 834 | case IDC_NEW_WINDOW: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 835 | CreateBrowser(lastProfile); |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 836 | break; |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 837 | case IDC_FOCUS_LOCATION: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 838 | ActivateOrCreateBrowser(lastProfile)->ExecuteCommand(IDC_FOCUS_LOCATION); |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 839 | break; |
[email protected] | cddc524 | 2009-12-07 18:54:33 | [diff] [blame] | 840 | case IDC_FOCUS_SEARCH: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 841 | ActivateOrCreateBrowser(lastProfile)->ExecuteCommand(IDC_FOCUS_SEARCH); |
[email protected] | cddc524 | 2009-12-07 18:54:33 | [diff] [blame] | 842 | break; |
[email protected] | 863ff66 | 2009-01-26 20:18:18 | [diff] [blame] | 843 | case IDC_NEW_INCOGNITO_WINDOW: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 844 | Browser::OpenEmptyWindow(lastProfile->GetOffTheRecordProfile()); |
[email protected] | 863ff66 | 2009-01-26 20:18:18 | [diff] [blame] | 845 | break; |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 846 | case IDC_RESTORE_TAB: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 847 | Browser::OpenWindowWithRestoredTabs(lastProfile); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 848 | break; |
[email protected] | e19516d | 2009-04-28 17:15:19 | [diff] [blame] | 849 | case IDC_OPEN_FILE: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 850 | CreateBrowser(lastProfile)->ExecuteCommand(IDC_OPEN_FILE); |
[email protected] | e19516d | 2009-04-28 17:15:19 | [diff] [blame] | 851 | break; |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 852 | case IDC_CLEAR_BROWSING_DATA: { |
[email protected] | 93e18176 | 2009-05-29 14:30:38 | [diff] [blame] | 853 | // There may not be a browser open, so use the default profile. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 854 | if (Browser* browser = ActivateBrowser(lastProfile)) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 855 | browser->OpenClearBrowsingDataDialog(); |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 856 | } else { |
[email protected] | ddddfda | 2011-07-14 23:19:39 | [diff] [blame] | 857 | Browser::OpenClearBrowsingDataDialogWindow(lastProfile); |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 858 | } |
[email protected] | 93e18176 | 2009-05-29 14:30:38 | [diff] [blame] | 859 | break; |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 860 | } |
[email protected] | 4aee565 | 2009-11-19 18:59:21 | [diff] [blame] | 861 | case IDC_IMPORT_SETTINGS: { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 862 | if (Browser* browser = ActivateBrowser(lastProfile)) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 863 | browser->OpenImportSettingsDialog(); |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 864 | } else { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 865 | Browser::OpenImportSettingsDialogWindow(lastProfile); |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 866 | } |
[email protected] | 4aee565 | 2009-11-19 18:59:21 | [diff] [blame] | 867 | break; |
| 868 | } |
[email protected] | af7c25e | 2010-01-23 05:46:45 | [diff] [blame] | 869 | case IDC_SHOW_BOOKMARK_MANAGER: |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 870 | content::RecordAction(UserMetricsAction("ShowBookmarkManager")); |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 871 | if (Browser* browser = ActivateBrowser(lastProfile)) { |
[email protected] | 47e532b | 2010-04-23 17:46:40 | [diff] [blame] | 872 | // Open a bookmark manager tab. |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 873 | browser->OpenBookmarkManager(); |
| 874 | } else { |
[email protected] | 47e532b | 2010-04-23 17:46:40 | [diff] [blame] | 875 | // No browser window, so create one for the bookmark manager tab. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 876 | Browser::OpenBookmarkManagerWindow(lastProfile); |
[email protected] | 90a8bf25 | 2010-03-12 00:09:47 | [diff] [blame] | 877 | } |
[email protected] | af7c25e | 2010-01-23 05:46:45 | [diff] [blame] | 878 | break; |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 879 | case IDC_SHOW_HISTORY: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 880 | if (Browser* browser = ActivateBrowser(lastProfile)) |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 881 | browser->ShowHistoryTab(); |
| 882 | else |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 883 | Browser::OpenHistoryWindow(lastProfile); |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 884 | break; |
| 885 | case IDC_SHOW_DOWNLOADS: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 886 | if (Browser* browser = ActivateBrowser(lastProfile)) |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 887 | browser->ShowDownloadsTab(); |
| 888 | else |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 889 | Browser::OpenDownloadsWindow(lastProfile); |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 890 | break; |
[email protected] | bb37e6ec | 2009-11-18 17:59:36 | [diff] [blame] | 891 | case IDC_MANAGE_EXTENSIONS: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 892 | if (Browser* browser = ActivateBrowser(lastProfile)) |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 893 | browser->ShowExtensionsTab(); |
| 894 | else |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 895 | Browser::OpenExtensionsWindow(lastProfile); |
[email protected] | bb37e6ec | 2009-11-18 17:59:36 | [diff] [blame] | 896 | break; |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 897 | case IDC_HELP_PAGE: |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 898 | if (Browser* browser = ActivateBrowser(lastProfile)) |
[email protected] | 202802e4 | 2011-07-06 11:40:46 | [diff] [blame] | 899 | browser->ShowHelpTab(); |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 900 | else |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 901 | Browser::OpenHelpWindow(lastProfile); |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 902 | break; |
[email protected] | f9bc9b9 | 2009-11-24 00:55:35 | [diff] [blame] | 903 | case IDC_SYNC_BOOKMARKS: |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 904 | // The profile may be NULL during shutdown -- see |
| 905 | // http://code.google.com/p/chromium/issues/detail?id=43048 . |
| 906 | // |
| 907 | // TODO(akalin,viettrungluu): Figure out whether this method can |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 908 | // be prevented from being called if lastProfile is NULL. |
| 909 | if (!lastProfile) { |
| 910 | LOG(WARNING) << "NULL lastProfile detected -- not doing anything"; |
[email protected] | 446e16a | 2010-05-03 21:23:58 | [diff] [blame] | 911 | break; |
| 912 | } |
[email protected] | f9bc9b9 | 2009-11-24 00:55:35 | [diff] [blame] | 913 | // TODO(akalin): Add a constant to denote starting sync from the |
| 914 | // main menu and use that instead of START_FROM_WRENCH. |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 915 | sync_ui_util::OpenSyncMyBookmarksDialog( |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 916 | lastProfile, ActivateBrowser(lastProfile), |
[email protected] | c8de64a | 2011-01-25 17:10:23 | [diff] [blame] | 917 | ProfileSyncService::START_FROM_WRENCH); |
[email protected] | f9bc9b9 | 2009-11-24 00:55:35 | [diff] [blame] | 918 | break; |
[email protected] | ceaaf181 | 2010-01-20 22:13:09 | [diff] [blame] | 919 | case IDC_TASK_MANAGER: |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 920 | content::RecordAction(UserMetricsAction("TaskManager")); |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 921 | TaskManagerMac::Show(false); |
[email protected] | ceaaf181 | 2010-01-20 22:13:09 | [diff] [blame] | 922 | break; |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 923 | case IDC_OPTIONS: |
| 924 | [self showPreferences:sender]; |
| 925 | break; |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 926 | default: |
| 927 | // Background Applications use dynamic values that must be less than the |
| 928 | // smallest value among the predefined IDC_* labels. |
| 929 | if ([sender tag] < IDC_MinimumLabelValue) |
| 930 | [self executeApplication:sender]; |
| 931 | break; |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 932 | } |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 933 | } |
| 934 | |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 935 | // Run a (background) application in a new tab. |
| 936 | - (void)executeApplication:(id)sender { |
| 937 | NSInteger tag = [sender tag]; |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 938 | Profile* profile = [self lastProfile]; |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 939 | DCHECK(profile); |
| 940 | BackgroundApplicationListModel applications(profile); |
| 941 | DCHECK(tag >= 0 && |
| 942 | tag < static_cast<int>(applications.size())); |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 943 | const Extension* extension = applications.GetExtension(tag); |
[email protected] | 78d78a6 | 2011-09-29 18:24:33 | [diff] [blame] | 944 | BackgroundModeManager::LaunchBackgroundApplication(profile, extension); |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 945 | } |
| 946 | |
[email protected] | 947fc0d | 2010-01-14 22:33:05 | [diff] [blame] | 947 | // Same as |-commandDispatch:|, but executes commands using a disposition |
| 948 | // determined by the key flags. This will get called in the case where the |
| 949 | // frontmost window is not a browser window, and the user has command-clicked |
| 950 | // a button in a background browser window whose action is |
| 951 | // |-commandDispatchUsingKeyModifiers:| |
| 952 | - (void)commandDispatchUsingKeyModifiers:(id)sender { |
| 953 | DCHECK(sender); |
| 954 | if ([sender respondsToSelector:@selector(window)]) { |
| 955 | id delegate = [[sender window] windowController]; |
| 956 | if ([delegate isKindOfClass:[BrowserWindowController class]]) { |
| 957 | [delegate commandDispatchUsingKeyModifiers:sender]; |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
[email protected] | ff81e0a | 2009-04-13 14:58:54 | [diff] [blame] | 962 | // NSApplication delegate method called when someone clicks on the |
| 963 | // dock icon and there are no open windows. To match standard mac |
| 964 | // behavior, we should open a new window. |
| 965 | - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication |
| 966 | hasVisibleWindows:(BOOL)flag { |
[email protected] | 7063140 | 2010-04-26 20:16:54 | [diff] [blame] | 967 | // If the browser is currently trying to quit, don't do anything and return NO |
| 968 | // to prevent AppKit from doing anything. |
| 969 | // TODO(rohitrao): Remove this code when http://crbug.com/40861 is resolved. |
| 970 | if (browser_shutdown::IsTryingToQuit()) |
| 971 | return NO; |
| 972 | |
[email protected] | 0236be2 | 2012-01-11 01:05:35 | [diff] [blame] | 973 | // Don't do anything if there are visible tabbed or popup windows. This will |
| 974 | // cause AppKit to unminimize the most recently minimized window. If the |
| 975 | // visible windows are panels or notifications, we still need to open a new |
| 976 | // window. |
| 977 | if (flag) { |
| 978 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 979 | iter != BrowserList::end(); ++iter) { |
| 980 | Browser* browser = *iter; |
| 981 | if (browser->is_type_tabbed() || browser->is_type_popup()) |
| 982 | return YES; |
| 983 | } |
| 984 | } |
[email protected] | ff81e0a | 2009-04-13 14:58:54 | [diff] [blame] | 985 | |
[email protected] | 0d1210d6 | 2010-09-07 17:31:38 | [diff] [blame] | 986 | // If launched as a hidden login item (due to installation of a persistent app |
| 987 | // or by the user, for example in System Preferenecs->Accounts->Login Items), |
| 988 | // allow session to be restored first time the user clicks on a Dock icon. |
| 989 | // Normally, it'd just open a new empty page. |
| 990 | { |
| 991 | static BOOL doneOnce = NO; |
| 992 | if (!doneOnce) { |
| 993 | doneOnce = YES; |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 994 | if (base::mac::WasLaunchedAsHiddenLoginItem()) { |
[email protected] | 0d1210d6 | 2010-09-07 17:31:38 | [diff] [blame] | 995 | SessionService* sessionService = |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 996 | SessionServiceFactory::GetForProfile([self lastProfile]); |
[email protected] | 0d1210d6 | 2010-09-07 17:31:38 | [diff] [blame] | 997 | if (sessionService && |
| 998 | sessionService->RestoreIfNecessary(std::vector<GURL>())) |
| 999 | return NO; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
[email protected] | ff81e0a | 2009-04-13 14:58:54 | [diff] [blame] | 1003 | // Otherwise open a new window. |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1004 | { |
[email protected] | 0fbd7033 | 2010-06-01 19:28:34 | [diff] [blame] | 1005 | AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1006 | Browser::OpenEmptyWindow([self lastProfile]); |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1007 | } |
[email protected] | ff81e0a | 2009-04-13 14:58:54 | [diff] [blame] | 1008 | |
| 1009 | // We've handled the reopen event, so return NO to tell AppKit not |
| 1010 | // to do anything. |
| 1011 | return NO; |
| 1012 | } |
| 1013 | |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 1014 | - (void)initMenuState { |
[email protected] | 3111f08b | 2009-04-30 16:01:52 | [diff] [blame] | 1015 | menuState_.reset(new CommandUpdater(NULL)); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 1016 | menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 1017 | menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
[email protected] | 863ff66 | 2009-01-26 20:18:18 | [diff] [blame] | 1018 | menuState_->UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); |
[email protected] | e19516d | 2009-04-28 17:15:19 | [diff] [blame] | 1019 | menuState_->UpdateCommandEnabled(IDC_OPEN_FILE, true); |
[email protected] | 93e18176 | 2009-05-29 14:30:38 | [diff] [blame] | 1020 | menuState_->UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true); |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 1021 | menuState_->UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 1022 | menuState_->UpdateCommandEnabled(IDC_FOCUS_LOCATION, true); |
[email protected] | cddc524 | 2009-12-07 18:54:33 | [diff] [blame] | 1023 | menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); |
[email protected] | af7c25e | 2010-01-23 05:46:45 | [diff] [blame] | 1024 | menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); |
[email protected] | 91a5b3e | 2009-10-30 19:32:22 | [diff] [blame] | 1025 | menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
| 1026 | menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
[email protected] | bb37e6ec | 2009-11-18 17:59:36 | [diff] [blame] | 1027 | menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); |
[email protected] | 1fdff70 | 2009-10-22 00:36:18 | [diff] [blame] | 1028 | menuState_->UpdateCommandEnabled(IDC_HELP_PAGE, true); |
[email protected] | 4aee565 | 2009-11-19 18:59:21 | [diff] [blame] | 1029 | menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); |
[email protected] | 1c41a93 | 2010-11-22 23:41:23 | [diff] [blame] | 1030 | menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 1031 | menuState_->UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, true); |
[email protected] | ceaaf181 | 2010-01-20 22:13:09 | [diff] [blame] | 1032 | menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
[email protected] | 88d7494 | 2009-01-21 22:04:44 | [diff] [blame] | 1033 | } |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 1034 | |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 1035 | // Conditionally adds the Profile menu to the main menu bar. |
| 1036 | - (void)initProfileMenu { |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 1037 | NSMenu* mainMenu = [NSApp mainMenu]; |
| 1038 | NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; |
[email protected] | e354ca4 | 2011-08-03 20:31:40 | [diff] [blame] | 1039 | |
| 1040 | // On Leopard, hiding main menubar items does not work. This manifests itself |
| 1041 | // in Chromium as squished menu items <http://crbug.com/90753>. To prevent |
| 1042 | // this, remove the Profile menu on Leopard, regardless of the user's |
| 1043 | // multiprofile state. |
[email protected] | 6b2d30bc | 2011-10-11 18:16:39 | [diff] [blame] | 1044 | if (!ProfileManager::IsMultipleProfilesEnabled() || |
| 1045 | base::mac::IsOSLeopard()) { |
[email protected] | e354ca4 | 2011-08-03 20:31:40 | [diff] [blame] | 1046 | [mainMenu removeItem:profileMenu]; |
| 1047 | return; |
| 1048 | } |
| 1049 | |
[email protected] | 6b2d30bc | 2011-10-11 18:16:39 | [diff] [blame] | 1050 | // The controller will unhide the menu if necessary. |
| 1051 | [profileMenu setHidden:YES]; |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 1052 | |
[email protected] | 6b2d30bc | 2011-10-11 18:16:39 | [diff] [blame] | 1053 | profileMenuController_.reset( |
| 1054 | [[ProfileMenuController alloc] initWithMainMenuItem:profileMenu]); |
[email protected] | 961a693 | 2011-07-19 19:52:46 | [diff] [blame] | 1055 | } |
| 1056 | |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 1057 | // The Confirm to Quit preference is atypical in that the preference lives in |
| 1058 | // the app menu right above the Quit menu item. This method will refresh the |
| 1059 | // display of that item depending on the preference state. |
| 1060 | - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item { |
| 1061 | // Format the string so that the correct key equivalent is displayed. |
| 1062 | NSString* acceleratorString = [ConfirmQuitPanelController keyCommandString]; |
| 1063 | NSString* title = l10n_util::GetNSStringF(IDS_CONFIRM_TO_QUIT_OPTION, |
| 1064 | base::SysNSStringToUTF16(acceleratorString)); |
| 1065 | [item setTitle:title]; |
| 1066 | |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1067 | const PrefService* prefService = [self lastProfile]->GetPrefs(); |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 1068 | bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); |
| 1069 | [item setState:enabled ? NSOnState : NSOffState]; |
| 1070 | } |
| 1071 | |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1072 | - (void)registerServicesMenuTypesTo:(NSApplication*)app { |
[email protected] | 09ea24c | 2010-08-23 19:05:41 | [diff] [blame] | 1073 | // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which |
| 1074 | // handles requests from services. |
| 1075 | NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; |
| 1076 | [app registerServicesMenuSendTypes:types returnTypes:types]; |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1077 | } |
| 1078 | |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1079 | - (Profile*)lastProfile { |
[email protected] | 7fd5a46 | 2011-06-19 16:57:23 | [diff] [blame] | 1080 | // Return the profile of the last-used BrowserWindowController, if available. |
| 1081 | if (lastProfile_) |
| 1082 | return lastProfile_; |
| 1083 | |
[email protected] | 056f879 | 2011-07-20 15:40:15 | [diff] [blame] | 1084 | // On first launch, no profile will be stored, so use last from Local State. |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 1085 | if (g_browser_process->profile_manager()) |
[email protected] | 056f879 | 2011-07-20 15:40:15 | [diff] [blame] | 1086 | return g_browser_process->profile_manager()->GetLastUsedProfile(); |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 1087 | |
[email protected] | f631400 | 2009-04-23 01:18:13 | [diff] [blame] | 1088 | return NULL; |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 1089 | } |
| 1090 | |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1091 | // Various methods to open URLs that we get in a native fashion. We use |
| 1092 | // BrowserInit here because on the other platforms, URLs to open come through |
| 1093 | // the ProcessSingleton, and it calls BrowserInit. It's best to bottleneck the |
| 1094 | // openings through that for uniform handling. |
| 1095 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1096 | - (void)openUrls:(const std::vector<GURL>&)urls { |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1097 | // If the browser hasn't started yet, just queue up the URLs. |
| 1098 | if (!startupComplete_) { |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1099 | startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
[email protected] | 136140c | 2009-05-19 13:58:25 | [diff] [blame] | 1100 | return; |
| 1101 | } |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1102 | |
[email protected] | 0e86351 | 2009-05-28 19:45:07 | [diff] [blame] | 1103 | Browser* browser = BrowserList::GetLastActive(); |
| 1104 | // if no browser window exists then create one with no tabs to be filled in |
| 1105 | if (!browser) { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1106 | browser = Browser::Create([self lastProfile]); |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 1107 | browser->window()->Show(); |
[email protected] | 0e86351 | 2009-05-28 19:45:07 | [diff] [blame] | 1108 | } |
| 1109 | |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 1110 | CommandLine dummy(CommandLine::NO_PROGRAM); |
[email protected] | dfa08b04 | 2011-12-28 23:07:21 | [diff] [blame] | 1111 | BrowserInit::IsFirstRun first_run = first_run::IsChromeFirstRun() ? |
[email protected] | e4a377cf | 2011-10-05 02:51:49 | [diff] [blame] | 1112 | BrowserInit::IS_FIRST_RUN : BrowserInit::IS_NOT_FIRST_RUN; |
| 1113 | BrowserInit::LaunchWithProfile launch(FilePath(), dummy, first_run); |
[email protected] | 0e86351 | 2009-05-28 19:45:07 | [diff] [blame] | 1114 | launch.OpenURLsInBrowser(browser, false, urls); |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1115 | } |
| 1116 | |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1117 | - (void)getUrl:(NSAppleEventDescriptor*)event |
| 1118 | withReply:(NSAppleEventDescriptor*)reply { |
| 1119 | NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] |
| 1120 | stringValue]; |
| 1121 | |
| 1122 | GURL gurl(base::SysNSStringToUTF8(urlStr)); |
| 1123 | std::vector<GURL> gurlVector; |
| 1124 | gurlVector.push_back(gurl); |
| 1125 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1126 | [self openUrls:gurlVector]; |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1127 | } |
| 1128 | |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 1129 | // Apple Event handler that receives print event from service |
| 1130 | // process, gets the required data and launches Print dialog. |
| 1131 | - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event { |
| 1132 | // Pull parameter list out of Apple Event. |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 1133 | NSAppleEventDescriptor* paramList = |
[email protected] | 13aec6c4 | 2011-10-27 21:22:08 | [diff] [blame] | 1134 | [event paramDescriptorForKeyword:cloud_print::kAECloudPrintClass]; |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 1135 | |
| 1136 | if (paramList != nil) { |
| 1137 | // Pull required fields out of parameter list. |
| 1138 | NSString* mime = [[paramList descriptorAtIndex:1] stringValue]; |
| 1139 | NSString* inputPath = [[paramList descriptorAtIndex:2] stringValue]; |
| 1140 | NSString* printTitle = [[paramList descriptorAtIndex:3] stringValue]; |
[email protected] | e8368e9 | 2011-08-20 04:05:56 | [diff] [blame] | 1141 | NSString* printTicket = [[paramList descriptorAtIndex:4] stringValue]; |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 1142 | // Convert the title to UTF 16 as required. |
| 1143 | string16 title16 = base::SysNSStringToUTF16(printTitle); |
[email protected] | e8368e9 | 2011-08-20 04:05:56 | [diff] [blame] | 1144 | string16 printTicket16 = base::SysNSStringToUTF16(printTicket); |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 1145 | print_dialog_cloud::CreatePrintDialogForFile( |
| 1146 | FilePath([inputPath UTF8String]), title16, |
[email protected] | d955fc9 | 2011-09-19 20:49:03 | [diff] [blame] | 1147 | printTicket16, [mime UTF8String], /*modal=*/false, |
| 1148 | /*delete_on_close=*/false); |
[email protected] | a529af5 | 2011-08-15 20:56:17 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | // Calls the helper class to install the virtual driver to the |
| 1153 | // service process. |
| 1154 | - (void)installCloudPrint:(NSAppleEventDescriptor*)event { |
| 1155 | cloud_print::VirtualDriverInstallHelper::SetUpInstall(); |
| 1156 | } |
| 1157 | |
| 1158 | // Calls the helper class to uninstall the virtual driver to the |
| 1159 | // service process. |
| 1160 | - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event { |
| 1161 | cloud_print::VirtualDriverInstallHelper::SetUpUninstall(); |
| 1162 | } |
| 1163 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1164 | - (void)application:(NSApplication*)sender |
| 1165 | openFiles:(NSArray*)filenames { |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1166 | std::vector<GURL> gurlVector; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1167 | for (NSString* file in filenames) { |
| 1168 | GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file))); |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1169 | gurlVector.push_back(gurl); |
| 1170 | } |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1171 | if (!gurlVector.empty()) |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1172 | [self openUrls:gurlVector]; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1173 | else |
| 1174 | NOTREACHED() << "Nothing to open!"; |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1175 | |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1176 | [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; |
[email protected] | 57750f82 | 2009-04-21 21:43:09 | [diff] [blame] | 1177 | } |
[email protected] | 3f34599d | 2009-03-25 22:11:43 | [diff] [blame] | 1178 | |
[email protected] | 3111f08b | 2009-04-30 16:01:52 | [diff] [blame] | 1179 | // Show the preferences window, or bring it to the front if it's already |
| 1180 | // visible. |
| 1181 | - (IBAction)showPreferences:(id)sender { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1182 | if (Browser* browser = ActivateBrowser([self lastProfile])) { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 1183 | // Show options tab in the active browser window. |
| 1184 | browser->OpenOptionsDialog(); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 1185 | } else { |
[email protected] | 44517765 | 2011-03-09 02:04:05 | [diff] [blame] | 1186 | // No browser window, so create one for the options tab. |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1187 | Browser::OpenOptionsWindow([self lastProfile]); |
[email protected] | 4a42d27 | 2010-06-18 01:29:42 | [diff] [blame] | 1188 | } |
[email protected] | d989f07c | 2009-11-14 00:35:46 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1191 | // Called when the about window is closed. We use this to release the |
| 1192 | // window controller. |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 1193 | - (void)aboutWindowClosed:(NSNotification*)notification { |
| 1194 | NSWindow* window = [aboutController_ window]; |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 1195 | DCHECK_EQ([notification object], window); |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1196 | [[NSNotificationCenter defaultCenter] |
[email protected] | 49aeee5 | 2009-10-26 19:58:13 | [diff] [blame] | 1197 | removeObserver:self |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 1198 | name:NSWindowWillCloseNotification |
| 1199 | object:window]; |
| 1200 | // AboutWindowControllers are autoreleased in |
| 1201 | // -[AboutWindowController windowWillClose:]. |
| 1202 | aboutController_ = nil; |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | - (IBAction)orderFrontStandardAboutPanel:(id)sender { |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1206 | if (!aboutController_) { |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 1207 | aboutController_ = |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1208 | [[AboutWindowController alloc] initWithProfile:[self lastProfile]]; |
[email protected] | 49aeee5 | 2009-10-26 19:58:13 | [diff] [blame] | 1209 | |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1210 | // Watch for a notification of when it goes away so that we can destroy |
| 1211 | // the controller. |
| 1212 | [[NSNotificationCenter defaultCenter] |
| 1213 | addObserver:self |
| 1214 | selector:@selector(aboutWindowClosed:) |
[email protected] | d4e1865 | 2009-11-19 21:52:16 | [diff] [blame] | 1215 | name:NSWindowWillCloseNotification |
| 1216 | object:[aboutController_ window]]; |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1217 | } |
[email protected] | 49aeee5 | 2009-10-26 19:58:13 | [diff] [blame] | 1218 | |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1219 | [aboutController_ showWindow:self]; |
[email protected] | bde3dda | 2009-05-20 22:13:07 | [diff] [blame] | 1220 | } |
| 1221 | |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 1222 | - (IBAction)toggleConfirmToQuit:(id)sender { |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1223 | PrefService* prefService = [self lastProfile]->GetPrefs(); |
[email protected] | a99fce0e | 2011-03-21 20:58:48 | [diff] [blame] | 1224 | bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); |
| 1225 | prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); |
| 1226 | } |
| 1227 | |
[email protected] | 3d4bd23f | 2009-10-06 03:58:38 | [diff] [blame] | 1228 | // Explicitly bring to the foreground when creating new windows from the dock. |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 1229 | - (void)commandFromDock:(id)sender { |
[email protected] | 3d4bd23f | 2009-10-06 03:58:38 | [diff] [blame] | 1230 | [NSApp activateIgnoringOtherApps:YES]; |
| 1231 | [self commandDispatch:sender]; |
| 1232 | } |
| 1233 | |
[email protected] | 227fcee | 2010-06-11 19:19:37 | [diff] [blame] | 1234 | - (NSMenu*)applicationDockMenu:(NSApplication*)sender { |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1235 | NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease]; |
[email protected] | a585a8db | 2011-06-20 18:58:35 | [diff] [blame] | 1236 | Profile* profile = [self lastProfile]; |
[email protected] | 93b59fc | 2010-12-21 20:00:47 | [diff] [blame] | 1237 | |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1238 | NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); |
[email protected] | 8c6b029d | 2011-01-21 22:39:51 | [diff] [blame] | 1239 | scoped_nsobject<NSMenuItem> item( |
| 1240 | [[NSMenuItem alloc] initWithTitle:titleStr |
| 1241 | action:@selector(commandFromDock:) |
| 1242 | keyEquivalent:@""]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 1243 | [item setTarget:self]; |
| 1244 | [item setTag:IDC_NEW_WINDOW]; |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1245 | [dockMenu addItem:item]; |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 1246 | |
| 1247 | titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1248 | item.reset([[NSMenuItem alloc] initWithTitle:titleStr |
[email protected] | 8c6b029d | 2011-01-21 22:39:51 | [diff] [blame] | 1249 | action:@selector(commandFromDock:) |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1250 | keyEquivalent:@""]); |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 1251 | [item setTarget:self]; |
| 1252 | [item setTag:IDC_NEW_INCOGNITO_WINDOW]; |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1253 | [dockMenu addItem:item]; |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 1254 | |
[email protected] | 8c6b029d | 2011-01-21 22:39:51 | [diff] [blame] | 1255 | // TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit |
| 1256 | // tests which use the mock in place of the profile-initialized model. |
| 1257 | |
| 1258 | // Avoid breaking unit tests which have no profile. |
| 1259 | if (profile) { |
| 1260 | BackgroundApplicationListModel applications(profile); |
| 1261 | if (applications.size()) { |
| 1262 | int position = 0; |
| 1263 | NSString* menuStr = |
| 1264 | l10n_util::GetNSStringWithFixup(IDS_BACKGROUND_APPS_MAC); |
| 1265 | scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:menuStr]); |
| 1266 | for (ExtensionList::const_iterator cursor = applications.begin(); |
| 1267 | cursor != applications.end(); |
| 1268 | ++cursor, ++position) { |
[email protected] | 2ce9c8975 | 2011-02-25 18:24:34 | [diff] [blame] | 1269 | DCHECK_EQ(applications.GetPosition(*cursor), position); |
[email protected] | 8c6b029d | 2011-01-21 22:39:51 | [diff] [blame] | 1270 | NSString* itemStr = |
| 1271 | base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name())); |
| 1272 | scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc] |
| 1273 | initWithTitle:itemStr |
| 1274 | action:@selector(commandFromDock:) |
| 1275 | keyEquivalent:@""]); |
| 1276 | [appItem setTarget:self]; |
| 1277 | [appItem setTag:position]; |
| 1278 | [appMenu addItem:appItem]; |
| 1279 | } |
| 1280 | scoped_nsobject<NSMenuItem> appMenuItem([[NSMenuItem alloc] |
| 1281 | initWithTitle:menuStr |
| 1282 | action:@selector(commandFromDock:) |
| 1283 | keyEquivalent:@""]); |
| 1284 | [appMenuItem setTarget:self]; |
| 1285 | [appMenuItem setTag:position]; |
| 1286 | [appMenuItem setSubmenu:appMenu]; |
| 1287 | [dockMenu addItem:appMenuItem]; |
| 1288 | } |
| 1289 | } |
| 1290 | |
[email protected] | 018a396 | 2009-09-17 22:23:44 | [diff] [blame] | 1291 | return dockMenu; |
[email protected] | 288bfcd3 | 2009-09-14 18:14:46 | [diff] [blame] | 1292 | } |
| 1293 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1294 | - (const std::vector<GURL>&)startupUrls { |
| 1295 | return startupUrls_; |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1298 | - (void)clearStartupUrls { |
| 1299 | startupUrls_.clear(); |
[email protected] | caadfca | 2010-01-22 21:51:21 | [diff] [blame] | 1300 | } |
| 1301 | |
[email protected] | 7e4c69d0 | 2011-05-11 22:16:47 | [diff] [blame] | 1302 | - (BookmarkMenuBridge*)bookmarkMenuBridge { |
| 1303 | return bookmarkMenuBridge_.get(); |
| 1304 | } |
| 1305 | |
[email protected] | ebbe94b | 2012-01-18 20:11:56 | [diff] [blame^] | 1306 | - (void)applicationDidChangeScreenParameters:(NSNotification*)notification { |
[email protected] | 6a45507 | 2011-11-02 01:32:28 | [diff] [blame] | 1307 | // During this callback the working area is not always already updated. Defer. |
| 1308 | [self performSelector:@selector(delayedPanelManagerScreenParametersUpdate) |
| 1309 | withObject:nil |
| 1310 | afterDelay:0]; |
| 1311 | } |
| 1312 | |
| 1313 | - (void)delayedPanelManagerScreenParametersUpdate { |
| 1314 | PanelManager::GetInstance()->OnDisplayChanged(); |
| 1315 | } |
| 1316 | |
[email protected] | d630d7d5 | 2010-02-21 00:55:11 | [diff] [blame] | 1317 | @end // @implementation AppController |
[email protected] | 60ad3e2 | 2009-09-18 21:07:19 | [diff] [blame] | 1318 | |
| 1319 | //--------------------------------------------------------------------------- |
| 1320 | |
[email protected] | 0934de8 | 2011-03-09 18:42:16 | [diff] [blame] | 1321 | namespace browser { |
| 1322 | |
| 1323 | void ShowInstantConfirmDialog(gfx::NativeWindow parent, Profile* profile) { |
| 1324 | if (Browser* browser = ActivateBrowser(profile)) { |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 1325 | browser->OpenInstantConfirmDialog(); |
[email protected] | 0934de8 | 2011-03-09 18:42:16 | [diff] [blame] | 1326 | } else { |
[email protected] | b99081b | 2011-03-10 17:43:47 | [diff] [blame] | 1327 | Browser::OpenInstantConfirmDialogWindow(profile); |
[email protected] | 0934de8 | 2011-03-09 18:42:16 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | } // namespace browser |
| 1332 | |
[email protected] | 216e904 | 2009-10-29 17:05:23 | [diff] [blame] | 1333 | namespace app_controller_mac { |
| 1334 | |
| 1335 | bool IsOpeningNewWindow() { |
| 1336 | return g_is_opening_new_window; |
| 1337 | } |
| 1338 | |
| 1339 | } // namespace app_controller_mac |