OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "components/nacl/renderer/plugin/module_ppapi.h" | 7 #include "components/nacl/renderer/plugin/module_ppapi.h" |
8 #include "components/nacl/renderer/plugin/plugin.h" | 8 #include "components/nacl/renderer/plugin/plugin.h" |
9 #include "components/nacl/renderer/plugin/utility.h" | 9 #include "components/nacl/renderer/plugin/utility.h" |
10 #include "native_client/src/shared/imc/nacl_imc_c.h" | 10 #include "native_client/src/shared/imc/nacl_imc_c.h" |
11 #include "native_client/src/shared/platform/nacl_secure_random.h" | 11 #include "native_client/src/shared/platform/nacl_secure_random.h" |
12 #include "native_client/src/shared/platform/nacl_time.h" | 12 #include "native_client/src/shared/platform/nacl_time.h" |
13 #include "native_client/src/trusted/desc/nrd_all_modules.h" | 13 #include "native_client/src/trusted/desc/nrd_all_modules.h" |
14 | 14 |
15 namespace plugin { | 15 namespace plugin { |
16 | 16 |
17 ModulePpapi::ModulePpapi() : pp::Module(), | 17 ModulePpapi::ModulePpapi() : pp::Module(), |
18 init_was_successful_(false), | 18 init_was_successful_(false), |
19 private_interface_(NULL) { | 19 private_interface_(NULL) { |
20 MODULE_PRINTF(("ModulePpapi::ModulePpapi (this=%p)\n", | 20 MODULE_PRINTF(("ModulePpapi::ModulePpapi (this=%p)\n", |
21 static_cast<void*>(this))); | 21 static_cast<void*>(this))); |
22 } | 22 } |
23 | 23 |
24 ModulePpapi::~ModulePpapi() { | 24 ModulePpapi::~ModulePpapi() { |
25 if (init_was_successful_) { | 25 if (init_was_successful_) { |
26 NaClSrpcModuleFini(); | |
27 NaClNrdAllModulesFini(); | 26 NaClNrdAllModulesFini(); |
28 } | 27 } |
29 MODULE_PRINTF(("ModulePpapi::~ModulePpapi (this=%p)\n", | 28 MODULE_PRINTF(("ModulePpapi::~ModulePpapi (this=%p)\n", |
30 static_cast<void*>(this))); | 29 static_cast<void*>(this))); |
31 } | 30 } |
32 | 31 |
33 bool ModulePpapi::Init() { | 32 bool ModulePpapi::Init() { |
34 // Ask the browser for an interface which provides missing functions | 33 // Ask the browser for an interface which provides missing functions |
35 private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>( | 34 private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>( |
36 GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); | 35 GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); |
37 | 36 |
38 if (NULL == private_interface_) { | 37 if (NULL == private_interface_) { |
39 MODULE_PRINTF(("ModulePpapi::Init failed: " | 38 MODULE_PRINTF(("ModulePpapi::Init failed: " |
40 "GetBrowserInterface returned NULL\n")); | 39 "GetBrowserInterface returned NULL\n")); |
41 return false; | 40 return false; |
42 } | 41 } |
43 SetNaClInterface(private_interface_); | 42 SetNaClInterface(private_interface_); |
44 | 43 |
45 #if NACL_LINUX || NACL_OSX | 44 #if NACL_LINUX || NACL_OSX |
46 // Note that currently we do not need random numbers inside the | 45 // Note that currently we do not need random numbers inside the |
47 // NaCl trusted plugin on Unix, but NaClSecureRngModuleInit() is | 46 // NaCl trusted plugin on Unix, but NaClSecureRngModuleInit() is |
48 // strict and will raise a fatal error unless we provide it with a | 47 // strict and will raise a fatal error unless we provide it with a |
49 // /dev/urandom FD beforehand. | 48 // /dev/urandom FD beforehand. |
50 NaClSecureRngModuleSetUrandomFd(dup(private_interface_->UrandomFD())); | 49 NaClSecureRngModuleSetUrandomFd(dup(private_interface_->UrandomFD())); |
51 #endif | 50 #endif |
52 | 51 |
53 // In the plugin, we don't need high resolution time of day. | 52 // In the plugin, we don't need high resolution time of day. |
54 NaClAllowLowResolutionTimeOfDay(); | 53 NaClAllowLowResolutionTimeOfDay(); |
55 NaClNrdAllModulesInit(); | 54 NaClNrdAllModulesInit(); |
56 NaClSrpcModuleInit(); | |
57 | 55 |
58 #if NACL_WINDOWS | 56 #if NACL_WINDOWS |
59 NaClSetBrokerDuplicateHandleFunc(private_interface_->BrokerDuplicateHandle); | 57 NaClSetBrokerDuplicateHandleFunc(private_interface_->BrokerDuplicateHandle); |
60 #endif | 58 #endif |
61 | 59 |
62 init_was_successful_ = true; | 60 init_was_successful_ = true; |
63 return true; | 61 return true; |
64 } | 62 } |
65 | 63 |
66 pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) { | 64 pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) { |
(...skipping 10 matching lines...) Expand all Loading... |
77 | 75 |
78 | 76 |
79 namespace pp { | 77 namespace pp { |
80 | 78 |
81 Module* CreateModule() { | 79 Module* CreateModule() { |
82 MODULE_PRINTF(("CreateModule ()\n")); | 80 MODULE_PRINTF(("CreateModule ()\n")); |
83 return new plugin::ModulePpapi(); | 81 return new plugin::ModulePpapi(); |
84 } | 82 } |
85 | 83 |
86 } // namespace pp | 84 } // namespace pp |
OLD | NEW |