OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
10 #include "ppapi/c/private/ppb_proxy_private.h" | 10 #include "ppapi/c/private/ppb_proxy_private.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get(); | 87 InterfaceProxy* proxy = target_proxies_[msg.routing_id()].get(); |
88 if (!proxy) { | 88 if (!proxy) { |
89 // Autocreate any proxy objects to handle requests from the plugin. Since | 89 // Autocreate any proxy objects to handle requests from the plugin. Since |
90 // we always support all known PPB_* interfaces (modulo the trusted bit), | 90 // we always support all known PPB_* interfaces (modulo the trusted bit), |
91 // there's very little checking necessary. | 91 // there's very little checking necessary. |
92 const InterfaceProxy::Info* info = GetPPBInterfaceInfo( | 92 const InterfaceProxy::Info* info = GetPPBInterfaceInfo( |
93 static_cast<InterfaceID>(msg.routing_id())); | 93 static_cast<InterfaceID>(msg.routing_id())); |
94 if (!info || | 94 if (!info || |
95 (info->is_trusted && disallow_trusted_interfaces())) | 95 (info->is_trusted && disallow_trusted_interfaces())) |
96 return true; | 96 return true; |
97 | 97 proxy = CreatePPBInterfaceProxy(info); |
98 const void* local_interface = GetLocalInterface(info->name); | |
99 if (!local_interface) { | |
100 // This should always succeed since the browser should support the stuff | |
101 // the proxy does. If this happens, something is out of sync. | |
102 NOTREACHED(); | |
103 return true; | |
104 } | |
105 | |
106 proxy = info->create_proxy(this, local_interface); | |
107 target_proxies_[info->id].reset(proxy); | |
108 } | 98 } |
109 | 99 |
110 return proxy->OnMessageReceived(msg); | 100 return proxy->OnMessageReceived(msg); |
111 } | 101 } |
112 | 102 |
113 void HostDispatcher::OnChannelError() { | 103 void HostDispatcher::OnChannelError() { |
114 Dispatcher::OnChannelError(); // Stop using the channel. | 104 Dispatcher::OnChannelError(); // Stop using the channel. |
115 | 105 |
116 // Tell the host about the crash so it can clean up. | 106 // Tell the host about the crash so it can clean up. |
117 GetPPBProxy()->PluginCrashed(pp_module()); | 107 GetPPBProxy()->PluginCrashed(pp_module()); |
(...skipping 17 matching lines...) Expand all Loading... |
135 bool supported = false; | 125 bool supported = false; |
136 Send(new PpapiMsg_SupportsInterface(interface, &supported)); | 126 Send(new PpapiMsg_SupportsInterface(interface, &supported)); |
137 plugin_interface_support_[static_cast<int>(info->id)] = | 127 plugin_interface_support_[static_cast<int>(info->id)] = |
138 supported ? INTERFACE_SUPPORTED : INTERFACE_UNSUPPORTED; | 128 supported ? INTERFACE_SUPPORTED : INTERFACE_UNSUPPORTED; |
139 | 129 |
140 if (supported) | 130 if (supported) |
141 return info->interface; | 131 return info->interface; |
142 return NULL; | 132 return NULL; |
143 } | 133 } |
144 | 134 |
| 135 InterfaceProxy* HostDispatcher::GetOrCreatePPBInterfaceProxy( |
| 136 InterfaceID id) { |
| 137 InterfaceProxy* proxy = target_proxies_[id].get(); |
| 138 if (!proxy) { |
| 139 const InterfaceProxy::Info* info = GetPPBInterfaceInfo(id); |
| 140 if (!info) |
| 141 return NULL; |
| 142 |
| 143 // Sanity check. This function won't normally be called for trusted |
| 144 // interfaces, but in case somebody does this, we don't want to then give |
| 145 // the plugin the ability to call that trusted interface (since the |
| 146 // checking occurs at proxy-creation time). |
| 147 if (info->is_trusted && disallow_trusted_interfaces()) |
| 148 return NULL; |
| 149 |
| 150 proxy = CreatePPBInterfaceProxy(info); |
| 151 } |
| 152 return proxy; |
| 153 } |
| 154 |
145 const PPB_Proxy_Private* HostDispatcher::GetPPBProxy() { | 155 const PPB_Proxy_Private* HostDispatcher::GetPPBProxy() { |
146 if (!ppb_proxy_) { | 156 if (!ppb_proxy_) { |
147 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( | 157 ppb_proxy_ = reinterpret_cast<const PPB_Proxy_Private*>( |
148 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); | 158 GetLocalInterface(PPB_PROXY_PRIVATE_INTERFACE)); |
149 } | 159 } |
150 return ppb_proxy_; | 160 return ppb_proxy_; |
151 } | 161 } |
152 | 162 |
| 163 InterfaceProxy* HostDispatcher::CreatePPBInterfaceProxy( |
| 164 const InterfaceProxy::Info* info) { |
| 165 const void* local_interface = GetLocalInterface(info->name); |
| 166 if (!local_interface) { |
| 167 // This should always succeed since the browser should support the stuff |
| 168 // the proxy does. If this happens, something is out of sync. |
| 169 NOTREACHED(); |
| 170 return NULL; |
| 171 } |
| 172 |
| 173 InterfaceProxy* proxy = info->create_proxy(this, local_interface); |
| 174 target_proxies_[info->id].reset(proxy); |
| 175 return proxy; |
| 176 } |
| 177 |
153 } // namespace proxy | 178 } // namespace proxy |
154 } // namespace pp | 179 } // namespace pp |
155 | 180 |
OLD | NEW |