Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1885)

Unified Diff: remoting/host/plugin/host_plugin.cc

Issue 19803010: Localized Chromoting Host on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/plugin/host_plugin.cc
diff --git a/remoting/host/plugin/host_plugin.cc b/remoting/host/plugin/host_plugin.cc
index 80d7cce99b28bf7c52510072466eeff001067371..20bb1d4b3acb1a5317be85a033262f4d98a34b3c 100644
--- a/remoting/host/plugin/host_plugin.cc
+++ b/remoting/host/plugin/host_plugin.cc
@@ -15,6 +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/base/resources.h"
+#include "remoting/base/string_resources.h"
#include "remoting/host/plugin/constants.h"
#include "remoting/host/plugin/host_log_handler.h"
#include "remoting/host/plugin/host_plugin_utils.h"
@@ -25,6 +27,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 +59,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 +364,39 @@ 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);
+
+ // Do not use .pak files on Windows.
+#if !defined(OS_WIN)
Sergey Ulanov 2013/07/23 22:45:40 how is g_ui_name supposed to be initialized on Win
alexeypa (please no reviews) 2013/07/23 23:35:26 g_ui_name and g_ui_description are not used on Win
+ remoting::LoadResources("");
+
+ g_ui_name = new std::string(l10n_util::GetStringUTF8(IDR_PRODUCT_NAME));
+ g_ui_description = new std::string(
+ l10n_util::GetStringUTF8(IDR_PRODUCT_DESCRIPTION));
+
+#endif // !defined(OS_WIN)
+}
+
+void ShutdownPlugin() {
+ // Do not use .pak files on Windows.
+#if !defined(OS_WIN)
+ delete g_ui_name;
+ delete g_ui_description;
+
+ remoting::UnloadResources();
+#endif // !defined(OS_WIN)
+
+ 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 +450,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();
Sergey Ulanov 2013/07/23 22:45:40 can we call l10n_util::GetStringUTF8() here instea
Sergey Ulanov 2013/07/23 22:45:40 Are you sure we need to localize this name and the
alexeypa (please no reviews) 2013/07/23 23:35:26 We can live without localizing them but once we go
alexeypa (please no reviews) 2013/07/23 23:35:26 No, because the plugin still owns the string and i
Sergey Ulanov 2013/07/25 18:40:57 I still think that name and description shouldn't
alexeypa (please no reviews) 2013/07/25 18:48:03 It gives something in return. It let's the plugin
Sergey Ulanov 2013/07/26 17:58:25 Ok, makes sense. Maybe add translateable="false" f
alexeypa (please no reviews) 2013/07/26 18:55:01 Why? They are already translated and the translati
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 +535,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 +543,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,8 +557,8 @@ 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;
}

Powered by Google App Engine
This is Rietveld 408576698