Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Unified Diff: content/browser/renderer_host/pepper/pepper_socket_utils.cc

Issue 11441012: PPB_UDPSocket_Private is switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/pepper/pepper_socket_utils.cc
diff --git a/content/browser/renderer_host/pepper/pepper_socket_utils.cc b/content/browser/renderer_host/pepper/pepper_socket_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b5e43b3ac5ab903d63e00eba3de7c7df762fa651
--- /dev/null
+++ b/content/browser/renderer_host/pepper/pepper_socket_utils.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/pepper/pepper_socket_utils.h"
+
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/site_instance.h"
+#include "content/public/common/content_client.h"
+#include "ppapi/c/private/ppb_net_address_private.h"
+#include "ppapi/shared_impl/private/net_address_private_impl.h"
+
+namespace content {
+namespace pepper_socket_utils {
+
+SocketPermissionRequest CreateSocketPermissionRequest(
+ SocketPermissionRequest::OperationType type,
+ const PP_NetAddress_Private& net_addr) {
+ std::string host = ppapi::NetAddressPrivateImpl::DescribeNetAddress(net_addr,
+ false);
+ int port = 0;
+ std::vector<unsigned char> address;
+ ppapi::NetAddressPrivateImpl::NetAddressToIPEndPoint(net_addr,
+ &address,
+ &port);
+ return SocketPermissionRequest(type, host, port);
+}
+
+bool CanUseSocketAPIs(ProcessType plugin_process_type,
+ const SocketPermissionRequest& params,
+ RenderViewHost* render_view_host) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (plugin_process_type == PROCESS_TYPE_PPAPI_PLUGIN) {
+ // Always allow socket APIs for out-process plugins (except NACL).
+ return true;
+ }
+
+ if (!render_view_host)
+ return false;
+ SiteInstance* site_instance = render_view_host->GetSiteInstance();
+ if (!site_instance)
+ return false;
+ if (!GetContentClient()->browser()->AllowPepperSocketAPI(
+ site_instance->GetBrowserContext(),
+ site_instance->GetSiteURL(),
+ params)) {
+ LOG(ERROR) << "Host " << site_instance->GetSiteURL().host()
+ << " cannot use socket API or destination is not allowed";
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace pepper_socket_utils
+} // namespace content
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_socket_utils.h ('k') | content/browser/renderer_host/pepper/pepper_udp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698