michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: interface nsIURI; michael@0: interface nsIDOMWindow; michael@0: interface nsIChannel; michael@0: interface nsIDocument; michael@0: michael@0: /** michael@0: * Utility functions for determining whether a given URI, channel, or window michael@0: * hierarchy is third party with respect to a known URI. michael@0: */ michael@0: [scriptable, uuid(d994fd1d-d2fe-4372-9ae7-88b08b7d9d90)] michael@0: interface mozIThirdPartyUtil : nsISupports michael@0: { michael@0: /** michael@0: * isThirdPartyURI michael@0: * michael@0: * Determine whether two URIs are third party with respect to each other. michael@0: * This is determined by computing the base domain for both URIs. If they can michael@0: * be determined, and the base domains match, the request is defined as first michael@0: * party. If it cannot be determined because one or both URIs do not have a michael@0: * base domain (for instance, in the case of IP addresses, host aliases such michael@0: * as 'localhost', or a file:// URI), an exact string comparison on host is michael@0: * performed. michael@0: * michael@0: * For example, the URI "http://mail.google.com/" is not third party with michael@0: * respect to "http://images.google.com/", but "http://mail.yahoo.com/" and michael@0: * "http://192.168.1.1/" are. michael@0: * michael@0: * @return true if aFirstURI is third party with respect to aSecondURI. michael@0: * michael@0: * @throws if either URI is null, has a malformed host, or has an empty host michael@0: * and is not a file:// URI. michael@0: */ michael@0: boolean isThirdPartyURI(in nsIURI aFirstURI, in nsIURI aSecondURI); michael@0: michael@0: /** michael@0: * isThirdPartyWindow michael@0: * michael@0: * Determine whether the given window hierarchy is third party. This is done michael@0: * as follows: michael@0: * michael@0: * 1) Obtain the URI of the principal associated with 'aWindow'. Call this the michael@0: * 'bottom URI'. michael@0: * 2) If 'aURI' is provided, determine if it is third party with respect to michael@0: * the bottom URI. If so, return. michael@0: * 3) Find the same-type parent window, if there is one, and its URI. michael@0: * Determine whether it is third party with respect to the bottom URI. If michael@0: * so, return. michael@0: * michael@0: * Therefore, each level in the window hierarchy is tested. (This means that michael@0: * nested iframes with different base domains, even though the bottommost and michael@0: * topmost URIs might be equal, will be considered third party.) michael@0: * michael@0: * @param aWindow michael@0: * The bottommost window in the hierarchy. michael@0: * @param aURI michael@0: * A URI to test against. If null, the URI of the principal michael@0: * associated with 'aWindow' will be used. michael@0: * michael@0: * For example, if 'aURI' is "http://mail.google.com/", 'aWindow' has a URI michael@0: * of "http://google.com/", and its parent is the topmost content window with michael@0: * a URI of "http://mozilla.com", the result will be true. michael@0: * michael@0: * @return true if 'aURI' is third party with respect to any of the URIs michael@0: * associated with aWindow and its same-type parents. michael@0: * michael@0: * @throws if aWindow is null; the same-type parent of any window in the michael@0: * hierarchy cannot be determined; or the URI associated with any michael@0: * window in the hierarchy is null, has a malformed host, or has an michael@0: * empty host and is not a file:// URI. michael@0: * michael@0: * @see isThirdPartyURI michael@0: */ michael@0: boolean isThirdPartyWindow(in nsIDOMWindow aWindow, [optional] in nsIURI aURI); michael@0: michael@0: /** michael@0: * isThirdPartyChannel michael@0: * michael@0: * Determine whether the given channel and its content window hierarchy is michael@0: * third party. This is done as follows: michael@0: * michael@0: * 1) If 'aChannel' is an nsIHttpChannel and has the michael@0: * 'forceAllowThirdPartyCookie' property set, then: michael@0: * a) If 'aURI' is null, return false. michael@0: * b) Otherwise, find the URI of the channel, determine whether it is michael@0: * foreign with respect to 'aURI', and return. michael@0: * 2) Find the URI of the channel and determine whether it is third party with michael@0: * respect to the URI of the channel. If so, return. michael@0: * 3) Obtain the bottommost nsIDOMWindow, and its same-type parent if it michael@0: * exists, from the channel's notification callbacks. Then: michael@0: * a) If the parent is the same as the bottommost window, and the channel michael@0: * has the LOAD_DOCUMENT_URI flag set, return false. This represents the michael@0: * case where a toplevel load is occurring and the window's URI has not michael@0: * yet been updated. (We have already checked that 'aURI' is not foreign michael@0: * with respect to the channel URI.) michael@0: * b) Otherwise, return the result of isThirdPartyWindow with arguments michael@0: * of the channel's bottommost window and the channel URI, respectively. michael@0: * michael@0: * Therefore, both the channel's URI and each level in the window hierarchy michael@0: * associated with the channel is tested. michael@0: * michael@0: * @param aChannel michael@0: * The channel associated with the load. michael@0: * @param aURI michael@0: * A URI to test against. If null, the URI of the channel will be used. michael@0: * michael@0: * For example, if 'aURI' is "http://mail.google.com/", 'aChannel' has a URI michael@0: * of "http://google.com/", and its parent is the topmost content window with michael@0: * a URI of "http://mozilla.com", the result will be true. michael@0: * michael@0: * @return true if aURI is third party with respect to the channel URI or any michael@0: * of the URIs associated with the same-type window hierarchy of the michael@0: * channel. michael@0: * michael@0: * @throws if 'aChannel' is null; the channel has no notification callbacks or michael@0: * an associated window; or isThirdPartyWindow throws. michael@0: * michael@0: * @see isThirdPartyWindow michael@0: */ michael@0: boolean isThirdPartyChannel(in nsIChannel aChannel, [optional] in nsIURI aURI); michael@0: michael@0: /** michael@0: * getBaseDomain michael@0: * michael@0: * Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be michael@0: * "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing michael@0: * dot may be present. If aHostURI is an IP address, an alias such as michael@0: * 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will michael@0: * be the exact host. The result of this function should only be used in exact michael@0: * string comparisons, since substring comparisons will not be valid for the michael@0: * special cases elided above. michael@0: * michael@0: * @param aHostURI michael@0: * The URI to analyze. michael@0: * michael@0: * @return the base domain. michael@0: */ michael@0: AUTF8String getBaseDomain(in nsIURI aHostURI); michael@0: michael@0: michael@0: /** michael@0: * getFirstPartyURI michael@0: * michael@0: * Obtain the top-level url bar URI for either a channel or a document. michael@0: * Either parameter may be null (but not both). michael@0: * michael@0: * @param aChannel michael@0: * An arbitrary channel for some content element of a first party michael@0: * load. Can be null. michael@0: * michael@0: * @param aDoc michael@0: * An arbitrary third party document. Can be null. michael@0: * michael@0: * @return the first party url bar URI for the load. michael@0: * michael@0: * @throws if the URI cannot be obtained or the URI lacks a hostname and the michael@0: * URI's scheme is not white listed. michael@0: */ michael@0: [noscript] nsIURI getFirstPartyURI(in nsIChannel aChannel, michael@0: in nsIDocument aDoc); michael@0: michael@0: /** michael@0: * getFirstPartyIsolationURI michael@0: * michael@0: * If first-party isolation is active, then michael@0: * obtains the top-level url bar URI for either a channel or a document. michael@0: * Otherwise returns null. michael@0: * Either parameter may be null (but not both). michael@0: * michael@0: * @param aChannel michael@0: * An arbitrary channel for some content element of a first party michael@0: * load. Can be null. michael@0: * michael@0: * @param aDoc michael@0: * An arbitrary third party document. Can be null. michael@0: * michael@0: * @return the first party url bar URI for the load. michael@0: * michael@0: * @throws if the URI cannot be obtained or the URI lacks a hostname and the michael@0: * URI's scheme is not white listed. michael@0: */ michael@0: [noscript] nsIURI getFirstPartyIsolationURI(in nsIChannel aChannel, michael@0: in nsIDocument aDoc); michael@0: michael@0: /** michael@0: * getFirstPartyURIFromChannel michael@0: * michael@0: * Obtain the top-level url bar URI for a channel. michael@0: * michael@0: * @param aChannel michael@0: * An arbitrary channel for some content element of a first party michael@0: * load. michael@0: * michael@0: * @param aLogErrors michael@0: * If true, log errors to the Error Console. michael@0: * michael@0: * @return the first party url bar URI for the load. michael@0: * michael@0: * @throws if the URI cannot be obtained or the URI lacks a hostname and the michael@0: * URI's scheme is not white listed. michael@0: */ michael@0: nsIURI getFirstPartyURIFromChannel(in nsIChannel aChannel, michael@0: in bool aLogErrors); michael@0: michael@0: /** michael@0: * getFirstPartyHostForIsolation michael@0: * michael@0: * Obtain the host or pseudo-host for aFirstPartyURI. Some examples: michael@0: * aFirstPartyURI Return Value michael@0: * -------------- ------------ michael@0: * https://news.google.com/nwshp?hl=en "news.google.com" michael@0: * about:home "--NoFirstPartyHost-about-home--" michael@0: * chrome://browser/content/browser.xul "--NoFirstPartyHost-chrome-browser.xul--" michael@0: * michael@0: * @param aFirstPartyURI michael@0: * The first party URI. michael@0: * michael@0: * @return host or pseudo host. michael@0: * michael@0: * @throws if the URI lacks a host and the scheme is not a whitelisted one michael@0: * for which we generate a pseudo host. michael@0: */ michael@0: AUTF8String getFirstPartyHostForIsolation(in nsIURI aFirstPartyURI); michael@0: }; michael@0: michael@0: %{ C++ michael@0: /** michael@0: * The mozIThirdPartyUtil implementation is an XPCOM service registered michael@0: * under the ContractID: michael@0: */ michael@0: #define THIRDPARTYUTIL_CONTRACTID "@mozilla.org/thirdpartyutil;1" michael@0: %} michael@0: