diff options
author | ygorshenin@google.com <ygorshenin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 15:29:19 +0000 |
---|---|---|
committer | ygorshenin@google.com <ygorshenin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-15 15:29:19 +0000 |
commit | 961e89716c14bd6c7e1f3394b9696ee60810a676 (patch) | |
tree | 258a13f7cbd6a8b971f2fca1aad36dbcff9b2f9a | |
parent | 292a635a2c28ac2968940fb9e15f93be45ada4dd (diff) | |
download | chromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.zip chromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.tar.gz chromium_src-961e89716c14bd6c7e1f3394b9696ee60810a676.tar.bz2 |
GetDocumentURL is added to PPB_Testing_Dev.
Fixed Test{TCP|UDP}SocketPrivateShared.
BUG=105863
TEST=
Review URL: http://codereview.chromium.org/8840007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114637 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 511 insertions, 145 deletions
diff --git a/ppapi/api/dev/ppb_testing_dev.idl b/ppapi/api/dev/ppb_testing_dev.idl index 2ec6832..9e51b42 100644 --- a/ppapi/api/dev/ppb_testing_dev.idl +++ b/ppapi/api/dev/ppb_testing_dev.idl @@ -11,7 +11,8 @@ label Chrome { M14 = 0.7, - M15 = 0.8 + M15 = 0.8, + M17 = 0.9 }; interface PPB_Testing_Dev { @@ -102,4 +103,15 @@ interface PPB_Testing_Dev { [version=0.8] void SimulateInputEvent([in] PP_Instance instance, [in] PP_Resource input_event); + + /** + * Returns the URL for the document. This is a safe way to retrieve + * window.location.href. + * If the canonicalized URL is valid, the method will parse the URL + * and fill in the components structure. This pointer may be NULL + * to specify that no component information is necessary. + */ + [version=0.9] + PP_Var GetDocumentURL([in] PP_Instance instance, + [out] PP_URLComponents_Dev components); }; diff --git a/ppapi/api/dev/ppb_url_util_dev.idl b/ppapi/api/dev/ppb_url_util_dev.idl new file mode 100644 index 0000000..cd698e4 --- /dev/null +++ b/ppapi/api/dev/ppb_url_util_dev.idl @@ -0,0 +1,149 @@ +/* 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. + */ + +/** + * This file defines the <code>PPB_URLUtil_Dev</code> interface. + */ + +label Chrome { + M17 = 0.6 +}; + +/* + * A component specifies the range of the part of the URL. The begin specifies + * the index into the string of the first character of that component. The len + * specifies the length of that component. + * + * This range does not include any special delimiter for that component, so + * the scheme doesn't include the trailing colon, the username and password + * don't include the @ and :, the port doesn't include the colon, the query + * doesn't include the ?, and the ref doesn't include the #. + * + * The exception is that the path *does* include the first /, since that's an + * integral part of the path. + * + * If the component is not present at all, begin will be 0 and len will be -1. + * If the component is present but empty, the length will be 0 instead. Example: + * http://foo/search -> query = (0, -1) + * http://foo/search? -> query = (18, 0) + */ +[assert_size(8)] +struct PP_URLComponent_Dev { + int32_t begin; + int32_t len; +}; + +[assert_size(64)] +struct PP_URLComponents_Dev { + PP_URLComponent_Dev scheme; + PP_URLComponent_Dev username; + PP_URLComponent_Dev password; + PP_URLComponent_Dev host; + PP_URLComponent_Dev port; + PP_URLComponent_Dev path; + PP_URLComponent_Dev query; + PP_URLComponent_Dev ref; +}; + +/* + * URL encoding: URLs are supplied to this interface as NULL-terminated 8-bit + * strings. You can pass non-ASCII characters which will be interpreted as + * UTF-8. Canonicalized URL strings returned by these functions will be ASCII + * except for the reference fragment (stuff after the '#') which will be + * encoded as UTF-8. + */ +interface PPB_URLUtil_Dev { + /* + * Canonicalizes the given URL string according to the rules of the host + * browser. If the URL is invalid or the var is not a string, this will + * return a Null var and the components structure will be unchanged. + * + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ + PP_Var Canonicalize([in] PP_Var url, [out] PP_URLComponents_Dev components); + + /* + * Resolves the given URL relative to the given base URL. The resulting URL + * is returned as a string. If the resolution is invalid or either of the + * inputs are not strings, a Null var will be returned. The resulting URL + * will also be canonicalized according to the rules of the browser. + * + * Note that the "relative" URL may in fact be absolute, in which case it + * will be returned. This function is identical to resolving the full URL + * for an <a href="..."> on a web page. Attempting to resolve a relative URL + * on a base URL that doesn't support this (e.g. "data") will fail and will + * return a Null var, unless the relative URL is itself absolute. + * + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ + PP_Var ResolveRelativeToURL( + [in] PP_Var base_url, + [in] PP_Var relative_string, + [out] PP_URLComponents_Dev components); + + /* + * Identical to ResolveRelativeToURL except that the base URL is the base + * URL of the document containing the given plugin instance. + * + * Danger: This will be identical to resolving a relative URL on the page, + * and might be overridden by the page to something different than its actual + * URL via the <base> tag. Therefore, resolving a relative URL of "" won't + * necessarily give you the URL of the page! + */ + PP_Var ResolveRelativeToDocument( + [in] PP_Instance instance, + [in] PP_Var relative_string, + [out] PP_URLComponents_Dev components); + + /* + * Checks whether the given two URLs are in the same security origin. Returns + * FALSE if either of the URLs are invalid. + */ + PP_Bool IsSameSecurityOrigin([in] PP_Var url_a, [in] PP_Var url_b); + + /* + * Checks whether the document hosting the given plugin instance can access + * the given URL according to the same origin policy of the browser. Returns + * PP_FALSE if the instance or the URL is invalid. + */ + PP_Bool DocumentCanRequest([in] PP_Instance instance, [in] PP_Var url); + + /* + * Checks whether the document containing the |active| plugin instance can + * access the document containing the |target| plugin instance according to + * the security policy of the browser. This includes the same origin policy + * and any cross-origin capabilities enabled by the document. If either of + * the plugin instances are invalid, returns PP_FALSE. + */ + PP_Bool DocumentCanAccessDocument([in] PP_Instance active, + [in] PP_Instance target); + + /* + * Returns the URL for the document. This is a safe way to retrieve + * window.location.href. + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ + PP_Var GetDocumentURL([in] PP_Instance instance, + [out] PP_URLComponents_Dev components); + + /* + * Returns the Source URL for the plugin. This returns the URL that would be + * streamed to the plugin if it were a NPAPI plugin. This is usually the src + * attribute on the <embed> element, but the rules are obscure and different + * based on whether the plugin is loaded from an <embed> element or an + * <object> element. + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ + PP_Var GetPluginInstanceURL([in] PP_Instance instance, + [out] PP_URLComponents_Dev components); +}; diff --git a/ppapi/c/dev/ppb_testing_dev.h b/ppapi/c/dev/ppb_testing_dev.h index a494e28..c892f6b 100644 --- a/ppapi/c/dev/ppb_testing_dev.h +++ b/ppapi/c/dev/ppb_testing_dev.h @@ -3,21 +3,24 @@ * found in the LICENSE file. */ -/* From dev/ppb_testing_dev.idl modified Sat Nov 19 15:58:18 2011. */ +/* From dev/ppb_testing_dev.idl modified Wed Dec 14 12:58:12 2011. */ #ifndef PPAPI_C_DEV_PPB_TESTING_DEV_H_ #define PPAPI_C_DEV_PPB_TESTING_DEV_H_ +#include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_macros.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" #define PPB_TESTING_DEV_INTERFACE_0_7 "PPB_Testing(Dev);0.7" #define PPB_TESTING_DEV_INTERFACE_0_8 "PPB_Testing(Dev);0.8" -#define PPB_TESTING_DEV_INTERFACE PPB_TESTING_DEV_INTERFACE_0_8 +#define PPB_TESTING_DEV_INTERFACE_0_9 "PPB_Testing(Dev);0.9" +#define PPB_TESTING_DEV_INTERFACE PPB_TESTING_DEV_INTERFACE_0_9 /** * @file @@ -112,6 +115,15 @@ struct PPB_Testing_Dev { * performs. */ void (*SimulateInputEvent)(PP_Instance instance, PP_Resource input_event); + /** + * Returns the URL for the document. This is a safe way to retrieve + * window.location.href. + * If the canonicalized URL is valid, the method will parse the URL + * and fill in the components structure. This pointer may be NULL + * to specify that no component information is necessary. + */ + struct PP_Var (*GetDocumentURL)(PP_Instance instance, + struct PP_URLComponents_Dev* components); }; struct PPB_Testing_Dev_0_7 { @@ -123,6 +135,17 @@ struct PPB_Testing_Dev_0_7 { uint32_t (*GetLiveObjectsForInstance)(PP_Instance instance); PP_Bool (*IsOutOfProcess)(); }; + +struct PPB_Testing_Dev_0_8 { + PP_Bool (*ReadImageData)(PP_Resource device_context_2d, + PP_Resource image, + const struct PP_Point* top_left); + void (*RunMessageLoop)(PP_Instance instance); + void (*QuitMessageLoop)(PP_Instance instance); + uint32_t (*GetLiveObjectsForInstance)(PP_Instance instance); + PP_Bool (*IsOutOfProcess)(); + void (*SimulateInputEvent)(PP_Instance instance, PP_Resource input_event); +}; /** * @} */ diff --git a/ppapi/c/dev/ppb_url_util_dev.h b/ppapi/c/dev/ppb_url_util_dev.h index fbdb5480..26bddf1 100644 --- a/ppapi/c/dev/ppb_url_util_dev.h +++ b/ppapi/c/dev/ppb_url_util_dev.h @@ -2,6 +2,9 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + +/* From dev/ppb_url_util_dev.idl modified Wed Dec 7 17:25:52 2011. */ + #ifndef PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ #define PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ @@ -14,22 +17,34 @@ #define PPB_URLUTIL_DEV_INTERFACE_0_6 "PPB_URLUtil(Dev);0.6" #define PPB_URLUTIL_DEV_INTERFACE PPB_URLUTIL_DEV_INTERFACE_0_6 -// A component specifies the range of the part of the URL. The begin specifies -// the index into the string of the first character of that component. The len -// specifies the length of that component. -// -// This range does not include any special delimiter for that component, so -// the scheme doesn't include the trailing colon, the username and password -// don't include the @ and :, the port doesn't include the colon, the query -// doesn't include the ?, and the ref doesn't include the #. -// -// The exception is that the path *does* include the first /, since that's an -// integral part of the path. -// -// If the component is not present at all, begin will be 0 and len will be -1. -// If the component is present but empty, the length will be 0 instead. Example: -// http://foo/search -> query = (0, -1) -// http://foo/search? -> query = (18, 0) +/** + * @file + * This file defines the <code>PPB_URLUtil_Dev</code> interface. + */ + + +/** + * @addtogroup Structs + * @{ + */ +/* + * A component specifies the range of the part of the URL. The begin specifies + * the index into the string of the first character of that component. The len + * specifies the length of that component. + * + * This range does not include any special delimiter for that component, so + * the scheme doesn't include the trailing colon, the username and password + * don't include the @ and :, the port doesn't include the colon, the query + * doesn't include the ?, and the ref doesn't include the #. + * + * The exception is that the path *does* include the first /, since that's an + * integral part of the path. + * + * If the component is not present at all, begin will be 0 and len will be -1. + * If the component is present but empty, the length will be 0 instead. Example: + * http://foo/search -> query = (0, -1) + * http://foo/search? -> query = (18, 0) + */ struct PP_URLComponent_Dev { int32_t begin; int32_t len; @@ -47,89 +62,111 @@ struct PP_URLComponents_Dev { struct PP_URLComponent_Dev ref; }; PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_URLComponents_Dev, 64); +/** + * @} + */ -// URL encoding: URLs are supplied to this interface as NULL-terminated 8-bit -// strings. You can pass non-ASCII characters which will be interpreted as -// UTF-8. Canonicalized URL strings returned by these functions will be ASCII -// except for the reference fragment (stuff after the '#') which will be -// encoded as UTF-8. +/** + * @addtogroup Interfaces + * @{ + */ +/* + * URL encoding: URLs are supplied to this interface as NULL-terminated 8-bit + * strings. You can pass non-ASCII characters which will be interpreted as + * UTF-8. Canonicalized URL strings returned by these functions will be ASCII + * except for the reference fragment (stuff after the '#') which will be + * encoded as UTF-8. + */ struct PPB_URLUtil_Dev { - // Canonicalizes the given URL string according to the rules of the host - // browser. If the URL is invalid or the var is not a string, this will - // return a Null var and the components structure will be unchanged. - // - // The components pointer, if non-NULL and the canonicalized URL is valid, - // will identify the components of the resulting URL. Components may be NULL - // to specify that no component information is necessary. + /* + * Canonicalizes the given URL string according to the rules of the host + * browser. If the URL is invalid or the var is not a string, this will + * return a Null var and the components structure will be unchanged. + * + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ struct PP_Var (*Canonicalize)(struct PP_Var url, struct PP_URLComponents_Dev* components); - - // Resolves the given URL relative to the given base URL. The resulting URL - // is returned as a string. If the resolution is invalid or either of the - // inputs are not strings, a Null var will be returned. The resulting URL - // will also be canonicalized according to the rules of the browser. - // - // Note that the "relative" URL may in fact be absolute, in which case it - // will be returned. This function is identical to resolving the full URL - // for an <a href="..."> on a web page. Attempting to resolve a relative URL - // on a base URL that doesn't support this (e.g. "data") will fail and will - // return a Null var, unless the relative URL is itself absolute. - // - // The components pointer, if non-NULL and the canonicalized URL is valid, - // will identify the components of the resulting URL. Components may be NULL - // to specify that no component information is necessary. + /* + * Resolves the given URL relative to the given base URL. The resulting URL + * is returned as a string. If the resolution is invalid or either of the + * inputs are not strings, a Null var will be returned. The resulting URL + * will also be canonicalized according to the rules of the browser. + * + * Note that the "relative" URL may in fact be absolute, in which case it + * will be returned. This function is identical to resolving the full URL + * for an <a href="..."> on a web page. Attempting to resolve a relative URL + * on a base URL that doesn't support this (e.g. "data") will fail and will + * return a Null var, unless the relative URL is itself absolute. + * + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ struct PP_Var (*ResolveRelativeToURL)( struct PP_Var base_url, struct PP_Var relative_string, struct PP_URLComponents_Dev* components); - - // Identical to ResolveRelativeToURL except that the base URL is the base - // URL of the document containing the given plugin instance. - // - // Danger: This will be identical to resolving a relative URL on the page, - // and might be overridden by the page to something different than its actual - // URL via the <base> tag. Therefore, resolving a relative URL of "" won't - // necessarily give you the URL of the page! + /* + * Identical to ResolveRelativeToURL except that the base URL is the base + * URL of the document containing the given plugin instance. + * + * Danger: This will be identical to resolving a relative URL on the page, + * and might be overridden by the page to something different than its actual + * URL via the <base> tag. Therefore, resolving a relative URL of "" won't + * necessarily give you the URL of the page! + */ struct PP_Var (*ResolveRelativeToDocument)( PP_Instance instance, struct PP_Var relative_string, struct PP_URLComponents_Dev* components); - - // Checks whether the given two URLs are in the same security origin. Returns - // FALSE if either of the URLs are invalid. + /* + * Checks whether the given two URLs are in the same security origin. Returns + * FALSE if either of the URLs are invalid. + */ PP_Bool (*IsSameSecurityOrigin)(struct PP_Var url_a, struct PP_Var url_b); - - // Checks whether the document hosting the given plugin instance can access - // the given URL according to the same origin policy of the browser. Returns - // PP_FALSE if the instance or the URL is invalid. + /* + * Checks whether the document hosting the given plugin instance can access + * the given URL according to the same origin policy of the browser. Returns + * PP_FALSE if the instance or the URL is invalid. + */ PP_Bool (*DocumentCanRequest)(PP_Instance instance, struct PP_Var url); - - // Checks whether the document containing the |active| plugin instance can - // access the document containing the |target| plugin instance according to - // the security policy of the browser. This includes the same origin policy - // and any cross-origin capabilities enabled by the document. If either of - // the plugin instances are invalid, returns PP_FALSE. + /* + * Checks whether the document containing the |active| plugin instance can + * access the document containing the |target| plugin instance according to + * the security policy of the browser. This includes the same origin policy + * and any cross-origin capabilities enabled by the document. If either of + * the plugin instances are invalid, returns PP_FALSE. + */ PP_Bool (*DocumentCanAccessDocument)(PP_Instance active, PP_Instance target); - - // Returns the URL for the document. This is a safe way to retrieve - // window.location.href. - // The components pointer, if non-NULL and the canonicalized URL is valid, - // will identify the components of the resulting URL. Components may be NULL - // to specify that no component information is necessary. + /* + * Returns the URL for the document. This is a safe way to retrieve + * window.location.href. + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ struct PP_Var (*GetDocumentURL)(PP_Instance instance, struct PP_URLComponents_Dev* components); - - // Returns the Source URL for the plugin. This returns the URL that would be - // streamed to the plugin if it were a NPAPI plugin. This is usually the src - // attribute on the <embed> element, but the rules are obscure and different - // based on whether the plugin is loaded from an <embed> element or an - // <object> element. - // The components pointer, if non-NULL and the canonicalized URL is valid, - // will identify the components of the resulting URL. Components may be NULL - // to specify that no component information is necessary. + /* + * Returns the Source URL for the plugin. This returns the URL that would be + * streamed to the plugin if it were a NPAPI plugin. This is usually the src + * attribute on the <embed> element, but the rules are obscure and different + * based on whether the plugin is loaded from an <embed> element or an + * <object> element. + * The components pointer, if non-NULL and the canonicalized URL is valid, + * will identify the components of the resulting URL. Components may be NULL + * to specify that no component information is necessary. + */ struct PP_Var (*GetPluginInstanceURL)( - PP_Instance instance, struct PP_URLComponents_Dev* components); + PP_Instance instance, + struct PP_URLComponents_Dev* components); }; +/** + * @} + */ #endif /* PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ */ diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc index ceb8aae..69b04a0 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc @@ -14,6 +14,7 @@ #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_point.h" +#include "ppapi/cpp/var.h" #include "srpcgen/ppb_rpc.h" using ppapi_proxy::DebugPrintf; @@ -90,4 +91,27 @@ void PpbTestingRpcServer::PPB_Testing_GetLiveObjectsForInstance( rpc->result = NACL_SRPC_RESULT_OK; } +void PpbTestingRpcServer::PPB_Testing_GetDocumentURL( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + nacl_abi_size_t* components_bytes, char* components, + nacl_abi_size_t* url_bytes, char* url) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + if (*components_bytes != sizeof(struct PP_URLComponents_Dev)) + return; + if (*url_bytes != ppapi_proxy::kMaxVarSize) + return; + + struct PP_Var pp_url = PPBTestingInterface()->GetDocumentURL( + instance, reinterpret_cast<struct PP_URLComponents_Dev*>(components)); + + if (!ppapi_proxy::SerializeTo(&pp_url, url, url_bytes)) + return; + + DebugPrintf("PPB_Testing_Dev::GetDocumentURL: url=%s\n", + pp::Var(pp::Var::PassRef(), pp_url).AsString().c_str()); + rpc->result = NACL_SRPC_RESULT_OK; +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc index c0fe3c1..ab894f7 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -85,6 +85,7 @@ InterfaceMapElement interface_map[] = { true }, { PPB_TESTING_DEV_INTERFACE_0_7, PluginTesting::GetInterface(), true }, { PPB_TESTING_DEV_INTERFACE_0_8, PluginTesting::GetInterface(), true }, + { PPB_TESTING_DEV_INTERFACE_0_9, PluginTesting::GetInterface(), true }, { PPB_UDPSOCKET_PRIVATE_INTERFACE, PluginUDPSocketPrivate::GetInterface(), true }, { PPB_URLLOADER_INTERFACE, PluginURLLoader::GetInterface(), true }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc index 7c5a8a6..6b928ec 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc @@ -4,6 +4,9 @@ #include "native_client/src/shared/ppapi_proxy/plugin_ppb_testing.h" +#include <cstddef> +#include <new> + #include "native_client/src/include/nacl_scoped_ptr.h" #include "native_client/src/include/portability.h" #include "native_client/src/shared/ppapi_proxy/object_serialize.h" @@ -23,6 +26,8 @@ namespace { const nacl_abi_size_t kPPPointBytes = static_cast<nacl_abi_size_t>(sizeof(struct PP_Point)); +const nacl_abi_size_t kPPURLComponentsDevBytes = + static_cast<nacl_abi_size_t>(sizeof(struct PP_URLComponents_Dev)); PP_Bool ReadImageData(PP_Resource device_context_2d, PP_Resource image, @@ -97,6 +102,35 @@ PP_Bool IsOutOfProcess() { return PP_FALSE; } +struct PP_Var GetDocumentURL(PP_Instance instance, + struct PP_URLComponents_Dev* components) { + DebugPrintf("PPB_Testing::GetDocumentURL: " + "instance=%"NACL_PRIu32"\n", instance); + + NaClSrpcChannel* channel = GetMainSrpcChannel(); + nacl_abi_size_t components_size = kPPURLComponentsDevBytes; + nacl_abi_size_t url_size = kMaxVarSize; + nacl::scoped_array<char> url_bytes(new (std::nothrow) char[url_size]); + if (url_bytes.get() == NULL) + return PP_MakeUndefined(); + + NaClSrpcError srpc_result = + PpbTestingRpcClient::PPB_Testing_GetDocumentURL( + channel, + instance, + &components_size, reinterpret_cast<char*>(components), + &url_size, url_bytes.get()); + + struct PP_Var url = PP_MakeUndefined(); + if (srpc_result == NACL_SRPC_RESULT_OK) + (void) DeserializeTo(url_bytes.get(), url_size, 1, &url); + + DebugPrintf("PPB_Testing::GetDocumentURL: %s\n", + NaClSrpcErrorString(srpc_result)); + + return url; +} + } // namespace const PPB_Testing_Dev* PluginTesting::GetInterface() { @@ -105,7 +139,9 @@ const PPB_Testing_Dev* PluginTesting::GetInterface() { RunMessageLoop, QuitMessageLoop, GetLiveObjectsForInstance, - IsOutOfProcess + IsOutOfProcess, + NULL, + GetDocumentURL }; return &testing_interface; } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index e5739ba..97f0155 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -2553,6 +2553,25 @@ NaClSrpcError PpbTestingRpcClient::PPB_Testing_GetLiveObjectsForInstance( return retval; } +NaClSrpcError PpbTestingRpcClient::PPB_Testing_GetDocumentURL( + NaClSrpcChannel* channel, + PP_Instance instance, + nacl_abi_size_t* components_bytes, char* components, + nacl_abi_size_t* url_bytes, char* url) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_Testing_GetDocumentURL:i:CC", + instance, + components_bytes, components, + url_bytes, url + ); + return retval; +} + NaClSrpcError PpbUDPSocketPrivateRpcClient::PPB_UDPSocket_Private_Create( NaClSrpcChannel* channel, PP_Instance instance_id, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index b40fd2d..60936f0 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -2056,6 +2056,21 @@ static void PPB_Testing_GetLiveObjectsForInstanceDispatcher( ); } +static void PPB_Testing_GetDocumentURLDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbTestingRpcServer::PPB_Testing_GetDocumentURL( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr, + &(outputs[1]->u.count), outputs[1]->arrays.carr + ); +} + static void PPB_UDPSocket_Private_CreateDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -2677,6 +2692,7 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_Testing_RunMessageLoop:i:", PPB_Testing_RunMessageLoopDispatcher }, { "PPB_Testing_QuitMessageLoop:i:", PPB_Testing_QuitMessageLoopDispatcher }, { "PPB_Testing_GetLiveObjectsForInstance:i:i", PPB_Testing_GetLiveObjectsForInstanceDispatcher }, + { "PPB_Testing_GetDocumentURL:i:CC", PPB_Testing_GetDocumentURLDispatcher }, { "PPB_UDPSocket_Private_Create:i:i", PPB_UDPSocket_Private_CreateDispatcher }, { "PPB_UDPSocket_Private_IsUDPSocket:i:i", PPB_UDPSocket_Private_IsUDPSocketDispatcher }, { "PPB_UDPSocket_Private_Bind:iCi:i", PPB_UDPSocket_Private_BindDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc index 305fffc..ceb62f7 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc @@ -33,5 +33,12 @@ 'outputs': [['live_object_count', 'int32_t'], # uint32_t ] }, + {'name': 'PPB_Testing_GetDocumentURL', + 'inputs': [['instance', 'PP_Instance'], + ], + 'outputs': [['components', 'char[]'], # PP_URLComponents_Dev + ['url', 'char[]'], # PP_Var + ] + }, ] } diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 588be46..97cd7b3 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -1021,6 +1021,12 @@ class PpbTestingRpcServer { NaClSrpcClosure* done, PP_Instance instance, int32_t* live_object_count); + static void PPB_Testing_GetDocumentURL( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + nacl_abi_size_t* components_bytes, char* components, + nacl_abi_size_t* url_bytes, char* url); private: PpbTestingRpcServer(); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index 1eee263..6085308 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -888,6 +888,11 @@ class PpbTestingRpcClient { NaClSrpcChannel* channel, PP_Instance instance, int32_t* live_object_count); + static NaClSrpcError PPB_Testing_GetDocumentURL( + NaClSrpcChannel* channel, + PP_Instance instance, + nacl_abi_size_t* components_bytes, char* components, + nacl_abi_size_t* url_bytes, char* url); private: PpbTestingRpcClient(); diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc index bb9bad0..77d1af0 100644 --- a/ppapi/proxy/ppb_testing_proxy.cc +++ b/ppapi/proxy/ppb_testing_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_input_event_api.h" +using ppapi::thunk::EnterInstance; using ppapi::thunk::EnterResource; using ppapi::thunk::PPB_InputEvent_API; @@ -87,13 +88,21 @@ void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) { API_ID_PPB_TESTING, instance_id, input_event_data)); } +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); +} + const PPB_Testing_Dev testing_interface = { &ReadImageData, &RunMessageLoop, &QuitMessageLoop, &GetLiveObjectsForInstance, &IsOutOfProcess, - &SimulateInputEvent + &SimulateInputEvent, + &GetDocumentURL }; InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) { diff --git a/ppapi/tests/test_tcp_socket_private_shared.cc b/ppapi/tests/test_tcp_socket_private_shared.cc index a052118..013aa89 100644 --- a/ppapi/tests/test_tcp_socket_private_shared.cc +++ b/ppapi/tests/test_tcp_socket_private_shared.cc @@ -4,9 +4,6 @@ #include "ppapi/tests/test_tcp_socket_private_shared.h" -#include <string.h> -#include <new> -#include <string> #include <vector> #include "ppapi/cpp/module.h" @@ -15,10 +12,6 @@ REGISTER_TEST_CASE(TCPSocketPrivateShared); -// TODO(ygorshenin): get rid of using external server in tests, -// http://crbug.com/105863 -const char* const TestTCPSocketPrivateShared::kHost = "www.google.com"; - TestTCPSocketPrivateShared::TestTCPSocketPrivateShared( TestingInstance* instance) : TestCase(instance), tcp_socket_private_interface_(NULL) { @@ -29,7 +22,16 @@ bool TestTCPSocketPrivateShared::Init() { pp::Module::Get()->GetBrowserInterface(PPB_TCPSOCKET_PRIVATE_INTERFACE)); if (!tcp_socket_private_interface_) instance_->AppendError("TCPSocketPrivate interface not available"); - return tcp_socket_private_interface_ && InitTestingInterface(); + + bool init_host_port = false; + if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) + instance_->AppendError("Can't init host and port"); + else + init_host_port = true; + + return tcp_socket_private_interface_ && + init_host_port && + InitTestingInterface(); } void TestTCPSocketPrivateShared::RunTests(const std::string& filter) { @@ -53,12 +55,12 @@ std::string TestTCPSocketPrivateShared::CreateSocket(PP_Resource* socket) { } std::string TestTCPSocketPrivateShared::SyncConnect(PP_Resource socket, - const char* host, - int port) { + const std::string& host, + uint16_t port) { TestCompletionCallback callback(instance_->pp_instance(), force_async_); int32_t rv = tcp_socket_private_interface_->Connect( - socket, host, port, + socket, host.c_str(), port, static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) @@ -88,24 +90,6 @@ std::string TestTCPSocketPrivateShared::SyncConnectWithNetAddress( PASS(); } -std::string TestTCPSocketPrivateShared::SyncSSLHandshake(PP_Resource socket, - const char* host, - int port) { - TestCompletionCallback callback(instance_->pp_instance(), force_async_); - - int32_t rv = tcp_socket_private_interface_->SSLHandshake( - socket, host, port, - static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); - - if (force_async_ && rv != PP_OK_COMPLETIONPENDING) - return ReportError("PPB_TCPSocket_Private::SSLHandshake force_async", rv); - if (rv == PP_OK_COMPLETIONPENDING) - rv = callback.WaitForResult(); - if (rv != PP_OK) - return ReportError("PPB_TCPSocket_Private::SSLHandshake", rv); - PASS(); -} - std::string TestTCPSocketPrivateShared::SyncRead(PP_Resource socket, char* buffer, int32_t num_bytes, @@ -189,7 +173,7 @@ std::string TestTCPSocketPrivateShared::TestGetAddress() { if (!error_message.empty()) return error_message; - error_message = SyncConnect(socket, kHost, kPort); + error_message = SyncConnect(socket, host_, port_); if (!error_message.empty()) return error_message; @@ -214,14 +198,11 @@ std::string TestTCPSocketPrivateShared::TestConnect() { error_message = CreateSocket(&socket); if (!error_message.empty()) return error_message; - error_message = SyncConnect(socket, kHost, kPort); - if (!error_message.empty()) - return error_message; - error_message = SyncSSLHandshake(socket, kHost, kPort); + error_message = SyncConnect(socket, host_, port_); if (!error_message.empty()) return error_message; error_message = - CheckHTTPResponse(socket, "GET /robots.txt\r\n", "HTTP/1.0 200 OK"); + CheckHTTPResponse(socket, "GET / HTTP/1.0\r\n\r\n", "HTTP/1.0 200 OK"); if (!error_message.empty()) return error_message; tcp_socket_private_interface_->Disconnect(socket); @@ -236,10 +217,7 @@ std::string TestTCPSocketPrivateShared::TestReconnect() { error_message = CreateSocket(&socket); if (!error_message.empty()) return error_message; - error_message = SyncConnect(socket, kHost, kPort); - if (!error_message.empty()) - return error_message; - error_message = SyncSSLHandshake(socket, kHost, kPort); + error_message = SyncConnect(socket, host_, port_); if (!error_message.empty()) return error_message; @@ -256,14 +234,14 @@ std::string TestTCPSocketPrivateShared::TestReconnect() { error_message = SyncConnectWithNetAddress(socket, remote_address); if (!error_message.empty()) return error_message; - error_message = SyncSSLHandshake(socket, kHost, kPort); - if (!error_message.empty()) - return error_message; - error_message = - CheckHTTPResponse(socket, "GET /robots.txt\r\n", "HTTP/1.0 200 OK"); + error_message = CheckHTTPResponse(socket, + "GET / HTTP/1.0\r\n\r\n", + "HTTP/1.0 200 OK"); if (!error_message.empty()) return error_message; tcp_socket_private_interface_->Disconnect(socket); PASS(); } + +// TODO(ygorshenin): test SSLHandshake somehow diff --git a/ppapi/tests/test_tcp_socket_private_shared.h b/ppapi/tests/test_tcp_socket_private_shared.h index 72b43b8..1285102 100644 --- a/ppapi/tests/test_tcp_socket_private_shared.h +++ b/ppapi/tests/test_tcp_socket_private_shared.h @@ -22,14 +22,11 @@ class TestTCPSocketPrivateShared : public TestCase { void QuitMessageLoop(); private: - static const char* const kHost; - static const int kPort = 443; - std::string CreateSocket(PP_Resource* socket); - std::string SyncConnect(PP_Resource socket, const char* host, int port); + std::string SyncConnect(PP_Resource socket, + const std::string& host, uint16_t port); std::string SyncConnectWithNetAddress(PP_Resource socket, const PP_NetAddress_Private& addr); - std::string SyncSSLHandshake(PP_Resource socket, const char* host, int port); std::string SyncRead(PP_Resource socket, char* buffer, int32_t num_bytes, int32_t* bytes_read); std::string SyncWrite(PP_Resource socket, const char* buffer, @@ -44,6 +41,8 @@ class TestTCPSocketPrivateShared : public TestCase { std::string TestReconnect(); const PPB_TCPSocket_Private* tcp_socket_private_interface_; + std::string host_; + uint16_t port_; }; #endif // PPAPI_TESTS_TEST_TCP_SOCKET_PRIVATE_SHARED_H_ diff --git a/ppapi/tests/test_udp_socket_private_shared.cc b/ppapi/tests/test_udp_socket_private_shared.cc index 192f00f..da97cae 100644 --- a/ppapi/tests/test_udp_socket_private_shared.cc +++ b/ppapi/tests/test_udp_socket_private_shared.cc @@ -11,10 +11,6 @@ REGISTER_TEST_CASE(UDPSocketPrivateShared); -// TODO(ygorshenin): get rid of using external server in tests, -// http://crbug.com/105863 -const char* const TestUDPSocketPrivateShared::kHost = "www.google.com"; - TestUDPSocketPrivateShared::TestUDPSocketPrivateShared( TestingInstance* instance) : TestCase(instance), @@ -33,7 +29,15 @@ bool TestUDPSocketPrivateShared::Init() { if (!udp_socket_private_interface_) instance_->AppendError("UDPSocketPrivate interface not available"); - return tcp_socket_private_interface_ && udp_socket_private_interface_ && + bool init_host_port = false; + if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) + instance_->AppendError("Can't init host and port"); + else + init_host_port = true; + + return tcp_socket_private_interface_ && + udp_socket_private_interface_ && + init_host_port && InitTestingInterface(); } @@ -54,7 +58,7 @@ std::string TestUDPSocketPrivateShared::GenerateNetAddress( TestCompletionCallback callback(instance_->pp_instance(), force_async_); int32_t rv = tcp_socket_private_interface_->Connect( - *socket, kHost, kPort, + *socket, host_.c_str(), port_, static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("PPB_TCPSocket_Private::Connect force_async", rv); diff --git a/ppapi/tests/test_udp_socket_private_shared.h b/ppapi/tests/test_udp_socket_private_shared.h index 8104d01..25b4afa 100644 --- a/ppapi/tests/test_udp_socket_private_shared.h +++ b/ppapi/tests/test_udp_socket_private_shared.h @@ -20,9 +20,6 @@ class TestUDPSocketPrivateShared : public TestCase { void QuitMessageLoop(); private: - static const char* const kHost; - static const int kPort = 80; - // Creates tcp_socket and connects to www.google.com:80. After that, // stores into |address| local address and returns created // tcp_socket. This is a way to create |PP_NetAddress_Private| @@ -37,6 +34,8 @@ class TestUDPSocketPrivateShared : public TestCase { const PPB_TCPSocket_Private* tcp_socket_private_interface_; const PPB_UDPSocket_Private* udp_socket_private_interface_; + std::string host_; + uint16_t port_; }; #endif // PPAPI_TESTS_TEST_UDP_SOCKET_PRIVATE_SHARED_H_ diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc index d5df942..a98c693 100644 --- a/ppapi/tests/test_utils.cc +++ b/ppapi/tests/test_utils.cc @@ -5,6 +5,7 @@ #include "ppapi/tests/test_utils.h" #include <stdio.h> +#include <stdlib.h> #if defined(_MSC_VER) #include <windows.h> #else @@ -13,6 +14,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/module.h" +#include "ppapi/cpp/var.h" const int kActionTimeoutMs = 10000; @@ -39,6 +41,36 @@ void PlatformSleep(int duration_ms) { #endif } +bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port) { + if (!host || !port) + return false; + + const PPB_Testing_Dev* testing = GetTestingInterface(); + if (!testing) + return false; + + PP_URLComponents_Dev components; + pp::Var pp_url(pp::Var::PassRef(), + testing->GetDocumentURL(instance, &components)); + if (!pp_url.is_string()) + return false; + std::string url = pp_url.AsString(); + + if (components.host.len < 0) + return false; + host->assign(url.substr(components.host.begin, components.host.len)); + + if (components.port.len <= 0) + return false; + + int i = atoi(url.substr(components.port.begin, components.port.len).c_str()); + if (i < 0 || i > 65535) + return false; + *port = static_cast<uint16_t>(i); + + return true; +} + TestCompletionCallback::TestCompletionCallback(PP_Instance instance) : have_result_(false), result_(PP_OK_COMPLETIONPENDING), diff --git a/ppapi/tests/test_utils.h b/ppapi/tests/test_utils.h index 8cfd2dd..8cff24e 100644 --- a/ppapi/tests/test_utils.h +++ b/ppapi/tests/test_utils.h @@ -18,6 +18,7 @@ extern const int kActionTimeoutMs; const PPB_Testing_Dev* GetTestingInterface(); std::string ReportError(const char* method, int32_t error); void PlatformSleep(int duration_ms); +bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port); class TestCompletionCallback { public: diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index d86c222..6154817 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -239,13 +239,21 @@ void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { plugin_instance->SimulateInputEvent(input_event_data); } +PP_Var GetDocumentURL(PP_Instance instance, PP_URLComponents_Dev* components) { + PluginInstance* plugin_instance = host_globals->GetInstance(instance); + if (!plugin_instance) + return PP_MakeUndefined(); + return plugin_instance->GetDocumentURL(instance, components); +} + const PPB_Testing_Dev testing_interface = { &ReadImageData, &RunMessageLoop, &QuitMessageLoop, &GetLiveObjectsForInstance, &IsOutOfProcess, - &SimulateInputEvent + &SimulateInputEvent, + &GetDocumentURL }; // GetInterface ---------------------------------------------------------------- @@ -340,7 +348,8 @@ const void* GetInterface(const char* name) { if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnablePepperTesting)) { if (strcmp(name, PPB_TESTING_DEV_INTERFACE) == 0 || - strcmp(name, PPB_TESTING_DEV_INTERFACE_0_7) == 0) { + strcmp(name, PPB_TESTING_DEV_INTERFACE_0_7) == 0 || + strcmp(name, PPB_TESTING_DEV_INTERFACE_0_8) == 0) { return &testing_interface; } } |