diff options
-rw-r--r-- | chrome/app/chrome_command_ids.h | 1 | ||||
-rw-r--r-- | chrome/app/nibs/MainMenu.xib | 33 | ||||
-rw-r--r-- | chrome/browser/app_controller_mac.h | 5 | ||||
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 19 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/profile_menu_controller.h | 45 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/profile_menu_controller.mm | 79 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
7 files changed, 176 insertions, 8 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index e85d964..53a53f5 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -212,6 +212,7 @@ #define IDC_INTERNET_OPTIONS 45100 // ChromeOS only #define IDC_LANGUAGE_OPTIONS 45200 // ChromeOS only #define IDC_HISTORY_MENU 46000 // OSX only +#define IDC_PROFILE_MAIN_MENU 46100 // OSX only #define IDC_INPUT_METHODS_MENU 46300 // Linux only // Custom context menu entries diff --git a/chrome/app/nibs/MainMenu.xib b/chrome/app/nibs/MainMenu.xib index ae55a8f..e76672a 100644 --- a/chrome/app/nibs/MainMenu.xib +++ b/chrome/app/nibs/MainMenu.xib @@ -2,17 +2,17 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">10J567</string> - <string key="IBDocument.InterfaceBuilderVersion">788</string> + <string key="IBDocument.SystemVersion">10J869</string> + <string key="IBDocument.InterfaceBuilderVersion">851</string> <string key="IBDocument.AppKitVersion">1038.35</string> - <string key="IBDocument.HIToolboxVersion">462.00</string> + <string key="IBDocument.HIToolboxVersion">461.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">788</string> + <string key="NS.object.0">851</string> </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="205"/> + <integer value="29"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1161,6 +1161,15 @@ <string key="NSName">_NSWindowsMenu</string> </object> </object> + <object class="NSMenuItem" id="657848419"> + <reference key="NSMenu" ref="649796088"/> + <string key="NSTitle">^IDS_PROFILES_OPTIONS_GROUP_NAME</string> + <string key="NSKeyEquiv"/> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="353210768"/> + <reference key="NSMixedImage" ref="549394948"/> + <int key="NSTag">46100</int> + </object> <object class="NSMenuItem" id="391199113"> <reference key="NSMenu" ref="649796088"/> <string key="NSTitle">^IDS_HELP_MENU_MAC</string> @@ -1859,6 +1868,7 @@ <reference ref="299901009"/> <reference ref="586577488"/> <reference ref="445514911"/> + <reference ref="657848419"/> </object> <reference key="parent" ref="0"/> <string key="objectName">Main Menu</string> @@ -2690,6 +2700,11 @@ <reference key="object" ref="499460629"/> <reference key="parent" ref="789758025"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">691</int> + <reference key="object" ref="657848419"/> + <reference key="parent" ref="649796088"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -2886,6 +2901,7 @@ <string>687.IBPluginDependency</string> <string>689.IBPluginDependency</string> <string>689.ImportedFromIB2</string> + <string>691.IBPluginDependency</string> <string>72.IBPluginDependency</string> <string>72.ImportedFromIB2</string> <string>73.IBPluginDependency</string> @@ -2962,7 +2978,7 @@ <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> - <string>{{592, 471}, {358, 263}}</string> + <string>{{512, 142}, {358, 263}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>{{197, 734}, {243, 243}}</string> @@ -3006,7 +3022,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>{{525, 802}, {197, 73}}</string> - <string>{{177, 734}, {1578, 20}}</string> + <string>{{70, 405}, {1852, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>{74, 862}</string> @@ -3102,6 +3118,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> @@ -3141,7 +3158,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">690</int> + <int key="maxID">691</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h index fda926e..5f24f86 100644 --- a/chrome/browser/app_controller_mac.h +++ b/chrome/browser/app_controller_mac.h @@ -19,6 +19,7 @@ class CommandUpdater; class GURL; class HistoryMenuBridge; class Profile; +@class ProfileMenuController; // The application controller object, created by loading the MainMenu nib. // This handles things like responding to menus when there are no windows @@ -39,6 +40,10 @@ class Profile; scoped_ptr<HistoryMenuBridge> historyMenuBridge_; AboutWindowController* aboutController_; // Weak. + // The profile menu, which appears right before the Help menu. It is only + // available when multiple profiles is enabled. + scoped_nsobject<ProfileMenuController> profileMenuController_; + // If we're told to open URLs (in particular, via |-application:openFiles:| by // Launch Services) before we've launched the browser, we queue them up in // |startupUrls_| so that they can go in the first browser window/tab. diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index d0abfce..4eb186f 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -41,6 +41,7 @@ #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" #import "chrome/browser/ui/cocoa/history_menu_bridge.h" +#import "chrome/browser/ui/cocoa/profile_menu_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" #include "chrome/browser/ui/cocoa/task_manager_mac.h" @@ -154,6 +155,7 @@ void RecordLastRunAppBundlePath() { @interface AppController (Private) - (void)initMenuState; +- (void)initProfileMenu; - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; - (void)registerServicesMenuTypesTo:(NSApplication*)app; - (void)openUrls:(const std::vector<GURL>&)urls; @@ -214,6 +216,9 @@ void RecordLastRunAppBundlePath() { // Set up the command updater for when there are no windows open [self initMenuState]; + + // Initialize the Profile menu. + [self initProfileMenu]; } // (NSApplicationDelegate protocol) This is the Apple-approved place to override @@ -971,6 +976,20 @@ void RecordLastRunAppBundlePath() { menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); } +// Conditionally adds the Profile menu to the main menu bar. +- (void)initProfileMenu { + bool enableMenu = ProfileManager::IsMultipleProfilesEnabled(); + + NSMenu* mainMenu = [NSApp mainMenu]; + NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; + [profileMenu setHidden:!enableMenu]; + + if (enableMenu) { + profileMenuController_.reset( + [[ProfileMenuController alloc] initWithMainMenuItem:profileMenu]); + } +} + // The Confirm to Quit preference is atypical in that the preference lives in // the app menu right above the Quit menu item. This method will refresh the // display of that item depending on the preference state. diff --git a/chrome/browser/ui/cocoa/profile_menu_controller.h b/chrome/browser/ui/cocoa/profile_menu_controller.h new file mode 100644 index 0000000..68d32c2 --- /dev/null +++ b/chrome/browser/ui/cocoa/profile_menu_controller.h @@ -0,0 +1,45 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_COCOA_PROFILE_MENU_CONTROLLER_H_ +#define CHROME_BROWSER_UI_COCOA_PROFILE_MENU_CONTROLLER_H_ +#pragma once + +#import <Cocoa/Cocoa.h> + +#include "base/memory/scoped_nsobject.h" +#include "base/memory/scoped_ptr.h" + +class Browser; +@class MenuController; +class ProfileMenuModel; + +namespace ProfileMenuControllerInternal { +class Observer; +} + +// This controller manages the title and submenu of the Profiles item in the +// system menu bar. It updates the contents of the menu and the menu's title +// whenever the active browser changes. +@interface ProfileMenuController : NSObject { + @private + // The model for the profile submenu. + scoped_ptr<ProfileMenuModel> submenuModel_; + + // The Cocoa controller that creates the NSMenu from the model. + scoped_nsobject<MenuController> submenuController_; + + // A BrowserList::Observer to be notified when the active browser changes. + scoped_ptr<ProfileMenuControllerInternal::Observer> observer_; + + // The main menu item to which the profile menu is attached. + __weak NSMenuItem* mainMenuItem_; +} + +// Designated initializer. +- (id)initWithMainMenuItem:(NSMenuItem*)item; + +@end + +#endif // CHROME_BROWSER_UI_COCOA_PROFILE_MENU_CONTROLLER_H_ diff --git a/chrome/browser/ui/cocoa/profile_menu_controller.mm b/chrome/browser/ui/cocoa/profile_menu_controller.mm new file mode 100644 index 0000000..f97a092 --- /dev/null +++ b/chrome/browser/ui/cocoa/profile_menu_controller.mm @@ -0,0 +1,79 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/ui/cocoa/profile_menu_controller.h" + +#include "base/sys_string_conversions.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_list.h" +#import "chrome/browser/ui/cocoa/menu_controller.h" +#include "chrome/browser/ui/profile_menu_model.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util_mac.h" + +@interface ProfileMenuController (Private) +- (void)activeBrowserChangedTo:(Browser*)browser; +@end + +namespace ProfileMenuControllerInternal { + +class Observer : public BrowserList::Observer { + public: + Observer(ProfileMenuController* controller) : controller_(controller) { + BrowserList::AddObserver(this); + } + + ~Observer() { + BrowserList::RemoveObserver(this); + } + + // BrowserList::Observer: + virtual void OnBrowserAdded(const Browser* browser) {} + virtual void OnBrowserRemoved(const Browser* browser) {} + virtual void OnBrowserSetLastActive(const Browser* browser) { + [controller_ activeBrowserChangedTo:const_cast<Browser*>(browser)]; + } + + private: + ProfileMenuController* controller_; // Weak; owns this. +}; + +} // namespace ProfileMenuControllerInternal + +//////////////////////////////////////////////////////////////////////////////// + +@implementation ProfileMenuController + +- (id)initWithMainMenuItem:(NSMenuItem*)item { + if ((self = [super init])) { + mainMenuItem_ = item; + observer_.reset(new ProfileMenuControllerInternal::Observer(self)); + } + return self; +} + +// Private ///////////////////////////////////////////////////////////////////// + +// Notifies the controller that the active browser has changed and that the +// menu item and menu need to be updated to reflect that. +- (void)activeBrowserChangedTo:(Browser*)browser { + submenuModel_.reset(new ProfileMenuModel(browser)); + submenuController_.reset( + [[MenuController alloc] initWithModel:submenuModel_.get() + useWithPopUpButtonCell:NO]); + + [mainMenuItem_ setSubmenu:[submenuController_ menu]]; + + NSMenu* submenu = [mainMenuItem_ submenu]; + if (browser) { + [submenu setTitle: + base::SysUTF8ToNSString(browser->profile()->GetProfileName())]; + } + + if (![[submenu title] length]) + [submenu setTitle:l10n_util::GetNSString(IDS_PROFILES_OPTIONS_GROUP_NAME)]; +} + +@end diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8b9360ff..7a45515 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2537,6 +2537,8 @@ 'browser/ui/cocoa/omnibox/omnibox_view_mac.mm', 'browser/ui/cocoa/page_info_bubble_controller.h', 'browser/ui/cocoa/page_info_bubble_controller.mm', + 'browser/ui/cocoa/profile_menu_controller.h', + 'browser/ui/cocoa/profile_menu_controller.mm', 'browser/ui/cocoa/repost_form_warning_mac.h', 'browser/ui/cocoa/repost_form_warning_mac.mm', 'browser/ui/cocoa/restart_browser.h', |