diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 22:56:03 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 22:56:03 +0000 |
commit | 39ef434b2a6dfe7ff3ae252a681bc7ccabdaf94f (patch) | |
tree | ce014e395174bc4b68b240081ec6cdc9bcd8ed1c /webkit | |
parent | 903b6f5823dfaa8d3d287096726715bcc34c2714 (diff) | |
download | chromium_src-39ef434b2a6dfe7ff3ae252a681bc7ccabdaf94f.zip chromium_src-39ef434b2a6dfe7ff3ae252a681bc7ccabdaf94f.tar.gz chromium_src-39ef434b2a6dfe7ff3ae252a681bc7ccabdaf94f.tar.bz2 |
Implement the UrlUtil pepper interface. Pull PPAPI to get that interface.
TEST=unit test included
Review URL: http://codereview.chromium.org/3041048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_util.cc | 171 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_url_util.h | 16 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 |
4 files changed, 193 insertions, 0 deletions
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index df7c3e26..3e21d0a 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -27,6 +27,7 @@ #include "third_party/ppapi/c/ppb_url_loader.h" #include "third_party/ppapi/c/ppb_url_request_info.h" #include "third_party/ppapi/c/ppb_url_response_info.h" +#include "third_party/ppapi/c/ppb_url_util.h" #include "third_party/ppapi/c/ppb_var.h" #include "third_party/ppapi/c/ppb_widget.h" #include "third_party/ppapi/c/ppp.h" @@ -51,6 +52,7 @@ #include "webkit/glue/plugins/pepper_url_loader.h" #include "webkit/glue/plugins/pepper_url_request_info.h" #include "webkit/glue/plugins/pepper_url_response_info.h" +#include "webkit/glue/plugins/pepper_url_util.h" #include "webkit/glue/plugins/pepper_var.h" #include "webkit/glue/plugins/pepper_widget.h" #include "webkit/glue/plugins/ppb_private.h" @@ -192,6 +194,8 @@ const void* GetInterface(const char* name) { return Font::GetInterface(); if (strcmp(name, PPB_FIND_INTERFACE) == 0) return PluginInstance::GetFindInterface(); + if (strcmp(name, PPB_URLUTIL_INTERFACE) == 0) + return GetUrlUtilInterface(); if (strcmp(name, PPB_PRIVATE_INTERFACE) == 0) return Private::GetInterface(); if (strcmp(name, PPB_FILECHOOSER_INTERFACE) == 0) diff --git a/webkit/glue/plugins/pepper_url_util.cc b/webkit/glue/plugins/pepper_url_util.cc new file mode 100644 index 0000000..1ba091f --- /dev/null +++ b/webkit/glue/plugins/pepper_url_util.cc @@ -0,0 +1,171 @@ +// Copyright (c) 2010 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 "webkit/glue/plugins/pepper_url_util.h" + +#include "googleurl/src/gurl.h" +#include "third_party/ppapi/c/ppb_url_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" +#include "third_party/WebKit/WebKit/chromium/public/WebElement.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/WebKit/chromium/public/WebNode.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" +#include "webkit/glue/plugins/pepper_string.h" +#include "webkit/glue/plugins/pepper_var.h" + +namespace pepper { + +namespace { + +void ConvertComponent(const url_parse::Component& input, + PP_UrlComponent* output) { + output->begin = input.begin; + output->len = input.len; +} + +// 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* 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); +} + +// Used for returning the given GURL from a PPAPI function, with an optional +// out param indicating the components. +PP_Var GenerateUrlReturn(const GURL& url, PP_UrlComponents* components) { + if (!url.is_valid()) + return PP_MakeNull(); + ConvertComponents(url.parsed_for_possibly_invalid_spec(), components); + return StringToPPVar(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 +// unchanged. +bool SecurityOriginForInstance(PP_Instance instance_id, + WebKit::WebSecurityOrigin* security_origin) { + PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); + if (!instance) + return false; + + WebKit::WebElement plugin_element = instance->container()->element(); + WebKit::WebFrame* plugin_frame = plugin_element.document().frame(); + if (!plugin_frame) + return false; + + *security_origin = plugin_frame->securityOrigin(); + return true; +} + +PP_Var Canonicalize(PP_Var url, PP_UrlComponents* components) { + String* url_string = GetString(url); + if (!url_string) + return PP_MakeNull(); + return GenerateUrlReturn(GURL(url_string->value()), components); +} + +PP_Var ResolveRelativeToUrl(PP_Var base_url, + PP_Var relative, + PP_UrlComponents* components) { + String* base_url_string = GetString(base_url); + String* relative_string = GetString(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_gurl.Resolve(relative_string->value()), + components); +} + +PP_Var ResolveRelativeToDocument(PP_Instance instance_id, + PP_Var relative, + PP_UrlComponents* components) { + PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); + if (!instance) + return PP_MakeNull(); + + String* relative_string = GetString(relative); + if (!relative_string) + return PP_MakeNull(); + + WebKit::WebElement plugin_element = instance->container()->element(); + GURL document_url = plugin_element.document().baseURL(); + return GenerateUrlReturn(document_url.Resolve(relative_string->value()), + components); +} + +bool IsSameSecurityOrigin(PP_Var url_a, PP_Var url_b) { + String* url_a_string = GetString(url_a); + String* url_b_string = GetString(url_b); + if (!url_a_string || !url_b_string) + return 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 false; + + return gurl_a.GetOrigin() == gurl_b.GetOrigin(); +} + +bool DocumentCanRequest(PP_Instance instance, PP_Var url) { + String* url_string = GetString(url); + if (!url_string) + return false; + + WebKit::WebSecurityOrigin security_origin; + if (!SecurityOriginForInstance(instance, &security_origin)) + return false; + + GURL gurl(url_string->value()); + if (!gurl.is_valid()) + return false; + + return security_origin.canRequest(gurl); +} + +bool DocumentCanAccessDocument(PP_Instance active, PP_Instance target) { + WebKit::WebSecurityOrigin active_origin; + if (!SecurityOriginForInstance(active, &active_origin)) + return false; + + WebKit::WebSecurityOrigin target_origin; + if (!SecurityOriginForInstance(active, &target_origin)) + return false; + + return active_origin.canAccess(target_origin); +} + +} // namespace + +const PPB_UrlUtil ppb_url_util = { + &Canonicalize, + &ResolveRelativeToUrl, + &ResolveRelativeToDocument, + &IsSameSecurityOrigin, + &DocumentCanRequest, + &DocumentCanAccessDocument +}; + +const PPB_UrlUtil* GetUrlUtilInterface() { + return &ppb_url_util; +} + +} // namespace pepper diff --git a/webkit/glue/plugins/pepper_url_util.h b/webkit/glue/plugins/pepper_url_util.h new file mode 100644 index 0000000..d68d65a --- /dev/null +++ b/webkit/glue/plugins/pepper_url_util.h @@ -0,0 +1,16 @@ +// Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_URL_UTIL_H_ +#define WEBKIT_GLUE_PLUGINS_PEPPER_URL_UTIL_H_ + +typedef struct _ppb_UrlUtil PPB_UrlUtil; + +namespace pepper { + +const PPB_UrlUtil* GetUrlUtilInterface(); + +} // namespace pepper + +#endif // WEBKIT_GLUE_PLUGINS_PEPPER_URL_UTIL_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 7aadc4d..f098ad7 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -203,6 +203,8 @@ 'plugins/pepper_url_request_info.h', 'plugins/pepper_url_response_info.cc', 'plugins/pepper_url_response_info.h', + 'plugins/pepper_url_util.cc', + 'plugins/pepper_url_util.h', 'plugins/pepper_var.cc', 'plugins/pepper_var.h', 'plugins/pepper_webplugin_impl.cc', |