Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 18089012: Swap main menu with app-specific menu when app window focused. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_controller_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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;
tapted 2013/07/05 04:50:54 maybe showOrHideMenuItemsForPackagedApp ?
jackhou1 2013/07/05 08:35:14 Done.
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 object:nil]; 303 object:nil];
300 [notificationCenter 304 [notificationCenter
301 addObserver:self 305 addObserver:self
302 selector:@selector(popoverDidClose:) 306 selector:@selector(popoverDidClose:)
303 name:NSPopoverDidCloseNotification 307 name:NSPopoverDidCloseNotification
304 object:nil]; 308 object:nil];
305 } 309 }
306 310
307 // Set up the command updater for when there are no windows open 311 // Set up the command updater for when there are no windows open
308 [self initMenuState]; 312 [self initMenuState];
309 313
tapted 2013/07/05 04:50:54 Should we add the notification up here, to keep it
jackhou1 2013/07/05 08:35:14 Done.
310 // Initialize the Profile menu. 314 // Initialize the Profile menu.
311 [self initProfileMenu]; 315 [self initProfileMenu];
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];
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
1128 selector:@selector(updateMenuBar:)
1129 name:NSWindowDidBecomeMainNotification
1130 object:nil];
1121 } 1131 }
1122 1132
1123 // Conditionally adds the Profile menu to the main menu bar. 1133 // Conditionally adds the Profile menu to the main menu bar.
1124 - (void)initProfileMenu { 1134 - (void)initProfileMenu {
1125 NSMenu* mainMenu = [NSApp mainMenu]; 1135 NSMenu* mainMenu = [NSApp mainMenu];
1126 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; 1136 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU];
1127 1137
1128 if (!ProfileManager::IsMultipleProfilesEnabled()) { 1138 if (!ProfileManager::IsMultipleProfilesEnabled()) {
1129 [mainMenu removeItem:profileMenu]; 1139 [mainMenu removeItem:profileMenu];
1130 return; 1140 return;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 [self performSelector:@selector(delayedScreenParametersUpdate) 1380 [self performSelector:@selector(delayedScreenParametersUpdate)
1371 withObject:nil 1381 withObject:nil
1372 afterDelay:0]; 1382 afterDelay:0];
1373 } 1383 }
1374 1384
1375 - (void)delayedScreenParametersUpdate { 1385 - (void)delayedScreenParametersUpdate {
1376 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_, 1386 FOR_EACH_OBSERVER(ui::WorkAreaWatcherObserver, workAreaChangeObservers_,
1377 WorkAreaChanged()); 1387 WorkAreaChanged());
1378 } 1388 }
1379 1389
1390 // If the window is an app window, show the menu bar for that app, otherwise
1391 // restore the Chrome menu bar.
1392 - (void)updateMenuBar:(NSNotification*)notification {
1393 NSMenu* mainMenu = [NSApp mainMenu];
1394 apps::ShellWindow* shell_window =
tapted 2013/07/05 04:50:54 should be shellWindow
jackhou1 2013/07/05 08:35:14 Done.
1395 extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
1396 [notification object]);
1397
1398 if (!shell_window) {
1399 // Restore the Chrome main menu bar.
tapted 2013/07/05 04:50:54 move this comment down to before the for loop?
jackhou1 2013/07/05 08:35:14 Done.
1400 if (!appMenuItem_)
1401 return;
1402
1403 [mainMenu removeItem:appMenuItem_];
1404 appMenuItem_.reset();
1405
1406 for (NSMenuItem* item in [mainMenu itemArray])
1407 [item setHidden:NO];
1408
1409 return;
1410 }
1411
1412 const extensions::Extension* app = shell_window->extension();
1413 NSString* app_id = base::SysUTF8ToNSString(app->id());
tapted 2013/07/05 04:50:54 should be appId
jackhou1 2013/07/05 08:35:14 Done.
1414 NSString* title = base::SysUTF8ToNSString(app->name());
1415
1416 if (appMenuItem_) {
1417 if ([[appMenuItem_ title] isEqualToString:app_id])
1418 return;
1419
1420 [mainMenu removeItem:appMenuItem_];
1421 }
1422
1423 // Hide everything and add a menu item for the app.
1424 for (NSMenuItem* item in [mainMenu itemArray])
1425 [item setHidden:YES];
1426
1427 appMenuItem_.reset(
1428 [[NSMenuItem alloc] initWithTitle:app_id
1429 action:nil
1430 keyEquivalent:@""]);
1431 base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:title]);
1432 [appMenuItem_ setSubmenu:appMenu];
1433 [mainMenu addItem:appMenuItem_];
1434 }
1435
1380 @end // @implementation AppController 1436 @end // @implementation AppController
1381 1437
1382 //--------------------------------------------------------------------------- 1438 //---------------------------------------------------------------------------
1383 1439
1384 namespace app_controller_mac { 1440 namespace app_controller_mac {
1385 1441
1386 bool IsOpeningNewWindow() { 1442 bool IsOpeningNewWindow() {
1387 return g_is_opening_new_window; 1443 return g_is_opening_new_window;
1388 } 1444 }
1389 1445
1390 } // namespace app_controller_mac 1446 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698