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..8fbf1e2ee1a7dbfbc6365b0bb004d56f17db195e 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; |
tapted
2013/07/05 04:50:54
maybe showOrHideMenuItemsForPackagedApp ?
jackhou1
2013/07/05 08:35:14
Done.
|
@end |
class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
@@ -1118,6 +1122,12 @@ 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 |
+ selector:@selector(updateMenuBar:) |
+ name:NSWindowDidBecomeMainNotification |
+ object:nil]; |
} |
// Conditionally adds the Profile menu to the main menu bar. |
@@ -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)updateMenuBar:(NSNotification*)notification { |
+ NSMenu* mainMenu = [NSApp mainMenu]; |
+ apps::ShellWindow* shell_window = |
tapted
2013/07/05 04:50:54
should be shellWindow
jackhou1
2013/07/05 08:35:14
Done.
|
+ extensions::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( |
+ [notification object]); |
+ |
+ if (!shell_window) { |
+ // 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.
|
+ if (!appMenuItem_) |
+ return; |
+ |
+ [mainMenu removeItem:appMenuItem_]; |
+ appMenuItem_.reset(); |
+ |
+ for (NSMenuItem* item in [mainMenu itemArray]) |
+ [item setHidden:NO]; |
+ |
+ return; |
+ } |
+ |
+ const extensions::Extension* app = shell_window->extension(); |
+ 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.
|
+ NSString* title = base::SysUTF8ToNSString(app->name()); |
+ |
+ if (appMenuItem_) { |
+ if ([[appMenuItem_ title] isEqualToString:app_id]) |
+ return; |
+ |
+ [mainMenu removeItem:appMenuItem_]; |
+ } |
+ |
+ // Hide everything and add a menu item for the app. |
+ for (NSMenuItem* item in [mainMenu itemArray]) |
+ [item setHidden:YES]; |
+ |
+ appMenuItem_.reset( |
+ [[NSMenuItem alloc] initWithTitle:app_id |
+ action:nil |
+ keyEquivalent:@""]); |
+ base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:title]); |
+ [appMenuItem_ setSubmenu:appMenu]; |
+ [mainMenu addItem:appMenuItem_]; |
+} |
+ |
@end // @implementation AppController |
//--------------------------------------------------------------------------- |