Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsISupports.idl" |
michael@0 | 6 | |
michael@0 | 7 | interface nsIURI; |
michael@0 | 8 | interface nsIDOMWindow; |
michael@0 | 9 | interface nsIChannel; |
michael@0 | 10 | interface nsIDocument; |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * Utility functions for determining whether a given URI, channel, or window |
michael@0 | 14 | * hierarchy is third party with respect to a known URI. |
michael@0 | 15 | */ |
michael@0 | 16 | [scriptable, uuid(d994fd1d-d2fe-4372-9ae7-88b08b7d9d90)] |
michael@0 | 17 | interface mozIThirdPartyUtil : nsISupports |
michael@0 | 18 | { |
michael@0 | 19 | /** |
michael@0 | 20 | * isThirdPartyURI |
michael@0 | 21 | * |
michael@0 | 22 | * Determine whether two URIs are third party with respect to each other. |
michael@0 | 23 | * This is determined by computing the base domain for both URIs. If they can |
michael@0 | 24 | * be determined, and the base domains match, the request is defined as first |
michael@0 | 25 | * party. If it cannot be determined because one or both URIs do not have a |
michael@0 | 26 | * base domain (for instance, in the case of IP addresses, host aliases such |
michael@0 | 27 | * as 'localhost', or a file:// URI), an exact string comparison on host is |
michael@0 | 28 | * performed. |
michael@0 | 29 | * |
michael@0 | 30 | * For example, the URI "http://mail.google.com/" is not third party with |
michael@0 | 31 | * respect to "http://images.google.com/", but "http://mail.yahoo.com/" and |
michael@0 | 32 | * "http://192.168.1.1/" are. |
michael@0 | 33 | * |
michael@0 | 34 | * @return true if aFirstURI is third party with respect to aSecondURI. |
michael@0 | 35 | * |
michael@0 | 36 | * @throws if either URI is null, has a malformed host, or has an empty host |
michael@0 | 37 | * and is not a file:// URI. |
michael@0 | 38 | */ |
michael@0 | 39 | boolean isThirdPartyURI(in nsIURI aFirstURI, in nsIURI aSecondURI); |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * isThirdPartyWindow |
michael@0 | 43 | * |
michael@0 | 44 | * Determine whether the given window hierarchy is third party. This is done |
michael@0 | 45 | * as follows: |
michael@0 | 46 | * |
michael@0 | 47 | * 1) Obtain the URI of the principal associated with 'aWindow'. Call this the |
michael@0 | 48 | * 'bottom URI'. |
michael@0 | 49 | * 2) If 'aURI' is provided, determine if it is third party with respect to |
michael@0 | 50 | * the bottom URI. If so, return. |
michael@0 | 51 | * 3) Find the same-type parent window, if there is one, and its URI. |
michael@0 | 52 | * Determine whether it is third party with respect to the bottom URI. If |
michael@0 | 53 | * so, return. |
michael@0 | 54 | * |
michael@0 | 55 | * Therefore, each level in the window hierarchy is tested. (This means that |
michael@0 | 56 | * nested iframes with different base domains, even though the bottommost and |
michael@0 | 57 | * topmost URIs might be equal, will be considered third party.) |
michael@0 | 58 | * |
michael@0 | 59 | * @param aWindow |
michael@0 | 60 | * The bottommost window in the hierarchy. |
michael@0 | 61 | * @param aURI |
michael@0 | 62 | * A URI to test against. If null, the URI of the principal |
michael@0 | 63 | * associated with 'aWindow' will be used. |
michael@0 | 64 | * |
michael@0 | 65 | * For example, if 'aURI' is "http://mail.google.com/", 'aWindow' has a URI |
michael@0 | 66 | * of "http://google.com/", and its parent is the topmost content window with |
michael@0 | 67 | * a URI of "http://mozilla.com", the result will be true. |
michael@0 | 68 | * |
michael@0 | 69 | * @return true if 'aURI' is third party with respect to any of the URIs |
michael@0 | 70 | * associated with aWindow and its same-type parents. |
michael@0 | 71 | * |
michael@0 | 72 | * @throws if aWindow is null; the same-type parent of any window in the |
michael@0 | 73 | * hierarchy cannot be determined; or the URI associated with any |
michael@0 | 74 | * window in the hierarchy is null, has a malformed host, or has an |
michael@0 | 75 | * empty host and is not a file:// URI. |
michael@0 | 76 | * |
michael@0 | 77 | * @see isThirdPartyURI |
michael@0 | 78 | */ |
michael@0 | 79 | boolean isThirdPartyWindow(in nsIDOMWindow aWindow, [optional] in nsIURI aURI); |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * isThirdPartyChannel |
michael@0 | 83 | * |
michael@0 | 84 | * Determine whether the given channel and its content window hierarchy is |
michael@0 | 85 | * third party. This is done as follows: |
michael@0 | 86 | * |
michael@0 | 87 | * 1) If 'aChannel' is an nsIHttpChannel and has the |
michael@0 | 88 | * 'forceAllowThirdPartyCookie' property set, then: |
michael@0 | 89 | * a) If 'aURI' is null, return false. |
michael@0 | 90 | * b) Otherwise, find the URI of the channel, determine whether it is |
michael@0 | 91 | * foreign with respect to 'aURI', and return. |
michael@0 | 92 | * 2) Find the URI of the channel and determine whether it is third party with |
michael@0 | 93 | * respect to the URI of the channel. If so, return. |
michael@0 | 94 | * 3) Obtain the bottommost nsIDOMWindow, and its same-type parent if it |
michael@0 | 95 | * exists, from the channel's notification callbacks. Then: |
michael@0 | 96 | * a) If the parent is the same as the bottommost window, and the channel |
michael@0 | 97 | * has the LOAD_DOCUMENT_URI flag set, return false. This represents the |
michael@0 | 98 | * case where a toplevel load is occurring and the window's URI has not |
michael@0 | 99 | * yet been updated. (We have already checked that 'aURI' is not foreign |
michael@0 | 100 | * with respect to the channel URI.) |
michael@0 | 101 | * b) Otherwise, return the result of isThirdPartyWindow with arguments |
michael@0 | 102 | * of the channel's bottommost window and the channel URI, respectively. |
michael@0 | 103 | * |
michael@0 | 104 | * Therefore, both the channel's URI and each level in the window hierarchy |
michael@0 | 105 | * associated with the channel is tested. |
michael@0 | 106 | * |
michael@0 | 107 | * @param aChannel |
michael@0 | 108 | * The channel associated with the load. |
michael@0 | 109 | * @param aURI |
michael@0 | 110 | * A URI to test against. If null, the URI of the channel will be used. |
michael@0 | 111 | * |
michael@0 | 112 | * For example, if 'aURI' is "http://mail.google.com/", 'aChannel' has a URI |
michael@0 | 113 | * of "http://google.com/", and its parent is the topmost content window with |
michael@0 | 114 | * a URI of "http://mozilla.com", the result will be true. |
michael@0 | 115 | * |
michael@0 | 116 | * @return true if aURI is third party with respect to the channel URI or any |
michael@0 | 117 | * of the URIs associated with the same-type window hierarchy of the |
michael@0 | 118 | * channel. |
michael@0 | 119 | * |
michael@0 | 120 | * @throws if 'aChannel' is null; the channel has no notification callbacks or |
michael@0 | 121 | * an associated window; or isThirdPartyWindow throws. |
michael@0 | 122 | * |
michael@0 | 123 | * @see isThirdPartyWindow |
michael@0 | 124 | */ |
michael@0 | 125 | boolean isThirdPartyChannel(in nsIChannel aChannel, [optional] in nsIURI aURI); |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * getBaseDomain |
michael@0 | 129 | * |
michael@0 | 130 | * Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be |
michael@0 | 131 | * "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing |
michael@0 | 132 | * dot may be present. If aHostURI is an IP address, an alias such as |
michael@0 | 133 | * 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will |
michael@0 | 134 | * be the exact host. The result of this function should only be used in exact |
michael@0 | 135 | * string comparisons, since substring comparisons will not be valid for the |
michael@0 | 136 | * special cases elided above. |
michael@0 | 137 | * |
michael@0 | 138 | * @param aHostURI |
michael@0 | 139 | * The URI to analyze. |
michael@0 | 140 | * |
michael@0 | 141 | * @return the base domain. |
michael@0 | 142 | */ |
michael@0 | 143 | AUTF8String getBaseDomain(in nsIURI aHostURI); |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | /** |
michael@0 | 147 | * getFirstPartyURI |
michael@0 | 148 | * |
michael@0 | 149 | * Obtain the top-level url bar URI for either a channel or a document. |
michael@0 | 150 | * Either parameter may be null (but not both). |
michael@0 | 151 | * |
michael@0 | 152 | * @param aChannel |
michael@0 | 153 | * An arbitrary channel for some content element of a first party |
michael@0 | 154 | * load. Can be null. |
michael@0 | 155 | * |
michael@0 | 156 | * @param aDoc |
michael@0 | 157 | * An arbitrary third party document. Can be null. |
michael@0 | 158 | * |
michael@0 | 159 | * @return the first party url bar URI for the load. |
michael@0 | 160 | * |
michael@0 | 161 | * @throws if the URI cannot be obtained or the URI lacks a hostname and the |
michael@0 | 162 | * URI's scheme is not white listed. |
michael@0 | 163 | */ |
michael@0 | 164 | [noscript] nsIURI getFirstPartyURI(in nsIChannel aChannel, |
michael@0 | 165 | in nsIDocument aDoc); |
michael@0 | 166 | |
michael@0 | 167 | /** |
michael@0 | 168 | * getFirstPartyIsolationURI |
michael@0 | 169 | * |
michael@0 | 170 | * If first-party isolation is active, then |
michael@0 | 171 | * obtains the top-level url bar URI for either a channel or a document. |
michael@0 | 172 | * Otherwise returns null. |
michael@0 | 173 | * Either parameter may be null (but not both). |
michael@0 | 174 | * |
michael@0 | 175 | * @param aChannel |
michael@0 | 176 | * An arbitrary channel for some content element of a first party |
michael@0 | 177 | * load. Can be null. |
michael@0 | 178 | * |
michael@0 | 179 | * @param aDoc |
michael@0 | 180 | * An arbitrary third party document. Can be null. |
michael@0 | 181 | * |
michael@0 | 182 | * @return the first party url bar URI for the load. |
michael@0 | 183 | * |
michael@0 | 184 | * @throws if the URI cannot be obtained or the URI lacks a hostname and the |
michael@0 | 185 | * URI's scheme is not white listed. |
michael@0 | 186 | */ |
michael@0 | 187 | [noscript] nsIURI getFirstPartyIsolationURI(in nsIChannel aChannel, |
michael@0 | 188 | in nsIDocument aDoc); |
michael@0 | 189 | |
michael@0 | 190 | /** |
michael@0 | 191 | * getFirstPartyURIFromChannel |
michael@0 | 192 | * |
michael@0 | 193 | * Obtain the top-level url bar URI for a channel. |
michael@0 | 194 | * |
michael@0 | 195 | * @param aChannel |
michael@0 | 196 | * An arbitrary channel for some content element of a first party |
michael@0 | 197 | * load. |
michael@0 | 198 | * |
michael@0 | 199 | * @param aLogErrors |
michael@0 | 200 | * If true, log errors to the Error Console. |
michael@0 | 201 | * |
michael@0 | 202 | * @return the first party url bar URI for the load. |
michael@0 | 203 | * |
michael@0 | 204 | * @throws if the URI cannot be obtained or the URI lacks a hostname and the |
michael@0 | 205 | * URI's scheme is not white listed. |
michael@0 | 206 | */ |
michael@0 | 207 | nsIURI getFirstPartyURIFromChannel(in nsIChannel aChannel, |
michael@0 | 208 | in bool aLogErrors); |
michael@0 | 209 | |
michael@0 | 210 | /** |
michael@0 | 211 | * getFirstPartyHostForIsolation |
michael@0 | 212 | * |
michael@0 | 213 | * Obtain the host or pseudo-host for aFirstPartyURI. Some examples: |
michael@0 | 214 | * aFirstPartyURI Return Value |
michael@0 | 215 | * -------------- ------------ |
michael@0 | 216 | * https://news.google.com/nwshp?hl=en "news.google.com" |
michael@0 | 217 | * about:home "--NoFirstPartyHost-about-home--" |
michael@0 | 218 | * chrome://browser/content/browser.xul "--NoFirstPartyHost-chrome-browser.xul--" |
michael@0 | 219 | * |
michael@0 | 220 | * @param aFirstPartyURI |
michael@0 | 221 | * The first party URI. |
michael@0 | 222 | * |
michael@0 | 223 | * @return host or pseudo host. |
michael@0 | 224 | * |
michael@0 | 225 | * @throws if the URI lacks a host and the scheme is not a whitelisted one |
michael@0 | 226 | * for which we generate a pseudo host. |
michael@0 | 227 | */ |
michael@0 | 228 | AUTF8String getFirstPartyHostForIsolation(in nsIURI aFirstPartyURI); |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | %{ C++ |
michael@0 | 232 | /** |
michael@0 | 233 | * The mozIThirdPartyUtil implementation is an XPCOM service registered |
michael@0 | 234 | * under the ContractID: |
michael@0 | 235 | */ |
michael@0 | 236 | #define THIRDPARTYUTIL_CONTRACTID "@mozilla.org/thirdpartyutil;1" |
michael@0 | 237 | %} |
michael@0 | 238 |