mozIThirdPartyUtil.idl 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsISupports.idl"
  5. interface nsIURI;
  6. interface mozIDOMWindowProxy;
  7. interface nsIChannel;
  8. /**
  9. * Utility functions for determining whether a given URI, channel, or window
  10. * hierarchy is third party with respect to a known URI.
  11. */
  12. [scriptable, uuid(fd82700e-ffb4-4932-b7d6-08f0b5697dda)]
  13. interface mozIThirdPartyUtil : nsISupports
  14. {
  15. /**
  16. * isThirdPartyURI
  17. *
  18. * Determine whether two URIs are third party with respect to each other.
  19. * This is determined by computing the base domain for both URIs. If they can
  20. * be determined, and the base domains match, the request is defined as first
  21. * party. If it cannot be determined because one or both URIs do not have a
  22. * base domain (for instance, in the case of IP addresses, host aliases such
  23. * as 'localhost', or a file:// URI), an exact string comparison on host is
  24. * performed.
  25. *
  26. * For example, the URI "http://mail.google.com/" is not third party with
  27. * respect to "http://images.google.com/", but "http://mail.yahoo.com/" and
  28. * "http://192.168.1.1/" are.
  29. *
  30. * @return true if aFirstURI is third party with respect to aSecondURI.
  31. *
  32. * @throws if either URI is null, has a malformed host, or has an empty host
  33. * and is not a file:// URI.
  34. */
  35. boolean isThirdPartyURI(in nsIURI aFirstURI, in nsIURI aSecondURI);
  36. /**
  37. * isThirdPartyWindow
  38. *
  39. * Determine whether the given window hierarchy is third party. This is done
  40. * as follows:
  41. *
  42. * 1) Obtain the URI of the principal associated with 'aWindow'. Call this the
  43. * 'bottom URI'.
  44. * 2) If 'aURI' is provided, determine if it is third party with respect to
  45. * the bottom URI. If so, return.
  46. * 3) Find the same-type parent window, if there is one, and its URI.
  47. * Determine whether it is third party with respect to the bottom URI. If
  48. * so, return.
  49. *
  50. * Therefore, each level in the window hierarchy is tested. (This means that
  51. * nested iframes with different base domains, even though the bottommost and
  52. * topmost URIs might be equal, will be considered third party.)
  53. *
  54. * @param aWindow
  55. * The bottommost window in the hierarchy.
  56. * @param aURI
  57. * A URI to test against. If null, the URI of the principal
  58. * associated with 'aWindow' will be used.
  59. *
  60. * For example, if 'aURI' is "http://mail.google.com/", 'aWindow' has a URI
  61. * of "http://google.com/", and its parent is the topmost content window with
  62. * a URI of "http://mozilla.com", the result will be true.
  63. *
  64. * @return true if 'aURI' is third party with respect to any of the URIs
  65. * associated with aWindow and its same-type parents.
  66. *
  67. * @throws if aWindow is null; the same-type parent of any window in the
  68. * hierarchy cannot be determined; or the URI associated with any
  69. * window in the hierarchy is null, has a malformed host, or has an
  70. * empty host and is not a file:// URI.
  71. *
  72. * @see isThirdPartyURI
  73. */
  74. boolean isThirdPartyWindow(in mozIDOMWindowProxy aWindow, [optional] in nsIURI aURI);
  75. /**
  76. * isThirdPartyChannel
  77. *
  78. * Determine whether the given channel and its content window hierarchy is
  79. * third party. This is done as follows:
  80. *
  81. * 1) If 'aChannel' is an nsIHttpChannel and has the
  82. * 'forceAllowThirdPartyCookie' property set, then:
  83. * a) If 'aURI' is null, return false.
  84. * b) Otherwise, find the URI of the channel, determine whether it is
  85. * foreign with respect to 'aURI', and return.
  86. * 2) Find the URI of the channel and determine whether it is third party with
  87. * respect to the URI of the channel. If so, return.
  88. * 3) Obtain the bottommost nsIDOMWindow, and its same-type parent if it
  89. * exists, from the channel's notification callbacks. Then:
  90. * a) If the parent is the same as the bottommost window, and the channel
  91. * has the LOAD_DOCUMENT_URI flag set, return false. This represents the
  92. * case where a toplevel load is occurring and the window's URI has not
  93. * yet been updated. (We have already checked that 'aURI' is not foreign
  94. * with respect to the channel URI.)
  95. * b) Otherwise, return the result of isThirdPartyWindow with arguments
  96. * of the channel's bottommost window and the channel URI, respectively.
  97. *
  98. * Therefore, both the channel's URI and each level in the window hierarchy
  99. * associated with the channel is tested.
  100. *
  101. * @param aChannel
  102. * The channel associated with the load.
  103. * @param aURI
  104. * A URI to test against. If null, the URI of the channel will be used.
  105. *
  106. * For example, if 'aURI' is "http://mail.google.com/", 'aChannel' has a URI
  107. * of "http://google.com/", and its parent is the topmost content window with
  108. * a URI of "http://mozilla.com", the result will be true.
  109. *
  110. * @return true if aURI is third party with respect to the channel URI or any
  111. * of the URIs associated with the same-type window hierarchy of the
  112. * channel.
  113. *
  114. * @throws if 'aChannel' is null; the channel has no notification callbacks or
  115. * an associated window; or isThirdPartyWindow throws.
  116. *
  117. * @see isThirdPartyWindow
  118. */
  119. boolean isThirdPartyChannel(in nsIChannel aChannel, [optional] in nsIURI aURI);
  120. /**
  121. * getBaseDomain
  122. *
  123. * Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
  124. * "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
  125. * dot may be present. If aHostURI is an IP address, an alias such as
  126. * 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
  127. * be the exact host. The result of this function should only be used in exact
  128. * string comparisons, since substring comparisons will not be valid for the
  129. * special cases elided above.
  130. *
  131. * @param aHostURI
  132. * The URI to analyze.
  133. *
  134. * @return the base domain.
  135. */
  136. AUTF8String getBaseDomain(in nsIURI aHostURI);
  137. /**
  138. * getURIFromWindow
  139. *
  140. * Returns the URI associated with the script object principal for the
  141. * window.
  142. */
  143. nsIURI getURIFromWindow(in mozIDOMWindowProxy aWindow);
  144. /**
  145. * getTopWindowForChannel
  146. *
  147. * Returns the top-level window associated with the given channel.
  148. */
  149. mozIDOMWindowProxy getTopWindowForChannel(in nsIChannel aChannel);
  150. };
  151. %{ C++
  152. /**
  153. * The mozIThirdPartyUtil implementation is an XPCOM service registered
  154. * under the ContractID:
  155. */
  156. #define THIRDPARTYUTIL_CONTRACTID "@mozilla.org/thirdpartyutil;1"
  157. %}