Skip to content

Commit

Permalink
Localized Chromoting Host on Mac and Linux.
Browse files Browse the repository at this point in the history
This CL implements generation of localizable strings from remoting_strings.grd file. Depending on the platform the localized resources are placed to:
  - Mac: localized .string and .pak resources are added to each application bundle under 'Resources/<locale>.lproj'
  - Linux: localized .pak files are placed under 'remoting_locales' directory next to the binary locading them.
  - Windows: .rc resources are generated from .jinja2 templates and embedded into a relevant binary.

Chrome l10n and i18n APIs are used to retrieve the current locale and RTL flag (Mac & Linux). The it2me plugin sets the locale to match the locale of the browser.

Collateral changes:
  - UiString is not used any more.
  - Increased width of disconnect window message on Mac.
  - The host plugin version is correctly reported on Mac.
  - Dialogs use RTL templates in case of RTL languages. No more updating the templates dynamically (Windows).
  - remoting_unittests.ResourcesTest row runs on Mac, LInux and Windows.
  - '@' is used for variable substitutions by remoting_localize.py.
  - HOST_PLUGIN_MIME_TYPE is defined in one place now.
  - Deleted unused commong_resources.grd.

Mac installer and preference panel are not localized yet.

BUG=155204

Review URL: https://chromiumcodereview.appspot.com/19803010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213997 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
alexeypa@chromium.org committed Jul 26, 2013
1 parent 8d9ba45 commit 40f4268
Show file tree
Hide file tree
Showing 54 changed files with 774 additions and 590 deletions.
35 changes: 0 additions & 35 deletions remoting/base/resources.cc

This file was deleted.

8 changes: 6 additions & 2 deletions remoting/base/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

namespace remoting {

// Loads chromoting resources. Returns false in case of a failure. |pref_locale|
// Loads (or reloads) Chromoting resources for the given locale. |pref_locale|
// is passed to l10n_util::GetApplicationLocale(), so the default system locale
// is used if |pref_locale| is empty.
// is used if |pref_locale| is empty. Returns |true| if the shared resource
// bundle has been initialized.
bool LoadResources(const std::string& pref_locale);

// Unloads Chromoting resources.
void UnloadResources();

} // namespace remoting

#endif // REMOTING_HOST_BASE_RESOURCES_H_
44 changes: 44 additions & 0 deletions remoting/base/resources_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2013 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.

#include "remoting/base/resources.h"

#include <dlfcn.h>

#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"

namespace remoting {

namespace {
const char kLocaleResourcesDirName[] = "remoting_locales";
} // namespace

bool LoadResources(const std::string& pref_locale) {
if (ui::ResourceBundle::HasSharedInstance()) {
ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale);
} else {
// Retrive the path to the module containing this function.
Dl_info info;
CHECK(dladdr(reinterpret_cast<void*>(&LoadResources), &info) != 0);

// Point DIR_LOCALES to 'remoting_locales'.
base::FilePath path = base::FilePath(info.dli_fname).DirName();
PathService::Override(ui::DIR_LOCALES,
path.AppendASCII(kLocaleResourcesDirName));

ui::ResourceBundle::InitSharedInstanceLocaleOnly(pref_locale, NULL);
}

return true;
}

void UnloadResources() {
ui::ResourceBundle::CleanupSharedInstance();
}

} // namespace remoting
43 changes: 43 additions & 0 deletions remoting/base/resources_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2013 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 <Cocoa/Cocoa.h>

#include "remoting/base/resources.h"
#include "base/mac/bundle_locations.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"

// A dummy class used to locate the host plugin's bundle.
@interface NSBundleLocator : NSObject
@end

@implementation NSBundleLocator
@end

namespace remoting {

bool LoadResources(const std::string& pref_locale) {
if (ui::ResourceBundle::HasSharedInstance()) {
ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(pref_locale);
} else {
// Use the plugin's bundle instead of the hosting app bundle.
base::mac::SetOverrideFrameworkBundle(
[NSBundle bundleForClass:[NSBundleLocator class]]);

// Override the locale with the value from Cocoa.
if (pref_locale.empty())
l10n_util::OverrideLocaleWithCocoaLocale();

ui::ResourceBundle::InitSharedInstanceLocaleOnly(pref_locale, NULL);
}

return true;
}

void UnloadResources() {
ui::ResourceBundle::CleanupSharedInstance();
}

} // namespace remoting
44 changes: 19 additions & 25 deletions remoting/base/resources_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,46 @@

