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 39442383924734c51772269c420b3a6aeb2ca097..adf95ce0c045529cfe602b2b7336423fb0e1341e 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" |
| @@ -25,6 +26,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)updateMenuBar:(NSNotification*)notification; |
| @end |
| class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| @@ -1118,6 +1122,11 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); |
| menuState_->UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, true); |
| menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
| + |
| + [[NSNotificationCenter defaultCenter] |
| + addObserver:self |
|
tapted
2013/07/04 02:43:33
Is there an appropriate place to removeObserver as
|
| + selector:@selector(updateMenuBar:) |
| + 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.
|
| } |
| // Conditionally adds the Profile menu to the main menu bar. |
| @@ -1377,6 +1386,51 @@ 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)updateMenuBar:(NSNotification*)notification { |
| + NSMenu* mainMenu = [NSApp mainMenu]; |
| + apps::ShellWindow* shell_window = |
| + extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( |
| + [notification object]); |
| + |
| + if (!shell_window) { |
| + // 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.
|
| + if (!appMenuItem_) |
| + return; |
| + |
| + [mainMenu removeItem:appMenuItem_]; |
| + appMenuItem_.reset(); |
| + |
| + for (NSMenuItem* item in [mainMenu itemArray]) |
| + [item setHidden:NO]; |
| + |
| + return; |
| + } |
| + |
| + // Hide everything and add a menu item for the app. |
| + 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.
|
| + [item setHidden:YES]; |
| + |
| + 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
|
| + |
| + if (appMenuItem_) { |
| + 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.
|
| + return; |
| + |
| + [mainMenu removeItem:appMenuItem_]; |
| + appMenuItem_.reset(); |
|
tapted
2013/07/04 02:43:33
nit: this .reset is redundant
jackhou1
2013/07/05 03:52:37
Done.
|
| + } |
| + |
| + appMenuItem_.reset( |
| + [[NSMenuItem alloc] initWithTitle:title |
| + action:nil |
| + keyEquivalent:@""]); |
| + base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:title]); |
| + [appMenuItem_ setSubmenu:appMenu]; |
| + [mainMenu addItem:appMenuItem_]; |
| +} |
| + |
| @end // @implementation AppController |
| //--------------------------------------------------------------------------- |