OLD | NEW |
1 // Copyright (c) 2010 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2010 The Native Client 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 "native_client/src/shared/ppapi_proxy/browser_ppp.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "native_client/src/include/nacl_scoped_ptr.h" | 9 #include "native_client/src/include/nacl_scoped_ptr.h" |
10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace ppapi_proxy { | 22 namespace ppapi_proxy { |
23 | 23 |
24 // | 24 // |
25 // The following methods are the SRPC dispatchers for ppapi/c/ppp.h. | 25 // The following methods are the SRPC dispatchers for ppapi/c/ppp.h. |
26 // | 26 // |
27 | 27 |
28 int32_t BrowserPpp::InitializeModule( | 28 int32_t BrowserPpp::InitializeModule( |
29 PP_Module module_id, | 29 PP_Module module_id, |
30 PPB_GetInterface get_browser_interface, | 30 PPB_GetInterface get_browser_interface, |
31 PP_Instance instance) { | 31 PP_Instance instance) { |
32 DebugPrintf("BrowserPpp::InitializeModule(%"NACL_PRIu64", %p)\n", | 32 DebugPrintf("Browser::PPP_InitializeModule(%"NACL_PRIu64", %p)\n", |
33 module_id, get_browser_interface); | 33 module_id, get_browser_interface); |
34 SetBrowserGetInterface(get_browser_interface); | 34 SetBrowserGetInterface(get_browser_interface); |
35 SetBrowserPppForInstance(instance, this); | 35 SetBrowserPppForInstance(instance, this); |
36 nacl::scoped_ptr<nacl::DescWrapper> wrapper( | 36 nacl::scoped_ptr<nacl::DescWrapper> wrapper( |
37 BrowserUpcall::Start(&upcall_thread_, channel_)); | 37 BrowserUpcall::Start(&upcall_thread_, channel_)); |
38 if (wrapper.get() == NULL) { | 38 if (wrapper.get() == NULL) { |
39 return PP_ERROR_FAILED; | 39 return PP_ERROR_FAILED; |
40 } | 40 } |
41 // Set up the callbacks allowed on the main channel. | 41 // Set up the callbacks allowed on the main channel. |
42 NaClSrpcService* service = reinterpret_cast<NaClSrpcService*>( | 42 NaClSrpcService* service = reinterpret_cast<NaClSrpcService*>( |
43 calloc(1, sizeof(*service))); | 43 calloc(1, sizeof(*service))); |
44 if (NULL == service) { | 44 if (NULL == service) { |
45 DebugPrintf("Couldn't create callback services.\n"); | 45 DebugPrintf("Browser::PPP_InitializeModule: " |
| 46 "could not create callback services.\n"); |
46 return PP_ERROR_FAILED; | 47 return PP_ERROR_FAILED; |
47 } | 48 } |
48 if (!NaClSrpcServiceHandlerCtor(service, PpbRpcs::srpc_methods)) { | 49 if (!NaClSrpcServiceHandlerCtor(service, PpbRpcs::srpc_methods)) { |
49 DebugPrintf("Couldn't construct callback services.\n"); | 50 DebugPrintf("Browser::PPP_InitializeModule: " |
| 51 "could not construct callback services.\n"); |
50 free(service); | 52 free(service); |
51 return PP_ERROR_FAILED; | 53 return PP_ERROR_FAILED; |
52 } | 54 } |
53 // Export the service on the channel. | 55 // Export the service on the channel. |
54 channel_->server = service; | 56 channel_->server = service; |
55 char* service_string = const_cast<char*>(service->service_string); | 57 char* service_string = const_cast<char*>(service->service_string); |
56 SetModuleIdForSrpcChannel(channel_, module_id); | 58 SetModuleIdForSrpcChannel(channel_, module_id); |
57 // Do the RPC. | 59 // Do the RPC. |
58 int32_t browser_pid = static_cast<int32_t>(GETPID()); | 60 int32_t browser_pid = static_cast<int32_t>(GETPID()); |
59 int32_t success; | 61 int32_t success; |
60 NaClSrpcError retval = | 62 NaClSrpcError retval = |
61 PppRpcClient::PPP_InitializeModule(channel_, | 63 PppRpcClient::PPP_InitializeModule(channel_, |
62 browser_pid, | 64 browser_pid, |
63 module_id, | 65 module_id, |
64 wrapper->desc(), | 66 wrapper->desc(), |
65 service_string, | 67 service_string, |
66 &plugin_pid_, | 68 &plugin_pid_, |
67 &success); | 69 &success); |
68 if (retval != NACL_SRPC_RESULT_OK) { | 70 if (retval != NACL_SRPC_RESULT_OK) { |
69 DebugPrintf("InitializeModule failed %02x\n", retval); | 71 DebugPrintf("Browser::PPP_InitializeModule failed %02x\n", retval); |
70 return PP_ERROR_FAILED; | 72 return PP_ERROR_FAILED; |
71 } | 73 } |
72 DebugPrintf("InitializeModule succeeded %02x\n", success); | 74 DebugPrintf("Browser::PPP_InitializeModule succeeded %02x\n", success); |
73 return success; | 75 return success; |
74 } | 76 } |
75 | 77 |
76 void BrowserPpp::ShutdownModule() { | 78 void BrowserPpp::ShutdownModule() { |
77 DebugPrintf("BrowserPpp::ShutdownModule\n"); | 79 DebugPrintf("Browser::PPP_ShutdownModule\n"); |
78 PppRpcClient::PPP_ShutdownModule(channel_); | 80 PppRpcClient::PPP_ShutdownModule(channel_); |
79 NaClThreadJoin(&upcall_thread_); | 81 NaClThreadJoin(&upcall_thread_); |
80 UnsetModuleIdForSrpcChannel(channel_); | 82 UnsetModuleIdForSrpcChannel(channel_); |
81 } | 83 } |
82 | 84 |
83 const void* BrowserPpp::GetInterface(const char* interface_name) { | 85 const void* BrowserPpp::GetInterface(const char* interface_name) { |
84 DebugPrintf("BrowserPpp::GetInterface('%s')\n", interface_name); | 86 DebugPrintf("Browser::PPP_GetInterface('%s')\n", interface_name); |
85 int32_t exports_interface_name; | 87 int32_t exports_interface_name; |
86 NaClSrpcError retval = | 88 NaClSrpcError retval = |
87 PppRpcClient::PPP_GetInterface(channel_, | 89 PppRpcClient::PPP_GetInterface(channel_, |
88 const_cast<char*>(interface_name), | 90 const_cast<char*>(interface_name), |
89 &exports_interface_name); | 91 &exports_interface_name); |
90 if (retval != NACL_SRPC_RESULT_OK || !exports_interface_name) { | 92 if (retval != NACL_SRPC_RESULT_OK || !exports_interface_name) { |
91 DebugPrintf(" Interface '%s' not supported\n", interface_name); | 93 DebugPrintf("Browser::PPP_GetInterface: '%s' not found\n", interface_name); |
92 return NULL; | 94 return NULL; |
93 } | 95 } |
94 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) { | 96 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) { |
95 DebugPrintf(" Interface '%s' proxied\n", interface_name); | 97 DebugPrintf("Browser::PPP_GetInterface: '%s' proxied\n", interface_name); |
96 return reinterpret_cast<const void*>(BrowserInstance::GetInterface()); | 98 return reinterpret_cast<const void*>(BrowserInstance::GetInterface()); |
97 } | 99 } |
98 // TODO(sehr): other interfaces go here. | 100 // TODO(sehr): other interfaces go here. |
99 return NULL; | 101 return NULL; |
100 } | 102 } |
101 | 103 |
102 } // namespace ppapi_proxy | 104 } // namespace ppapi_proxy |
OLD | NEW |