OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "apps/shell_window.h" | |
7 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
12 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
19 #include "chrome/browser/background/background_application_list_model.h" | 20 #include "chrome/browser/background/background_application_list_model.h" |
20 #include "chrome/browser/background/background_mode_manager.h" | 21 #include "chrome/browser/background/background_mode_manager.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/browser_shutdown.h" | 23 #include "chrome/browser/browser_shutdown.h" |
23 #include "chrome/browser/command_updater.h" | 24 #include "chrome/browser/command_updater.h" |
24 #include "chrome/browser/download/download_service.h" | 25 #include "chrome/browser/download/download_service.h" |
25 #include "chrome/browser/download/download_service_factory.h" | 26 #include "chrome/browser/download/download_service_factory.h" |
26 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
27 #include "chrome/browser/extensions/extension_system.h" | 28 #include "chrome/browser/extensions/extension_system.h" |
29 #include "chrome/browser/extensions/shell_window_registry.h" | |
28 #include "chrome/browser/first_run/first_run.h" | 30 #include "chrome/browser/first_run/first_run.h" |
29 #include "chrome/browser/lifetime/application_lifetime.h" | 31 #include "chrome/browser/lifetime/application_lifetime.h" |
30 #include "chrome/browser/printing/print_dialog_cloud.h" | 32 #include "chrome/browser/printing/print_dialog_cloud.h" |
31 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 33 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/browser/service/service_process_control.h" | 35 #include "chrome/browser/service/service_process_control.h" |
34 #include "chrome/browser/sessions/session_restore.h" | 36 #include "chrome/browser/sessions/session_restore.h" |
35 #include "chrome/browser/sessions/session_service.h" | 37 #include "chrome/browser/sessions/session_service.h" |
36 #include "chrome/browser/sessions/session_service_factory.h" | 38 #include "chrome/browser/sessions/session_service_factory.h" |
37 #include "chrome/browser/sessions/tab_restore_service.h" | 39 #include "chrome/browser/sessions/tab_restore_service.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
61 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 63 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
62 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 64 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
63 #include "chrome/browser/ui/extensions/application_launch.h" | 65 #include "chrome/browser/ui/extensions/application_launch.h" |
64 #include "chrome/browser/ui/host_desktop.h" | 66 #include "chrome/browser/ui/host_desktop.h" |
65 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 67 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
66 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 68 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
67 #include "chrome/common/chrome_notification_types.h" | 69 #include "chrome/common/chrome_notification_types.h" |
68 #include "chrome/common/chrome_paths_internal.h" | 70 #include "chrome/common/chrome_paths_internal.h" |
69 #include "chrome/common/chrome_switches.h" | 71 #include "chrome/common/chrome_switches.h" |
70 #include "chrome/common/cloud_print/cloud_print_class_mac.h" | 72 #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
73 #include "chrome/common/extensions/extension.h" | |
71 #include "chrome/common/extensions/extension_constants.h" | 74 #include "chrome/common/extensions/extension_constants.h" |
72 #include "chrome/common/mac/app_mode_common.h" | 75 #include "chrome/common/mac/app_mode_common.h" |
73 #include "chrome/common/pref_names.h" | 76 #include "chrome/common/pref_names.h" |
74 #include "chrome/common/service_messages.h" | 77 #include "chrome/common/service_messages.h" |
75 #include "chrome/common/url_constants.h" | 78 #include "chrome/common/url_constants.h" |
76 #include "content/public/browser/browser_thread.h" | 79 #include "content/public/browser/browser_thread.h" |
77 #include "content/public/browser/download_manager.h" | 80 #include "content/public/browser/download_manager.h" |
78 #include "content/public/browser/notification_service.h" | 81 #include "content/public/browser/notification_service.h" |
79 #include "content/public/browser/notification_types.h" | 82 #include "content/public/browser/notification_types.h" |
80 #include "content/public/browser/plugin_service.h" | 83 #include "content/public/browser/plugin_service.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 - (void)getUrl:(NSAppleEventDescriptor*)event | 188 - (void)getUrl:(NSAppleEventDescriptor*)event |
186 withReply:(NSAppleEventDescriptor*)reply; | 189 withReply:(NSAppleEventDescriptor*)reply; |
187 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | 190 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; |
188 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 191 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
189 - (void)windowChangedToProfile:(Profile*)profile; | 192 - (void)windowChangedToProfile:(Profile*)profile; |
190 - (void)checkForAnyKeyWindows; | 193 - (void)checkForAnyKeyWindows; |
191 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 194 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
192 - (BOOL)shouldQuitWithInProgressDownloads; | 195 - (BOOL)shouldQuitWithInProgressDownloads; |
193 - (void)executeApplication:(id)sender; | 196 - (void)executeApplication:(id)sender; |
194 - (void)profileWasRemoved:(const base::FilePath&)profilePath; | 197 - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
198 - (void)updateMenuBar:(NSNotification*)notification; | |
195 @end | 199 @end |
196 | 200 |
197 class AppControllerProfileObserver : public ProfileInfoCacheObserver { | 201 class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
198 public: | 202 public: |
199 AppControllerProfileObserver( | 203 AppControllerProfileObserver( |
200 ProfileManager* profile_manager, AppController* app_controller) | 204 ProfileManager* profile_manager, AppController* app_controller) |
201 : profile_manager_(profile_manager), | 205 : profile_manager_(profile_manager), |
202 app_controller_(app_controller) { | 206 app_controller_(app_controller) { |
203 DCHECK(profile_manager_); | 207 DCHECK(profile_manager_); |
204 DCHECK(app_controller_); | 208 DCHECK(app_controller_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 name:NSWindowDidBecomeKeyNotification | 280 name:NSWindowDidBecomeKeyNotification |
277 object:nil]; | 281 object:nil]; |
278 [notificationCenter | 282 [notificationCenter |
279 addObserver:self | 283 addObserver:self |
280 selector:@selector(windowLayeringDidChange:) | 284 selector:@selector(windowLayeringDidChange:) |
281 name:NSWindowDidResignKeyNotification | 285 name:NSWindowDidResignKeyNotification |
282 object:nil]; | 286 object:nil]; |
283 [notificationCenter | 287 [notificationCenter |
284 addObserver:self | 288 addObserver:self |
285 selector:@selector(windowLayeringDidChange:) | 289 selector:@selector(windowLayeringDidChange:) |
286 name:NSWindowDidBecomeMainNotification | 290 name:NSWindowDidBecomeMainNotification |
tapted
2013/07/04 02:43:33
hm... I think this observer might be getting clobb
jackhou1
2013/07/05 03:52:37
Nup, both get called.
tapted
2013/07/05 04:50:54
Ah, interesting. And from the documentation it doe
| |
287 object:nil]; | 291 object:nil]; |
288 [notificationCenter | 292 [notificationCenter |
289 addObserver:self | 293 addObserver:self |
290 selector:@selector(windowLayeringDidChange:) | 294 selector:@selector(windowLayeringDidChange:) |
291 name:NSWindowDidResignMainNotification | 295 name:NSWindowDidResignMainNotification |
292 object:nil]; | 296 object:nil]; |
293 | 297 |
294 if (base::mac::IsOSLionOrLater()) { | 298 if (base::mac::IsOSLionOrLater()) { |
295 [notificationCenter | 299 [notificationCenter |
296 addObserver:self | 300 addObserver:self |
(...skipping 15 matching lines...) Expand all Loading... | |
312 } | 316 } |
313 | 317 |
314 - (void)unregisterEventHandlers { | 318 - (void)unregisterEventHandlers { |
315 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 319 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
316 [em removeEventHandlerForEventClass:kInternetEventClass | 320 [em removeEventHandlerForEventClass:kInternetEventClass |
317 andEventID:kAEGetURL]; | 321 andEventID:kAEGetURL]; |
318 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass | 322 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass |
319 andEventID:cloud_print::kAECloudPrintClass]; | 323 andEventID:cloud_print::kAECloudPrintClass]; |
320 [em removeEventHandlerForEventClass:'WWW!' | 324 [em removeEventHandlerForEventClass:'WWW!' |
321 andEventID:'OURL']; | 325 andEventID:'OURL']; |
322 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 326 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
tapted
2013/07/04 02:43:33
(this will probably do the removeObserver bit for
| |
323 } | 327 } |
324 | 328 |
325 // (NSApplicationDelegate protocol) This is the Apple-approved place to override | 329 // (NSApplicationDelegate protocol) This is the Apple-approved place to override |
326 // the default handlers. | 330 // the default handlers. |
327 - (void)applicationWillFinishLaunching:(NSNotification*)notification { | 331 - (void)applicationWillFinishLaunching:(NSNotification*)notification { |
328 // Nothing here right now. | 332 // Nothing here right now. |
329 } | 333 } |
330 | 334 |
331 - (BOOL)tryToTerminateApplication:(NSApplication*)app { | 335 - (BOOL)tryToTerminateApplication:(NSApplication*)app { |
332 // Check for in-process downloads, and prompt the user if they really want | 336 // Check for in-process downloads, and prompt the user if they really want |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); | 1115 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); |
1112 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); | 1116 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); |
1113 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true); | 1117 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
1114 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 1118 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
1115 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); | 1119 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); |
1116 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 1120 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
1117 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); | 1121 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); |
1118 menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); | 1122 menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); |
1119 menuState_->UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, true); | 1123 menuState_->UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, true); |
1120 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); | 1124 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
1125 | |
1126 [[NSNotificationCenter defaultCenter] | |
1127 addObserver:self | |
tapted
2013/07/04 02:43:33
Is there an appropriate place to removeObserver as
| |
1128 selector:@selector(updateMenuBar:) | |
1129 name:NSWindowDidBecomeMainNotification object:nil]; | |
tapted
2013/07/04 02:43:33
nit: object:nil on a new line
jackhou1
2013/07/05 03:52:37
Done.
| |
1121 } | 1130 } |
1122 | 1131 |
1123 // Conditionally adds the Profile menu to the main menu bar. | 1132 // Conditionally adds the Profile menu to the main menu bar. |
1124 - (void)initProfileMenu { | 1133 - (void)initProfileMenu { |
1125 NSMenu* mainMenu = [NSApp mainMenu]; | 1134 NSMenu* mainMenu = [NSApp mainMenu]; |
1126 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; | 1135 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; |
1127 | 1136 |
1128 if (!ProfileManager::IsMultipleProfilesEnabled()) { | 1137 if (!ProfileManager::IsMultipleProfilesEnabled()) { |
1129 [mainMenu removeItem:profileMenu]; | 1138 [mainMenu removeItem:profileMenu]; |
1130 return; | 1139 return; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1370 [self performSelector:@selector(delayedScreenParametersUpdate) | 1379 [self performSelector:@selector(delayedScreenParametersUpdate) |
1371 withObject:nil | 1380 withObject:nil |
1372 afterDelay:0]; | 1381 afterDelay:0]; |
1373 } | 1382 } |
1374 | 1383 |
1375 - (void)delayedScreenParametersUpdate { | 1384 - (void)delayedScreenParametersUpdate { |
1376 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_, | 1385 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_, |
1377 WorkAreaChanged()); | 1386 WorkAreaChanged()); |
1378 } | 1387 } |
1379 | 1388 |
1389 // If the window is an app window, show the menu bar for that app, otherwise | |
1390 // restore the Chrome menu bar. | |
1391 - (void)updateMenuBar:(NSNotification*)notification { | |
1392 NSMenu* mainMenu = [NSApp mainMenu]; | |
1393 apps::ShellWindow* shell_window = | |
1394 extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | |
1395 [notification object]); | |
1396 | |
1397 if (!shell_window) { | |
1398 // Restore the Chrome menu bar. | |
tapted
2013/07/04 02:43:33
nit: menu -> main menu? And move down to before th
jackhou1
2013/07/05 03:52:37
Done.
| |
1399 if (!appMenuItem_) | |
1400 return; | |
1401 | |
1402 [mainMenu removeItem:appMenuItem_]; | |
1403 appMenuItem_.reset(); | |
1404 | |
1405 for (NSMenuItem* item in [mainMenu itemArray]) | |
1406 [item setHidden:NO]; | |
1407 | |
1408 return; | |
1409 } | |
1410 | |
1411 // Hide everything and add a menu item for the app. | |
1412 for (NSMenuItem* item in [mainMenu itemArray]) | |
tapted
2013/07/04 02:43:33
This looks like it will hide appMenuItem_ when an
jackhou1
2013/07/05 03:52:37
Done.
| |
1413 [item setHidden:YES]; | |
1414 | |
1415 NSString* title = base::SysUTF8ToNSString(shell_window->extension()->name()); | |
tapted
2013/07/04 02:43:33
note: menu_controller.mm does some sanitization of
jackhou1
2013/07/05 03:52:37
I think it's mostly for non-text stuff like check
| |
1416 | |
1417 if (appMenuItem_) { | |
1418 if ([[appMenuItem_ title] isEqualToString:title]) | |
tapted
2013/07/04 02:43:33
since we've got the whole extension, maybe it's be
jackhou1
2013/07/05 03:52:37
Done.
| |
1419 return; | |
1420 | |
1421 [mainMenu removeItem:appMenuItem_]; | |
1422 appMenuItem_.reset(); | |
tapted
2013/07/04 02:43:33
nit: this .reset is redundant
jackhou1
2013/07/05 03:52:37
Done.
| |
1423 } | |
1424 | |
1425 appMenuItem_.reset( | |
1426 [[NSMenuItem alloc] initWithTitle:title | |
1427 action:nil | |
1428 keyEquivalent:@""]); | |
1429 base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:title]); | |
1430 [appMenuItem_ setSubmenu:appMenu]; | |
1431 [mainMenu addItem:appMenuItem_]; | |
1432 } | |
1433 | |
1380 @end // @implementation AppController | 1434 @end // @implementation AppController |
1381 | 1435 |
1382 //--------------------------------------------------------------------------- | 1436 //--------------------------------------------------------------------------- |
1383 | 1437 |
1384 namespace app_controller_mac { | 1438 namespace app_controller_mac { |
1385 | 1439 |
1386 bool IsOpeningNewWindow() { | 1440 bool IsOpeningNewWindow() { |
1387 return g_is_opening_new_window; | 1441 return g_is_opening_new_window; |
1388 } | 1442 } |
1389 | 1443 |
1390 } // namespace app_controller_mac | 1444 } // namespace app_controller_mac |
OLD | NEW |