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/pepper_socket_utils.h" | 5 #include "content/browser/renderer_host/pepper/pepper_socket_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string_util.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/site_instance.h" | 16 #include "content/public/browser/site_instance.h" |
16 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
17 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
18 #include "ppapi/c/private/ppb_net_address_private.h" | 19 #include "ppapi/c/private/ppb_net_address_private.h" |
19 #include "ppapi/shared_impl/private/net_address_private_impl.h" | 20 #include "ppapi/shared_impl/private/net_address_private_impl.h" |
20 #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" | 21 #include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 namespace pepper_socket_utils { | 24 namespace pepper_socket_utils { |
24 | 25 |
25 SocketPermissionRequest CreateSocketPermissionRequest( | 26 SocketPermissionRequest CreateSocketPermissionRequest( |
26 SocketPermissionRequest::OperationType type, | 27 SocketPermissionRequest::OperationType type, |
27 const PP_NetAddress_Private& net_addr) { | 28 const PP_NetAddress_Private& net_addr) { |
28 std::string host = ppapi::NetAddressPrivateImpl::DescribeNetAddress(net_addr, | 29 std::string host = ppapi::NetAddressPrivateImpl::DescribeNetAddress(net_addr, |
29 false); | 30 false); |
30 int port = 0; | 31 int port = 0; |
31 std::vector<unsigned char> address; | 32 std::vector<unsigned char> address; |
32 ppapi::NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr, | 33 ppapi::NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr, |
33 &address, | 34 &address, |
34 &port); | 35 &port); |
35 return SocketPermissionRequest(type, host, port); | 36 return SocketPermissionRequest(type, host, port); |
36 } | 37 } |
37 | 38 |
38 bool CanUseSocketAPIs(bool external_plugin, | 39 bool CanUseSocketAPIs(bool external_plugin, |
39 bool private_api, | 40 bool private_api, |
40 const SocketPermissionRequest* params, | 41 const SocketPermissionRequest* params, |
41 int render_process_id, | 42 int render_process_id, |
42 int render_view_id) { | 43 int render_frame_id) { |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
44 RenderViewHost* render_view_host = RenderViewHost::FromID(render_process_id, | |
45 render_view_id); | |
46 return render_view_host && CanUseSocketAPIs(external_plugin, | |
47 private_api, | |
48 params, | |
49 render_view_host); | |
50 } | |
51 | |
52 bool CanUseSocketAPIs(bool external_plugin, | |
53 bool private_api, | |
54 const SocketPermissionRequest* params, | |
55 RenderViewHost* render_view_host) { | |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
57 | |
58 if (!external_plugin) { | 45 if (!external_plugin) { |
59 // Always allow socket APIs for out-process plugins (other than external | 46 // Always allow socket APIs for out-process plugins (other than external |
60 // plugins instantiated by the embeeder through | 47 // plugins instantiated by the embeeder through |
61 // BrowserPpapiHost::CreateExternalPluginProcess). | 48 // BrowserPpapiHost::CreateExternalPluginProcess). |
62 return true; | 49 return true; |
63 } | 50 } |
64 | 51 |
65 if (!render_view_host) | 52 RenderFrameHost* render_frame_host = |
| 53 RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 54 if (!render_frame_host) |
66 return false; | 55 return false; |
67 SiteInstance* site_instance = render_view_host->GetSiteInstance(); | 56 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
68 if (!site_instance) | 57 if (!site_instance) |
69 return false; | 58 return false; |
70 if (!GetContentClient()->browser()->AllowPepperSocketAPI( | 59 if (!GetContentClient()->browser()->AllowPepperSocketAPI( |
71 site_instance->GetBrowserContext(), | 60 site_instance->GetBrowserContext(), |
72 site_instance->GetSiteURL(), | 61 site_instance->GetSiteURL(), |
73 private_api, | 62 private_api, |
74 params)) { | 63 params)) { |
75 LOG(ERROR) << "Host " << site_instance->GetSiteURL().host() | 64 LOG(ERROR) << "Host " << site_instance->GetSiteURL().host() |
76 << " cannot use socket API or destination is not allowed"; | 65 << " cannot use socket API or destination is not allowed"; |
77 return false; | 66 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ppapi::PPB_X509Certificate_Fields* fields) { | 119 ppapi::PPB_X509Certificate_Fields* fields) { |
131 scoped_refptr<net::X509Certificate> cert = | 120 scoped_refptr<net::X509Certificate> cert = |
132 net::X509Certificate::CreateFromBytes(der, length); | 121 net::X509Certificate::CreateFromBytes(der, length); |
133 if (!cert.get()) | 122 if (!cert.get()) |
134 return false; | 123 return false; |
135 return GetCertificateFields(*cert.get(), fields); | 124 return GetCertificateFields(*cert.get(), fields); |
136 } | 125 } |
137 | 126 |
138 } // namespace pepper_socket_utils | 127 } // namespace pepper_socket_utils |
139 } // namespace content | 128 } // namespace content |
OLD | NEW |