OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/stringize_macros.h" | 15 #include "base/strings/stringize_macros.h" |
16 #include "net/socket/ssl_server_socket.h" | 16 #include "net/socket/ssl_server_socket.h" |
17 #include "remoting/base/plugin_thread_task_runner.h" | 17 #include "remoting/base/plugin_thread_task_runner.h" |
18 #include "remoting/host/plugin/constants.h" | 18 #include "remoting/base/resources.h" |
| 19 #include "remoting/base/string_resources.h" |
19 #include "remoting/host/plugin/host_log_handler.h" | 20 #include "remoting/host/plugin/host_log_handler.h" |
20 #include "remoting/host/plugin/host_plugin_utils.h" | 21 #include "remoting/host/plugin/host_plugin_utils.h" |
21 #include "remoting/host/plugin/host_script_object.h" | 22 #include "remoting/host/plugin/host_script_object.h" |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include "ui/base/win/dpi.h" | 24 #include "ui/base/win/dpi.h" |
24 #endif | 25 #endif |
25 #include "third_party/npapi/bindings/npapi.h" | 26 #include "third_party/npapi/bindings/npapi.h" |
26 #include "third_party/npapi/bindings/npfunctions.h" | 27 #include "third_party/npapi/bindings/npfunctions.h" |
27 #include "third_party/npapi/bindings/npruntime.h" | 28 #include "third_party/npapi/bindings/npruntime.h" |
| 29 #include "ui/base/l10n/l10n_util.h" |
28 | 30 |
29 // Symbol export is handled with a separate def file on Windows. | 31 // Symbol export is handled with a separate def file on Windows. |
30 #if defined (__GNUC__) && __GNUC__ >= 4 | 32 #if defined (__GNUC__) && __GNUC__ >= 4 |
31 #define EXPORT __attribute__((visibility("default"))) | 33 #define EXPORT __attribute__((visibility("default"))) |
32 #else | 34 #else |
33 #define EXPORT | 35 #define EXPORT |
34 #endif | 36 #endif |
35 | 37 |
36 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
37 // TODO(wez): libvpx expects these 64-bit division functions to be provided | 39 // TODO(wez): libvpx expects these 64-bit division functions to be provided |
(...skipping 11 matching lines...) Expand all Loading... |
49 } | 51 } |
50 #endif | 52 #endif |
51 | 53 |
52 using remoting::g_npnetscape_funcs; | 54 using remoting::g_npnetscape_funcs; |
53 using remoting::HostLogHandler; | 55 using remoting::HostLogHandler; |
54 using remoting::HostNPScriptObject; | 56 using remoting::HostNPScriptObject; |
55 using remoting::StringFromNPIdentifier; | 57 using remoting::StringFromNPIdentifier; |
56 | 58 |
57 namespace { | 59 namespace { |
58 | 60 |
| 61 bool g_initialized = false; |
| 62 |
59 base::AtExitManager* g_at_exit_manager = NULL; | 63 base::AtExitManager* g_at_exit_manager = NULL; |
60 | 64 |
| 65 // The plugin name and description returned by GetValue(). |
| 66 std::string* g_ui_name = NULL; |
| 67 std::string* g_ui_description = NULL; |
| 68 |
61 // NPAPI plugin implementation for remoting host. | 69 // NPAPI plugin implementation for remoting host. |
62 // Documentation for most of the calls in this class can be found here: | 70 // Documentation for most of the calls in this class can be found here: |
63 // https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins | 71 // https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins |
64 class HostNPPlugin : public remoting::PluginThreadTaskRunner::Delegate { | 72 class HostNPPlugin : public remoting::PluginThreadTaskRunner::Delegate { |
65 public: | 73 public: |
66 // |mode| is the display mode of plug-in. Values: | 74 // |mode| is the display mode of plug-in. Values: |
67 // NP_EMBED: (1) Instance was created by an EMBED tag and shares the browser | 75 // NP_EMBED: (1) Instance was created by an EMBED tag and shares the browser |
68 // window with other content. | 76 // window with other content. |
69 // NP_FULL: (2) Instance was created by a separate file and is the primary | 77 // NP_FULL: (2) Instance was created by a separate file and is the primary |
70 // content in the window. | 78 // content in the window. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 NPP instance_; | 356 NPP instance_; |
349 NPObject* scriptable_object_; | 357 NPObject* scriptable_object_; |
350 | 358 |
351 scoped_refptr<remoting::PluginThreadTaskRunner> plugin_task_runner_; | 359 scoped_refptr<remoting::PluginThreadTaskRunner> plugin_task_runner_; |
352 scoped_refptr<remoting::AutoThreadTaskRunner> plugin_auto_task_runner_; | 360 scoped_refptr<remoting::AutoThreadTaskRunner> plugin_auto_task_runner_; |
353 | 361 |
354 std::map<uint32_t, DelayedTask> timers_; | 362 std::map<uint32_t, DelayedTask> timers_; |
355 base::Lock timers_lock_; | 363 base::Lock timers_lock_; |
356 }; | 364 }; |
357 | 365 |
| 366 void InitializePlugin() { |
| 367 if (g_initialized) |
| 368 return; |
| 369 |
| 370 g_initialized = true; |
| 371 g_at_exit_manager = new base::AtExitManager; |
| 372 |
| 373 // Init an empty command line for common objects that use it. |
| 374 CommandLine::Init(0, NULL); |
| 375 |
| 376 if (remoting::LoadResources("")) { |
| 377 g_ui_name = new std::string( |
| 378 l10n_util::GetStringUTF8(IDR_REMOTING_HOST_PLUGIN_NAME)); |
| 379 g_ui_description = new std::string( |
| 380 l10n_util::GetStringUTF8(IDR_REMOTING_HOST_PLUGIN_DESCRIPTION)); |
| 381 } else { |
| 382 g_ui_name = new std::string(); |
| 383 g_ui_description = new std::string(); |
| 384 } |
| 385 } |
| 386 |
| 387 void ShutdownPlugin() { |
| 388 delete g_ui_name; |
| 389 delete g_ui_description; |
| 390 |
| 391 remoting::UnloadResources(); |
| 392 |
| 393 delete g_at_exit_manager; |
| 394 } |
| 395 |
358 // Utility functions to map NPAPI Entry Points to C++ Objects. | 396 // Utility functions to map NPAPI Entry Points to C++ Objects. |
359 HostNPPlugin* PluginFromInstance(NPP instance) { | 397 HostNPPlugin* PluginFromInstance(NPP instance) { |
360 return reinterpret_cast<HostNPPlugin*>(instance->pdata); | 398 return reinterpret_cast<HostNPPlugin*>(instance->pdata); |
361 } | 399 } |
362 | 400 |
363 NPError CreatePlugin(NPMIMEType pluginType, | 401 NPError CreatePlugin(NPMIMEType pluginType, |
364 NPP instance, | 402 NPP instance, |
365 uint16 mode, | 403 uint16 mode, |
366 int16 argc, | 404 int16 argc, |
367 char** argn, | 405 char** argn, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 plugin->Save(save); | 439 plugin->Save(save); |
402 delete plugin; | 440 delete plugin; |
403 instance->pdata = NULL; | 441 instance->pdata = NULL; |
404 return NPERR_NO_ERROR; | 442 return NPERR_NO_ERROR; |
405 } else { | 443 } else { |
406 return NPERR_INVALID_PLUGIN_ERROR; | 444 return NPERR_INVALID_PLUGIN_ERROR; |
407 } | 445 } |
408 } | 446 } |
409 | 447 |
410 NPError GetValue(NPP instance, NPPVariable variable, void* value) { | 448 NPError GetValue(NPP instance, NPPVariable variable, void* value) { |
| 449 // NP_GetValue() can be called before NP_Initialize(). |
| 450 InitializePlugin(); |
| 451 |
411 switch(variable) { | 452 switch(variable) { |
412 default: | 453 default: |
413 VLOG(2) << "GetValue - default " << variable; | 454 VLOG(2) << "GetValue - default " << variable; |
414 return NPERR_GENERIC_ERROR; | 455 return NPERR_GENERIC_ERROR; |
415 case NPPVpluginNameString: | 456 case NPPVpluginNameString: |
416 VLOG(2) << "GetValue - name string"; | 457 VLOG(2) << "GetValue - name string"; |
417 *reinterpret_cast<const char**>(value) = HOST_PLUGIN_NAME; | 458 *reinterpret_cast<const char**>(value) = g_ui_name->c_str(); |
418 break; | 459 break; |
419 case NPPVpluginDescriptionString: | 460 case NPPVpluginDescriptionString: |
420 VLOG(2) << "GetValue - description string"; | 461 VLOG(2) << "GetValue - description string"; |
421 *reinterpret_cast<const char**>(value) = HOST_PLUGIN_DESCRIPTION; | 462 *reinterpret_cast<const char**>(value) = g_ui_description->c_str(); |
422 break; | 463 break; |
423 case NPPVpluginNeedsXEmbed: | 464 case NPPVpluginNeedsXEmbed: |
424 VLOG(2) << "GetValue - NeedsXEmbed"; | 465 VLOG(2) << "GetValue - NeedsXEmbed"; |
425 *(static_cast<NPBool*>(value)) = true; | 466 *(static_cast<NPBool*>(value)) = true; |
426 break; | 467 break; |
427 case NPPVpluginScriptableNPObject: | 468 case NPPVpluginScriptableNPObject: |
428 VLOG(2) << "GetValue - scriptable object"; | 469 VLOG(2) << "GetValue - scriptable object"; |
429 HostNPPlugin* plugin = PluginFromInstance(instance); | 470 HostNPPlugin* plugin = PluginFromInstance(instance); |
430 if (!plugin) | 471 if (!plugin) |
431 return NPERR_INVALID_PLUGIN_ERROR; | 472 return NPERR_INVALID_PLUGIN_ERROR; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 524 |
484 return NPERR_NO_ERROR; | 525 return NPERR_NO_ERROR; |
485 } | 526 } |
486 | 527 |
487 EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnetscape_funcs | 528 EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* npnetscape_funcs |
488 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 529 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
489 , NPPluginFuncs* nppfuncs | 530 , NPPluginFuncs* nppfuncs |
490 #endif | 531 #endif |
491 ) { | 532 ) { |
492 VLOG(2) << "NP_Initialize"; | 533 VLOG(2) << "NP_Initialize"; |
493 if (g_at_exit_manager) | 534 InitializePlugin(); |
494 return NPERR_MODULE_LOAD_FAILED_ERROR; | |
495 | 535 |
496 if(npnetscape_funcs == NULL) | 536 if(npnetscape_funcs == NULL) |
497 return NPERR_INVALID_FUNCTABLE_ERROR; | 537 return NPERR_INVALID_FUNCTABLE_ERROR; |
498 | 538 |
499 if(((npnetscape_funcs->version & 0xff00) >> 8) > NP_VERSION_MAJOR) | 539 if(((npnetscape_funcs->version & 0xff00) >> 8) > NP_VERSION_MAJOR) |
500 return NPERR_INCOMPATIBLE_VERSION_ERROR; | 540 return NPERR_INCOMPATIBLE_VERSION_ERROR; |
501 | 541 |
502 g_at_exit_manager = new base::AtExitManager; | |
503 g_npnetscape_funcs = npnetscape_funcs; | 542 g_npnetscape_funcs = npnetscape_funcs; |
504 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 543 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
505 NP_GetEntryPoints(nppfuncs); | 544 NP_GetEntryPoints(nppfuncs); |
506 #endif | 545 #endif |
507 // Init an empty command line for common objects that use it. | |
508 CommandLine::Init(0, NULL); | |
509 | 546 |
510 #if defined(OS_WIN) | 547 #if defined(OS_WIN) |
511 ui::EnableHighDPISupport(); | 548 ui::EnableHighDPISupport(); |
512 #endif | 549 #endif |
513 | 550 |
514 return NPERR_NO_ERROR; | 551 return NPERR_NO_ERROR; |
515 } | 552 } |
516 | 553 |
517 EXPORT NPError API_CALL NP_Shutdown() { | 554 EXPORT NPError API_CALL NP_Shutdown() { |
518 VLOG(2) << "NP_Shutdown"; | 555 VLOG(2) << "NP_Shutdown"; |
519 delete g_at_exit_manager; | 556 ShutdownPlugin(); |
520 g_at_exit_manager = NULL; | 557 |
521 return NPERR_NO_ERROR; | 558 return NPERR_NO_ERROR; |
522 } | 559 } |
523 | 560 |
524 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 561 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
525 EXPORT const char* API_CALL NP_GetMIMEDescription(void) { | 562 EXPORT const char* API_CALL NP_GetMIMEDescription(void) { |
526 VLOG(2) << "NP_GetMIMEDescription"; | 563 VLOG(2) << "NP_GetMIMEDescription"; |
527 return HOST_PLUGIN_MIME_TYPE "::"; | 564 return STRINGIZE(HOST_PLUGIN_MIME_TYPE) "::"; |
528 } | 565 } |
529 | 566 |
530 EXPORT NPError API_CALL NP_GetValue(void* npp, | 567 EXPORT NPError API_CALL NP_GetValue(void* npp, |
531 NPPVariable variable, | 568 NPPVariable variable, |
532 void* value) { | 569 void* value) { |
533 return GetValue((NPP)npp, variable, value); | 570 return GetValue((NPP)npp, variable, value); |
534 } | 571 } |
535 #endif | 572 #endif |
536 | 573 |
537 } // extern "C" | 574 } // extern "C" |
OLD | NEW |