summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 01:50:31 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 01:50:31 +0000
commit9ca245e3b2d0e2271c7124d3aceb8179903718e2 (patch)
treeaa5fdbad23bd9a91cb117c1610064242d8a00985 /ppapi/proxy
parenta2f013ebcd62eae5238ca4ee84b9d21e34197fd8 (diff)
downloadchromium_src-9ca245e3b2d0e2271c7124d3aceb8179903718e2.zip
chromium_src-9ca245e3b2d0e2271c7124d3aceb8179903718e2.tar.gz
chromium_src-9ca245e3b2d0e2271c7124d3aceb8179903718e2.tar.bz2
Implement a proxy for URL util. Some of the implementation that doesn't need to
be proxied moved into a new shared_impl file, which required a decent amount of glue to make it callable from both the implementation and the proxy. The payoff here is only marginal since the code is fairly simple, but I decided this is still better than duplication. This also includes some comments from my audio patch that I forgot in that CL. BUG=none TEST=ppapi_tests run out of process pass Review URL: http://codereview.chromium.org/6676045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78646 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/dispatcher.cc3
-rw-r--r--ppapi/proxy/interface_id.h1
-rw-r--r--ppapi/proxy/ppapi_messages.h17
-rw-r--r--ppapi/proxy/ppb_url_util_proxy.cc207
-rw-r--r--ppapi/proxy/ppb_url_util_proxy.h52
5 files changed, 280 insertions, 0 deletions
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 156374d..5656e4b 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -24,6 +24,7 @@
#include "ppapi/c/dev/ppb_opengles_dev.h"
#include "ppapi/c/dev/ppb_surface_3d_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_audio.h"
@@ -71,6 +72,7 @@
#include "ppapi/proxy/ppb_url_loader_proxy.h"
#include "ppapi/proxy/ppb_url_request_info_proxy.h"
#include "ppapi/proxy/ppb_url_response_info_proxy.h"
+#include "ppapi/proxy/ppb_url_util_proxy.h"
#include "ppapi/proxy/ppb_var_deprecated_proxy.h"
#include "ppapi/proxy/ppp_class_proxy.h"
#include "ppapi/proxy/ppp_instance_proxy.h"
@@ -132,6 +134,7 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_URLLoaderTrusted_Proxy::GetInfo());
AddPPB(PPB_URLRequestInfo_Proxy::GetInfo());
AddPPB(PPB_URLResponseInfo_Proxy::GetInfo());
+ AddPPB(PPB_URLUtil_Proxy::GetInfo());
AddPPB(PPB_Var_Deprecated_Proxy::GetInfo());
// PPP (plugin) interfaces.
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index ceeb7b3..da8d859 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -43,6 +43,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_URL_LOADER_TRUSTED,
INTERFACE_ID_PPB_URL_REQUEST_INFO,
INTERFACE_ID_PPB_URL_RESPONSE_INFO,
+ INTERFACE_ID_PPB_URL_UTIL,
INTERFACE_ID_PPB_VAR,
INTERFACE_ID_PPB_VAR_DEPRECATED,
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 1c89ae2..2ecc03a 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -650,6 +650,23 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef,
pp::proxy::HostResource /* response */,
pp::proxy::PPBFileRef_CreateInfo /* result */)
+// PPB_URLUtil.
+IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument,
+ PP_Instance /* instance */,
+ pp::proxy::SerializedVar /* relative */,
+ pp::proxy::SerializedVar /* result */)
+IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_DocumentCanRequest,
+ PP_Instance /* instance */,
+ pp::proxy::SerializedVar /* relative */,
+ PP_Bool /* result */)
+IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_DocumentCanAccessDocument,
+ PP_Instance /* active */,
+ PP_Instance /* target */,
+ PP_Bool /* result */)
+IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLUtil_GetDocumentURL,
+ PP_Instance /* active */,
+ pp::proxy::SerializedVar /* result */)
+
// PPB_Var.
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBVar_AddRefObject,
int64 /* object_id */)
diff --git a/ppapi/proxy/ppb_url_util_proxy.cc b/ppapi/proxy/ppb_url_util_proxy.cc
new file mode 100644
index 0000000..bcff053
--- /dev/null
+++ b/ppapi/proxy/ppb_url_util_proxy.cc
@@ -0,0 +1,207 @@
+// Copyright (c) 2011 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 "ppapi/proxy/ppb_url_util_proxy.h"
+
+#include "base/basictypes.h"
+#include "ppapi/c/dev/ppb_url_util_dev.h"
+#include "ppapi/c/dev/ppb_var_deprecated.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/url_util_impl.h"
+
+namespace pp {
+namespace proxy {
+
+using pp::shared_impl::URLUtilImpl;
+
+namespace {
+
+URLUtilImpl::VarFromUtf8 GetVarFromUtf8() {
+ const PPB_Var_Deprecated* var_deprecated =
+ static_cast<const PPB_Var_Deprecated*>(
+ PluginDispatcher::GetInterfaceFromDispatcher(
+ PPB_VAR_DEPRECATED_INTERFACE));
+ return var_deprecated->VarFromUtf8;
+}
+
+const std::string* GetStringFromVar(PP_Var var) {
+ return PluginVarTracker::GetInstance()->GetExistingString(var);
+}
+
+PP_Var Canonicalize(PP_Var url,
+ PP_URLComponents_Dev* components) {
+ return URLUtilImpl::Canonicalize(&GetStringFromVar, GetVarFromUtf8(),
+ 0, url, components);
+}
+
+// Helper function for the functions below that optionally take a components
+// structure. It's annoying to serialze the large PP_URLComponents structure
+// and this data often isn't needed.
+//
+// To avoid this, we instead just parse the result again in the plugin, which
+// this function does if the given URL is valid and the components are
+// non-NULL. The URL var will be returned.
+PP_Var ConvertComponentsAndReturnURL(PP_Var url,
+ PP_URLComponents_Dev* components) {
+ if (!components)
+ return url; // Common case - plugin doesn't care about parsing.
+
+ const std::string* url_string = GetStringFromVar(url);
+ if (!url_string)
+ return url;
+
+ PP_Var result = Canonicalize(url, components);
+ PluginVarTracker::GetInstance()->Release(url);
+ return result;
+}
+
+PP_Var ResolveRelativeToURL(PP_Var base_url,
+ PP_Var relative,
+ PP_URLComponents_Dev* components) {
+ return URLUtilImpl::ResolveRelativeToURL(&GetStringFromVar, GetVarFromUtf8(),
+ 0, base_url, relative, components);
+}
+
+PP_Var ResolveRelativeToDocument(PP_Instance instance,
+ PP_Var relative_string,
+ PP_URLComponents_Dev* components) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeNull();
+
+ ReceiveSerializedVarReturnValue result;
+ dispatcher->Send(new PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument(
+ INTERFACE_ID_PPB_URL_UTIL, instance,
+ SerializedVarSendInput(dispatcher, relative_string),
+ &result));
+ return ConvertComponentsAndReturnURL(result.Return(dispatcher), components);
+}
+
+PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) {
+ return URLUtilImpl::IsSameSecurityOrigin(&GetStringFromVar, url_a, url_b);
+}
+
+PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanRequest(
+ INTERFACE_ID_PPB_URL_UTIL, instance,
+ SerializedVarSendInput(dispatcher, url),
+ &result));
+ return result;
+}
+
+PP_Bool DocumentCanAccessDocument(PP_Instance active, PP_Instance target) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(active);
+ if (!dispatcher)
+ return PP_FALSE;
+
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBURLUtil_DocumentCanAccessDocument(
+ INTERFACE_ID_PPB_URL_UTIL, active, target, &result));
+ return result;
+}
+
+PP_Var GetDocumentURL(PP_Instance instance,
+ struct PP_URLComponents_Dev* components) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return PP_MakeNull();
+
+ ReceiveSerializedVarReturnValue result;
+ dispatcher->Send(new PpapiHostMsg_PPBURLUtil_GetDocumentURL(
+ INTERFACE_ID_PPB_URL_UTIL, instance, &result));
+ return ConvertComponentsAndReturnURL(result.Return(dispatcher), components);
+}
+
+const PPB_URLUtil_Dev url_util_interface = {
+ &Canonicalize,
+ &ResolveRelativeToURL,
+ &ResolveRelativeToDocument,
+ &IsSameSecurityOrigin,
+ &DocumentCanRequest,
+ &DocumentCanAccessDocument,
+ &GetDocumentURL
+};
+
+InterfaceProxy* CreateURLUtilProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_URLUtil_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_URLUtil_Proxy::PPB_URLUtil_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_URLUtil_Proxy::~PPB_URLUtil_Proxy() {
+}
+
+// static
+const InterfaceProxy::Info* PPB_URLUtil_Proxy::GetInfo() {
+ static const Info info = {
+ &url_util_interface,
+ PPB_URLUTIL_DEV_INTERFACE,
+ INTERFACE_ID_PPB_URL_UTIL,
+ false,
+ &CreateURLUtilProxy,
+ };
+ return &info;
+}
+
+bool PPB_URLUtil_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_URLUtil_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument,
+ OnMsgResolveRelativeToDocument)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_DocumentCanRequest,
+ OnMsgDocumentCanRequest)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_DocumentCanAccessDocument,
+ OnMsgDocumentCanAccessDocument)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLUtil_GetDocumentURL,
+ OnMsgGetDocumentURL)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_URLUtil_Proxy::OnMsgResolveRelativeToDocument(
+ PP_Instance instance,
+ SerializedVarReceiveInput relative,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(),
+ ppb_url_util_target()->ResolveRelativeToDocument(
+ instance, relative.Get(dispatcher()), NULL));
+}
+
+void PPB_URLUtil_Proxy::OnMsgDocumentCanRequest(PP_Instance instance,
+ SerializedVarReceiveInput url,
+ PP_Bool* result) {
+ *result = ppb_url_util_target()->DocumentCanRequest(instance,
+ url.Get(dispatcher()));
+}
+
+void PPB_URLUtil_Proxy::OnMsgDocumentCanAccessDocument(PP_Instance active,
+ PP_Instance target,
+ PP_Bool* result) {
+ *result = ppb_url_util_target()->DocumentCanAccessDocument(
+ active, target);
+}
+
+void PPB_URLUtil_Proxy::OnMsgGetDocumentURL(PP_Instance instance,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(),
+ ppb_url_util_target()->GetDocumentURL(instance, NULL));
+}
+
+} // namespace proxy
+} // namespace pp
+
diff --git a/ppapi/proxy/ppb_url_util_proxy.h b/ppapi/proxy/ppb_url_util_proxy.h
new file mode 100644
index 0000000..2d4e001
--- /dev/null
+++ b/ppapi/proxy/ppb_url_util_proxy.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2011 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.
+
+#ifndef PPAPI_PROXY_PPB_URL_UTIL_PROXY_H_
+#define PPAPI_PROXY_PPB_URL_UTIL_PROXY_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/proxy/serialized_var.h"
+
+struct PPB_URLUtil_Dev;
+
+namespace pp {
+namespace proxy {
+
+class PPB_URLUtil_Proxy : public InterfaceProxy {
+ public:
+ PPB_URLUtil_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_URLUtil_Proxy();
+
+ static const Info* GetInfo();
+
+ const PPB_URLUtil_Dev* ppb_url_util_target() const {
+ return static_cast<const PPB_URLUtil_Dev*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgResolveRelativeToDocument(PP_Instance instance,
+ SerializedVarReceiveInput relative,
+ SerializedVarReturnValue result);
+ void OnMsgDocumentCanRequest(PP_Instance instance,
+ SerializedVarReceiveInput url,
+ PP_Bool* result);
+ void OnMsgDocumentCanAccessDocument(PP_Instance active,
+ PP_Instance target,
+ PP_Bool* result);
+ void OnMsgGetDocumentURL(PP_Instance instance,
+ SerializedVarReturnValue result);
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_URLUtil_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_URL_UTIL_PROXY_H_
+