diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-10 17:23:57 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-10 17:23:57 +0000 |
commit | 0346023c3a4180f8cf67d4e825beb87bdbd98f73 (patch) | |
tree | 333733068c017be1aa53e0af945c0a0cecc6318d /ppapi | |
parent | cf58c966ebdca1fcf2adbbe4a2f5bad875a8382a (diff) | |
download | chromium_src-0346023c3a4180f8cf67d4e825beb87bdbd98f73.zip chromium_src-0346023c3a4180f8cf67d4e825beb87bdbd98f73.tar.gz chromium_src-0346023c3a4180f8cf67d4e825beb87bdbd98f73.tar.bz2 |
Convert URLUtil to the thunk system.
This removes some duplicate code between the proxy and the impl.
Review URL: http://codereview.chromium.org/8159012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/ppapi_proxy.gypi | 2 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 1 | ||||
-rw-r--r-- | ppapi/proxy/interface_id.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/interface_list.cc | 15 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 38 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 110 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.h | 25 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_util_proxy.cc | 217 | ||||
-rw-r--r-- | ppapi/proxy/ppb_url_util_proxy.h | 55 | ||||
-rw-r--r-- | ppapi/shared_impl/url_util_impl.cc | 28 | ||||
-rw-r--r-- | ppapi/shared_impl/url_util_impl.h | 17 | ||||
-rw-r--r-- | ppapi/thunk/interfaces_ppb_public_dev.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_api.h | 14 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_thunk.cc | 10 | ||||
-rw-r--r-- | ppapi/thunk/ppb_url_util_thunk.cc | 74 |
15 files changed, 289 insertions, 319 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 296d5e6..7dfd427 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -116,8 +116,6 @@ 'proxy/ppb_url_loader_proxy.h', 'proxy/ppb_url_response_info_proxy.cc', 'proxy/ppb_url_response_info_proxy.h', - 'proxy/ppb_url_util_proxy.cc', - 'proxy/ppb_url_util_proxy.h', 'proxy/ppb_var_deprecated_proxy.cc', 'proxy/ppb_var_deprecated_proxy.h', 'proxy/ppb_var_proxy.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index a072284..b7bc00c 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -163,6 +163,7 @@ 'thunk/ppb_url_request_info_thunk.cc', 'thunk/ppb_url_response_info_api.h', 'thunk/ppb_url_response_info_thunk.cc', + 'thunk/ppb_url_util_thunk.cc', 'thunk/ppb_video_capture_api.h', 'thunk/ppb_video_capture_thunk.cc', 'thunk/ppb_video_decoder_api.h', diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 7f45bfa..a2f97df 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -45,7 +45,6 @@ enum InterfaceID { INTERFACE_ID_PPB_TEXT_INPUT, INTERFACE_ID_PPB_URL_LOADER, INTERFACE_ID_PPB_URL_RESPONSE_INFO, - INTERFACE_ID_PPB_URL_UTIL, INTERFACE_ID_PPB_VAR_DEPRECATED, INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, INTERFACE_ID_PPB_VIDEO_DECODER_DEV, diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 2511f3b..c317fc3 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -83,7 +83,6 @@ #include "ppapi/proxy/ppb_text_input_proxy.h" #include "ppapi/proxy/ppb_url_loader_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/ppb_var_proxy.h" #include "ppapi/proxy/ppb_video_capture_proxy.h" @@ -164,7 +163,12 @@ InterfaceList::InterfaceList() { #undef PROXIED_API #undef PROXIED_IFACE - // New-style AddPPB not converted to the macros above. + // Manually add some special proxies. Some of these don't have interfaces + // that they support, so aren't covered by the macros above, but have proxies + // for message routing. Others have different implementations between the + // proxy and the impl and there's no obvious message routing. + AddProxy(INTERFACE_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); + AddProxy(INTERFACE_ID_PPP_CLASS, &PPP_Class_Proxy::Create); AddPPB(PPB_CORE_INTERFACE, INTERFACE_ID_PPB_CORE, PPB_Core_Proxy::GetPPB_Core_Interface()); AddPPB(PPB_MEMORY_DEV_INTERFACE, INTERFACE_ID_NONE, @@ -174,12 +178,6 @@ InterfaceList::InterfaceList() { AddPPB(PPB_VAR_INTERFACE, INTERFACE_ID_NONE, GetPPB_Var_Interface()); - // Manually add some special proxies. These don't have interfaces that they - // support, so aren't covered by the macros above, but have proxies for - // message routing. - AddProxy(INTERFACE_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); - AddProxy(INTERFACE_ID_PPP_CLASS, &PPP_Class_Proxy::Create); - // PPB (browser) interfaces. AddPPB(PPB_Crypto_Proxy::GetInfo()); AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); @@ -193,7 +191,6 @@ InterfaceList::InterfaceList() { AddPPB(PPB_PDF_Proxy::GetInfo()); AddPPB(PPB_Testing_Proxy::GetInfo()); AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); - AddPPB(PPB_URLUtil_Proxy::GetInfo()); AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); #ifdef ENABLE_FLAPPER_HACKS diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 9b4442b..aada5ee 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -896,6 +896,24 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_LockMouse, uint32_t /* serialized_callback */) IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBInstance_UnlockMouse, PP_Instance /* instance */) +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument, + PP_Instance /* instance */, + ppapi::proxy::SerializedVar /* relative */, + ppapi::proxy::SerializedVar /* result */) +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_DocumentCanRequest, + PP_Instance /* instance */, + ppapi::proxy::SerializedVar /* relative */, + PP_Bool /* result */) +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument, + PP_Instance /* active */, + PP_Instance /* target */, + PP_Bool /* result */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetDocumentURL, + PP_Instance /* active */, + ppapi::proxy::SerializedVar /* result */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, + PP_Instance /* active */, + ppapi::proxy::SerializedVar /* result */) IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBPDF_GetFontFileWithFallback, @@ -975,26 +993,6 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLResponseInfo_GetBodyAsFileRef, ppapi::HostResource /* response */, ppapi::PPB_FileRef_CreateInfo /* result */) -// PPB_URLUtil. -IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_ResolveRelativeToDocument, - PP_Instance /* instance */, - ppapi::proxy::SerializedVar /* relative */, - ppapi::proxy::SerializedVar /* result */) -IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBURLUtil_DocumentCanRequest, - PP_Instance /* instance */, - ppapi::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 */, - ppapi::proxy::SerializedVar /* result */) -IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLUtil_GetPluginInstanceURL, - PP_Instance /* active */, - ppapi::proxy::SerializedVar /* result */) - // PPB_Var. IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBVar_AddRefObject, int64 /* object_id */, diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index d1fa264..d26c29f 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -14,6 +14,7 @@ #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/url_util_impl.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -99,6 +100,16 @@ bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { OnMsgLockMouse) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse, OnMsgUnlockMouse) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ResolveRelativeToDocument, + OnMsgResolveRelativeToDocument) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanRequest, + OnMsgDocumentCanRequest) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_DocumentCanAccessDocument, + OnMsgDocumentCanAccessDocument) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetDocumentURL, + OnMsgGetDocumentURL) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_GetPluginInstanceURL, + OnMsgGetPluginInstanceURL) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -280,6 +291,56 @@ void PPB_Instance_Proxy::SubscribeToPolicyUpdates(PP_Instance instance) { NOTIMPLEMENTED(); } +PP_Var PPB_Instance_Proxy::ResolveRelativeToDocument( + PP_Instance instance, + PP_Var relative, + PP_URLComponents_Dev* components) { + ReceiveSerializedVarReturnValue result; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_ResolveRelativeToDocument( + INTERFACE_ID_PPB_INSTANCE, instance, + SerializedVarSendInput(dispatcher(), relative), + &result)); + return URLUtilImpl::ConvertComponentsAndReturnURL(result.Return(dispatcher()), + components); +} + +PP_Bool PPB_Instance_Proxy::DocumentCanRequest(PP_Instance instance, + PP_Var url) { + PP_Bool result = PP_FALSE; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanRequest( + INTERFACE_ID_PPB_INSTANCE, instance, + SerializedVarSendInput(dispatcher(), url), + &result)); + return result; +} + +PP_Bool PPB_Instance_Proxy::DocumentCanAccessDocument(PP_Instance instance, + PP_Instance target) { + PP_Bool result = PP_FALSE; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_DocumentCanAccessDocument( + INTERFACE_ID_PPB_INSTANCE, instance, target, &result)); + return result; +} + +PP_Var PPB_Instance_Proxy::GetDocumentURL(PP_Instance instance, + PP_URLComponents_Dev* components) { + ReceiveSerializedVarReturnValue result; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetDocumentURL( + INTERFACE_ID_PPB_INSTANCE, instance, &result)); + return URLUtilImpl::ConvertComponentsAndReturnURL(result.Return(dispatcher()), + components); +} + +PP_Var PPB_Instance_Proxy::GetPluginInstanceURL( + PP_Instance instance, + PP_URLComponents_Dev* components) { + ReceiveSerializedVarReturnValue result; + dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetPluginInstanceURL( + INTERFACE_ID_PPB_INSTANCE, instance, &result)); + return URLUtilImpl::ConvertComponentsAndReturnURL(result.Return(dispatcher()), + components); +} + void PPB_Instance_Proxy::PostMessage(PP_Instance instance, PP_Var message) { dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage( @@ -453,5 +514,54 @@ void PPB_Instance_Proxy::OnMsgUnlockMouse(PP_Instance instance) { enter.functions()->UnlockMouse(instance); } +void PPB_Instance_Proxy::OnMsgResolveRelativeToDocument( + PP_Instance instance, + SerializedVarReceiveInput relative, + SerializedVarReturnValue result) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + result.Return(dispatcher(), + enter.functions()->ResolveRelativeToDocument( + instance, relative.Get(dispatcher()), NULL)); + } +} + +void PPB_Instance_Proxy::OnMsgDocumentCanRequest(PP_Instance instance, + SerializedVarReceiveInput url, + PP_Bool* result) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + *result = enter.functions()->DocumentCanRequest(instance, + url.Get(dispatcher())); + } +} + +void PPB_Instance_Proxy::OnMsgDocumentCanAccessDocument(PP_Instance active, + PP_Instance target, + PP_Bool* result) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(active, true); + if (enter.succeeded()) + *result = enter.functions()->DocumentCanAccessDocument(active, target); +} + +void PPB_Instance_Proxy::OnMsgGetDocumentURL(PP_Instance instance, + SerializedVarReturnValue result) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + result.Return(dispatcher(), + enter.functions()->GetDocumentURL(instance, NULL)); + } +} + +void PPB_Instance_Proxy::OnMsgGetPluginInstanceURL( + PP_Instance instance, + SerializedVarReturnValue result) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) { + result.Return(dispatcher(), + enter.functions()->GetPluginInstanceURL(instance, NULL)); + } +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 3a4200a..75538ca 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -78,6 +78,18 @@ class PPB_Instance_Proxy : public InterfaceProxy, double minimum_factor, double maximium_factor) OVERRIDE; virtual void SubscribeToPolicyUpdates(PP_Instance instance) OVERRIDE; + virtual PP_Var ResolveRelativeToDocument( + PP_Instance instance, + PP_Var relative, + PP_URLComponents_Dev* components) OVERRIDE; + virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) OVERRIDE; + virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance, + PP_Instance target) OVERRIDE; + virtual PP_Var GetDocumentURL(PP_Instance instance, + PP_URLComponents_Dev* components) OVERRIDE; + virtual PP_Var GetPluginInstanceURL( + PP_Instance instance, + PP_URLComponents_Dev* components) OVERRIDE; virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE; virtual int32_t LockMouse(PP_Instance instance, PP_CompletionCallback callback) OVERRIDE; @@ -128,6 +140,19 @@ class PPB_Instance_Proxy : public InterfaceProxy, void OnMsgLockMouse(PP_Instance instance, uint32_t serialized_callback); void OnMsgUnlockMouse(PP_Instance instance); + 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); + void OnMsgGetPluginInstanceURL(PP_Instance instance, + SerializedVarReturnValue result); }; } // namespace proxy diff --git a/ppapi/proxy/ppb_url_util_proxy.cc b/ppapi/proxy/ppb_url_util_proxy.cc deleted file mode 100644 index b3cea08..0000000 --- a/ppapi/proxy/ppb_url_util_proxy.cc +++ /dev/null @@ -1,217 +0,0 @@ -// 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/plugin_resource_tracker.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/url_util_impl.h" -#include "ppapi/shared_impl/var.h" - -namespace ppapi { -namespace proxy { - -namespace { - -PP_Var Canonicalize(PP_Var url, - PP_URLComponents_Dev* components) { - return URLUtilImpl::Canonicalize(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. - - StringVar* url_string = StringVar::FromPPVar(url); - if (!url_string) - return url; - - PP_Var result = Canonicalize(url, components); - PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(url); - return result; -} - -PP_Var ResolveRelativeToURL(PP_Var base_url, - PP_Var relative, - PP_URLComponents_Dev* components) { - return URLUtilImpl::ResolveRelativeToURL(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(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); -} - -PP_Var GetPluginInstanceURL(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_GetPluginInstanceURL( - 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, - &GetPluginInstanceURL -}; - -InterfaceProxy* CreateURLUtilProxy(Dispatcher* dispatcher) { - return new PPB_URLUtil_Proxy(dispatcher); -} - -} // namespace - -PPB_URLUtil_Proxy::PPB_URLUtil_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_url_util_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_url_util_impl_ = static_cast<const PPB_URLUtil_Dev*>( - dispatcher->local_get_interface()(PPB_URLUTIL_DEV_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_HANDLER(PpapiHostMsg_PPBURLUtil_GetPluginInstanceURL, - OnMsgGetPluginInstanceURL) - 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_impl_->ResolveRelativeToDocument( - instance, relative.Get(dispatcher()), NULL)); -} - -void PPB_URLUtil_Proxy::OnMsgDocumentCanRequest(PP_Instance instance, - SerializedVarReceiveInput url, - PP_Bool* result) { - *result = ppb_url_util_impl_->DocumentCanRequest(instance, - url.Get(dispatcher())); -} - -void PPB_URLUtil_Proxy::OnMsgDocumentCanAccessDocument(PP_Instance active, - PP_Instance target, - PP_Bool* result) { - *result = ppb_url_util_impl_->DocumentCanAccessDocument( - active, target); -} - -void PPB_URLUtil_Proxy::OnMsgGetDocumentURL(PP_Instance instance, - SerializedVarReturnValue result) { - result.Return(dispatcher(), - ppb_url_util_impl_->GetDocumentURL(instance, NULL)); -} - -void PPB_URLUtil_Proxy::OnMsgGetPluginInstanceURL( - PP_Instance instance, SerializedVarReturnValue result) { - result.Return(dispatcher(), - ppb_url_util_impl_->GetPluginInstanceURL(instance, NULL)); -} - -} // namespace proxy -} // namespace ppapi - diff --git a/ppapi/proxy/ppb_url_util_proxy.h b/ppapi/proxy/ppb_url_util_proxy.h deleted file mode 100644 index 0571377..0000000 --- a/ppapi/proxy/ppb_url_util_proxy.h +++ /dev/null @@ -1,55 +0,0 @@ -// 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 ppapi { -namespace proxy { - -class PPB_URLUtil_Proxy : public InterfaceProxy { - public: - PPB_URLUtil_Proxy(Dispatcher* dispatcher); - virtual ~PPB_URLUtil_Proxy(); - - static const Info* GetInfo(); - - // 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); - void OnMsgGetPluginInstanceURL(PP_Instance instance, - SerializedVarReturnValue result); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_URLUtil_Dev* ppb_url_util_impl_; - - DISALLOW_COPY_AND_ASSIGN(PPB_URLUtil_Proxy); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_URL_UTIL_PROXY_H_ - diff --git a/ppapi/shared_impl/url_util_impl.cc b/ppapi/shared_impl/url_util_impl.cc index ddad401..5bced6c 100644 --- a/ppapi/shared_impl/url_util_impl.cc +++ b/ppapi/shared_impl/url_util_impl.cc @@ -5,7 +5,9 @@ #include "ppapi/shared_impl/url_util_impl.h" #include "googleurl/src/gurl.h" +#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" namespace ppapi { @@ -41,18 +43,17 @@ void ConvertComponents(const url_parse::Parsed& input, } // namespace // static -PP_Var URLUtilImpl::Canonicalize(PP_Module pp_module, - PP_Var url, +PP_Var URLUtilImpl::Canonicalize(PP_Var url, PP_URLComponents_Dev* components) { StringVar* url_string = StringVar::FromPPVar(url); if (!url_string) return PP_MakeNull(); - return GenerateURLReturn(pp_module, GURL(url_string->value()), components); + return GenerateURLReturn(url_string->pp_module(), + GURL(url_string->value()), components); } // static -PP_Var URLUtilImpl::ResolveRelativeToURL(PP_Module pp_module, - PP_Var base_url, +PP_Var URLUtilImpl::ResolveRelativeToURL(PP_Var base_url, PP_Var relative, PP_URLComponents_Dev* components) { StringVar* base_url_string = StringVar::FromPPVar(base_url); @@ -63,7 +64,7 @@ PP_Var URLUtilImpl::ResolveRelativeToURL(PP_Module pp_module, GURL base_gurl(base_url_string->value()); if (!base_gurl.is_valid()) return PP_MakeNull(); - return GenerateURLReturn(pp_module, + return GenerateURLReturn(base_url_string->pp_module(), base_gurl.Resolve(relative_string->value()), components); } @@ -94,4 +95,19 @@ PP_Var URLUtilImpl::GenerateURLReturn(PP_Module module, return StringVar::StringToPPVar(module, url.possibly_invalid_spec()); } +PP_Var URLUtilImpl::ConvertComponentsAndReturnURL( + const PP_Var& url, + PP_URLComponents_Dev* components) { + if (!components) + return url; // Common case - plugin doesn't care about parsing. + + StringVar* url_string = StringVar::FromPPVar(url); + if (!url_string) + return url; + + PP_Var result = Canonicalize(url, components); + TrackerBase::Get()->GetVarTracker()->ReleaseVar(url); + return result; +} + } // namespace ppapi diff --git a/ppapi/shared_impl/url_util_impl.h b/ppapi/shared_impl/url_util_impl.h index ae869c3..b7fae83 100644 --- a/ppapi/shared_impl/url_util_impl.h +++ b/ppapi/shared_impl/url_util_impl.h @@ -23,11 +23,9 @@ namespace ppapi { class PPAPI_SHARED_EXPORT URLUtilImpl { public: // PPB_URLUtil shared functions. - static PP_Var Canonicalize(PP_Module pp_module, - PP_Var url, + static PP_Var Canonicalize(PP_Var url, PP_URLComponents_Dev* components); - static PP_Var ResolveRelativeToURL(PP_Module pp_module, - PP_Var base_url, + static PP_Var ResolveRelativeToURL(PP_Var base_url, PP_Var relative, PP_URLComponents_Dev* components); static PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b); @@ -37,6 +35,17 @@ class PPAPI_SHARED_EXPORT URLUtilImpl { static PP_Var GenerateURLReturn(PP_Module pp_module, const GURL& url, PP_URLComponents_Dev* components); + + // Helper function that optionally take a components structure and fills it + // out with the parsed version of the given URL. If the components pointer is + // NULL, this function will do nothing. + // + // It's annoying to serialze the large PP_URLComponents structure across IPC + // and the data isn't often requested by plugins. This function is used on + // the plugin side to fill in the components for those cases where it's + // actually needed. + static PP_Var ConvertComponentsAndReturnURL(const PP_Var& url, + PP_URLComponents_Dev* components); }; } // namespace ppapi diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index ced24e6..fb744db0 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -46,6 +46,7 @@ PROXIED_IFACE(PPB_Instance, PPB_MOUSELOCK_DEV_INTERFACE_0_1, PPB_MouseLock_Dev) UNPROXIED_IFACE(PPB_Instance, PPB_QUERYPOLICY_DEV_INTERFACE_0_1, PPB_QueryPolicy_Dev) +PROXIED_IFACE(PPB_Instance, PPB_URLUTIL_DEV_INTERFACE_0_6, PPB_URLUtil_Dev) UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev) UNPROXIED_IFACE(PPB_LayerCompositor, PPB_LAYER_COMPOSITOR_DEV_INTERFACE_0_2, PPB_LayerCompositor_Dev) diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 0ce23f4..fa66e2e 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -5,6 +5,7 @@ #ifndef PPAPI_THUNK_INSTANCE_API_H_ #define PPAPI_THUNK_INSTANCE_API_H_ +#include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/ppb_instance.h" #include "ppapi/c/pp_bool.h" @@ -82,6 +83,19 @@ class PPB_Instance_FunctionAPI { // QueryPolicy. virtual void SubscribeToPolicyUpdates(PP_Instance instance) = 0; + // URLUtil. + virtual PP_Var ResolveRelativeToDocument( + PP_Instance instance, + PP_Var relative, + PP_URLComponents_Dev* components) = 0; + virtual PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) = 0; + virtual PP_Bool DocumentCanAccessDocument(PP_Instance instance, + PP_Instance target) = 0; + virtual PP_Var GetDocumentURL(PP_Instance instance, + PP_URLComponents_Dev* components) = 0; + virtual PP_Var GetPluginInstanceURL(PP_Instance instance, + PP_URLComponents_Dev* components) = 0; + static const proxy::InterfaceID interface_id = proxy::INTERFACE_ID_PPB_INSTANCE; }; diff --git a/ppapi/thunk/ppb_instance_thunk.cc b/ppapi/thunk/ppb_instance_thunk.cc index 9cc9bd5..07951bc 100644 --- a/ppapi/thunk/ppb_instance_thunk.cc +++ b/ppapi/thunk/ppb_instance_thunk.cc @@ -13,28 +13,28 @@ namespace thunk { namespace { PP_Var GetWindowObject(PP_Instance instance) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); return enter.functions()->GetWindowObject(instance); } PP_Var GetOwnerElementObject(PP_Instance instance) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); return enter.functions()->GetOwnerElementObject(instance); } PP_Bool BindGraphics(PP_Instance instance, PP_Resource graphics_id) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_FALSE; return enter.functions()->BindGraphics(instance, graphics_id); } PP_Bool IsFullFrame(PP_Instance instance) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_FALSE; return enter.functions()->IsFullFrame(instance); @@ -43,7 +43,7 @@ PP_Bool IsFullFrame(PP_Instance instance) { PP_Var ExecuteScript(PP_Instance instance, PP_Var script, PP_Var* exception) { - EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); return enter.functions()->ExecuteScript(instance, script, exception); diff --git a/ppapi/thunk/ppb_url_util_thunk.cc b/ppapi/thunk/ppb_url_util_thunk.cc new file mode 100644 index 0000000..1a6b4a8 --- /dev/null +++ b/ppapi/thunk/ppb_url_util_thunk.cc @@ -0,0 +1,74 @@ +// 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/c/pp_errors.h" +#include "ppapi/shared_impl/url_util_impl.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_instance_api.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Var ResolveRelativeToDocument(PP_Instance instance, + PP_Var relative, + PP_URLComponents_Dev* components) { + EnterInstance enter(instance); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->ResolveRelativeToDocument(instance, relative, + components); +} + +PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) { + EnterInstance enter(instance); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->DocumentCanRequest(instance, url); +} + +PP_Bool DocumentCanAccessDocument(PP_Instance active, PP_Instance target) { + EnterInstance enter(active); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->DocumentCanAccessDocument(active, target); +} + +PP_Var GetDocumentURL(PP_Instance instance, + PP_URLComponents_Dev* components) { + EnterInstance enter(instance); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->GetDocumentURL(instance, components); +} + +PP_Var GetPluginInstanceURL(PP_Instance instance, + PP_URLComponents_Dev* components) { + EnterInstance enter(instance); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->GetPluginInstanceURL(instance, components); +} + +const PPB_URLUtil_Dev g_ppb_url_util = { + &URLUtilImpl::Canonicalize, + &URLUtilImpl::ResolveRelativeToURL, + &ResolveRelativeToDocument, + &URLUtilImpl::IsSameSecurityOrigin, + &DocumentCanRequest, + &DocumentCanAccessDocument, + &GetDocumentURL, + &GetPluginInstanceURL +}; + +} // namespace + +const PPB_URLUtil_Dev* GetPPB_URLUtil_Dev_Thunk() { + return &g_ppb_url_util; +} + +} // namespace thunk +} // namespace ppapi |