| 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, | 78 // TODO(brettw): It might be more testable to inject the PPB_Proxy_Private |
| 79 sizeof(PluginInterfaceSupport) * INTERFACE_ID_COUNT); | 79 // instead of requesting it from GetLocalInterface. |
| 80 | |
| 81 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( | 80 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( |
| 82 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); | 81 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); |
| 83 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; | 82 DCHECK(ppb_proxy_) << "The proxy interface should always be supported."; |
| 84 | 83 |
| 85 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); | 84 ppb_proxy_->SetReserveInstanceIDCallback(pp_module_, &ReserveInstanceID); |
| 86 } | 85 } |
| 87 | 86 |
| 88 HostDispatcher::~HostDispatcher() { | 87 HostDispatcher::~HostDispatcher() { |
| 89 g_module_to_dispatcher->erase(pp_module_); | 88 g_module_to_dispatcher->erase(pp_module_); |
| 90 } | 89 } |
| (...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. | 200 // Tell the host about the crash so it can clean up and display notification. |
| 202 ppb_proxy_->PluginCrashed(pp_module()); | 201 ppb_proxy_->PluginCrashed(pp_module()); |
| 203 } | 202 } |
| 204 | 203 |
| 205 const void* HostDispatcher::GetProxiedInterface(const std::string& interface) { | 204 const void* HostDispatcher::GetProxiedInterface(const std::string& interface) { |
| 206 // First see if we even have a proxy for this interface. | 205 // First see if we even have a proxy for this interface. |
| 207 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface); | 206 const InterfaceProxy::Info* info = GetPPPInterfaceInfo(interface); |
| 208 if (!info) | 207 if (!info) |
| 209 return NULL; | 208 return NULL; |
| 210 | 209 |
| 211 if (plugin_interface_support_[static_cast<int>(info->id)] != | 210 PluginIFSupportedMap::iterator iter(plugin_if_supported_.find(interface)); |
| 212 INTERFACE_UNQUERIED) { | 211 if (iter == plugin_if_supported_.end()) { |
| 213 // Already queried the plugin if it supports this interface. | 212 // Need to query. Cache the result so we only do this once. |
| 214 if (plugin_interface_support_[info->id] == INTERFACE_SUPPORTED) | 213 bool supported = false; |
| 215 return info->interface_ptr; | 214 Send(new PpapiMsg_SupportsInterface(interface, &supported)); |
| 216 return NULL; | 215 std::pair<PluginIFSupportedMap::iterator, bool> iter_success_pair; |
| 216 iter_success_pair = plugin_if_supported_.insert( |
| 217 PluginIFSupportedMap::value_type(interface, supported)); |
| 218 iter = iter_success_pair.first; |
| 217 } | 219 } |
| 218 | 220 if (iter->second) |
| 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 |