2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-06-08 01:33:30 +04:00
|
|
|
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
|
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* URIs are essentially structured names for things -- anything. This interface
|
|
|
|
* provides accessors to set and query the most basic components of an URI.
|
|
|
|
* Subclasses, including nsIURL, impose greater structure on the URI.
|
1999-06-08 01:33:30 +04:00
|
|
|
*
|
2016-12-28 14:40:21 +03:00
|
|
|
* This interface follows Tim Berners-Lee's URI spec (RFC3986) [1], where the
|
2002-03-06 10:48:55 +03:00
|
|
|
* basic URI components are defined as such:
|
2011-05-22 05:12:45 +04:00
|
|
|
* <pre>
|
2016-12-28 14:40:21 +03:00
|
|
|
* ftp://username:password@hostname:portnumber/pathname?query#ref
|
|
|
|
* \ / \ / \ / \ /\ / \ / \ /
|
|
|
|
* - --------------- ------ -------- ------- --- -
|
|
|
|
* | | | | | | |
|
|
|
|
* | | | | FilePath Query Ref
|
|
|
|
* | | | Port \ /
|
|
|
|
* | | Host / ------------
|
|
|
|
* | UserPass / |
|
|
|
|
* Scheme / Path
|
2000-05-17 11:12:40 +04:00
|
|
|
* \ /
|
|
|
|
* --------------------------------
|
|
|
|
* |
|
|
|
|
* PrePath
|
2007-04-27 20:50:11 +04:00
|
|
|
* </pre>
|
2002-03-06 10:48:55 +03:00
|
|
|
* The definition of the URI components has been extended to allow for
|
|
|
|
* internationalized domain names [2] and the more generic IRI structure [3].
|
2001-03-24 03:22:18 +03:00
|
|
|
*
|
2016-12-28 14:40:21 +03:00
|
|
|
* [1] https://tools.ietf.org/html/rfc3986
|
|
|
|
* [2] https://tools.ietf.org/html/rfc5890
|
|
|
|
* [3] https://tools.ietf.org/html/rfc3987
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
|
|
|
|
1999-06-25 21:59:34 +04:00
|
|
|
%{C++
|
2016-08-26 09:02:31 +03:00
|
|
|
#include "nsStringGlue.h"
|
|
|
|
|
1999-06-25 21:59:34 +04:00
|
|
|
#undef GetPort // XXX Windows!
|
1999-06-29 03:11:55 +04:00
|
|
|
#undef SetPort // XXX Windows!
|
2017-08-02 14:43:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class Encoding;
|
|
|
|
}
|
1999-06-25 21:59:34 +04:00
|
|
|
%}
|
|
|
|
|
2017-08-02 14:43:30 +03:00
|
|
|
[ptr] native Encoding(const mozilla::Encoding);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/**
|
|
|
|
* nsIURI - interface for an uniform resource identifier w/ i18n support.
|
|
|
|
*
|
|
|
|
* AUTF8String attributes may contain unescaped UTF-8 characters.
|
|
|
|
* Consumers should be careful to escape the UTF-8 strings as necessary, but
|
|
|
|
* should always try to "display" the UTF-8 version as provided by this
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* AUTF8String attributes may also contain escaped characters.
|
|
|
|
*
|
|
|
|
* Unescaping URI segments is unadvised unless there is intimate
|
|
|
|
* knowledge of the underlying charset or there is no plan to display (or
|
|
|
|
* otherwise enforce a charset on) the resulting URI substring.
|
2009-02-23 23:59:26 +03:00
|
|
|
*
|
|
|
|
* The correct way to create an nsIURI from a string is via
|
|
|
|
* nsIIOService.newURI.
|
2011-06-09 23:10:42 +04:00
|
|
|
*
|
|
|
|
* NOTE: nsBinaryInputStream::ReadObject contains a hackaround to intercept the
|
|
|
|
* old (pre-gecko6) nsIURI IID and swap in the current IID instead, in order
|
|
|
|
* for sessionstore to work after an upgrade. If this IID is revved further,
|
|
|
|
* we will need to add additional checks there for all intermediate IIDs, until
|
2017-03-22 13:39:31 +03:00
|
|
|
* ContentPrincipal is fixed to serialize its URIs as nsISupports (bug 662693).
|
2002-03-06 10:48:55 +03:00
|
|
|
*/
|
2015-08-17 22:34:17 +03:00
|
|
|
[scriptable, uuid(92073a54-6d78-4f30-913a-b871813208c6)]
|
1999-06-08 01:33:30 +04:00
|
|
|
interface nsIURI : nsISupports
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
/************************************************************************
|
|
|
|
* The URI is broken down into the following principal components:
|
|
|
|
*/
|
2001-01-31 04:33:03 +03:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* Returns a string representation of the URI. Setting the spec causes
|
2009-02-23 23:59:26 +03:00
|
|
|
* the new spec to be parsed per the rules for the scheme the URI
|
|
|
|
* currently has. In particular, setting the spec to a URI string with a
|
|
|
|
* different scheme will generally produce incorrect results; no one
|
|
|
|
* outside of a protocol handler implementation should be doing that. If
|
|
|
|
* the URI stores information from the nsIIOService.newURI call used to
|
|
|
|
* create it other than just the parsed string, then behavior of this
|
|
|
|
* information on setting the spec attribute is undefined.
|
2002-03-06 10:48:55 +03:00
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
attribute AUTF8String spec;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2016-08-26 09:02:31 +03:00
|
|
|
%{ C++
|
|
|
|
// An infallible wrapper for GetSpec() that returns a failure indication
|
|
|
|
// string if GetSpec() fails. It is most useful for creating
|
|
|
|
// logging/warning/error messages produced for human consumption, and when
|
|
|
|
// matching a URI spec against a fixed spec such as about:blank.
|
|
|
|
nsCString GetSpecOrDefault()
|
|
|
|
{
|
|
|
|
nsCString spec;
|
|
|
|
nsresult rv = GetSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
spec.Assign("[nsIURI::GetSpec failed]");
|
|
|
|
}
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2000-05-17 11:12:40 +04:00
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* The prePath (eg. scheme://user:password@host:port) returns the string
|
|
|
|
* before the path. This is useful for authentication or managing sessions.
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
2000-05-17 11:12:40 +04:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
readonly attribute AUTF8String prePath;
|
2000-05-17 11:12:40 +04:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* The Scheme is the protocol to which this URI refers. The scheme is
|
2016-12-28 14:40:21 +03:00
|
|
|
* restricted to the US-ASCII charset per RFC3986. Setting this is
|
2009-02-23 23:59:26 +03:00
|
|
|
* highly discouraged outside of a protocol handler implementation, since
|
|
|
|
* that will generally lead to incorrect results.
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
attribute ACString scheme;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* The username:password (or username only if value doesn't contain a ':')
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
attribute AUTF8String userPass;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/**
|
|
|
|
* The optional username and password, assuming the preHost consists of
|
|
|
|
* username:password.
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
|
|
|
*/
|
|
|
|
attribute AUTF8String username;
|
|
|
|
attribute AUTF8String password;
|
2000-02-03 06:44:22 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/**
|
|
|
|
* The host:port (or simply the host, if port == -1).
|
|
|
|
*
|
2016-08-18 06:25:00 +03:00
|
|
|
* If this attribute is set to a value that only has a host part, the port
|
|
|
|
* will not be reset. To reset the port as well use setHostAndPort.
|
2002-03-06 10:48:55 +03:00
|
|
|
*/
|
|
|
|
attribute AUTF8String hostPort;
|
2000-02-03 06:44:22 +03:00
|
|
|
|
2016-08-18 06:25:00 +03:00
|
|
|
/**
|
|
|
|
* This function will always set a host and a port. If the port part is
|
|
|
|
* empty, the value of the port will be set to the default value.
|
|
|
|
*/
|
|
|
|
void setHostAndPort(in AUTF8String hostport);
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* The host is the internet domain name to which this URI refers. It could
|
2017-07-11 20:09:10 +03:00
|
|
|
* be an IPv4 (or IPv6) address literal. Otherwise it is an ASCII or punycode
|
|
|
|
* encoded string.
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
attribute AUTF8String host;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* A port value of -1 corresponds to the protocol's default port (eg. -1
|
|
|
|
* implies port 80 for http URIs).
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
1999-10-12 05:39:37 +04:00
|
|
|
attribute long port;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* The path, typically including at least a leading '/' (but may also be
|
|
|
|
* empty, depending on the protocol).
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
2016-12-28 14:40:21 +03:00
|
|
|
*
|
|
|
|
* This attribute contains query and ref parts for historical reasons.
|
|
|
|
* Use the 'filePath' attribute if you do not want those parts included.
|
2002-03-06 10:48:55 +03:00
|
|
|
*/
|
2017-07-29 14:50:21 +03:00
|
|
|
attribute AUTF8String pathQueryRef;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* An URI supports the following methods:
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* URI equivalence test (not a strict string comparison).
|
|
|
|
*
|
|
|
|
* eg. http://foo.com:80/ == http://foo.com/
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
1999-10-12 05:39:37 +04:00
|
|
|
boolean equals(in nsIURI other);
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2001-01-31 04:33:03 +03:00
|
|
|
/**
|
2002-03-06 10:48:55 +03:00
|
|
|
* An optimization to do scheme checks without requiring the users of nsIURI
|
|
|
|
* to GetScheme, thereby saving extra allocating and freeing. Returns true if
|
|
|
|
* the schemes match (case ignored).
|
|
|
|
*/
|
2001-03-13 05:01:07 +03:00
|
|
|
boolean schemeIs(in string scheme);
|
2001-01-31 04:33:03 +03:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
/**
|
2011-05-22 05:12:21 +04:00
|
|
|
* Clones the current URI.
|
1999-06-08 01:33:30 +04:00
|
|
|
*/
|
1999-10-12 05:39:37 +04:00
|
|
|
nsIURI clone();
|
1999-07-23 01:14:51 +04:00
|
|
|
|
1999-11-03 08:13:44 +03:00
|
|
|
/**
|
|
|
|
* This method resolves a relative string into an absolute URI string,
|
2002-03-06 10:48:55 +03:00
|
|
|
* using this URI as the base.
|
1999-11-03 08:13:44 +03:00
|
|
|
*
|
2002-03-06 10:48:55 +03:00
|
|
|
* NOTE: some implementations may have no concept of a relative URI.
|
1999-11-03 08:13:44 +03:00
|
|
|
*/
|
2002-03-06 10:48:55 +03:00
|
|
|
AUTF8String resolve(in AUTF8String relativePath);
|
2000-02-03 06:44:22 +03:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/************************************************************************
|
|
|
|
* Additional attributes:
|
|
|
|
*/
|
1999-07-16 15:14:36 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/**
|
|
|
|
* The URI spec with an ASCII compatible encoding. Host portion follows
|
|
|
|
* the IDNA draft spec. Other parts are URL-escaped per the rules of
|
|
|
|
* RFC2396. The result is strictly ASCII.
|
|
|
|
*/
|
|
|
|
readonly attribute ACString asciiSpec;
|
|
|
|
|
2015-08-17 22:34:17 +03:00
|
|
|
/**
|
|
|
|
* The host:port (or simply the host, if port == -1), with an ASCII compatible
|
|
|
|
* encoding. Host portion follows the IDNA draft spec. The result is strictly
|
|
|
|
* ASCII.
|
|
|
|
*/
|
|
|
|
readonly attribute ACString asciiHostPort;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
/**
|
|
|
|
* The URI host with an ASCII compatible encoding. Follows the IDNA
|
|
|
|
* draft spec for converting internationalized domain names (UTF-8) to
|
|
|
|
* ASCII for compatibility with existing internet infrasture.
|
|
|
|
*/
|
|
|
|
readonly attribute ACString asciiHost;
|
|
|
|
|
2011-07-27 09:11:08 +04:00
|
|
|
/************************************************************************
|
|
|
|
* Additional attribute & methods added for .ref support:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the reference portion (the part after the "#") of the URI.
|
|
|
|
* If there isn't one, an empty string is returned.
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
|
|
|
*/
|
|
|
|
attribute AUTF8String ref;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* URI equivalence test (not a strict string comparison), ignoring
|
|
|
|
* the value of the .ref member.
|
|
|
|
*
|
|
|
|
* eg. http://foo.com/# == http://foo.com/
|
|
|
|
* http://foo.com/#aaa == http://foo.com/#bbb
|
|
|
|
*/
|
|
|
|
boolean equalsExceptRef(in nsIURI other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clones the current URI, clearing the 'ref' attribute in the clone.
|
|
|
|
*/
|
|
|
|
nsIURI cloneIgnoringRef();
|
|
|
|
|
2016-07-27 01:38:46 +03:00
|
|
|
/**
|
|
|
|
* Clones the current URI, replacing the 'ref' attribute in the clone with
|
|
|
|
* the ref supplied.
|
|
|
|
*/
|
|
|
|
nsIURI cloneWithNewRef(in AUTF8String newRef);
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
/**
|
|
|
|
* returns a string for the current URI with the ref element cleared.
|
|
|
|
*/
|
2016-12-28 14:40:21 +03:00
|
|
|
readonly attribute AUTF8String specIgnoringRef;
|
2011-08-16 01:18:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if there is a reference portion (the part after the "#") of the URI.
|
|
|
|
*/
|
2016-12-28 14:40:21 +03:00
|
|
|
readonly attribute boolean hasRef;
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Additional attributes added for .query support:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a path including the directory and file portions of a
|
|
|
|
* URL. For example, the filePath of "http://host/foo/bar.html#baz"
|
|
|
|
* is "/foo/bar.html".
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
|
|
|
*/
|
|
|
|
attribute AUTF8String filePath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the query portion (the part after the "?") of the URL.
|
|
|
|
* If there isn't one, an empty string is returned.
|
|
|
|
*
|
|
|
|
* Some characters may be escaped.
|
|
|
|
*/
|
|
|
|
attribute AUTF8String query;
|
2017-08-02 14:43:30 +03:00
|
|
|
[noscript]
|
|
|
|
void setQueryWithEncoding(in AUTF8String query, in Encoding encoding);
|
2017-07-11 20:09:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the URI has a punycode encoded hostname, this will hold the UTF8
|
|
|
|
* representation of that hostname (if that representation doesn't contain
|
|
|
|
* blacklisted characters, and the network.IDN_show_punycode pref is false)
|
|
|
|
* Otherwise, if the hostname is ASCII, it will return the same as .asciiHost
|
|
|
|
*/
|
|
|
|
readonly attribute AUTF8String displayHost;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The displayHost:port (or simply the displayHost, if port == -1).
|
|
|
|
*/
|
|
|
|
readonly attribute AUTF8String displayHostPort;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the same as calling .spec, only with a UTF8 encoded hostname
|
|
|
|
* (if that hostname doesn't contain blacklisted characters, and
|
|
|
|
* the network.IDN_show_punycode pref is false)
|
|
|
|
*/
|
|
|
|
readonly attribute AUTF8String displaySpec;
|
2002-03-06 10:48:55 +03:00
|
|
|
};
|