| 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/browser/renderer_host/pepper/content_browser_pepper_host_facto
     ry.h" | 5 #include "content/browser/renderer_host/pepper/content_browser_pepper_host_facto
     ry.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 30 #include "ppapi/host/resource_host.h" | 30 #include "ppapi/host/resource_host.h" | 
| 31 #include "ppapi/proxy/ppapi_messages.h" | 31 #include "ppapi/proxy/ppapi_messages.h" | 
| 32 #include "ppapi/shared_impl/ppapi_permissions.h" | 32 #include "ppapi/shared_impl/ppapi_permissions.h" | 
| 33 | 33 | 
| 34 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) | 
| 35 #include "content/browser/renderer_host/pepper/pepper_vpn_provider_message_filte
     r_chromeos.h" | 35 #include "content/browser/renderer_host/pepper/pepper_vpn_provider_message_filte
     r_chromeos.h" | 
| 36 #endif | 36 #endif | 
| 37 | 37 | 
| 38 using ppapi::host::MessageFilterHost; | 38 using ppapi::host::MessageFilterHost; | 
| 39 using ppapi::host::ResourceHost; | 39 using ppapi::host::ResourceHost; | 
| 40 using ppapi::host::ResourceMessageFilter; |  | 
| 41 using ppapi::proxy::SerializedTrueTypeFontDesc; | 40 using ppapi::proxy::SerializedTrueTypeFontDesc; | 
| 42 using ppapi::UnpackMessage; | 41 using ppapi::UnpackMessage; | 
| 43 | 42 | 
| 44 namespace content { | 43 namespace content { | 
| 45 | 44 | 
| 46 namespace { | 45 namespace { | 
| 47 | 46 | 
| 48 const size_t kMaxSocketsAllowed = 1024; | 47 const size_t kMaxSocketsAllowed = 1024; | 
| 49 | 48 | 
| 50 bool CanCreateSocket() { | 49 bool CanCreateSocket() { | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 92     } | 91     } | 
| 93     case PpapiHostMsg_Gamepad_Create::ID: { | 92     case PpapiHostMsg_Gamepad_Create::ID: { | 
| 94       return std::unique_ptr<ResourceHost>( | 93       return std::unique_ptr<ResourceHost>( | 
| 95           new PepperGamepadHost(host_, instance, resource)); | 94           new PepperGamepadHost(host_, instance, resource)); | 
| 96     } | 95     } | 
| 97     case PpapiHostMsg_NetworkProxy_Create::ID: { | 96     case PpapiHostMsg_NetworkProxy_Create::ID: { | 
| 98       return std::unique_ptr<ResourceHost>( | 97       return std::unique_ptr<ResourceHost>( | 
| 99           new PepperNetworkProxyHost(host_, instance, resource)); | 98           new PepperNetworkProxyHost(host_, instance, resource)); | 
| 100     } | 99     } | 
| 101     case PpapiHostMsg_HostResolver_Create::ID: { | 100     case PpapiHostMsg_HostResolver_Create::ID: { | 
| 102       scoped_refptr<ResourceMessageFilter> host_resolver( | 101       scoped_refptr<ppapi::host::ResourceMessageFilter> host_resolver( | 
| 103           new PepperHostResolverMessageFilter(host_, instance, false)); | 102           new PepperHostResolverMessageFilter(host_, instance, false)); | 
| 104       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 103       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 105           host_->GetPpapiHost(), instance, resource, host_resolver)); | 104           host_->GetPpapiHost(), instance, resource, host_resolver)); | 
| 106     } | 105     } | 
| 107     case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { | 106     case PpapiHostMsg_FileRef_CreateForFileAPI::ID: { | 
| 108       PP_Resource file_system; | 107       PP_Resource file_system; | 
| 109       std::string internal_path; | 108       std::string internal_path; | 
| 110       if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( | 109       if (!UnpackMessage<PpapiHostMsg_FileRef_CreateForFileAPI>( | 
| 111               message, &file_system, &internal_path)) { | 110               message, &file_system, &internal_path)) { | 
| 112         NOTREACHED(); | 111         NOTREACHED(); | 
| 113         return std::unique_ptr<ResourceHost>(); | 112         return std::unique_ptr<ResourceHost>(); | 
| 114       } | 113       } | 
| 115       return std::unique_ptr<ResourceHost>(new PepperFileRefHost( | 114       return std::unique_ptr<ResourceHost>(new PepperFileRefHost( | 
| 116           host_, instance, resource, file_system, internal_path)); | 115           host_, instance, resource, file_system, internal_path)); | 
| 117     } | 116     } | 
| 118     case PpapiHostMsg_TCPSocket_Create::ID: { | 117     case PpapiHostMsg_TCPSocket_Create::ID: { | 
| 119       ppapi::TCPSocketVersion version; | 118       ppapi::TCPSocketVersion version; | 
| 120       if (!UnpackMessage<PpapiHostMsg_TCPSocket_Create>(message, &version) || | 119       if (!UnpackMessage<PpapiHostMsg_TCPSocket_Create>(message, &version) || | 
| 121           version == ppapi::TCP_SOCKET_VERSION_PRIVATE) { | 120           version == ppapi::TCP_SOCKET_VERSION_PRIVATE) { | 
| 122         return std::unique_ptr<ResourceHost>(); | 121         return std::unique_ptr<ResourceHost>(); | 
| 123       } | 122       } | 
| 124 | 123 | 
| 125       return CreateNewTCPSocket(instance, resource, version); | 124       return CreateNewTCPSocket(instance, resource, version); | 
| 126     } | 125     } | 
| 127     case PpapiHostMsg_UDPSocket_Create::ID: { | 126     case PpapiHostMsg_UDPSocket_Create::ID: { | 
| 128       if (CanCreateSocket()) { | 127       if (CanCreateSocket()) { | 
| 129         scoped_refptr<ResourceMessageFilter> udp_socket( | 128         scoped_refptr<ppapi::host::ResourceMessageFilter> udp_socket( | 
| 130             new PepperUDPSocketMessageFilter(host_, instance, false)); | 129             new PepperUDPSocketMessageFilter(host_, instance, false)); | 
| 131         return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 130         return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 132             host_->GetPpapiHost(), instance, resource, udp_socket)); | 131             host_->GetPpapiHost(), instance, resource, udp_socket)); | 
| 133       } else { | 132       } else { | 
| 134         return std::unique_ptr<ResourceHost>(); | 133         return std::unique_ptr<ResourceHost>(); | 
| 135       } | 134       } | 
| 136     } | 135     } | 
| 137   } | 136   } | 
| 138 | 137 | 
| 139   // Dev interfaces. | 138   // Dev interfaces. | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 183     } | 182     } | 
| 184   } | 183   } | 
| 185 | 184 | 
| 186   // Permissions for the following interfaces will be checked at the | 185   // Permissions for the following interfaces will be checked at the | 
| 187   // time of the corresponding instance's methods calls (because | 186   // time of the corresponding instance's methods calls (because | 
| 188   // permission check can be performed only on the UI | 187   // permission check can be performed only on the UI | 
| 189   // thread). Currently these interfaces are available only for | 188   // thread). Currently these interfaces are available only for | 
| 190   // whitelisted apps which may not have access to the other private | 189   // whitelisted apps which may not have access to the other private | 
| 191   // interfaces. | 190   // interfaces. | 
| 192   if (message.type() == PpapiHostMsg_HostResolver_CreatePrivate::ID) { | 191   if (message.type() == PpapiHostMsg_HostResolver_CreatePrivate::ID) { | 
| 193     scoped_refptr<ResourceMessageFilter> host_resolver( | 192     scoped_refptr<ppapi::host::ResourceMessageFilter> host_resolver( | 
| 194         new PepperHostResolverMessageFilter(host_, instance, true)); | 193         new PepperHostResolverMessageFilter(host_, instance, true)); | 
| 195     return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 194     return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 196         host_->GetPpapiHost(), instance, resource, host_resolver)); | 195         host_->GetPpapiHost(), instance, resource, host_resolver)); | 
| 197   } | 196   } | 
| 198   if (message.type() == PpapiHostMsg_TCPServerSocket_CreatePrivate::ID) { | 197   if (message.type() == PpapiHostMsg_TCPServerSocket_CreatePrivate::ID) { | 
| 199     if (CanCreateSocket()) { | 198     if (CanCreateSocket()) { | 
| 200       scoped_refptr<ResourceMessageFilter> tcp_server_socket( | 199       scoped_refptr<ppapi::host::ResourceMessageFilter> tcp_server_socket( | 
| 201           new PepperTCPServerSocketMessageFilter(this, host_, instance, true)); | 200           new PepperTCPServerSocketMessageFilter(this, host_, instance, true)); | 
| 202       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 201       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 203           host_->GetPpapiHost(), instance, resource, tcp_server_socket)); | 202           host_->GetPpapiHost(), instance, resource, tcp_server_socket)); | 
| 204     } else { | 203     } else { | 
| 205       return std::unique_ptr<ResourceHost>(); | 204       return std::unique_ptr<ResourceHost>(); | 
| 206     } | 205     } | 
| 207   } | 206   } | 
| 208   if (message.type() == PpapiHostMsg_TCPSocket_CreatePrivate::ID) { | 207   if (message.type() == PpapiHostMsg_TCPSocket_CreatePrivate::ID) { | 
| 209     return CreateNewTCPSocket(instance, resource, | 208     return CreateNewTCPSocket(instance, resource, | 
| 210                               ppapi::TCP_SOCKET_VERSION_PRIVATE); | 209                               ppapi::TCP_SOCKET_VERSION_PRIVATE); | 
| 211   } | 210   } | 
| 212   if (message.type() == PpapiHostMsg_UDPSocket_CreatePrivate::ID) { | 211   if (message.type() == PpapiHostMsg_UDPSocket_CreatePrivate::ID) { | 
| 213     if (CanCreateSocket()) { | 212     if (CanCreateSocket()) { | 
| 214       scoped_refptr<ResourceMessageFilter> udp_socket( | 213       scoped_refptr<ppapi::host::ResourceMessageFilter> udp_socket( | 
| 215           new PepperUDPSocketMessageFilter(host_, instance, true)); | 214           new PepperUDPSocketMessageFilter(host_, instance, true)); | 
| 216       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 215       return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 217           host_->GetPpapiHost(), instance, resource, udp_socket)); | 216           host_->GetPpapiHost(), instance, resource, udp_socket)); | 
| 218     } else { | 217     } else { | 
| 219       return std::unique_ptr<ResourceHost>(); | 218       return std::unique_ptr<ResourceHost>(); | 
| 220     } | 219     } | 
| 221   } | 220   } | 
| 222   if (message.type() == PpapiHostMsg_NetworkMonitor_Create::ID) { | 221   if (message.type() == PpapiHostMsg_NetworkMonitor_Create::ID) { | 
| 223     return std::unique_ptr<ResourceHost>( | 222     return std::unique_ptr<ResourceHost>( | 
| 224         new PepperNetworkMonitorHost(host_, instance, resource)); | 223         new PepperNetworkMonitorHost(host_, instance, resource)); | 
| 225   } | 224   } | 
| 226 | 225 | 
| 227   // Flash interfaces. | 226   // Flash interfaces. | 
| 228   if (GetPermissions().HasPermission(ppapi::PERMISSION_FLASH)) { | 227   if (GetPermissions().HasPermission(ppapi::PERMISSION_FLASH)) { | 
| 229     switch (message.type()) { | 228     switch (message.type()) { | 
| 230       case PpapiHostMsg_FlashFile_Create::ID: { | 229       case PpapiHostMsg_FlashFile_Create::ID: { | 
| 231         scoped_refptr<ResourceMessageFilter> file_filter( | 230         scoped_refptr<ppapi::host::ResourceMessageFilter> file_filter( | 
| 232             new PepperFlashFileMessageFilter(instance, host_)); | 231             new PepperFlashFileMessageFilter(instance, host_)); | 
| 233         return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 232         return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 234             host_->GetPpapiHost(), instance, resource, file_filter)); | 233             host_->GetPpapiHost(), instance, resource, file_filter)); | 
| 235       } | 234       } | 
| 236     } | 235     } | 
| 237   } | 236   } | 
| 238 | 237 | 
| 239   return std::unique_ptr<ResourceHost>(); | 238   return std::unique_ptr<ResourceHost>(); | 
| 240 } | 239 } | 
| 241 | 240 | 
| 242 std::unique_ptr<ppapi::host::ResourceHost> | 241 std::unique_ptr<ppapi::host::ResourceHost> | 
| 243 ContentBrowserPepperHostFactory::CreateAcceptedTCPSocket( | 242 ContentBrowserPepperHostFactory::CreateAcceptedTCPSocket( | 
| 244     PP_Instance instance, | 243     PP_Instance instance, | 
| 245     ppapi::TCPSocketVersion version, | 244     ppapi::TCPSocketVersion version, | 
| 246     std::unique_ptr<net::TCPSocket> socket) { | 245     std::unique_ptr<net::TCPSocket> socket) { | 
| 247   if (!CanCreateSocket()) | 246   if (!CanCreateSocket()) | 
| 248     return std::unique_ptr<ResourceHost>(); | 247     return std::unique_ptr<ResourceHost>(); | 
| 249   scoped_refptr<ResourceMessageFilter> tcp_socket( | 248   scoped_refptr<ppapi::host::ResourceMessageFilter> tcp_socket( | 
| 250       new PepperTCPSocketMessageFilter(host_, instance, version, | 249       new PepperTCPSocketMessageFilter(host_, instance, version, | 
| 251                                        std::move(socket))); | 250                                        std::move(socket))); | 
| 252   return std::unique_ptr<ResourceHost>( | 251   return std::unique_ptr<ResourceHost>( | 
| 253       new MessageFilterHost(host_->GetPpapiHost(), instance, 0, tcp_socket)); | 252       new MessageFilterHost(host_->GetPpapiHost(), instance, 0, tcp_socket)); | 
| 254 } | 253 } | 
| 255 | 254 | 
| 256 std::unique_ptr<ppapi::host::ResourceHost> | 255 std::unique_ptr<ppapi::host::ResourceHost> | 
| 257 ContentBrowserPepperHostFactory::CreateNewTCPSocket( | 256 ContentBrowserPepperHostFactory::CreateNewTCPSocket( | 
| 258     PP_Instance instance, | 257     PP_Instance instance, | 
| 259     PP_Resource resource, | 258     PP_Resource resource, | 
| 260     ppapi::TCPSocketVersion version) { | 259     ppapi::TCPSocketVersion version) { | 
| 261   if (!CanCreateSocket()) | 260   if (!CanCreateSocket()) | 
| 262     return std::unique_ptr<ResourceHost>(); | 261     return std::unique_ptr<ResourceHost>(); | 
| 263 | 262 | 
| 264   scoped_refptr<ResourceMessageFilter> tcp_socket( | 263   scoped_refptr<ppapi::host::ResourceMessageFilter> tcp_socket( | 
| 265       new PepperTCPSocketMessageFilter(this, host_, instance, version)); | 264       new PepperTCPSocketMessageFilter(this, host_, instance, version)); | 
| 266   if (!tcp_socket.get()) | 265   if (!tcp_socket.get()) | 
| 267     return std::unique_ptr<ResourceHost>(); | 266     return std::unique_ptr<ResourceHost>(); | 
| 268 | 267 | 
| 269   return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 268   return std::unique_ptr<ResourceHost>(new MessageFilterHost( | 
| 270       host_->GetPpapiHost(), instance, resource, tcp_socket)); | 269       host_->GetPpapiHost(), instance, resource, tcp_socket)); | 
| 271 } | 270 } | 
| 272 | 271 | 
| 273 const ppapi::PpapiPermissions& ContentBrowserPepperHostFactory::GetPermissions() | 272 const ppapi::PpapiPermissions& ContentBrowserPepperHostFactory::GetPermissions() | 
| 274     const { | 273     const { | 
| 275   return host_->GetPpapiHost()->permissions(); | 274   return host_->GetPpapiHost()->permissions(); | 
| 276 } | 275 } | 
| 277 | 276 | 
| 278 }  // namespace content | 277 }  // namespace content | 
| OLD | NEW | 
|---|