diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:08:39 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:08:39 +0000 |
commit | fc877cf756aca680933305c6cb147feecf63113e (patch) | |
tree | bdbeae4a96bd19176573960f14bbd7223cdcf869 /remoting/host/plugin/host_plugin.cc | |
parent | 5365e52c633777ee6dde1edba6258fb502ac205d (diff) | |
download | chromium_src-fc877cf756aca680933305c6cb147feecf63113e.zip chromium_src-fc877cf756aca680933305c6cb147feecf63113e.tar.gz chromium_src-fc877cf756aca680933305c6cb147feecf63113e.tar.bz2 |
Localized Chromoting Host on Mac and Linux.
Re-landing r214379. Two additional fixes:
- HOST_PLUGIN_MIME_TYPE is passed unquoted making the code the uses it responsible for stringizing it.
- msvs_cygwin_shell is set to 0 to avoid cygpath changing "remoting_locales\nl.pak" to "remoting_ocales\nl.pak".
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 now 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/21059003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/plugin/host_plugin.cc')
-rw-r--r-- | remoting/host/plugin/host_plugin.cc | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/remoting/host/plugin/host_plugin.cc b/remoting/host/plugin/host_plugin.cc index 80d7cce..0a8b161 100644 --- a/remoting/host/plugin/host_plugin.cc +++ b/remoting/host/plugin/host_plugin.cc @@ -15,7 +15,8 @@ #include "base/strings/stringize_macros.h" #include "net/socket/ssl_server_socket.h" #include "remoting/base/plugin_thread_task_runner.h" -#include "remoting/host/plugin/constants.h" +#include "remoting/base/resources.h" +#include "remoting/base/string_resources.h" #include "remoting/host/plugin/host_log_handler.h" #include "remoting/host/plugin/host_plugin_utils.h" #include "remoting/host/plugin/host_script_object.h" @@ -25,6 +26,7 @@ #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npfunctions.h" #include "third_party/npapi/bindings/npruntime.h" +#include "ui/base/l10n/l10n_util.h" // Symbol export is handled with a separate def file on Windows. #if defined (__GNUC__) && __GNUC__ >= 4 @@ -56,8 +58,14 @@ using remoting::StringFromNPIdentifier; namespace { +bool g_initialized = false; + base::AtExitManager* g_at_exit_manager = NULL; +// The plugin name and description returned by GetValue(). +std::string* g_ui_name = NULL; +std::string* g_ui_description = NULL; + // NPAPI plugin implementation for remoting host. // Documentation for most of the calls in this class can be found here: // https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins @@ -355,6 +363,36 @@ class HostNPPlugin : public remoting::PluginThreadTaskRunner::Delegate { base::Lock timers_lock_; }; +void InitializePlugin() { + if (g_initialized) + return; + + g_initialized = true; + g_at_exit_manager = new base::AtExitManager; + + // Init an empty command line for common objects that use it. + CommandLine::Init(0, NULL); + + if (remoting::LoadResources("")) { + g_ui_name = new std::string( + l10n_util::GetStringUTF8(IDR_REMOTING_HOST_PLUGIN_NAME)); + g_ui_description = new std::string( + l10n_util::GetStringUTF8(IDR_REMOTING_HOST_PLUGIN_DESCRIPTION)); + } else { + g_ui_name = new std::string(); + g_ui_description = new std::string(); + } +} + +void ShutdownPlugin() { + delete g_ui_name; + delete g_ui_description; + + remoting::UnloadResources(); + + delete g_at_exit_manager; +} + // Utility functions to map NPAPI Entry Points to C++ Objects. HostNPPlugin* PluginFromInstance(NPP instance) { return reinterpret_cast<HostNPPlugin*>(instance->pdata); @@ -408,17 +446,20 @@ NPError DestroyPlugin(NPP instance, } NPError GetValue(NPP instance, NPPVariable variable, void* value) { + // NP_GetValue() can be called before NP_Initialize(). + InitializePlugin(); + switch(variable) { default: VLOG(2) << "GetValue - default " << variable; return NPERR_GENERIC_ERROR; case NPPVpluginNameString: VLOG(2) << "GetValue - name string"; - *reinterpret_cast<const char**>(value) = HOST_PLUGIN_NAME; + *reinterpret_cast<const char**>(value) = g_ui_name->c_str(); break; case NPPVpluginDescriptionString: VLOG(2) << "GetValue - description string"; - *reinterpret_cast<const char**>(value) = HOST_PLUGIN_DESCRIPTION; + *reinterpret_cast<const char**>(value) = g_ui_description->c_str(); break; case NPPVpluginNeedsXEmbed: VLOG(2) << "GetValue - NeedsXEmbed"; @@ -490,8 +531,7 @@ EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnetscape_funcs #endif ) { VLOG(2) << "NP_Initialize"; - if (g_at_exit_manager) - return NPERR_MODULE_LOAD_FAILED_ERROR; + InitializePlugin(); if(npnetscape_funcs == NULL) return NPERR_INVALID_FUNCTABLE_ERROR; @@ -499,13 +539,10 @@ EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnetscape_funcs if(((npnetscape_funcs->version & 0xff00) >> 8) > NP_VERSION_MAJOR) return NPERR_INCOMPATIBLE_VERSION_ERROR; - g_at_exit_manager = new base::AtExitManager; g_npnetscape_funcs = npnetscape_funcs; #if defined(OS_POSIX) && !defined(OS_MACOSX) NP_GetEntryPoints(nppfuncs); #endif - // Init an empty command line for common objects that use it. - CommandLine::Init(0, NULL); #if defined(OS_WIN) ui::EnableHighDPISupport(); @@ -516,15 +553,15 @@ EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnetscape_funcs EXPORT NPError API_CALL NP_Shutdown() { VLOG(2) << "NP_Shutdown"; - delete g_at_exit_manager; - g_at_exit_manager = NULL; + ShutdownPlugin(); + return NPERR_NO_ERROR; } #if defined(OS_POSIX) && !defined(OS_MACOSX) EXPORT const char* API_CALL NP_GetMIMEDescription(void) { VLOG(2) << "NP_GetMIMEDescription"; - return HOST_PLUGIN_MIME_TYPE "::"; + return STRINGIZE(HOST_PLUGIN_MIME_TYPE) "::"; } EXPORT NPError API_CALL NP_GetValue(void* npp, |