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