OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 PPB_GetInterface get_interface = NULL; | 49 PPB_GetInterface get_interface = NULL; |
50 bool enable_dev_interfaces = false; | 50 bool enable_dev_interfaces = false; |
51 | 51 |
52 // Whether Pepper 3D interfaces should be enabled. | 52 // Whether Pepper 3D interfaces should be enabled. |
53 bool enable_3d_interfaces = true; | 53 bool enable_3d_interfaces = true; |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { | 57 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { |
58 // If there was no map, create one. | 58 // If there was no map, create one. |
59 if (instance_to_ppp_map == NULL) { | 59 if (NULL == instance_to_ppp_map) { |
60 instance_to_ppp_map = new std::map<PP_Instance, BrowserPpp*>; | 60 instance_to_ppp_map = new std::map<PP_Instance, BrowserPpp*>; |
61 } | 61 } |
62 // Add the instance to the map. | 62 // Add the instance to the map. |
63 (*instance_to_ppp_map)[instance] = browser_ppp; | 63 (*instance_to_ppp_map)[instance] = browser_ppp; |
64 } | 64 } |
65 | 65 |
66 void UnsetBrowserPppForInstance(PP_Instance instance) { | 66 void UnsetBrowserPppForInstance(PP_Instance instance) { |
67 if (instance_to_ppp_map == NULL) { | 67 if (NULL == instance_to_ppp_map) { |
68 // Something major is wrong here. We are deleting a map entry | 68 // Something major is wrong here. We are deleting a map entry |
69 // when there is no map. | 69 // when there is no map. |
70 NACL_NOTREACHED(); | 70 NACL_NOTREACHED(); |
71 return; | 71 return; |
72 } | 72 } |
73 // Erase the instance from the map. | 73 // Erase the instance from the map. |
74 instance_to_ppp_map->erase(instance); | 74 instance_to_ppp_map->erase(instance); |
75 // If there are no more instances alive, remove the map. | 75 // If there are no more instances alive, remove the map. |
76 if (instance_to_ppp_map->size() == 0) { | 76 if (instance_to_ppp_map->size() == 0) { |
77 delete instance_to_ppp_map; | 77 delete instance_to_ppp_map; |
78 instance_to_ppp_map = NULL; | 78 instance_to_ppp_map = NULL; |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 BrowserPpp* LookupBrowserPppForInstance(PP_Instance instance) { | 82 BrowserPpp* LookupBrowserPppForInstance(PP_Instance instance) { |
83 if (instance_to_ppp_map == NULL) { | 83 if (NULL == instance_to_ppp_map) { |
84 return NULL; | 84 return NULL; |
85 } | 85 } |
86 return (*instance_to_ppp_map)[instance]; | 86 return (*instance_to_ppp_map)[instance]; |
87 } | 87 } |
88 | 88 |
89 void SetModuleIdForSrpcChannel(NaClSrpcChannel* channel, PP_Module module_id) { | 89 void SetModuleIdForSrpcChannel(NaClSrpcChannel* channel, PP_Module module_id) { |
90 // If there was no map, create one. | 90 // If there was no map, create one. |
91 if (channel_to_module_id_map == NULL) { | 91 if (NULL == channel_to_module_id_map) { |
92 channel_to_module_id_map = new std::map<NaClSrpcChannel*, PP_Module>; | 92 channel_to_module_id_map = new std::map<NaClSrpcChannel*, PP_Module>; |
93 } | 93 } |
94 // Add the channel to the map. | 94 // Add the channel to the map. |
95 (*channel_to_module_id_map)[channel] = module_id; | 95 (*channel_to_module_id_map)[channel] = module_id; |
96 } | 96 } |
97 | 97 |
98 void SetInstanceIdForSrpcChannel(NaClSrpcChannel* channel, | 98 void SetInstanceIdForSrpcChannel(NaClSrpcChannel* channel, |
99 PP_Instance instance_id) { | 99 PP_Instance instance_id) { |
100 if (channel_to_instance_id_map == NULL) { | 100 if (NULL == channel_to_instance_id_map) { |
101 channel_to_instance_id_map = new std::map<NaClSrpcChannel*, PP_Instance>; | 101 channel_to_instance_id_map = new std::map<NaClSrpcChannel*, PP_Instance>; |
102 } | 102 } |
103 (*channel_to_instance_id_map)[channel] = instance_id; | 103 (*channel_to_instance_id_map)[channel] = instance_id; |
104 } | 104 } |
105 | 105 |
106 void UnsetModuleIdForSrpcChannel(NaClSrpcChannel* channel) { | 106 void UnsetModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
107 if (channel_to_module_id_map == NULL) { | 107 if (NULL == channel_to_module_id_map) { |
108 // Something major is wrong here. We are deleting a map entry | 108 // Something major is wrong here. We are deleting a map entry |
109 // when there is no map. | 109 // when there is no map. |
110 NACL_NOTREACHED(); | 110 NACL_NOTREACHED(); |
111 return; | 111 return; |
112 } | 112 } |
113 // Erase the channel from the map. | 113 // Erase the channel from the map. |
114 channel_to_module_id_map->erase(channel); | 114 channel_to_module_id_map->erase(channel); |
115 // If there are no more channels alive, remove the map. | 115 // If there are no more channels alive, remove the map. |
116 if (channel_to_module_id_map->size() == 0) { | 116 if (channel_to_module_id_map->size() == 0) { |
117 delete channel_to_module_id_map; | 117 delete channel_to_module_id_map; |
118 channel_to_module_id_map = NULL; | 118 channel_to_module_id_map = NULL; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void UnsetInstanceIdForSrpcChannel(NaClSrpcChannel* channel) { | 122 void UnsetInstanceIdForSrpcChannel(NaClSrpcChannel* channel) { |
123 if (channel_to_instance_id_map == NULL) { | 123 if (NULL == channel_to_instance_id_map) { |
124 NACL_NOTREACHED(); | 124 NACL_NOTREACHED(); |
125 return; | 125 return; |
126 } | 126 } |
127 channel_to_instance_id_map->erase(channel); | 127 channel_to_instance_id_map->erase(channel); |
128 if (channel_to_instance_id_map->size() == 0) { | 128 if (channel_to_instance_id_map->size() == 0) { |
129 delete channel_to_module_id_map; | 129 delete channel_to_module_id_map; |
130 channel_to_module_id_map = NULL; | 130 channel_to_module_id_map = NULL; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 PP_Module LookupModuleIdForSrpcChannel(NaClSrpcChannel* channel) { | 134 PP_Module LookupModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
135 if (channel_to_module_id_map == NULL) { | 135 if (NULL == channel_to_module_id_map) { |
136 return 0; | 136 return 0; |
137 } | 137 } |
138 return (*channel_to_module_id_map)[channel]; | 138 return (*channel_to_module_id_map)[channel]; |
139 } | 139 } |
140 | 140 |
141 PP_Module LookupInstanceIdForSrpcChannel(NaClSrpcChannel* channel) { | 141 PP_Module LookupInstanceIdForSrpcChannel(NaClSrpcChannel* channel) { |
142 if (channel_to_instance_id_map == NULL) { | 142 if (NULL == channel_to_instance_id_map) { |
143 return 0; | 143 return 0; |
144 } | 144 } |
145 return (*channel_to_instance_id_map)[channel]; | 145 return (*channel_to_instance_id_map)[channel]; |
146 } | 146 } |
147 | 147 |
148 NaClSrpcChannel* GetMainSrpcChannel(NaClSrpcRpc* upcall_rpc) { | 148 NaClSrpcChannel* GetMainSrpcChannel(NaClSrpcRpc* upcall_rpc) { |
149 // The upcall channel's server_instance_data member is initialized to point | 149 // The upcall channel's server_instance_data member is initialized to point |
150 // to the main channel for this instance. Here it is retrieved to use in | 150 // to the main channel for this instance. Here it is retrieved to use in |
151 // constructing a RemoteCallbackInfo. | 151 // constructing a RemoteCallbackInfo. |
152 return static_cast<NaClSrpcChannel*>( | 152 return static_cast<NaClSrpcChannel*>( |
153 upcall_rpc->channel->server_instance_data); | 153 upcall_rpc->channel->server_instance_data); |
154 } | 154 } |
155 | 155 |
156 NaClSrpcChannel* GetMainSrpcChannel(PP_Instance instance) { | 156 NaClSrpcChannel* GetMainSrpcChannel(PP_Instance instance) { |
157 return LookupBrowserPppForInstance(instance)->main_channel(); | 157 BrowserPpp* proxy = LookupBrowserPppForInstance(instance); |
| 158 if (NULL == proxy) |
| 159 return NULL; |
| 160 return proxy->main_channel(); |
158 } | 161 } |
159 | 162 |
160 void CleanUpAfterDeadNexe(PP_Instance instance) { | 163 void CleanUpAfterDeadNexe(PP_Instance instance) { |
161 DebugPrintf("CleanUpAfterDeadNexe\n"); | 164 DebugPrintf("CleanUpAfterDeadNexe\n"); |
162 BrowserPpp* proxy = LookupBrowserPppForInstance(instance); | 165 BrowserPpp* proxy = LookupBrowserPppForInstance(instance); |
163 if (proxy == NULL) | 166 if (NULL == proxy) |
164 return; | 167 return; |
165 proxy->plugin()->ReportDeadNexe(); // Shuts down and deletes the proxy. | 168 proxy->plugin()->ReportDeadNexe(); // Shuts down and deletes the proxy. |
166 } | 169 } |
167 | 170 |
168 void SetPPBGetInterface(PPB_GetInterface get_interface_function, | 171 void SetPPBGetInterface(PPB_GetInterface get_interface_function, |
169 bool allow_dev_interfaces, | 172 bool allow_dev_interfaces, |
170 bool allow_3d_interfaces) { | 173 bool allow_3d_interfaces) { |
171 get_interface = get_interface_function; | 174 get_interface = get_interface_function; |
172 enable_dev_interfaces = allow_dev_interfaces; | 175 enable_dev_interfaces = allow_dev_interfaces; |
173 enable_3d_interfaces = allow_3d_interfaces; | 176 enable_3d_interfaces = allow_3d_interfaces; |
(...skipping 26 matching lines...) Expand all Loading... |
200 for (size_t i = 0; i < NACL_ARRAY_SIZE(disabled_interface_names); i++) { | 203 for (size_t i = 0; i < NACL_ARRAY_SIZE(disabled_interface_names); i++) { |
201 if (strcmp(interface_name, disabled_interface_names[i]) == 0) | 204 if (strcmp(interface_name, disabled_interface_names[i]) == 0) |
202 return NULL; | 205 return NULL; |
203 } | 206 } |
204 } | 207 } |
205 return (*get_interface)(interface_name); | 208 return (*get_interface)(interface_name); |
206 } | 209 } |
207 | 210 |
208 const void* GetBrowserInterfaceSafe(const char* interface_name) { | 211 const void* GetBrowserInterfaceSafe(const char* interface_name) { |
209 const void* ppb_interface = GetBrowserInterface(interface_name); | 212 const void* ppb_interface = GetBrowserInterface(interface_name); |
210 if (ppb_interface == NULL) | 213 if (NULL == ppb_interface) |
211 DebugPrintf("PPB_GetInterface: %s not found\n", interface_name); | 214 DebugPrintf("PPB_GetInterface: %s not found\n", interface_name); |
212 CHECK(ppb_interface != NULL); | 215 CHECK(NULL != ppb_interface); |
213 return ppb_interface; | 216 return ppb_interface; |
214 } | 217 } |
215 | 218 |
216 const PPB_Core* PPBCoreInterface() { | 219 const PPB_Core* PPBCoreInterface() { |
217 static const PPB_Core* ppb = static_cast<const PPB_Core*>( | 220 static const PPB_Core* ppb = static_cast<const PPB_Core*>( |
218 GetBrowserInterfaceSafe(PPB_CORE_INTERFACE)); | 221 GetBrowserInterfaceSafe(PPB_CORE_INTERFACE)); |
219 return ppb; | 222 return ppb; |
220 } | 223 } |
221 | 224 |
222 const PPB_Graphics2D* PPBGraphics2DInterface() { | 225 const PPB_Graphics2D* PPBGraphics2DInterface() { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 477 } |
475 | 478 |
476 const PPB_UDPSocket_Private* PPBUDPSocketPrivateInterface() { | 479 const PPB_UDPSocket_Private* PPBUDPSocketPrivateInterface() { |
477 static const PPB_UDPSocket_Private* ppb = | 480 static const PPB_UDPSocket_Private* ppb = |
478 static_cast<const PPB_UDPSocket_Private*>( | 481 static_cast<const PPB_UDPSocket_Private*>( |
479 GetBrowserInterfaceSafe(PPB_UDPSOCKET_PRIVATE_INTERFACE)); | 482 GetBrowserInterfaceSafe(PPB_UDPSOCKET_PRIVATE_INTERFACE)); |
480 return ppb; | 483 return ppb; |
481 } | 484 } |
482 | 485 |
483 } // namespace ppapi_proxy | 486 } // namespace ppapi_proxy |
OLD | NEW |