#include "remoting/base/resources.h"

#include "remoting/base/common_resources.h"
#include "remoting/base/string_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace remoting {

// TODO(sergeyu): Resources loading doesn't work yet on OSX. Fix it and enable
// the test.
#if !defined(OS_MACOSX)
#define MAYBE_ProductName ProductName
#define MAYBE_ProductLogo ProductLogo
#else // !defined(OS_MACOSX)
#define MAYBE_ProductName DISABLED_ProductName
#define MAYBE_ProductLogo DISABLED_ProductLogo
#endif // defined(OS_MACOSX)

class ResourcesTest : public testing::Test {
protected:
ResourcesTest(): resources_available_(false) {
}

virtual void SetUp() OVERRIDE {
ASSERT_TRUE(LoadResources("en-US"));
resources_available_ = LoadResources("en-US");
}

virtual void TearDown() OVERRIDE {
ui::ResourceBundle::CleanupSharedInstance();
UnloadResources();
}

bool resources_available_;
};

TEST_F(ResourcesTest, MAYBE_ProductName) {
TEST_F(ResourcesTest, ProductName) {
#if defined(GOOGLE_CHROME_BUILD)
std::string expected_product_name = "Chrome Remote Desktop";
#else // defined(GOOGLE_CHROME_BUILD)
std::string expected_product_name = "Chromoting";
#endif // !defined(GOOGLE_CHROME_BUILD)
EXPECT_EQ(expected_product_name,
l10n_util::GetStringUTF8(IDR_PRODUCT_NAME));
}

TEST_F(ResourcesTest, MAYBE_ProductLogo) {
gfx::Image logo16 = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_PRODUCT_LOGO_16);
EXPECT_FALSE(logo16.IsEmpty());
gfx::Image logo32 = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_PRODUCT_LOGO_32);
EXPECT_FALSE(logo32.IsEmpty());
// Chrome-style i18n is not used on Windows.
#if defined(OS_WIN)
EXPECT_FALSE(resources_available_);
#else
EXPECT_TRUE(resources_available_);
#endif

if (resources_available_) {
EXPECT_EQ(expected_product_name,
l10n_util::GetStringUTF8(IDR_PRODUCT_NAME));
}
}

} // namespace remoting
17 changes: 17 additions & 0 deletions remoting/base/resources_win.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 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.

#include "remoting/base/resources.h"

