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/platform/nacl_secure_random.h" |
| 11 #include "native_client/src/shared/platform/nacl_time.h" |
| 12 #include "native_client/src/trusted/desc/nrd_all_modules.h" |
10 | 13 |
11 namespace plugin { | 14 namespace plugin { |
12 | 15 |
13 ModulePpapi::ModulePpapi() : pp::Module(), | 16 ModulePpapi::ModulePpapi() : pp::Module(), |
| 17 init_was_successful_(false), |
14 private_interface_(NULL) { | 18 private_interface_(NULL) { |
15 } | 19 } |
16 | 20 |
17 ModulePpapi::~ModulePpapi() { | 21 ModulePpapi::~ModulePpapi() { |
| 22 if (init_was_successful_) { |
| 23 NaClNrdAllModulesFini(); |
| 24 } |
18 } | 25 } |
19 | 26 |
20 bool ModulePpapi::Init() { | 27 bool ModulePpapi::Init() { |
21 // Ask the browser for an interface which provides missing functions | 28 // Ask the browser for an interface which provides missing functions |
22 private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>( | 29 private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>( |
23 GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); | 30 GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); |
24 | 31 |
25 if (NULL == private_interface_) { | 32 if (NULL == private_interface_) { |
26 return false; | 33 return false; |
27 } | 34 } |
28 SetNaClInterface(private_interface_); | 35 SetNaClInterface(private_interface_); |
29 | 36 |
| 37 #if NACL_LINUX || NACL_OSX |
| 38 // Note that currently we do not need random numbers inside the |
| 39 // NaCl trusted plugin on Unix, but NaClSecureRngModuleInit() is |
| 40 // strict and will raise a fatal error unless we provide it with a |
| 41 // /dev/urandom FD beforehand. |
| 42 NaClSecureRngModuleSetUrandomFd(dup(private_interface_->UrandomFD())); |
| 43 #endif |
| 44 |
| 45 // In the plugin, we don't need high resolution time of day. |
| 46 NaClAllowLowResolutionTimeOfDay(); |
| 47 NaClNrdAllModulesInit(); |
| 48 |
| 49 init_was_successful_ = true; |
30 return true; | 50 return true; |
31 } | 51 } |
32 | 52 |
33 pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) { | 53 pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) { |
34 return new Plugin(pp_instance); | 54 return new Plugin(pp_instance); |
35 } | 55 } |
36 | 56 |
37 } // namespace plugin | 57 } // namespace plugin |
38 | 58 |
39 | 59 |
40 namespace pp { | 60 namespace pp { |
41 | 61 |
42 Module* CreateModule() { | 62 Module* CreateModule() { |
43 return new plugin::ModulePpapi(); | 63 return new plugin::ModulePpapi(); |
44 } | 64 } |
45 | 65 |
46 } // namespace pp | 66 } // namespace pp |
OLD | NEW |