nsIURI.idl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsISupports.idl"
  6. /**
  7. * URIs are essentially structured names for things -- anything. This interface
  8. * provides accessors to set and query the most basic components of an URI.
  9. * Subclasses, including nsIURL, impose greater structure on the URI.
  10. *
  11. * This interface follows Tim Berners-Lee's URI spec (RFC3986) [1], where the
  12. * basic URI components are defined as such:
  13. * <pre>
  14. * ftp://username:password@hostname:portnumber/pathname?query#ref
  15. * \ / \ / \ / \ /\ / \ / \ /
  16. * - --------------- ------ -------- ------- --- -
  17. * | | | | | | |
  18. * | | | | FilePath Query Ref
  19. * | | | Port \ /
  20. * | | Host / ------------
  21. * | UserPass / |
  22. * Scheme / Path
  23. * \ /
  24. * --------------------------------
  25. * |
  26. * PrePath
  27. * </pre>
  28. * The definition of the URI components has been extended to allow for
  29. * internationalized domain names [2] and the more generic IRI structure [3].
  30. *
  31. * [1] https://tools.ietf.org/html/rfc3986
  32. * [2] https://tools.ietf.org/html/rfc5890
  33. * [3] https://tools.ietf.org/html/rfc3987
  34. */
  35. %{C++
  36. #include "nsStringGlue.h"
  37. #undef GetPort // XXX Windows!
  38. #undef SetPort // XXX Windows!
  39. %}
  40. /**
  41. * nsIURI - interface for an uniform resource identifier w/ i18n support.
  42. *
  43. * AUTF8String attributes may contain unescaped UTF-8 characters.
  44. * Consumers should be careful to escape the UTF-8 strings as necessary, but
  45. * should always try to "display" the UTF-8 version as provided by this
  46. * interface.
  47. *
  48. * AUTF8String attributes may also contain escaped characters.
  49. *
  50. * Unescaping URI segments is unadvised unless there is intimate
  51. * knowledge of the underlying charset or there is no plan to display (or
  52. * otherwise enforce a charset on) the resulting URI substring.
  53. *
  54. * The correct way to create an nsIURI from a string is via
  55. * nsIIOService.newURI.
  56. *
  57. * NOTE: nsBinaryInputStream::ReadObject contains a hackaround to intercept the
  58. * old (pre-gecko6) nsIURI IID and swap in the current IID instead, in order
  59. * for sessionstore to work after an upgrade. If this IID is revved further,
  60. * we will need to add additional checks there for all intermediate IIDs, until
  61. * nsPrincipal is fixed to serialize its URIs as nsISupports (bug 662693).
  62. */
  63. [scriptable, uuid(92073a54-6d78-4f30-913a-b871813208c6)]
  64. interface nsIURI : nsISupports
  65. {
  66. /************************************************************************
  67. * The URI is broken down into the following principal components:
  68. */
  69. /**
  70. * Returns a string representation of the URI. Setting the spec causes
  71. * the new spec to be parsed per the rules for the scheme the URI
  72. * currently has. In particular, setting the spec to a URI string with a
  73. * different scheme will generally produce incorrect results; no one
  74. * outside of a protocol handler implementation should be doing that. If
  75. * the URI stores information from the nsIIOService.newURI call used to
  76. * create it other than just the parsed string, then behavior of this
  77. * information on setting the spec attribute is undefined.
  78. *
  79. * Some characters may be escaped.
  80. */
  81. attribute AUTF8String spec;
  82. %{ C++
  83. // An infallible wrapper for GetSpec() that returns a failure indication
  84. // string if GetSpec() fails. It is most useful for creating
  85. // logging/warning/error messages produced for human consumption, and when
  86. // matching a URI spec against a fixed spec such as about:blank.
  87. nsCString GetSpecOrDefault()
  88. {
  89. nsCString spec;
  90. nsresult rv = GetSpec(spec);
  91. if (NS_FAILED(rv)) {
  92. spec.Assign("[nsIURI::GetSpec failed]");
  93. }
  94. return spec;
  95. }
  96. %}
  97. /**
  98. * The prePath (eg. scheme://user:password@host:port) returns the string
  99. * before the path. This is useful for authentication or managing sessions.
  100. *
  101. * Some characters may be escaped.
  102. */
  103. readonly attribute AUTF8String prePath;
  104. /**
  105. * The Scheme is the protocol to which this URI refers. The scheme is
  106. * restricted to the US-ASCII charset per RFC3986. Setting this is
  107. * highly discouraged outside of a protocol handler implementation, since
  108. * that will generally lead to incorrect results.
  109. */
  110. attribute ACString scheme;
  111. /**
  112. * The username:password (or username only if value doesn't contain a ':')
  113. *
  114. * Some characters may be escaped.
  115. */
  116. attribute AUTF8String userPass;
  117. /**
  118. * The optional username and password, assuming the preHost consists of
  119. * username:password.
  120. *
  121. * Some characters may be escaped.
  122. */
  123. attribute AUTF8String username;
  124. attribute AUTF8String password;
  125. /**
  126. * The host:port (or simply the host, if port == -1).
  127. *
  128. * If this attribute is set to a value that only has a host part, the port
  129. * will not be reset. To reset the port as well use setHostAndPort.
  130. *
  131. * Characters are NOT escaped.
  132. */
  133. attribute AUTF8String hostPort;
  134. /**
  135. * This function will always set a host and a port. If the port part is
  136. * empty, the value of the port will be set to the default value.
  137. */
  138. void setHostAndPort(in AUTF8String hostport);
  139. /**
  140. * The host is the internet domain name to which this URI refers. It could
  141. * be an IPv4 (or IPv6) address literal. If supported, it could be a
  142. * non-ASCII internationalized domain name.
  143. *
  144. * Characters are NOT escaped.
  145. */
  146. attribute AUTF8String host;
  147. /**
  148. * A port value of -1 corresponds to the protocol's default port (eg. -1
  149. * implies port 80 for http URIs).
  150. */
  151. attribute long port;
  152. /**
  153. * The path, typically including at least a leading '/' (but may also be
  154. * empty, depending on the protocol).
  155. *
  156. * Some characters may be escaped.
  157. *
  158. * This attribute contains query and ref parts for historical reasons.
  159. * Use the 'filePath' attribute if you do not want those parts included.
  160. */
  161. attribute AUTF8String path;
  162. /************************************************************************
  163. * An URI supports the following methods:
  164. */
  165. /**
  166. * URI equivalence test (not a strict string comparison).
  167. *
  168. * eg. http://foo.com:80/ == http://foo.com/
  169. */
  170. boolean equals(in nsIURI other);
  171. /**
  172. * An optimization to do scheme checks without requiring the users of nsIURI
  173. * to GetScheme, thereby saving extra allocating and freeing. Returns true if
  174. * the schemes match (case ignored).
  175. */
  176. boolean schemeIs(in string scheme);
  177. /**
  178. * Clones the current URI.
  179. */
  180. nsIURI clone();
  181. /**
  182. * This method resolves a relative string into an absolute URI string,
  183. * using this URI as the base.
  184. *
  185. * NOTE: some implementations may have no concept of a relative URI.
  186. */
  187. AUTF8String resolve(in AUTF8String relativePath);
  188. /************************************************************************
  189. * Additional attributes:
  190. */
  191. /**
  192. * The URI spec with an ASCII compatible encoding. Host portion follows
  193. * the IDNA draft spec. Other parts are URL-escaped per the rules of
  194. * RFC2396. The result is strictly ASCII.
  195. */
  196. readonly attribute ACString asciiSpec;
  197. /**
  198. * The host:port (or simply the host, if port == -1), with an ASCII compatible
  199. * encoding. Host portion follows the IDNA draft spec. The result is strictly
  200. * ASCII.
  201. */
  202. readonly attribute ACString asciiHostPort;
  203. /**
  204. * The URI host with an ASCII compatible encoding. Follows the IDNA
  205. * draft spec for converting internationalized domain names (UTF-8) to
  206. * ASCII for compatibility with existing internet infrasture.
  207. */
  208. readonly attribute ACString asciiHost;
  209. /**
  210. * The charset of the document from which this URI originated. An empty
  211. * value implies UTF-8.
  212. *
  213. * If this value is something other than UTF-8 then the URI components
  214. * (e.g., spec, prePath, username, etc.) will all be fully URL-escaped.
  215. * Otherwise, the URI components may contain unescaped multibyte UTF-8
  216. * characters.
  217. */
  218. readonly attribute ACString originCharset;
  219. /************************************************************************
  220. * Additional attribute & methods added for .ref support:
  221. */
  222. /**
  223. * Returns the reference portion (the part after the "#") of the URI.
  224. * If there isn't one, an empty string is returned.
  225. *
  226. * Some characters may be escaped.
  227. */
  228. attribute AUTF8String ref;
  229. /**
  230. * URI equivalence test (not a strict string comparison), ignoring
  231. * the value of the .ref member.
  232. *
  233. * eg. http://foo.com/# == http://foo.com/
  234. * http://foo.com/#aaa == http://foo.com/#bbb
  235. */
  236. boolean equalsExceptRef(in nsIURI other);
  237. /**
  238. * Clones the current URI, clearing the 'ref' attribute in the clone.
  239. */
  240. nsIURI cloneIgnoringRef();
  241. /**
  242. * Clones the current URI, replacing the 'ref' attribute in the clone with
  243. * the ref supplied.
  244. */
  245. nsIURI cloneWithNewRef(in AUTF8String newRef);
  246. /**
  247. * returns a string for the current URI with the ref element cleared.
  248. */
  249. readonly attribute AUTF8String specIgnoringRef;
  250. /**
  251. * Returns if there is a reference portion (the part after the "#") of the URI.
  252. */
  253. readonly attribute boolean hasRef;
  254. /************************************************************************
  255. * Additional attributes added for .query support:
  256. */
  257. /**
  258. * Returns a path including the directory and file portions of a
  259. * URL. For example, the filePath of "http://host/foo/bar.html#baz"
  260. * is "/foo/bar.html".
  261. *
  262. * Some characters may be escaped.
  263. */
  264. attribute AUTF8String filePath;
  265. /**
  266. * Returns the query portion (the part after the "?") of the URL.
  267. * If there isn't one, an empty string is returned.
  268. *
  269. * Some characters may be escaped.
  270. */
  271. attribute AUTF8String query;
  272. };