1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 /* From dev/ppb_url_util_dev.idl modified Fri Dec 16 17:34:59 2011. */ 7 8 #ifndef PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ 9 #define PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ 10 11 #include "ppapi/c/pp_bool.h" 12 #include "ppapi/c/pp_instance.h" 13 #include "ppapi/c/pp_macros.h" 14 #include "ppapi/c/pp_stdint.h" 15 #include "ppapi/c/pp_var.h" 16 17 #define PPB_URLUTIL_DEV_INTERFACE_0_6 "PPB_URLUtil(Dev);0.6" 18 #define PPB_URLUTIL_DEV_INTERFACE PPB_URLUTIL_DEV_INTERFACE_0_6 19 20 /** 21 * @file 22 * This file defines the <code>PPB_URLUtil_Dev</code> interface. 23 */ 24 25 26 /** 27 * @addtogroup Structs 28 * @{ 29 */ 30 /* 31 * A component specifies the range of the part of the URL. The begin specifies 32 * the index into the string of the first character of that component. The len 33 * specifies the length of that component. 34 * 35 * This range does not include any special delimiter for that component, so 36 * the scheme doesn't include the trailing colon, the username and password 37 * don't include the @ and :, the port doesn't include the colon, the query 38 * doesn't include the ?, and the ref doesn't include the #. 39 * 40 * The exception is that the path *does* include the first /, since that's an 41 * integral part of the path. 42 * 43 * If the component is not present at all, begin will be 0 and len will be -1. 44 * If the component is present but empty, the length will be 0 instead. Example: 45 * http://foo/search -> query = (0, -1) 46 * http://foo/search? -> query = (18, 0) 47 */ 48 struct PP_URLComponent_Dev { 49 int32_t begin; 50 int32_t len; 51 }; 52 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_URLComponent_Dev, 8); 53 54 struct PP_URLComponents_Dev { 55 struct PP_URLComponent_Dev scheme; 56 struct PP_URLComponent_Dev username; 57 struct PP_URLComponent_Dev password; 58 struct PP_URLComponent_Dev host; 59 struct PP_URLComponent_Dev port; 60 struct PP_URLComponent_Dev path; 61 struct PP_URLComponent_Dev query; 62 struct PP_URLComponent_Dev ref; 63 }; 64 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_URLComponents_Dev, 64); 65 /** 66 * @} 67 */ 68 69 /** 70 * @addtogroup Interfaces 71 * @{ 72 */ 73 /* 74 * URL encoding: URLs are supplied to this interface as NULL-terminated 8-bit 75 * strings. You can pass non-ASCII characters which will be interpreted as 76 * UTF-8. Canonicalized URL strings returned by these functions will be ASCII 77 * except for the reference fragment (stuff after the '#') which will be 78 * encoded as UTF-8. 79 */ 80 struct PPB_URLUtil_Dev_0_6 { 81 /* 82 * Canonicalizes the given URL string according to the rules of the host 83 * browser. If the URL is invalid or the var is not a string, this will 84 * return a Null var and the components structure will be unchanged. 85 * 86 * The components pointer, if non-NULL and the canonicalized URL is valid, 87 * will identify the components of the resulting URL. Components may be NULL 88 * to specify that no component information is necessary. 89 */ 90 struct PP_Var (*Canonicalize)(struct PP_Var url, 91 struct PP_URLComponents_Dev* components); 92 /* 93 * Resolves the given URL relative to the given base URL. The resulting URL 94 * is returned as a string. If the resolution is invalid or either of the 95 * inputs are not strings, a Null var will be returned. The resulting URL 96 * will also be canonicalized according to the rules of the browser. 97 * 98 * Note that the "relative" URL may in fact be absolute, in which case it 99 * will be returned. This function is identical to resolving the full URL 100 * for an <a href="..."> on a web page. Attempting to resolve a relative URL 101 * on a base URL that doesn't support this (e.g. "data") will fail and will 102 * return a Null var, unless the relative URL is itself absolute. 103 * 104 * The components pointer, if non-NULL and the canonicalized URL is valid, 105 * will identify the components of the resulting URL. Components may be NULL 106 * to specify that no component information is necessary. 107 */ 108 struct PP_Var (*ResolveRelativeToURL)( 109 struct PP_Var base_url, 110 struct PP_Var relative_string, 111 struct PP_URLComponents_Dev* components); 112 /* 113 * Identical to ResolveRelativeToURL except that the base URL is the base 114 * URL of the document containing the given plugin instance. 115 * 116 * Danger: This will be identical to resolving a relative URL on the page, 117 * and might be overridden by the page to something different than its actual 118 * URL via the <base> tag. Therefore, resolving a relative URL of "" won't 119 * necessarily give you the URL of the page! 120 */ 121 struct PP_Var (*ResolveRelativeToDocument)( 122 PP_Instance instance, 123 struct PP_Var relative_string, 124 struct PP_URLComponents_Dev* components); 125 /* 126 * Checks whether the given two URLs are in the same security origin. Returns 127 * FALSE if either of the URLs are invalid. 128 */ 129 PP_Bool (*IsSameSecurityOrigin)(struct PP_Var url_a, struct PP_Var url_b); 130 /* 131 * Checks whether the document hosting the given plugin instance can access 132 * the given URL according to the same origin policy of the browser. Returns 133 * PP_FALSE if the instance or the URL is invalid. 134 */ 135 PP_Bool (*DocumentCanRequest)(PP_Instance instance, struct PP_Var url); 136 /* 137 * Checks whether the document containing the |active| plugin instance can 138 * access the document containing the |target| plugin instance according to 139 * the security policy of the browser. This includes the same origin policy 140 * and any cross-origin capabilities enabled by the document. If either of 141 * the plugin instances are invalid, returns PP_FALSE. 142 */ 143 PP_Bool (*DocumentCanAccessDocument)(PP_Instance active, PP_Instance target); 144 /* 145 * Returns the URL for the document. This is a safe way to retrieve 146 * window.location.href. 147 * The components pointer, if non-NULL and the canonicalized URL is valid, 148 * will identify the components of the resulting URL. Components may be NULL 149 * to specify that no component information is necessary. 150 */ 151 struct PP_Var (*GetDocumentURL)(PP_Instance instance, 152 struct PP_URLComponents_Dev* components); 153 /* 154 * Returns the Source URL for the plugin. This returns the URL that would be 155 * streamed to the plugin if it were a NPAPI plugin. This is usually the src 156 * attribute on the <embed> element, but the rules are obscure and different 157 * based on whether the plugin is loaded from an <embed> element or an 158 * <object> element. 159 * The components pointer, if non-NULL and the canonicalized URL is valid, 160 * will identify the components of the resulting URL. Components may be NULL 161 * to specify that no component information is necessary. 162 */ 163 struct PP_Var (*GetPluginInstanceURL)( 164 PP_Instance instance, 165 struct PP_URLComponents_Dev* components); 166 }; 167 168 typedef struct PPB_URLUtil_Dev_0_6 PPB_URLUtil_Dev; 169 /** 170 * @} 171 */ 172 173 #endif /* PPAPI_C_DEV_PPB_URL_UTIL_DEV_H_ */ 174 175