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

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
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/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/command_updater.h" 25 #include "chrome/browser/command_updater.h"
25 #include "chrome/browser/download/download_service.h" 26 #include "chrome/browser/download/download_service.h"
26 #include "chrome/browser/download/download_service_factory.h" 27 #include "chrome/browser/download/download_service_factory.h"
27 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/extensions/extension_system.h" 29 #include "chrome/browser/extensions/extension_system.h"
30 #include "chrome/browser/extensions/shell_window_registry.h"
29 #include "chrome/browser/first_run/first_run.h" 31 #include "chrome/browser/first_run/first_run.h"
30 #include "chrome/browser/lifetime/application_lifetime.h" 32 #include "chrome/browser/lifetime/application_lifetime.h"
31 #include "chrome/browser/printing/print_dialog_cloud.h" 33 #include "chrome/browser/printing/print_dialog_cloud.h"
32 #include "chrome/browser/profiles/profile_info_cache_observer.h" 34 #include "chrome/browser/profiles/profile_info_cache_observer.h"
33 #include "chrome/browser/profiles/profile_manager.h" 35 #include "chrome/browser/profiles/profile_manager.h"
34 #include "chrome/browser/service/service_process_control.h" 36 #include "chrome/browser/service/service_process_control.h"
35 #include "chrome/browser/sessions/session_restore.h" 37 #include "chrome/browser/sessions/session_restore.h"
36 #include "chrome/browser/sessions/session_service.h" 38 #include "chrome/browser/sessions/session_service.h"
37 #include "chrome/browser/sessions/session_service_factory.h" 39 #include "chrome/browser/sessions/session_service_factory.h"
38 #include "chrome/browser/sessions/tab_restore_service.h" 40 #include "chrome/browser/sessions/tab_restore_service.h"
(...skipping 22 matching lines...) Expand all
61 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 63 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
62 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" 64 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
63 #include "chrome/browser/ui/cocoa/task_manager_mac.h" 65 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
64 #include "chrome/browser/ui/extensions/application_launch.h" 66 #include "chrome/browser/ui/extensions/application_launch.h"
65 #include "chrome/browser/ui/host_desktop.h" 67 #include "chrome/browser/ui/host_desktop.h"
66 #include "chrome/browser/ui/startup/startup_browser_creator.h" 68 #include "chrome/browser/ui/startup/startup_browser_creator.h"
67 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 69 #include "chrome/browser/ui/startup/startup_browser_creator_impl.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)showOrHideMenuItemsForPackagedApp:(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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
314 [[NSNotificationCenter defaultCenter]
315 addObserver:self
316 selector:@selector(showOrHideMenuItemsForPackagedApp:)
317 name:NSWindowDidBecomeMainNotification
318 object:nil];
319
310 // Initialize the Profile menu. 320 // Initialize the Profile menu.
311 [self initProfileMenu]; 321 [self initProfileMenu];
312 } 322 }
313 323
314 - (void)unregisterEventHandlers { 324 - (void)unregisterEventHandlers {
315 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 325 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
316 [em removeEventHandlerForEventClass:kInternetEventClass 326 [em removeEventHandlerForEventClass:kInternetEventClass
317 andEventID:kAEGetURL]; 327 andEventID:kAEGetURL];
318 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass 328 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass
319 andEventID:cloud_print::kAECloudPrintClass]; 329 andEventID:cloud_print::kAECloudPrintClass];
(...skipping 1050 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)showOrHideMenuItemsForPackagedApp:(NSNotification*)notification {
1393 NSMenu* mainMenu = [NSApp mainMenu];
1394 apps::ShellWindow* shellWindow =
1395 extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
1396 [notification object]);
1397
1398 if (!shellWindow) {
1399 if (!appMenuItem_)
1400 return;
1401
1402 [mainMenu removeItem:appMenuItem_];
1403 appMenuItem_.reset();
1404
1405 // Restore the Chrome main menu bar.
1406 for (NSMenuItem* item in [mainMenu itemArray])
1407 [item setHidden:NO];
1408
1409 return;
1410 }
1411
1412 const extensions::Extension* app = shellWindow->extension();
1413 NSString* appId = base::SysUTF8ToNSString(app->id());
1414 NSString* title = base::SysUTF8ToNSString(app->name());
1415
1416 if (appMenuItem_) {
1417 if ([[appMenuItem_ title] isEqualToString:appId])
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];
Nico 2013/07/19 19:43:05 nit: This could be in an else to the previous if,
jackhou1 2013/07/21 23:46:12 Done.
1426
1427 appMenuItem_.reset(
1428 [[NSMenuItem alloc] initWithTitle:appId
1429 action:nil
1430 keyEquivalent:@""]);
1431 base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:title]);
Nico 2013/07/19 19:43:05 Is the plan that apps can have their own menu entr
jackhou1 2013/07/21 23:46:12 I'm planning to add Quit, Hide, and Show to this m
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

Powered by Google App Engine
This is Rietveld 408576698