OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/pepper/pepper_socket_utils.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/site_instance.h" |
| 15 #include "content/public/common/content_client.h" |
| 16 #include "ppapi/c/private/ppb_net_address_private.h" |
| 17 #include "ppapi/shared_impl/private/net_address_private_impl.h" |
| 18 |
| 19 namespace content { |
| 20 namespace pepper_socket_utils { |
| 21 |
| 22 SocketPermissionRequest CreateSocketPermissionRequest( |
| 23 SocketPermissionRequest::OperationType type, |
| 24 const PP_NetAddress_Private& net_addr) { |
| 25 std::string host = ppapi::NetAddressPrivateImpl::DescribeNetAddress(net_addr, |
| 26 false); |
| 27 int port = 0; |
| 28 std::vector<unsigned char> address; |
| 29 ppapi::NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr, |
| 30 &address, |
| 31 &port); |
| 32 return SocketPermissionRequest(type, host, port); |
| 33 } |
| 34 |
| 35 bool CanUseSocketAPIs(ProcessType plugin_process_type, |
| 36 const SocketPermissionRequest& params, |
| 37 RenderViewHost* render_view_host) { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 |
| 40 if (plugin_process_type == PROCESS_TYPE_PPAPI_PLUGIN) { |
| 41 // Always allow socket APIs for out-process plugins (except NACL). |
| 42 return true; |
| 43 } |
| 44 |
| 45 if (!render_view_host) |
| 46 return false; |
| 47 SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 48 if (!site_instance) |
| 49 return false; |
| 50 if (!GetContentClient()->browser()->AllowPepperSocketAPI( |
| 51 site_instance->GetBrowserContext(), |
| 52 site_instance->GetSiteURL(), |
| 53 params)) { |
| 54 LOG(ERROR) << "Host " << site_instance->GetSiteURL().host() |
| 55 << " cannot use socket API or destination is not allowed"; |
| 56 return false; |
| 57 } |
| 58 |
| 59 return true; |
| 60 } |
| 61 |
| 62 } // namespace pepper_socket_utils |
| 63 } // namespace content |
OLD | NEW |