namespace remoting {

bool LoadResources(const std::string& pref_locale) {
// Do nothing since .pak files are not used on Windows.
return false;
}

void UnloadResources() {
}

} // namespace remoting
5 changes: 0 additions & 5 deletions remoting/branding_Chrome
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
COPYRIGHT=Copyright 2013 Google Inc. All Rights Reserved.
HOST_PLUGIN_FILE_NAME=Chrome Remote Desktop Host
HOST_PLUGIN_DESCRIPTION=Allow another user to access your computer securely over the Internet.
DAEMON_FILE_NAME=Chrome Remote Desktop Host Service
MAC_BUNDLE_ID=com.google.Chrome
MAC_CREATOR=rimZ
MAC_HOST_BUNDLE_ID=com.google.chrome_remote_desktop.remoting_me2me_host
MAC_UNINSTALLER_NAME=Chrome Remote Desktop Host Uninstaller
MAC_UNINSTALLER_BUNDLE_PREFIX=com.google.pkg
MAC_UNINSTALLER_BUNDLE_ID=com.google.chromeremotedesktop.host_uninstaller
MAC_UNINSTALLER_BUNDLE_NAME=Chrome Remote Desktop Host Uninstaller
MAC_PREFPANE_BUNDLE_ID=com.google.chromeremotedesktop.preferences
MAC_PREFPANE_BUNDLE_NAME=Chrome Remote Desktop Host Preferences
MAC_PREFPANE_ICON_LABEL=Chrome Remote&#x0a;Desktop Host
5 changes: 0 additions & 5 deletions remoting/branding_Chromium
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
COPYRIGHT=Copyright 2013 The Chromium Authors. All Rights Reserved.
HOST_PLUGIN_FILE_NAME=Chromoting Host
HOST_PLUGIN_DESCRIPTION=Allow another user to access your computer securely over the Internet.
DAEMON_FILE_NAME=Chromoting Host Service
MAC_BUNDLE_ID=org.chromium.Chromium
MAC_CREATOR=Cr24
MAC_HOST_BUNDLE_ID=org.chromium.chromoting.remoting_me2me_host
MAC_UNINSTALLER_NAME=Chromoting Host Uninstaller
MAC_UNINSTALLER_BUNDLE_PREFIX=org.chromium.pkg
MAC_UNINSTALLER_BUNDLE_ID=org.chromium.remoting.host_uninstaller
MAC_UNINSTALLER_BUNDLE_NAME=Chromoting Host Uninstaller
MAC_PREFPANE_BUNDLE_ID=org.chromium.remoting.preferences
MAC_PREFPANE_BUNDLE_NAME=Chromoting Host Preferences
MAC_PREFPANE_ICON_LABEL=Chromoting&#x0a;Host
6 changes: 2 additions & 4 deletions remoting/host/basic_desktop_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ BasicDesktopEnvironment::BasicDesktopEnvironment(
BasicDesktopEnvironmentFactory::BasicDesktopEnvironmentFactory(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const UiStrings& ui_strings)
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
: caller_task_runner_(caller_task_runner),
input_task_runner_(input_task_runner),
ui_task_runner_(ui_task_runner),
ui_strings_(ui_strings) {
ui_task_runner_(ui_task_runner) {
}

BasicDesktopEnvironmentFactory::~BasicDesktopEnvironmentFactory() {
Expand Down
11 changes: 1 addition & 10 deletions remoting/host/basic_desktop_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/ui_strings.h"

namespace remoting {

Expand All @@ -33,8 +32,6 @@ class BasicDesktopEnvironment : public DesktopEnvironment {
protected:
friend class BasicDesktopEnvironmentFactory;

// |ui_strings| are hosted by the BasicDesktopEnvironmentFactory instance that
// created |this|. |ui_strings| must outlive this object.
BasicDesktopEnvironment(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
Expand Down Expand Up @@ -72,8 +69,7 @@ class BasicDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
BasicDesktopEnvironmentFactory(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const UiStrings& ui_strings);
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
virtual ~BasicDesktopEnvironmentFactory();

// DesktopEnvironmentFactory implementation.
Expand All @@ -92,8 +88,6 @@ class BasicDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
return ui_task_runner_;
}

const UiStrings& ui_strings() const { return ui_strings_; }

private:
// Task runner on which methods of DesktopEnvironmentFactory interface should
// be called.
Expand All @@ -105,9 +99,6 @@ class BasicDesktopEnvironmentFactory : public DesktopEnvironmentFactory {
// Used to run UI code.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;

// Contains a copy of the localized UI strings.
const UiStrings ui_strings_;

DISALLOW_COPY_AND_ASSIGN(BasicDesktopEnvironmentFactory);
};

Expand Down
3 changes: 1 addition & 2 deletions remoting/host/continue_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ void ContinueWindow::DisconnectSession() {
client_session_control_->DisconnectSession();
}

ContinueWindow::ContinueWindow(const UiStrings& ui_strings)
: ui_strings_(ui_strings) {
ContinueWindow::ContinueWindow() {
}

void ContinueWindow::OnSessionExpired() {
Expand Down
8 changes: 1 addition & 7 deletions remoting/host/continue_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "remoting/host/host_window.h"
#include "remoting/host/ui_strings.h"

namespace remoting {

Expand All @@ -29,14 +28,12 @@ class ContinueWindow : public HostWindow {
void DisconnectSession();

protected:
explicit ContinueWindow(const UiStrings& ui_strings);
ContinueWindow();

// Shows and hides the UI.
virtual void ShowUi() = 0;
virtual void HideUi() = 0;

const UiStrings& ui_strings() const { return ui_strings_; }

private:
// Invoked periodically to ask for the local user whether the session should
// be continued.
Expand All @@ -51,9 +48,6 @@ class ContinueWindow : public HostWindow {
// Used to ask the local user whether the session should be continued.
base::OneShotTimer<ContinueWindow> session_expired_timer_;

// Localized UI strings.
UiStrings ui_strings_;

DISALLOW_COPY_AND_ASSIGN(ContinueWindow);
};

Expand Down
Loading

0 comments on commit 40f4268

Please sign in to comment.