Chromium Code Reviews| Index: chrome/browser/app_controller_mac.mm |
| diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm |
| index 703ae1648e4900d6be38f73505195ab0ec2a9d22..ba9b67a014a7dbb439e35edf0adca4b3010a5e57 100644 |
| --- a/chrome/browser/app_controller_mac.mm |
| +++ b/chrome/browser/app_controller_mac.mm |
| @@ -4,6 +4,7 @@ |
| #import "chrome/browser/app_controller_mac.h" |
| +#include "apps/shell_window.h" |
| #include "base/auto_reset.h" |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| @@ -26,6 +27,7 @@ |
| #include "chrome/browser/download/download_service_factory.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_system.h" |
| +#include "chrome/browser/extensions/shell_window_registry.h" |
| #include "chrome/browser/first_run/first_run.h" |
| #include "chrome/browser/lifetime/application_lifetime.h" |
| #include "chrome/browser/printing/print_dialog_cloud.h" |
| @@ -68,6 +70,7 @@ |
| #include "chrome/common/chrome_paths_internal.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
| +#include "chrome/common/extensions/extension.h" |
| #include "chrome/common/extensions/extension_constants.h" |
| #include "chrome/common/mac/app_mode_common.h" |
| #include "chrome/common/pref_names.h" |
| @@ -192,6 +195,7 @@ void RecordLastRunAppBundlePath() { |
| - (BOOL)shouldQuitWithInProgressDownloads; |
| - (void)executeApplication:(id)sender; |
| - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
| +- (void)showOrHideMenuItemsForPackagedApp:(NSNotification*)notification; |
| @end |
| class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| @@ -307,6 +311,12 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| // Set up the command updater for when there are no windows open |
| [self initMenuState]; |
| + [[NSNotificationCenter defaultCenter] |
| + addObserver:self |
| + selector:@selector(showOrHideMenuItemsForPackagedApp:) |
| + name:NSWindowDidBecomeMainNotification |
| + object:nil]; |
| + |
| // Initialize the Profile menu. |
| [self initProfileMenu]; |
| } |
| @@ -1377,6 +1387,52 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| WorkAreaChanged()); |
| } |
| +// If the window is an app window, show the menu bar for that app, otherwise |
| +// restore the Chrome menu bar. |
| +- (void)showOrHideMenuItemsForPackagedApp:(NSNotification*)notification { |
| + NSMenu* mainMenu = [NSApp mainMenu]; |
| + apps::ShellWindow* shellWindow = |
| + extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( |
| + [notification object]); |
| + |
| + if (!shellWindow) { |
| + if (!appMenuItem_) |
| + return; |
| + |
| + [mainMenu removeItem:appMenuItem_]; |
| + appMenuItem_.reset(); |
| + |
| + // Restore the Chrome main menu bar. |
| + for (NSMenuItem* item in [mainMenu itemArray]) |
| + [item setHidden:NO]; |
| + |
| + return; |
| + } |
| + |
| + const extensions::Extension* app = shellWindow->extension(); |
| + NSString* appId = base::SysUTF8ToNSString(app->id()); |
| + NSString* title = base::SysUTF8ToNSString(app->name()); |
| + |
| + if (appMenuItem_) { |
| + if ([[appMenuItem_ title] isEqualToString:appId]) |
| + return; |
| + |
| + [mainMenu removeItem:appMenuItem_]; |
| + } |
| + |
| + // Hide everything and add a menu item for the app. |
| + for (NSMenuItem* item in [mainMenu itemArray]) |
| + [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.
|
| + |
| + appMenuItem_.reset( |
| + [[NSMenuItem alloc] initWithTitle:appId |
| + action:nil |
| + keyEquivalent:@""]); |
| + 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
|
| + [appMenuItem_ setSubmenu:appMenu]; |
| + [mainMenu addItem:appMenuItem_]; |
| +} |
| + |
| @end // @implementation AppController |
| //--------------------------------------------------------------------------- |