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 #include "ppapi/proxy/host_dispatcher.h" | 5 #include "ppapi/proxy/host_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 allow_plugin_reentrancy_(false) { | 68 allow_plugin_reentrancy_(false) { |
69 if (!g_module_to_dispatcher) | 69 if (!g_module_to_dispatcher) |
70 g_module_to_dispatcher = new ModuleToDispatcherMap; | 70 g_module_to_dispatcher = new ModuleToDispatcherMap; |
71 (*g_module_to_dispatcher)[pp_module_] = this; | 71 (*g_module_to_dispatcher)[pp_module_] = this; |
72 | 72 |
73 const PPB_Var_Deprecated* var_interface = | 73 const PPB_Var_Deprecated* var_interface = |
74 static_cast<const PPB_Var_Deprecated*>( | 74 static_cast<const PPB_Var_Deprecated*>( |
75 local_get_interface(PPB_VAR_DEPRECATED_INTERFACE)); | 75 local_get_interface(PPB_VAR_DEPRECATED_INTERFACE)); |
76 SetSerializationRules(new HostVarSerializationRules(var_interface, module)); | 76 SetSerializationRules(new HostVarSerializationRules(var_interface, module)); |
77 | 77 |
78 memset(plugin_interface_support_, 0, | |
79 sizeof(PluginInterfaceSupport) * INTERFACE_ID_COUNT); | |
80 | |
81 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( | 78 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( |
82 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); | 79 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); |
83 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; | 80 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; |
84 | 81 |
85 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); | 82 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); |
86 } | 83 } |
87 | 84 |
88 HostDispatcher::~HostDispatcher() { | 85 HostDispatcher::~HostDispatcher() { |
89 g_module_to_dispatcher->erase(pp_module_); | 86 g_module_to_dispatcher->erase(pp_module_); |
90 } | 87 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // Tell the host about the crash so it can clean up and display notification. | 198 // Tell the host about the crash so it can clean up and display notification. |
202 ppb_proxy_->PluginCrashed(pp_module()); | 199 ppb_proxy_->PluginCrashed(pp_module()); |
203 } | 200 } |
204 | 201 |
205 const void* HostDispatcher::GetProxiedInterface(const std::string& interface) { | 202 const void* HostDispatcher::GetProxiedInterface(const std::string& interface) { |
206 // First see if we even have a proxy for this interface. | 203 // First see if we even have a proxy for this interface. |
207 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface); | 204 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface); |
208 if (!info) | 205 if (!info) |
209 return NULL; | 206 return NULL; |
210 | 207 |
211 if (plugin_interface_support_[static_cast<int>(info->id)] != | 208 PluginIFSupportMap::iterator iter(plugin_if_support_.find(interface)); |
212 INTERFACE_UNQUERIED) { | 209 if (iter == plugin_if_support_.end()) { |
213 // Already queried the plugin if it supports this interface. | 210 // Need to query. Cache the result so we only do this once. |
214 if (plugin_interface_support_[info->id] == INTERFACE_SUPPORTED) | 211 bool supported = false; |
215 return info->interface_ptr; | 212 Send(new PpapiMsg_SupportsInterface(interface, &supported)); |
216 return NULL; | 213 std::pair<PluginIFSupportMap::iterator, bool> iter_success_pair; |
| 214 iter_success_pair = plugin_if_support_.insert( |
| 215 PluginIFSupportMap::value_type(interface, |
| 216 supported ? INTERFACE_SUPPORTED : |
| 217 INTERFACE_UNSUPPORTED)); |
| 218 iter = iter_success_pair.first; |
217 } | 219 } |
218 | 220 if (iter->second == INTERFACE_SUPPORTED) |
219 // Need to re-query. Cache the result so we only do this once. | |
220 bool supported = false; | |
221 Send(new PpapiMsg_SupportsInterface(interface, &supported)); | |
222 plugin_interface_support_[static_cast<int>(info->id)] = | |
223 supported ? INTERFACE_SUPPORTED : INTERFACE_UNSUPPORTED; | |
224 | |
225 if (supported) | |
226 return info->interface_ptr; | 221 return info->interface_ptr; |
227 return NULL; | 222 return NULL; |
228 } | 223 } |
229 | 224 |
230 InterfaceProxy* HostDispatcher::GetOrCreatePPBInterfaceProxy( | 225 InterfaceProxy* HostDispatcher::GetOrCreatePPBInterfaceProxy( |
231 InterfaceID id) { | 226 InterfaceID id) { |
232 InterfaceProxy* proxy = target_proxies_[id].get(); | 227 InterfaceProxy* proxy = target_proxies_[id].get(); |
233 if (!proxy) { | 228 if (!proxy) { |
234 const InterfaceProxy::Info* info = GetPPBInterfaceInfo(id); | 229 const InterfaceProxy::Info* info = GetPPBInterfaceInfo(id); |
235 if (!info) | 230 if (!info) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 dispatcher_->ppb_proxy()->AddRefModule(dispatcher_->pp_module()); | 265 dispatcher_->ppb_proxy()->AddRefModule(dispatcher_->pp_module()); |
271 } | 266 } |
272 | 267 |
273 ScopedModuleReference::~ScopedModuleReference() { | 268 ScopedModuleReference::~ScopedModuleReference() { |
274 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); | 269 dispatcher_->ppb_proxy()->ReleaseModule(dispatcher_->pp_module()); |
275 } | 270 } |
276 | 271 |
277 } // namespace proxy | 272 } // namespace proxy |
278 } // namespace pp | 273 } // namespace pp |
279 | 274 |
OLD | NEW |