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 boolean schemeIs
(in string scheme
);
189 * Infallible version of SchemeIs for C++ callers.
192 bool SchemeIs
(const char* aScheme
) {
194 mozilla
::Unused
<< SchemeIs
(aScheme
, &ret
);
200 * This method resolves a relative string into an absolute URI string,
201 * using this URI as the base.
203 * NOTE: some implementations may have no concept of a relative URI.
205 AUTF8String resolve
(in AUTF8String relativePath
);
208 /************************************************************************
209 * Additional attributes:
213 * The URI spec with an ASCII compatible encoding. Host portion follows
214 * the IDNA draft spec. Other parts are URL-escaped per the rules of
215 * RFC2396. The result is strictly ASCII.
217 readonly attribute ACString asciiSpec
;
220 * The host:port (or simply the host, if port == -1), with an ASCII compatible
221 * encoding. Host portion follows the IDNA draft spec. The result is strictly
224 readonly attribute ACString asciiHostPort
;
227 * The URI host with an ASCII compatible encoding. Follows the IDNA
228 * draft spec for converting internationalized domain names (UTF-8) to
229 * ASCII for compatibility with existing internet infrasture.
231 readonly attribute ACString asciiHost
;
233 /************************************************************************
234 * Additional attribute & methods added for .ref support:
238 * Returns the reference portion (the part after the "#") of the URI.
239 * If there isn't one, an empty string is returned.
241 * Some characters may be escaped.
243 readonly attribute AUTF8String
ref;
246 * URI equivalence test (not a strict string comparison), ignoring
247 * the value of the .ref member.
249 * eg. http://foo.com/# == http://foo.com/
250 * http://foo.com/#aaa == http://foo.com/#bbb
252 boolean equalsExceptRef
(in nsIURI other
);
255 * returns a string for the current URI with the ref element cleared.
257 readonly attribute AUTF8String specIgnoringRef
;
260 * Returns if there is a reference portion (the part after the "#") of the URI.
262 readonly attribute
boolean hasRef
;
264 /************************************************************************
265 * Additional attributes added for .query support:
269 * Returns a path including the directory and file portions of a
270 * URL. For example, the filePath of "http://host/foo/bar.html#baz"
271 * is "/foo/bar.html".
273 * Some characters may be escaped.
275 readonly attribute AUTF8String filePath
;
278 * Returns the query portion (the part after the "?") of the URL.
279 * If there isn't one, an empty string is returned.
281 * Some characters may be escaped.
283 readonly attribute AUTF8String query
;
286 * If the URI has a punycode encoded hostname, this will hold the UTF8
287 * representation of that hostname (if that representation doesn't contain
288 * blacklisted characters, and the network.IDN_show_punycode pref is false)
289 * Otherwise, if the hostname is ASCII, it will return the same as .asciiHost
291 readonly attribute AUTF8String displayHost
;
294 * The displayHost:port (or simply the displayHost, if port == -1).
296 readonly attribute AUTF8String displayHostPort
;
299 * Returns the same as calling .spec, only with a UTF8 encoded hostname
300 * (if that hostname doesn't contain blacklisted characters, and
301 * the network.IDN_show_punycode pref is false)
303 readonly attribute AUTF8String displaySpec
;
306 * Returns the same as calling .prePath, only with a UTF8 encoded hostname
307 * (if that hostname doesn't contain blacklisted characters, and
308 * the network.IDN_show_punycode pref is false)
310 readonly attribute AUTF8String displayPrePath
;
313 * Returns an nsIURIMutator that can be used to make changes to the URI.
314 * After performing the setter operations on the mutator, one may call
315 * mutator.finalize() to get a new immutable URI with the desired
318 nsIURIMutator mutate
();
321 * Serializes a URI object to a URIParams data structure in order for being
322 * passed over IPC. For deserialization, see nsIURIMutator.
324 [noscript
, notxpcom
] void serialize
(in URIParams aParams
);