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