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/. */
6 #include
"nsISupports.idl"
9 * URIs are essentially structured names for things -- anything. This interface
10 * provides accessors to get the most basic components of an URI.
11 * If you need to change some parts of the URI use nsIURIMutator.
12 * Subclasses, including nsIURL, impose greater structure on the URI.
14 * This interface follows Tim Berners-Lee's URI spec (RFC3986) [1], where the
15 * basic URI components are defined as such:
17 * ftp://username:password@hostname:portnumber/pathname?query#ref
18 * \ / \ / \ / \ /\ / \ / \ /
19 * - --------------- ------ -------- ------- --- -
21 * | | | | FilePath Query Ref
23 * | | Host / ------------
27 * --------------------------------
31 * The definition of the URI components has been extended to allow for
32 * internationalized domain names [2] and the more generic IRI structure [3].
34 * [1] https://tools.ietf.org/html/rfc3986
35 * [2] https://tools.ietf.org/html/rfc5890
36 * [3] https://tools.ietf.org/html/rfc3987
42 #undef GetPort
// XXX Windows!
43 #undef SetPort
// XXX Windows!
50 } // namespace mozilla
53 [ptr] native Encoding
(const mozilla
::Encoding
);
54 [ref] native URIParams
(mozilla
::ipc
::URIParams
);
55 interface nsIURIMutator
;
58 * nsIURI - interface for an uniform resource identifier w/ i18n support.
60 * AUTF8String attributes may contain unescaped UTF-8 characters.
61 * Consumers should be careful to escape the UTF-8 strings as necessary, but
62 * should always try to "display" the UTF-8 version as provided by this
65 * AUTF8String attributes may also contain escaped characters.
67 * Unescaping URI segments is unadvised unless there is intimate
68 * knowledge of the underlying charset or there is no plan to display (or
69 * otherwise enforce a charset on) the resulting URI substring.
71 * The correct way to create an nsIURI from a string is via
72 * nsIIOService.newURI.
74 * NOTE: nsBinaryInputStream::ReadObject contains a hackaround to intercept the
75 * old (pre-gecko6) nsIURI IID and swap in the current IID instead, in order
76 * for sessionstore to work after an upgrade. If this IID is revved further,
77 * we will need to add additional checks there for all intermediate IIDs, until
78 * ContentPrincipal is fixed to serialize its URIs as nsISupports (bug 662693).
80 [scriptable
, builtinclass
, uuid(92073a54
-6d78
-4f30
-913a
-b871813208c6
)]
81 interface nsIURI
: nsISupports
83 /************************************************************************
84 * The URI is broken down into the following principal components:
88 * Returns a string representation of the URI.
90 * Some characters may be escaped.
92 readonly attribute AUTF8String spec
;
95 // An infallible wrapper for GetSpec() that returns a failure indication
96 // string if GetSpec() fails. It is most useful for creating
97 // logging/warning/error messages produced for human consumption, and when
98 // matching a URI spec against a fixed spec such as about:blank.
99 nsCString GetSpecOrDefault
()
102 nsresult rv
= GetSpec
(spec
);
104 spec.AssignLiteral
("[nsIURI::GetSpec failed]");
111 * The prePath (eg. scheme://user:password@host:port) returns the string
112 * before the path. This is useful for authentication or managing sessions.
114 * Some characters may be escaped.
116 readonly attribute AUTF8String prePath
;
119 * The Scheme is the protocol to which this URI refers. The scheme is
120 * restricted to the US-ASCII charset per RFC3986.
122 readonly attribute ACString scheme
;
125 * The username:password (or username only if value doesn't contain a ':')
127 * Some characters may be escaped.
129 readonly attribute AUTF8String userPass
;
132 * The optional username and password, assuming the preHost consists of
135 * Some characters may be escaped.
137 readonly attribute AUTF8String username
;
138 readonly attribute AUTF8String password
;
141 * The host:port (or simply the host, if port == -1).
143 readonly attribute AUTF8String hostPort
;
146 * The host is the internet domain name to which this URI refers. It could
147 * be an IPv4 (or IPv6) address literal. Otherwise it is an ASCII or punycode
150 readonly attribute AUTF8String host
;
153 * A port value of -1 corresponds to the protocol's default port (eg. -1
154 * implies port 80 for http URIs).
156 readonly attribute
long port
;
159 * The path, typically including at least a leading '/' (but may also be
160 * empty, depending on the protocol).
162 * Some characters may be escaped.
164 * This attribute contains query and ref parts for historical reasons.
165 * Use the 'filePath' attribute if you do not want those parts included.
167 readonly attribute AUTF8String pathQueryRef
;
170 /************************************************************************
171 * An URI supports the following methods:
175 * URI equivalence test (not a strict string comparison).
177 * eg. http://foo.com:80/ == http://foo.com/
179 boolean equals
(in nsIURI other
);
182 * An optimization to do scheme checks without requiring the users of nsIURI
183 * to GetScheme, thereby saving extra allocating and freeing. Returns true if
184 * the schemes match (case ignored).
186 [infallible
] boolean schemeIs
(in string scheme
);
189 * This method resolves a relative string into an absolute URI string,
190 * using this URI as the base.
192 * NOTE: some implementations may have no concept of a relative URI.
194 AUTF8String resolve
(in AUTF8String relativePath
);
197 /************************************************************************
198 * Additional attributes:
202 * The URI spec with an ASCII compatible encoding. Host portion follows
203 * the IDNA draft spec. Other parts are URL-escaped per the rules of
204 * RFC2396. The result is strictly ASCII.
206 readonly attribute ACString asciiSpec
;
209 * The host:port (or simply the host, if port == -1), with an ASCII compatible
210 * encoding. Host portion follows the IDNA draft spec. The result is strictly
213 readonly attribute ACString asciiHostPort
;
216 * The URI host with an ASCII compatible encoding. Follows the IDNA
217 * draft spec for converting internationalized domain names (UTF-8) to
218 * ASCII for compatibility with existing internet infrasture.
220 readonly attribute ACString asciiHost
;
222 /************************************************************************
223 * Additional attribute & methods added for .ref support:
227 * Returns the reference portion (the part after the "#") of the URI.
228 * If there isn't one, an empty string is returned.
230 * Some characters may be escaped.
232 readonly attribute AUTF8String
ref;
235 * URI equivalence test (not a strict string comparison), ignoring
236 * the value of the .ref member.
238 * eg. http://foo.com/# == http://foo.com/
239 * http://foo.com/#aaa == http://foo.com/#bbb
241 boolean equalsExceptRef
(in nsIURI other
);
244 * returns a string for the current URI with the ref element cleared.
246 readonly attribute AUTF8String specIgnoringRef
;
249 * Returns if there is a reference portion (the part after the "#") of the URI.
251 readonly attribute
boolean hasRef
;
253 /************************************************************************
254 * Additional attributes added for .query support:
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".
262 * Some characters may be escaped.
264 readonly attribute AUTF8String filePath
;
267 * Returns the query portion (the part after the "?") of the URL.
268 * If there isn't one, an empty string is returned.
270 * Some characters may be escaped.
272 readonly attribute AUTF8String query
;
275 * If the URI has a punycode encoded hostname, this will hold the UTF8
276 * representation of that hostname (if that representation doesn't contain
277 * blacklisted characters, and the network.IDN_show_punycode pref is false)
278 * Otherwise, if the hostname is ASCII, it will return the same as .asciiHost
280 readonly attribute AUTF8String displayHost
;
283 * The displayHost:port (or simply the displayHost, if port == -1).
285 readonly attribute AUTF8String displayHostPort
;
288 * Returns the same as calling .spec, only with a UTF8 encoded hostname
289 * (if that hostname doesn't contain blacklisted characters, and
290 * the network.IDN_show_punycode pref is false)
292 readonly attribute AUTF8String displaySpec
;
295 * Returns the same as calling .prePath, only with a UTF8 encoded hostname
296 * (if that hostname doesn't contain blacklisted characters, and
297 * the network.IDN_show_punycode pref is false)
299 readonly attribute AUTF8String displayPrePath
;
302 * Returns an nsIURIMutator that can be used to make changes to the URI.
303 * After performing the setter operations on the mutator, one may call
304 * mutator.finalize() to get a new immutable URI with the desired
307 nsIURIMutator mutate
();
310 * Serializes a URI object to a URIParams data structure in order for being
311 * passed over IPC. For deserialization, see nsIURIMutator.
313 [noscript
, notxpcom
] void serialize
(in URIParams aParams
);
317 friend std
::ostream
& operator
<<(std
::ostream
& aOut
, const nsIURI
& aURI
) {
318 nsIURI
* uri
= const_cast
<nsIURI
*>(&aURI
);
319 return aOut
<< "nsIURI { " << uri
->GetSpecOrDefault
() << " }";