diff options
author | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-30 22:32:57 +0000 |
---|---|---|
committer | jackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-30 22:32:57 +0000 |
commit | 1425fd546ee890fa8e5d8e01b9e718a1fde26b3a (patch) | |
tree | 5094e8cc1e8434af83d32c365c7e187074b433e2 /apps | |
parent | a14979882b4b877d041aa801947138ec61d7e082 (diff) | |
download | chromium_src-1425fd546ee890fa8e5d8e01b9e718a1fde26b3a.zip chromium_src-1425fd546ee890fa8e5d8e01b9e718a1fde26b3a.tar.gz chromium_src-1425fd546ee890fa8e5d8e01b9e718a1fde26b3a.tar.bz2 |
Add a main menu to the shim that matches the one in Chrome.
Currently the shim has no main menu. We construct one by adding a first
item (which gets replaced by OSX with the app's title) and hiding it.
Then a second item is added that will be used as the main menu.
BUG=168080
TEST=Start an app and close its window.
Cmd+Tab to the shim.
The main menu bar should have one unbolded item with the name of the app.
Review URL: https://chromiumcodereview.appspot.com/19490002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r-- | apps/DEPS | 2 | ||||
-rw-r--r-- | apps/app_shim/chrome_main_app_mode_mac.mm | 81 | ||||
-rw-r--r-- | apps/apps.gypi | 1 |
3 files changed, 78 insertions, 6 deletions
@@ -24,6 +24,7 @@ include_rules = [ "+chrome/browser/ui/web_applications/web_app_ui.h", "+chrome/browser/web_applications/web_app.h", "+chrome/browser/web_applications/web_app_mac.h", + "+chrome/common/chrome_constants.h", "+chrome/common/chrome_paths.h", "+chrome/common/chrome_paths_internal.h", "+chrome/common/chrome_switches.h", @@ -31,4 +32,5 @@ include_rules = [ "+chrome/common/mac/app_mode_common.h", "+chrome/installer", "+chrome/test/base/testing_profile.h", + "+grit/generated_resources.h", ] diff --git a/apps/app_shim/chrome_main_app_mode_mac.mm b/apps/app_shim/chrome_main_app_mode_mac.mm index 6aa92c2..46df8d2 100644 --- a/apps/app_shim/chrome_main_app_mode_mac.mm +++ b/apps/app_shim/chrome_main_app_mode_mac.mm @@ -13,6 +13,7 @@ #include "base/at_exit.h" #include "base/command_line.h" #include "base/logging.h" +#include "base/mac/bundle_locations.h" #include "base/mac/launch_services_util.h" #include "base/mac/mac_logging.h" #include "base/mac/mac_util.h" @@ -22,13 +23,17 @@ #include "base/path_service.h" #include "base/strings/sys_string_conversions.h" #include "base/threading/thread.h" +#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/mac/app_mode_common.h" +#include "grit/generated_resources.h" #include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_listener.h" #include "ipc/ipc_message.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/l10n/l10n_util.h" namespace { @@ -64,6 +69,9 @@ class AppShimController : public IPC::Listener { // Connects to Chrome and sends a LaunchApp message. void Init(); + // Builds main menu bar items. + void SetUpMenu(); + void SendSetAppHidden(bool hidden); void SendQuitApp(); @@ -81,7 +89,6 @@ class AppShimController : public IPC::Listener { // shim process should die. void OnLaunchAppDone(apps::AppShimLaunchResult result); - // Terminates the app shim process. void Close(); @@ -97,6 +104,10 @@ AppShimController::AppShimController() : channel_(NULL), void AppShimController::Init() { DCHECK(g_io_thread); + + SetUpMenu(); + + // Open an IPC channel to Chrome and send the initial app launch message. NSString* chrome_bundle_path = base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; @@ -123,6 +134,40 @@ void AppShimController::Init() { [NSApp setDelegate:nsapp_delegate_]; } +void AppShimController::SetUpMenu() { + NSString* title = base::SysUTF16ToNSString(g_info->app_mode_name); + + // Create a main menu since [NSApp mainMenu] is nil. + base::scoped_nsobject<NSMenu> main_menu([[NSMenu alloc] initWithTitle:title]); + + // The title of the first item is replaced by OSX with the name of the app and + // bold styling. Create a dummy item for this and make it hidden. + NSMenuItem* dummy_item = [main_menu addItemWithTitle:title + action:nil + keyEquivalent:@""]; + base::scoped_nsobject<NSMenu> dummy_submenu( + [[NSMenu alloc] initWithTitle:title]); + [dummy_item setSubmenu:dummy_submenu]; + [dummy_item setHidden:YES]; + + // Construct an unbolded app menu, to match how it appears in the Chrome menu + // bar when the app is focused. + NSMenuItem* item = [main_menu addItemWithTitle:title + action:nil + keyEquivalent:@""]; + base::scoped_nsobject<NSMenu> submenu([[NSMenu alloc] initWithTitle:title]); + [item setSubmenu:submenu]; + + // Add a quit entry. + NSString* quit_localized_string = + l10n_util::GetNSStringF(IDS_EXIT_MAC, g_info->app_mode_name); + [submenu addItemWithTitle:quit_localized_string + action:@selector(terminate:) + keyEquivalent:@"q"]; + + [NSApp setMainMenu:main_menu]; +} + void AppShimController::SendQuitApp() { channel_->Send(new AppShimHostMsg_QuitApp); } @@ -359,6 +404,32 @@ int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { g_info = info; + // Set bundle paths. This loads the bundles. + base::mac::SetOverrideOuterBundlePath(g_info->chrome_outer_bundle_path); + base::mac::SetOverrideFrameworkBundlePath( + g_info->chrome_versioned_path.Append(chrome::kFrameworkName)); + + // Calculate the preferred locale used by Chrome. + // We can't use l10n_util::OverrideLocaleWithCocoaLocale() because it calls + // [base::mac::OuterBundle() preferredLocalizations] which gets localizations + // from the bundle of the running app (i.e. it is equivalent to + // [[NSBundle mainBundle] preferredLocalizations]) instead of the target + // bundle. + NSArray* preferred_languages = [NSLocale preferredLanguages]; + NSArray* supported_languages = [base::mac::OuterBundle() localizations]; + std::string preferred_localization; + for (NSString* language in preferred_languages) { + if ([supported_languages containsObject:language]) { + preferred_localization = base::SysNSStringToUTF8(language); + break; + } + } + std::string locale = l10n_util::NormalizeLocale( + l10n_util::GetApplicationLocale(preferred_localization)); + + // Load localized strings. + ResourceBundle::InitSharedInstanceLocaleOnly(locale, NULL); + // Launch the IO thread. base::Thread::Options io_thread_options; io_thread_options.message_loop_type = base::MessageLoop::TYPE_IO; @@ -367,11 +438,9 @@ int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { g_io_thread = io_thread; // Find already running instances of Chrome. - NSString* chrome_bundle_path = - base::SysUTF8ToNSString(g_info->chrome_outer_bundle_path.value()); - NSBundle* chrome_bundle = [NSBundle bundleWithPath:chrome_bundle_path]; + NSString* chrome_bundle_id = [base::mac::OuterBundle() bundleIdentifier]; NSArray* existing_chrome = [NSRunningApplication - runningApplicationsWithBundleIdentifier:[chrome_bundle bundleIdentifier]]; + runningApplicationsWithBundleIdentifier:chrome_bundle_id]; // Launch Chrome if it isn't already running. ProcessSerialNumber psn; @@ -387,7 +456,7 @@ int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { command_line.AppendSwitchPath(switches::kProfileDirectory, info->profile_dir); bool success = - base::mac::OpenApplicationWithPath(info->chrome_outer_bundle_path, + base::mac::OpenApplicationWithPath(base::mac::OuterBundlePath(), command_line, kLSLaunchDefaults, &psn); diff --git a/apps/apps.gypi b/apps/apps.gypi index cb800dd..a4b14b3 100644 --- a/apps/apps.gypi +++ b/apps/apps.gypi @@ -20,6 +20,7 @@ ], 'include_dirs': [ '<(INTERMEDIATE_DIR)', + '<(grit_out_dir)', ], 'sources': [ 'app_launch_for_metro_restart_win.cc', |