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

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

Powered by Google App Engine
This is Rietveld 408576698