| 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 // Instances of NaCl modules spun up within the plugin as a subprocess. | 5 // Instances of NaCl modules spun up within the plugin as a subprocess. |
| 6 // This may represent the "main" nacl module, or it may represent helpers | 6 // This may represent the "main" nacl module, or it may represent helpers |
| 7 // that perform various tasks within the plugin, for example, | 7 // that perform various tasks within the plugin, for example, |
| 8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode | 8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode |
| 9 // into native code. | 9 // into native code. |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class BrowserInterface; | 25 class BrowserInterface; |
| 26 class Plugin; | 26 class Plugin; |
| 27 class ServiceRuntime; | 27 class ServiceRuntime; |
| 28 class SrpcParams; | 28 class SrpcParams; |
| 29 | 29 |
| 30 | 30 |
| 31 // A class representing an instance of a NaCl module, loaded by the plugin. | 31 // A class representing an instance of a NaCl module, loaded by the plugin. |
| 32 class NaClSubprocess { | 32 class NaClSubprocess { |
| 33 public: | 33 public: |
| 34 NaClSubprocess(const nacl::string& description, | 34 NaClSubprocess(const nacl::string& description, |
| 35 BrowserInterface* browser_interface, | |
| 36 ServiceRuntime* service_runtime, | 35 ServiceRuntime* service_runtime, |
| 37 SrpcClient* srpc_client) | 36 SrpcClient* srpc_client) |
| 38 : description_(description), | 37 : description_(description), |
| 39 browser_interface_(browser_interface), | |
| 40 service_runtime_(service_runtime), | 38 service_runtime_(service_runtime), |
| 41 srpc_client_(srpc_client) { | 39 srpc_client_(srpc_client) { |
| 42 } | 40 } |
| 43 virtual ~NaClSubprocess(); | 41 virtual ~NaClSubprocess(); |
| 44 | 42 |
| 45 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } | 43 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } |
| 46 void set_service_runtime(ServiceRuntime* service_runtime) { | 44 void set_service_runtime(ServiceRuntime* service_runtime) { |
| 47 service_runtime_.reset(service_runtime); | 45 service_runtime_.reset(service_runtime); |
| 48 } | 46 } |
| 49 | 47 |
| 50 // The socket used for communicating w/ the NaCl module. | 48 // The socket used for communicating w/ the NaCl module. |
| 51 SrpcClient* srpc_client() const { return srpc_client_.get(); } | 49 SrpcClient* srpc_client() const { return srpc_client_.get(); } |
| 52 void set_socket(SrpcClient* srpc_client) { srpc_client_.reset(srpc_client); } | |
| 53 | 50 |
| 54 // A basic description of the subprocess. | 51 // A basic description of the subprocess. |
| 55 nacl::string description() const; | 52 nacl::string description() const { return description_; } |
| 56 | 53 |
| 57 // A detailed description of the subprocess that may contain addresses. | 54 // A detailed description of the subprocess that may contain addresses. |
| 58 // Only use for debugging, but do not expose this to untrusted webapps. | 55 // Only use for debugging, but do not expose this to untrusted webapps. |
| 59 nacl::string detailed_description() const; | 56 nacl::string detailed_description() const; |
| 60 | 57 |
| 61 // Start up interfaces. | 58 // Start up interfaces. |
| 62 bool StartSrpcServices(); | 59 bool StartSrpcServices(); |
| 63 bool StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info); | 60 bool StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info); |
| 64 | 61 |
| 65 // Interact. | |
| 66 bool HasMethod(uintptr_t method_id) const; | |
| 67 bool InitParams(uintptr_t method_id, SrpcParams* params) const; | |
| 68 bool Invoke(uintptr_t method_id, SrpcParams* params) const; | |
| 69 | |
| 70 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up | 62 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up |
| 71 // outside of this function, but it will be initialized by this function, and | 63 // outside of this function, but it will be initialized by this function, and |
| 72 // on success any out-params (if any) will be placed in |out_params|. | 64 // on success any out-params (if any) will be placed in |out_params|. |
| 73 // Input types must be listed in |input_signature|, with the actual | 65 // Input types must be listed in |input_signature|, with the actual |
| 74 // arguments passed in as var-args. Returns |true| on success. | 66 // arguments passed in as var-args. Returns |true| on success. |
| 75 bool InvokeSrpcMethod(const nacl::string& method_name, | 67 bool InvokeSrpcMethod(const nacl::string& method_name, |
| 76 const nacl::string& input_signature, | 68 const nacl::string& input_signature, |
| 77 SrpcParams* out_params, | 69 SrpcParams* out_params, |
| 78 ...); | 70 ...); |
| 79 | 71 |
| 80 // Fully shut down the subprocess. | 72 // Fully shut down the subprocess. |
| 81 void Shutdown(); | 73 void Shutdown(); |
| 82 | 74 |
| 83 private: | 75 private: |
| 84 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); | 76 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); |
| 85 | 77 |
| 86 bool SetupSrpcInvocation(const nacl::string& method_name, | |
| 87 SrpcParams* params, | |
| 88 uintptr_t* kMethodIdent); | |
| 89 | |
| 90 bool VInvokeSrpcMethod(const nacl::string& method_name, | 78 bool VInvokeSrpcMethod(const nacl::string& method_name, |
| 91 const nacl::string& signature, | 79 const nacl::string& signature, |
| 92 SrpcParams* params, | 80 SrpcParams* params, |
| 93 va_list vl); | 81 va_list vl); |
| 94 | 82 |
| 95 nacl::string description_; | 83 nacl::string description_; |
| 96 | 84 |
| 97 BrowserInterface* browser_interface_; | |
| 98 // The service runtime representing the NaCl module instance. | 85 // The service runtime representing the NaCl module instance. |
| 99 nacl::scoped_ptr<ServiceRuntime> service_runtime_; | 86 nacl::scoped_ptr<ServiceRuntime> service_runtime_; |
| 100 // Ownership of srpc_client taken from the service runtime. | 87 // Ownership of srpc_client taken from the service runtime. |
| 101 nacl::scoped_ptr<SrpcClient> srpc_client_; | 88 nacl::scoped_ptr<SrpcClient> srpc_client_; |
| 102 }; | 89 }; |
| 103 | 90 |
| 104 } // namespace plugin | 91 } // namespace plugin |
| 105 | 92 |
| 106 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ | 93 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ |
| OLD | NEW |