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..a0a98549d1843e1ef99a0e732f669026f54cc7fe 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,8 +553,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; |
} |