| 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 "content/renderer/pepper/pepper_broker.h" | 5 #include "content/renderer/pepper/pepper_broker.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" | 8 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
| 9 #include "content/renderer/pepper/plugin_module.h" | 9 #include "content/renderer/pepper/plugin_module.h" |
| 10 #include "content/renderer/pepper/ppb_broker_impl.h" | 10 #include "content/renderer/pepper/ppb_broker_impl.h" |
| 11 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" | 11 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" |
| 12 #include "ipc/ipc_channel_handle.h" | 12 #include "ipc/ipc_channel_handle.h" |
| 13 #include "ppapi/proxy/broker_dispatcher.h" | 13 #include "ppapi/proxy/broker_dispatcher.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/shared_impl/platform_file.h" | 15 #include "ppapi/shared_impl/platform_file.h" |
| 16 | 16 |
| 17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 18 #include <windows.h> | 18 #include <windows.h> |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) { | 25 base::SyncSocket::Handle DuplicateHandle(base::SyncSocket::Handle handle) { |
| 26 base::SyncSocket::Handle out_handle = base::kInvalidPlatformFileValue; | 26 base::SyncSocket::Handle out_handle = base::SyncSocket::kInvalidHandle; |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 DWORD options = DUPLICATE_SAME_ACCESS; | 28 DWORD options = DUPLICATE_SAME_ACCESS; |
| 29 if (!::DuplicateHandle(::GetCurrentProcess(), | 29 if (!::DuplicateHandle(::GetCurrentProcess(), |
| 30 handle, | 30 handle, |
| 31 ::GetCurrentProcess(), | 31 ::GetCurrentProcess(), |
| 32 &out_handle, | 32 &out_handle, |
| 33 0, | 33 0, |
| 34 FALSE, | 34 FALSE, |
| 35 options)) { | 35 options)) { |
| 36 out_handle = base::kInvalidPlatformFileValue; | 36 out_handle = base::SyncSocket::kInvalidHandle; |
| 37 } | 37 } |
| 38 #elif defined(OS_POSIX) | 38 #elif defined(OS_POSIX) |
| 39 // If asked to close the source, we can simply re-use the source fd instead of | 39 // If asked to close the source, we can simply re-use the source fd instead of |
| 40 // dup()ing and close()ing. | 40 // dup()ing and close()ing. |
| 41 out_handle = ::dup(handle); | 41 out_handle = ::dup(handle); |
| 42 #else | 42 #else |
| 43 #error Not implemented. | 43 #error Not implemented. |
| 44 #endif | 44 #endif |
| 45 return out_handle; | 45 return out_handle; |
| 46 } | 46 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 if (!entry->second.client.get()) { | 182 if (!entry->second.client.get()) { |
| 183 // Client has gone away. | 183 // Client has gone away. |
| 184 pending_connects_.erase(entry); | 184 pending_connects_.erase(entry); |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (!result) { | 188 if (!result) { |
| 189 // Report failure. | 189 // Report failure. |
| 190 client->BrokerConnected( | 190 client->BrokerConnected( |
| 191 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), | 191 ppapi::PlatformFileToInt(base::SyncSocket::kInvalidHandle), |
| 192 PP_ERROR_NOACCESS); | 192 PP_ERROR_NOACCESS); |
| 193 pending_connects_.erase(entry); | 193 pending_connects_.erase(entry); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 if (dispatcher_) { | 197 if (dispatcher_) { |
| 198 ConnectPluginToBroker(client); | 198 ConnectPluginToBroker(client); |
| 199 pending_connects_.erase(entry); | 199 pending_connects_.erase(entry); |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Mark the request as authorized, continue waiting for the broker | 203 // Mark the request as authorized, continue waiting for the broker |
| 204 // connection. | 204 // connection. |
| 205 DCHECK(!entry->second.is_authorized); | 205 DCHECK(!entry->second.is_authorized); |
| 206 entry->second.is_authorized = true; | 206 entry->second.is_authorized = true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 PepperBroker::PendingConnection::PendingConnection() : is_authorized(false) {} | 209 PepperBroker::PendingConnection::PendingConnection() : is_authorized(false) {} |
| 210 | 210 |
| 211 PepperBroker::PendingConnection::~PendingConnection() {} | 211 PepperBroker::PendingConnection::~PendingConnection() {} |
| 212 | 212 |
| 213 void PepperBroker::ReportFailureToClients(int error_code) { | 213 void PepperBroker::ReportFailureToClients(int error_code) { |
| 214 DCHECK_NE(PP_OK, error_code); | 214 DCHECK_NE(PP_OK, error_code); |
| 215 for (ClientMap::iterator i = pending_connects_.begin(); | 215 for (ClientMap::iterator i = pending_connects_.begin(); |
| 216 i != pending_connects_.end(); | 216 i != pending_connects_.end(); |
| 217 ++i) { | 217 ++i) { |
| 218 base::WeakPtr<PPB_Broker_Impl>& weak_ptr = i->second.client; | 218 base::WeakPtr<PPB_Broker_Impl>& weak_ptr = i->second.client; |
| 219 if (weak_ptr.get()) { | 219 if (weak_ptr.get()) { |
| 220 weak_ptr->BrokerConnected( | 220 weak_ptr->BrokerConnected( |
| 221 ppapi::PlatformFileToInt(base::kInvalidPlatformFileValue), | 221 ppapi::PlatformFileToInt(base::SyncSocket::kInvalidHandle), |
| 222 error_code); | 222 error_code); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 pending_connects_.clear(); | 225 pending_connects_.clear(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void PepperBroker::ConnectPluginToBroker(PPB_Broker_Impl* client) { | 228 void PepperBroker::ConnectPluginToBroker(PPB_Broker_Impl* client) { |
| 229 base::SyncSocket::Handle plugin_handle = base::kInvalidPlatformFileValue; | 229 base::SyncSocket::Handle plugin_handle = base::SyncSocket::kInvalidHandle; |
| 230 int32_t result = PP_OK; | 230 int32_t result = PP_OK; |
| 231 | 231 |
| 232 // The socket objects will be deleted when this function exits, closing the | 232 // The socket objects will be deleted when this function exits, closing the |
| 233 // handles. Any uses of the socket must duplicate them. | 233 // handles. Any uses of the socket must duplicate them. |
| 234 scoped_ptr<base::SyncSocket> broker_socket(new base::SyncSocket()); | 234 scoped_ptr<base::SyncSocket> broker_socket(new base::SyncSocket()); |
| 235 scoped_ptr<base::SyncSocket> plugin_socket(new base::SyncSocket()); | 235 scoped_ptr<base::SyncSocket> plugin_socket(new base::SyncSocket()); |
| 236 if (base::SyncSocket::CreatePair(broker_socket.get(), plugin_socket.get())) { | 236 if (base::SyncSocket::CreatePair(broker_socket.get(), plugin_socket.get())) { |
| 237 result = dispatcher_->SendHandleToBroker(client->pp_instance(), | 237 result = dispatcher_->SendHandleToBroker(client->pp_instance(), |
| 238 broker_socket->handle()); | 238 broker_socket->handle()); |
| 239 | 239 |
| 240 // If the broker has its pipe handle, duplicate the plugin's handle. | 240 // If the broker has its pipe handle, duplicate the plugin's handle. |
| 241 // Otherwise, the plugin's handle will be automatically closed. | 241 // Otherwise, the plugin's handle will be automatically closed. |
| 242 if (result == PP_OK) | 242 if (result == PP_OK) |
| 243 plugin_handle = DuplicateHandle(plugin_socket->handle()); | 243 plugin_handle = DuplicateHandle(plugin_socket->handle()); |
| 244 } else { | 244 } else { |
| 245 result = PP_ERROR_FAILED; | 245 result = PP_ERROR_FAILED; |
| 246 } | 246 } |
| 247 | 247 |
| 248 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing | 248 // TOOD(ddorwin): Change the IPC to asynchronous: Queue an object containing |
| 249 // client and plugin_socket.release(), then return. | 249 // client and plugin_socket.release(), then return. |
| 250 // That message handler will then call client->BrokerConnected() with the | 250 // That message handler will then call client->BrokerConnected() with the |
| 251 // saved pipe handle. | 251 // saved pipe handle. |
| 252 // Temporarily, just call back. | 252 // Temporarily, just call back. |
| 253 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); | 253 client->BrokerConnected(ppapi::PlatformFileToInt(plugin_handle), result); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace content | 256 } // namespace content |
| OLD | NEW |