summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/ppapi_shared_proxy.gypi5
-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
-rw-r--r--ppapi/shared_impl/url_util_impl.cc106
-rw-r--r--ppapi/shared_impl/url_util_impl.h67
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h3
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.h3
-rw-r--r--webkit/plugins/ppapi/ppb_url_util_impl.cc93
12 files changed, 500 insertions, 63 deletions
diff --git a/ppapi/ppapi_shared_proxy.gypi b/ppapi/ppapi_shared_proxy.gypi
index 84f92b5..3915647 100644
--- a/ppapi/ppapi_shared_proxy.gypi
+++ b/ppapi/ppapi_shared_proxy.gypi
@@ -10,6 +10,7 @@
'dependencies': [
'ppapi_c',
'../base/base.gyp:base',
+ '../build/temp_gyp/googleurl.gyp:googleurl',
'../skia/skia.gyp:skia',
'../third_party/icu/icu.gyp:icuuc',
],
@@ -23,6 +24,8 @@
'shared_impl/char_set_impl.h',
'shared_impl/image_data_impl.cc',
'shared_impl/image_data_impl.h',
+ 'shared_impl/url_util_impl.cc',
+ 'shared_impl/url_util_impl.h',
],
'conditions': [
['OS=="win"', {
@@ -132,6 +135,8 @@
'proxy/ppb_url_request_info_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/ppp_class_proxy.cc',
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_
+
diff --git a/ppapi/shared_impl/url_util_impl.cc b/ppapi/shared_impl/url_util_impl.cc
new file mode 100644
index 0000000..32aab48
--- /dev/null
+++ b/ppapi/shared_impl/url_util_impl.cc
@@ -0,0 +1,106 @@
+// 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/shared_impl/url_util_impl.h"
+
+#include "googleurl/src/gurl.h"
+
+namespace pp {
+namespace shared_impl {
+
+namespace {
+
+void ConvertComponent(const url_parse::Component& input,
+ PP_URLComponent_Dev* output) {
+ output->begin = input.begin;
+ output->len = input.len;
+}
+
+// Converts components from a GoogleUrl parsed to a PPAPI parsed structure.
+// Output can be NULL to specify "do nothing." This rule is followed by all
+// the url util functions, so we implement it once here.
+//
+// Output can be NULL to specify "do nothing." This rule is followed by all the
+// url util functions, so we implement it once here.
+void ConvertComponents(const url_parse::Parsed& input,
+ PP_URLComponents_Dev* output) {
+ if (!output)
+ return;
+
+ ConvertComponent(input.scheme, &output->scheme);
+ ConvertComponent(input.username, &output->username);
+ ConvertComponent(input.password, &output->password);
+ ConvertComponent(input.host, &output->host);
+ ConvertComponent(input.port, &output->port);
+ ConvertComponent(input.path, &output->path);
+ ConvertComponent(input.query, &output->query);
+ ConvertComponent(input.ref, &output->ref);
+}
+
+} // namespace
+
+// static
+PP_Var URLUtilImpl::Canonicalize(StringFromVar string_from_var,
+ VarFromUtf8 var_from_utf8,
+ PP_Module pp_module,
+ PP_Var url,
+ PP_URLComponents_Dev* components) {
+ const std::string* url_string = string_from_var(url);
+ if (!url_string)
+ return PP_MakeNull();
+ return GenerateURLReturn(var_from_utf8, pp_module,
+ GURL(*url_string), components);
+}
+
+// static
+PP_Var URLUtilImpl::ResolveRelativeToURL(StringFromVar string_from_var,
+ VarFromUtf8 var_from_utf8,
+ PP_Module pp_module,
+ PP_Var base_url,
+ PP_Var relative,
+ PP_URLComponents_Dev* components) {
+ const std::string* base_url_string = string_from_var(base_url);
+ const std::string* relative_string = string_from_var(relative);
+ if (!base_url_string || !relative_string)
+ return PP_MakeNull();
+
+ GURL base_gurl(*base_url_string);
+ if (!base_gurl.is_valid())
+ return PP_MakeNull();
+ return GenerateURLReturn(var_from_utf8, pp_module,
+ base_gurl.Resolve(*relative_string),
+ components);
+}
+
+// static
+PP_Bool URLUtilImpl::IsSameSecurityOrigin(StringFromVar string_from_var,
+ PP_Var url_a, PP_Var url_b) {
+ const std::string* url_a_string = string_from_var(url_a);
+ const std::string* url_b_string = string_from_var(url_b);
+ if (!url_a_string || !url_b_string)
+ return PP_FALSE;
+
+ GURL gurl_a(*url_a_string);
+ GURL gurl_b(*url_b_string);
+ if (!gurl_a.is_valid() || !gurl_b.is_valid())
+ return PP_FALSE;
+
+ return gurl_a.GetOrigin() == gurl_b.GetOrigin() ? PP_TRUE : PP_FALSE;
+}
+
+// Used for returning the given GURL from a PPAPI function, with an optional
+// out param indicating the components.
+PP_Var URLUtilImpl::GenerateURLReturn(VarFromUtf8 var_from_utf8,
+ PP_Module module,
+ const GURL& url,
+ PP_URLComponents_Dev* components) {
+ if (!url.is_valid())
+ return PP_MakeNull();
+ ConvertComponents(url.parsed_for_possibly_invalid_spec(), components);
+ return var_from_utf8(module, url.possibly_invalid_spec().c_str(),
+ static_cast<uint32_t>(url.possibly_invalid_spec().size()));
+}
+
+} // namespace shared_impl
+} // namespace pp
diff --git a/ppapi/shared_impl/url_util_impl.h b/ppapi/shared_impl/url_util_impl.h
new file mode 100644
index 0000000..91c7999
--- /dev/null
+++ b/ppapi/shared_impl/url_util_impl.h
@@ -0,0 +1,67 @@
+// 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_SHARED_IMPL_URL_UTIL_IMPL_H_
+#define PPAPI_SHARED_IMPL_URL_UTIL_IMPL_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "googleurl/src/url_parse.h"
+#include "ppapi/c/dev/ppb_url_util_dev.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_var.h"
+
+class GURL;
+
+namespace pp {
+namespace shared_impl {
+
+// Contains the implementation of PPB_URLUtil that is shared between the proxy
+// and the renderer.
+class URLUtilImpl {
+ public:
+ // The functions here would normally take the var interface for constructing
+ // return strings. However, at the current time there's some mixup between
+ // using Var and VarDeprecated. To resolve this, we instead pass the pointer
+ // to the string creation function so can be used independently of this.
+ typedef PP_Var (*VarFromUtf8)(PP_Module, const char*, uint32_t);
+
+ // Function that converts the given var to a std::string or NULL if the
+ // var is not a string or is invalid.
+ //
+ // We could use PPB_Var for this, but that interface requires an additional
+ // string conversion. Both the proxy and the host side maintain the strings
+ // in a std::string, and the form we want for passing to GURL is also a
+ // std::string. Parameterizing this separately saves this, and also solves
+ // the same problem that VarFromUtf8 does.
+ typedef const std::string* (*StringFromVar)(PP_Var var);
+
+ // PPB_URLUtil shared functions.
+ static PP_Var Canonicalize(StringFromVar string_from_var,
+ VarFromUtf8 var_from_utf8,
+ PP_Module pp_module,
+ PP_Var url,
+ PP_URLComponents_Dev* components);
+ static PP_Var ResolveRelativeToURL(StringFromVar string_from_var,
+ VarFromUtf8 var_from_utf8,
+ PP_Module pp_module,
+ PP_Var base_url,
+ PP_Var relative,
+ PP_URLComponents_Dev* components);
+ static PP_Bool IsSameSecurityOrigin(StringFromVar string_from_var,
+ PP_Var url_a, PP_Var url_b);
+
+ // Used for returning the given GURL from a PPAPI function, with an optional
+ // out param indicating the components.
+ static PP_Var GenerateURLReturn(VarFromUtf8 var_from_utf8,
+ PP_Module pp_module,
+ const GURL& url,
+ PP_URLComponents_Dev* components);
+};
+
+} // namespace shared_impl
+} // namespace pp
+
+#endif
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index f8185cf..1effed1 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -226,7 +226,8 @@ class PluginDelegate {
virtual PlatformVideoDecoder* CreateVideoDecoder(
const PP_VideoDecoderConfig_Dev& decoder_config) = 0;
- // The caller will own the pointer returned from this.
+ // The caller is responsible for calling Shutdown() on the returned pointer
+ // to clean up the corresponding resources allocated during this call.
virtual PlatformAudio* CreateAudio(uint32_t sample_rate,
uint32_t sample_count,
PlatformAudio::Client* client) = 0;
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc
index 1a36e70..0d4f852 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_impl.cc
@@ -220,7 +220,11 @@ PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance)
}
PPB_Audio_Impl::~PPB_Audio_Impl() {
- // Calling ShutDown() makes sure StreamCreated cannot be called anymore.
+ // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
+ // releases the audio data associated with the pointer. Note however, that
+ // until ShutDown returns, StreamCreated may still be called. This will be
+ // OK since we'll just immediately clean up the data it stored later in this
+ // destructor.
if (audio_) {
audio_->ShutDown();
audio_ = NULL;
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h
index cc0c112..9590034 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.h
+++ b/webkit/plugins/ppapi/ppb_audio_impl.h
@@ -81,7 +81,8 @@ class PPB_Audio_Impl : public Resource,
// AudioConfig used for creating this Audio object.
scoped_refptr<PPB_AudioConfig_Impl> config_;
- // PluginDelegate audio object that we delegate audio IPC through.
+ // PluginDelegate audio object that we delegate audio IPC through. We don't
+ // own this pointer but are responsible for calling Shutdown on it.
PluginDelegate::PlatformAudio* audio_;
// Is a create callback pending to fire?
diff --git a/webkit/plugins/ppapi/ppb_url_util_impl.cc b/webkit/plugins/ppapi/ppb_url_util_impl.cc
index 4faf30f..674dafd 100644
--- a/webkit/plugins/ppapi/ppb_url_util_impl.cc
+++ b/webkit/plugins/ppapi/ppb_url_util_impl.cc
@@ -6,6 +6,8 @@
#include "googleurl/src/gurl.h"
#include "ppapi/c/dev/ppb_url_util_dev.h"
+#include "ppapi/c/ppb_var.h"
+#include "ppapi/shared_impl/url_util_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
@@ -14,6 +16,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
#include "webkit/plugins/ppapi/string.h"
@@ -22,39 +25,23 @@
namespace webkit {
namespace ppapi {
-namespace {
+using pp::shared_impl::URLUtilImpl;
-void ConvertComponent(const url_parse::Component& input,
- PP_URLComponent_Dev* output) {
- output->begin = input.begin;
- output->len = input.len;
-}
+namespace {
-// Output can be NULL to specify "do nothing." This rule is followed by all the
-// url util functions, so we implement it once here.
-void ConvertComponents(const url_parse::Parsed& input,
- PP_URLComponents_Dev* output) {
- if (!output)
- return;
-
- ConvertComponent(input.scheme, &output->scheme);
- ConvertComponent(input.username, &output->username);
- ConvertComponent(input.password, &output->password);
- ConvertComponent(input.host, &output->host);
- ConvertComponent(input.port, &output->port);
- ConvertComponent(input.path, &output->path);
- ConvertComponent(input.query, &output->query);
- ConvertComponent(input.ref, &output->ref);
+// Returns the PP_Module associated with the given string, or 0 on failure.
+PP_Module GetModuleFromVar(PP_Var string_var) {
+ scoped_refptr<StringVar> str(StringVar::FromPPVar(string_var));
+ if (!str)
+ return 0;
+ return str->module()->pp_module();
}
-// Used for returning the given GURL from a PPAPI function, with an optional
-// out param indicating the components.
-PP_Var GenerateURLReturn(PluginModule* module, const GURL& url,
- PP_URLComponents_Dev* components) {
- if (!url.is_valid())
- return PP_MakeNull();
- ConvertComponents(url.parsed_for_possibly_invalid_spec(), components);
- return StringVar::StringToPPVar(module, url.possibly_invalid_spec());
+const std::string* StringFromVar(PP_Var var) {
+ scoped_refptr<StringVar> string(StringVar::FromPPVar(var));
+ if (!string)
+ return NULL;
+ return &string->value();
}
// Sets |*security_origin| to be the WebKit security origin associated with the
@@ -77,27 +64,19 @@ bool SecurityOriginForInstance(PP_Instance instance_id,
}
PP_Var Canonicalize(PP_Var url, PP_URLComponents_Dev* components) {
- scoped_refptr<StringVar> url_string(StringVar::FromPPVar(url));
- if (!url_string)
- return PP_MakeNull();
- return GenerateURLReturn(url_string->module(),
- GURL(url_string->value()), components);
+ return URLUtilImpl::Canonicalize(&StringFromVar,
+ Var::GetInterface()->VarFromUtf8,
+ GetModuleFromVar(url),
+ url, components);
}
PP_Var ResolveRelativeToURL(PP_Var base_url,
PP_Var relative,
PP_URLComponents_Dev* components) {
- scoped_refptr<StringVar> base_url_string(StringVar::FromPPVar(base_url));
- scoped_refptr<StringVar> relative_string(StringVar::FromPPVar(relative));
- if (!base_url_string || !relative_string)
- return PP_MakeNull();
-
- GURL base_gurl(base_url_string->value());
- if (!base_gurl.is_valid())
- return PP_MakeNull();
- return GenerateURLReturn(base_url_string->module(),
- base_gurl.Resolve(relative_string->value()),
- components);
+ return URLUtilImpl::ResolveRelativeToURL(&StringFromVar,
+ Var::GetInterface()->VarFromUtf8,
+ GetModuleFromVar(base_url),
+ base_url, relative, components);
}
PP_Var ResolveRelativeToDocument(PP_Instance instance_id,
@@ -113,23 +92,15 @@ PP_Var ResolveRelativeToDocument(PP_Instance instance_id,
WebKit::WebElement plugin_element = instance->container()->element();
GURL document_url = plugin_element.document().baseURL();
- return GenerateURLReturn(instance->module(),
- document_url.Resolve(relative_string->value()),
- components);
+ return URLUtilImpl::GenerateURLReturn(
+ Var::GetInterface()->VarFromUtf8,
+ instance->module()->pp_module(),
+ document_url.Resolve(relative_string->value()),
+ components);
}
PP_Bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) {
- scoped_refptr<StringVar> url_a_string(StringVar::FromPPVar(url_a));
- scoped_refptr<StringVar> url_b_string(StringVar::FromPPVar(url_b));
- if (!url_a_string || !url_b_string)
- return PP_FALSE;
-
- GURL gurl_a(url_a_string->value());
- GURL gurl_b(url_b_string->value());
- if (!gurl_a.is_valid() || !gurl_b.is_valid())
- return PP_FALSE;
-
- return BoolToPPBool(gurl_a.GetOrigin() == gurl_b.GetOrigin());
+ return URLUtilImpl::IsSameSecurityOrigin(&StringFromVar, url_a, url_b);
}
PP_Bool DocumentCanRequest(PP_Instance instance, PP_Var url) {
@@ -170,7 +141,9 @@ PP_Var GetDocumentURL(PP_Instance instance_id,
if (!frame)
return PP_MakeNull();
- return GenerateURLReturn(instance->module(), frame->url(), components);
+ return URLUtilImpl::GenerateURLReturn(Var::GetInterface()->VarFromUtf8,
+ instance->module()->pp_module(),
+ frame->url(), components);
}
const PPB_URLUtil_Dev ppb_url_util = {