Index: webkit/plugins/ppapi/ppb_url_util_impl.cc |
=================================================================== |
--- webkit/plugins/ppapi/ppb_url_util_impl.cc (revision 78515) |
+++ webkit/plugins/ppapi/ppb_url_util_impl.cc (working copy) |
@@ -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,41 +25,25 @@ |
namespace webkit { |
namespace ppapi { |
+using pp::shared_impl::URLUtilImpl; |
+ |
namespace { |
-void ConvertComponent(const url_parse::Component& input, |
- PP_URLComponent_Dev* output) { |
- output->begin = input.begin; |
- output->len = input.len; |
+// 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(); |
} |
-// 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); |
+const std::string* StringFromVar(PP_Var var) { |
+ scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); |
+ if (!string) |
+ return NULL; |
+ return &string->value(); |
} |
-// 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()); |
-} |
- |
// Sets |*security_origin| to be the WebKit security origin associated with the |
// document containing the given plugin instance. On success, returns true. If |
// the instance is invalid, returns false and |*security_origin| will be |
@@ -77,27 +64,19 @@ |
} |
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 @@ |
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 @@ |
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 = { |