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_globals.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" |
6 #include <map> | 6 #include <map> |
7 | 7 |
8 namespace ppapi_proxy { | 8 namespace ppapi_proxy { |
9 | 9 |
10 // All of these methods are called from the browser main (UI, JavaScript, ...) | 10 // All of these methods are called from the browser main (UI, JavaScript, ...) |
11 // thread. | 11 // thread. |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 std::map<PP_Instance, BrowserPpp*>* instance_to_ppp_map = NULL; | 15 std::map<PP_Instance, BrowserPpp*>* instance_to_ppp_map = NULL; |
| 16 std::map<NaClSrpcChannel*, PP_Module>* channel_to_module_id_map = NULL; |
| 17 |
16 // The GetInterface pointer from the browser. | 18 // The GetInterface pointer from the browser. |
17 PPB_GetInterface get_interface; | 19 PPB_GetInterface get_interface; |
18 // For efficiency, cached results from GetInterface. | 20 // For efficiency, cached results from GetInterface. |
19 const PPB_Core* core_interface; | 21 const PPB_Core* core_interface; |
20 const PPB_Var* var_interface; | 22 const PPB_Var* var_interface; |
21 | 23 |
22 } // namespace | 24 } // namespace |
23 | 25 |
24 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { | 26 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { |
25 // If there was no map, create one. | 27 // If there was no map, create one. |
(...skipping 20 matching lines...) Expand all Loading... |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 BrowserPpp* LookupBrowserPppForInstance(PP_Instance instance) { | 51 BrowserPpp* LookupBrowserPppForInstance(PP_Instance instance) { |
50 if (instance_to_ppp_map == NULL) { | 52 if (instance_to_ppp_map == NULL) { |
51 return NULL; | 53 return NULL; |
52 } | 54 } |
53 return (*instance_to_ppp_map)[instance]; | 55 return (*instance_to_ppp_map)[instance]; |
54 } | 56 } |
55 | 57 |
| 58 void SetModuleIdForSrpcChannel(NaClSrpcChannel* channel, PP_Module module_id) { |
| 59 // If there was no map, create one. |
| 60 if (channel_to_module_id_map == NULL) { |
| 61 channel_to_module_id_map = new std::map<NaClSrpcChannel*, PP_Module>; |
| 62 } |
| 63 // Add the channel to the map. |
| 64 (*channel_to_module_id_map)[channel] = module_id; |
| 65 } |
| 66 |
| 67 void UnsetModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
| 68 if (channel_to_module_id_map == NULL) { |
| 69 // Something major is wrong here. We are deleting a map entry |
| 70 // when there is no map. |
| 71 // TODO(sehr): a CHECK here would be appropriate if we had one in NaCl. |
| 72 return; |
| 73 } |
| 74 // Erase the channel from the map. |
| 75 channel_to_module_id_map->erase(channel); |
| 76 // If there are no more channels alive, remove the map. |
| 77 if (channel_to_module_id_map->size() == 0) { |
| 78 delete channel_to_module_id_map; |
| 79 channel_to_module_id_map = NULL; |
| 80 } |
| 81 } |
| 82 |
| 83 PP_Module LookupModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
| 84 if (channel_to_module_id_map == NULL) { |
| 85 return NULL; |
| 86 } |
| 87 return (*channel_to_module_id_map)[channel]; |
| 88 } |
| 89 |
56 void SetBrowserGetInterface(PPB_GetInterface get_interface_function) { | 90 void SetBrowserGetInterface(PPB_GetInterface get_interface_function) { |
57 get_interface = get_interface_function; | 91 get_interface = get_interface_function; |
58 const void* core = (*get_interface_function)(PPB_CORE_INTERFACE); | 92 const void* core = (*get_interface_function)(PPB_CORE_INTERFACE); |
59 core_interface = reinterpret_cast<const PPB_Core*>(core); | 93 core_interface = reinterpret_cast<const PPB_Core*>(core); |
60 const void* var = (*get_interface_function)(PPB_VAR_INTERFACE); | 94 const void* var = (*get_interface_function)(PPB_VAR_INTERFACE); |
61 var_interface = reinterpret_cast<const PPB_Var*>(var); | 95 var_interface = reinterpret_cast<const PPB_Var*>(var); |
62 } | 96 } |
63 | 97 |
64 const void* GetBrowserInterface(const char* interface_name) { | 98 const void* GetBrowserInterface(const char* interface_name) { |
65 return (*get_interface)(interface_name); | 99 return (*get_interface)(interface_name); |
66 } | 100 } |
67 | 101 |
68 const PPB_Core* CoreInterface() { | 102 const PPB_Core* CoreInterface() { |
69 return core_interface; | 103 return core_interface; |
70 } | 104 } |
71 | 105 |
72 const PPB_Var* VarInterface() { | 106 const PPB_Var* VarInterface() { |
73 return var_interface; | 107 return var_interface; |
74 } | 108 } |
75 | 109 |
76 } // namespace ppapi_proxy | 110 } // namespace ppapi_proxy |
OLD | NEW |