OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 13 #include "base/logging.h" |
14 #include "base/stringize_macros.h" | 14 #include "base/stringize_macros.h" |
15 #include "remoting/base/plugin_message_loop_proxy.h" | 15 #include "remoting/base/plugin_message_loop_proxy.h" |
| 16 #include "remoting/host/plugin/host_log_handler.h" |
16 #include "remoting/host/plugin/host_plugin_utils.h" | 17 #include "remoting/host/plugin/host_plugin_utils.h" |
17 #include "remoting/host/plugin/host_script_object.h" | 18 #include "remoting/host/plugin/host_script_object.h" |
18 #include "third_party/npapi/bindings/npapi.h" | 19 #include "third_party/npapi/bindings/npapi.h" |
19 #include "third_party/npapi/bindings/npfunctions.h" | 20 #include "third_party/npapi/bindings/npfunctions.h" |
20 #include "third_party/npapi/bindings/npruntime.h" | 21 #include "third_party/npapi/bindings/npruntime.h" |
21 | 22 |
22 // Symbol export is handled with a separate def file on Windows. | 23 // Symbol export is handled with a separate def file on Windows. |
23 #if defined (__GNUC__) && __GNUC__ >= 4 | 24 #if defined (__GNUC__) && __GNUC__ >= 4 |
24 #define EXPORT __attribute__((visibility("default"))) | 25 #define EXPORT __attribute__((visibility("default"))) |
25 #else | 26 #else |
(...skipping 10 matching lines...) Expand all Loading... |
36 return a / b; | 37 return a / b; |
37 } | 38 } |
38 uint64_t __cdecl __udivdi3(uint64_t a, uint64_t b) { | 39 uint64_t __cdecl __udivdi3(uint64_t a, uint64_t b) { |
39 return a / b; | 40 return a / b; |
40 } | 41 } |
41 | 42 |
42 } | 43 } |
43 #endif | 44 #endif |
44 | 45 |
45 using remoting::g_npnetscape_funcs; | 46 using remoting::g_npnetscape_funcs; |
| 47 using remoting::HostLogHandler; |
46 using remoting::HostNPScriptObject; | 48 using remoting::HostNPScriptObject; |
47 using remoting::StringFromNPIdentifier; | 49 using remoting::StringFromNPIdentifier; |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 base::AtExitManager* g_at_exit_manager = NULL; | 53 base::AtExitManager* g_at_exit_manager = NULL; |
52 | 54 |
53 // The name and description are returned by GetValue, but are also | 55 // The name and description are returned by GetValue, but are also |
54 // combined with the MIME type to satisfy GetMIMEDescription, so we | 56 // combined with the MIME type to satisfy GetMIMEDescription, so we |
55 // use macros here to allow that to happen at compile-time. | 57 // use macros here to allow that to happen at compile-time. |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 347 } |
346 | 348 |
347 NPError CreatePlugin(NPMIMEType pluginType, | 349 NPError CreatePlugin(NPMIMEType pluginType, |
348 NPP instance, | 350 NPP instance, |
349 uint16 mode, | 351 uint16 mode, |
350 int16 argc, | 352 int16 argc, |
351 char** argn, | 353 char** argn, |
352 char** argv, | 354 char** argv, |
353 NPSavedData* saved) { | 355 NPSavedData* saved) { |
354 VLOG(2) << "CreatePlugin"; | 356 VLOG(2) << "CreatePlugin"; |
| 357 |
| 358 // Register a global log handler. |
| 359 // The LogMessage registration code is not thread-safe, so we need to perform |
| 360 // this while we're running in a single thread. |
| 361 HostLogHandler::RegisterLogMessageHandler(); |
| 362 |
355 HostNPPlugin* plugin = new HostNPPlugin(instance, mode); | 363 HostNPPlugin* plugin = new HostNPPlugin(instance, mode); |
356 instance->pdata = plugin; | 364 instance->pdata = plugin; |
357 if (!plugin->Init(argc, argn, argv, saved)) { | 365 if (!plugin->Init(argc, argn, argv, saved)) { |
358 delete plugin; | 366 delete plugin; |
359 instance->pdata = NULL; | 367 instance->pdata = NULL; |
360 return NPERR_INVALID_PLUGIN_ERROR; | 368 return NPERR_INVALID_PLUGIN_ERROR; |
361 } else { | 369 } else { |
362 return NPERR_NO_ERROR; | 370 return NPERR_NO_ERROR; |
363 } | 371 } |
364 } | 372 } |
365 | 373 |
366 NPError DestroyPlugin(NPP instance, | 374 NPError DestroyPlugin(NPP instance, |
367 NPSavedData** save) { | 375 NPSavedData** save) { |
368 VLOG(2) << "DestroyPlugin"; | 376 VLOG(2) << "DestroyPlugin"; |
| 377 |
| 378 // Normally, we would unregister the global log handler that we registered |
| 379 // in CreatePlugin. However, the LogHandler registration code is not thread- |
| 380 // safe so we could crash if we update (register or unregister) the |
| 381 // LogHandler while it's being read on another thread. |
| 382 // At this point, all our threads should be shutdown, but it's safer to leave |
| 383 // the handler registered until we're completely destroyed. |
| 384 |
369 HostNPPlugin* plugin = PluginFromInstance(instance); | 385 HostNPPlugin* plugin = PluginFromInstance(instance); |
370 if (plugin) { | 386 if (plugin) { |
371 plugin->Save(save); | 387 plugin->Save(save); |
372 delete plugin; | 388 delete plugin; |
373 instance->pdata = NULL; | 389 instance->pdata = NULL; |
374 return NPERR_NO_ERROR; | 390 return NPERR_NO_ERROR; |
375 } else { | 391 } else { |
376 return NPERR_INVALID_PLUGIN_ERROR; | 392 return NPERR_INVALID_PLUGIN_ERROR; |
377 } | 393 } |
378 } | 394 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 508 } |
493 | 509 |
494 EXPORT NPError API_CALL NP_GetValue(void* npp, | 510 EXPORT NPError API_CALL NP_GetValue(void* npp, |
495 NPPVariable variable, | 511 NPPVariable variable, |
496 void* value) { | 512 void* value) { |
497 return GetValue((NPP)npp, variable, value); | 513 return GetValue((NPP)npp, variable, value); |
498 } | 514 } |
499 #endif | 515 #endif |
500 | 516 |
501 } // extern "C" | 517 } // extern "C" |
OLD | NEW |