Bug 1323683 - Fold nsIURIWithQuery into nsIURI

native in moebius
This commit is contained in:
janekptacijarabaci 2018-04-22 21:20:53 +02:00 • committed by Roy Tam
commit 8dccc387f9
14 changed files with 110 additions and 107 deletions

View file

@ -167,6 +167,32 @@ nsNullPrincipalURI::SetPath(const nsACString &aPath)
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP
nsNullPrincipalURI::GetFilePath(nsACString &aFilePath)
{
aFilePath.Truncate();
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNullPrincipalURI::SetFilePath(const nsACString &aFilePath)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNullPrincipalURI::GetQuery(nsACString &aQuery)
{
aQuery.Truncate();
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNullPrincipalURI::SetQuery(const nsACString &aQuery)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP NS_IMETHODIMP
nsNullPrincipalURI::GetRef(nsACString &_ref) nsNullPrincipalURI::GetRef(nsACString &_ref)
{ {

View file

@ -582,16 +582,13 @@ Location::GetPathname(nsAString& aPathname)
return result; return result;
} }
nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(uri));
if (url) {
nsAutoCString file; nsAutoCString file;
result = url->GetFilePath(file); result = uri->GetFilePath(file);
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
AppendUTF8toUTF16(file, aPathname); AppendUTF8toUTF16(file, aPathname);
} }
}
return result; return result;
} }
@ -605,8 +602,7 @@ Location::SetPathname(const nsAString& aPathname)
return rv; return rv;
} }
nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(uri)); if (NS_SUCCEEDED(uri->SetFilePath(NS_ConvertUTF16toUTF8(aPathname)))) {
if (url && NS_SUCCEEDED(url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname)))) {
return SetURI(uri); return SetURI(uri);
} }

View file

@ -17,7 +17,6 @@
#include "nsEscape.h" #include "nsEscape.h"
#include "nsHostObjectProtocolHandler.h" #include "nsHostObjectProtocolHandler.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIURIWithQuery.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -525,22 +524,11 @@ URLMainThread::GetPathname(nsAString& aPathname, ErrorResult& aRv) const
// Do not throw! Not having a valid URI or URL should result in an empty // Do not throw! Not having a valid URI or URL should result in an empty
// string. // string.
nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(mURI));
if (url) {
nsAutoCString file; nsAutoCString file;
nsresult rv = url->GetFilePath(file); nsresult rv = mURI->GetFilePath(file);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(file, aPathname); CopyUTF8toUTF16(file, aPathname);
} }
return;
}
nsAutoCString path;
nsresult rv = mURI->GetPath(path);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(path, aPathname);
}
} }
void void
@ -548,11 +536,7 @@ URLMainThread::SetPathname(const nsAString& aPathname, ErrorResult& aRv)
{ {
// Do not throw! // Do not throw!
nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(mURI)); mURI->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
if (url) {
url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
return;
}
} }
void void
@ -566,14 +550,10 @@ URLMainThread::GetSearch(nsAString& aSearch, ErrorResult& aRv) const
nsAutoCString search; nsAutoCString search;
nsresult rv; nsresult rv;
nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(mURI)); rv = mURI->GetQuery(search);
if (url) {
rv = url->GetQuery(search);
if (NS_SUCCEEDED(rv) && !search.IsEmpty()) { if (NS_SUCCEEDED(rv) && !search.IsEmpty()) {
CopyUTF8toUTF16(NS_LITERAL_CSTRING("?") + search, aSearch); CopyUTF8toUTF16(NS_LITERAL_CSTRING("?") + search, aSearch);
} }
return;
}
} }
void void
@ -603,11 +583,7 @@ URLMainThread::SetSearchInternal(const nsAString& aSearch, ErrorResult& aRv)
{ {
// Ignore failures to be compatible with NS4. // Ignore failures to be compatible with NS4.
nsCOMPtr<nsIURIWithQuery> uriWithQuery(do_QueryInterface(mURI)); mURI->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
if (uriWithQuery) {
uriWithQuery->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
return;
}
} }
} // anonymous namespace } // anonymous namespace

View file

@ -371,6 +371,32 @@ nsMozIconURI::SetPath(const nsACString& aPath)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
NS_IMETHODIMP
nsMozIconURI::GetFilePath(nsACString& aFilePath)
{
aFilePath.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsMozIconURI::SetFilePath(const nsACString& aFilePath)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMozIconURI::GetQuery(nsACString& aQuery)
{
aQuery.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsMozIconURI::SetQuery(const nsACString& aQuery)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP NS_IMETHODIMP
nsMozIconURI::GetRef(nsACString& aRef) nsMozIconURI::GetRef(nsACString& aRef)
{ {

View file

@ -41,7 +41,6 @@ NS_IMPL_RELEASE(nsJARURI)
NS_INTERFACE_MAP_BEGIN(nsJARURI) NS_INTERFACE_MAP_BEGIN(nsJARURI)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJARURI) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJARURI)
NS_INTERFACE_MAP_ENTRY(nsIURI) NS_INTERFACE_MAP_ENTRY(nsIURI)
NS_INTERFACE_MAP_ENTRY(nsIURIWithQuery)
NS_INTERFACE_MAP_ENTRY(nsIURL) NS_INTERFACE_MAP_ENTRY(nsIURL)
NS_INTERFACE_MAP_ENTRY(nsIJARURI) NS_INTERFACE_MAP_ENTRY(nsIJARURI)
NS_INTERFACE_MAP_ENTRY(nsISerializable) NS_INTERFACE_MAP_ENTRY(nsISerializable)

View file

@ -41,7 +41,6 @@ class nsJARURI final : public nsIJARURI,
public: public:
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIURI NS_DECL_NSIURI
NS_DECL_NSIURIWITHQUERY
NS_DECL_NSIURL NS_DECL_NSIURL
NS_DECL_NSIJARURI NS_DECL_NSIJARURI
NS_DECL_NSISERIALIZABLE NS_DECL_NSISERIALIZABLE

View file

@ -132,7 +132,6 @@ XPIDL_SOURCES += [
'nsIURIClassifier.idl', 'nsIURIClassifier.idl',
'nsIURIWithBlobImpl.idl', 'nsIURIWithBlobImpl.idl',
'nsIURIWithPrincipal.idl', 'nsIURIWithPrincipal.idl',
'nsIURIWithQuery.idl',
'nsIURL.idl', 'nsIURL.idl',
'nsIURLParser.idl', 'nsIURLParser.idl',
'nsPILoadGroupInternal.idl', 'nsPILoadGroupInternal.idl',

View file

@ -10,16 +10,16 @@
* provides accessors to set and query the most basic components of an URI. * provides accessors to set and query the most basic components of an URI.
* Subclasses, including nsIURL, impose greater structure on the URI. * Subclasses, including nsIURL, impose greater structure on the URI.
* *
* This interface follows Tim Berners-Lee's URI spec (RFC2396) [1], where the * This interface follows Tim Berners-Lee's URI spec (RFC3986) [1], where the
* basic URI components are defined as such: * basic URI components are defined as such:
* <pre> * <pre>
* ftp://username:password@hostname:portnumber/pathname#ref * ftp://username:password@hostname:portnumber/pathname?query#ref
* \ / \ / \ / \ /\ \ / * \ / \ / \ / \ /\ / \ / \ /
* - --------------- ------ -------- | - * - --------------- ------ -------- ------- --- -
* | | | | | | * | | | | | | |
* | | | | | Ref * | | | | FilePath Query Ref
* | | | Port \ / * | | | Port \ /
* | | Host / -------- * | | Host / ------------
* | UserPass / | * | UserPass / |
* Scheme / Path * Scheme / Path
* \ / * \ /
@ -30,13 +30,9 @@
* The definition of the URI components has been extended to allow for * The definition of the URI components has been extended to allow for
* internationalized domain names [2] and the more generic IRI structure [3]. * internationalized domain names [2] and the more generic IRI structure [3].
* *
* Note also that the RFC defines #-separated fragment identifiers as being * [1] https://tools.ietf.org/html/rfc3986
* "not part of the URI". Despite this, we bundle them as part of the URI, for * [2] https://tools.ietf.org/html/rfc5890
* convenience. * [3] https://tools.ietf.org/html/rfc3987
*
* [1] http://www.ietf.org/rfc/rfc2396.txt
* [2] http://www.ietf.org/internet-drafts/draft-ietf-idn-idna-06.txt
* [3] http://www.ietf.org/internet-drafts/draft-masinter-url-i18n-08.txt
*/ */
%{C++ %{C++
@ -116,7 +112,7 @@ interface nsIURI : nsISupports
/** /**
* The Scheme is the protocol to which this URI refers. The scheme is * The Scheme is the protocol to which this URI refers. The scheme is
* restricted to the US-ASCII charset per RFC2396. Setting this is * restricted to the US-ASCII charset per RFC3986. Setting this is
* highly discouraged outside of a protocol handler implementation, since * highly discouraged outside of a protocol handler implementation, since
* that will generally lead to incorrect results. * that will generally lead to incorrect results.
*/ */
@ -174,6 +170,9 @@ interface nsIURI : nsISupports
* empty, depending on the protocol). * empty, depending on the protocol).
* *
* Some characters may be escaped. * Some characters may be escaped.
*
* This attribute contains query and ref parts for historical reasons.
* Use the 'filePath' attribute if you do not want those parts included.
*/ */
attribute AUTF8String path; attribute AUTF8String path;
@ -287,4 +286,25 @@ interface nsIURI : nsISupports
* Returns if there is a reference portion (the part after the "#") of the URI. * Returns if there is a reference portion (the part after the "#") of the URI.
*/ */
readonly attribute boolean hasRef; 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;
}; };

View file

@ -1,30 +0,0 @@
/* 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/. */
#include "nsIURI.idl"
/**
* nsIURIWithQuery is implemented by URIs which have a query parameter.
* This is useful for the URL API.
*/
[scriptable, uuid(367510ee-8556-435a-8f99-b5fd357e08cc)]
interface nsIURIWithQuery : nsIURI
{
/**
* 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;
};

View file

@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIURIWithQuery.idl" #include "nsIURI.idl"
/** /**
* The nsIURL interface provides convenience methods that further * The nsIURL interface provides convenience methods that further
@ -20,7 +20,7 @@
* filePath * filePath
*/ */
[scriptable, uuid(86adcd89-0b70-47a2-b0fe-5bb2c5f37e31)] [scriptable, uuid(86adcd89-0b70-47a2-b0fe-5bb2c5f37e31)]
interface nsIURL : nsIURIWithQuery interface nsIURL : nsIURI
{ {
/************************************************************************* /*************************************************************************
* The URL path is broken down into the following principal components: * The URL path is broken down into the following principal components:
@ -28,7 +28,7 @@ interface nsIURL : nsIURIWithQuery
* attribute AUTF8String filePath; * attribute AUTF8String filePath;
* attribute AUTF8String query; * attribute AUTF8String query;
* *
* These are inherited from nsIURIWithQuery. * These are inherited from nsIURI.
*/ */
/************************************************************************* /*************************************************************************

View file

@ -48,7 +48,7 @@ nsSimpleURI::~nsSimpleURI()
NS_IMPL_ADDREF(nsSimpleURI) NS_IMPL_ADDREF(nsSimpleURI)
NS_IMPL_RELEASE(nsSimpleURI) NS_IMPL_RELEASE(nsSimpleURI)
NS_INTERFACE_TABLE_HEAD(nsSimpleURI) NS_INTERFACE_TABLE_HEAD(nsSimpleURI)
NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsIURIWithQuery, nsISerializable, NS_INTERFACE_TABLE(nsSimpleURI, nsIURI, nsISerializable,
nsIClassInfo, nsIMutable, nsIIPCSerializableURI) nsIClassInfo, nsIMutable, nsIIPCSerializableURI)
NS_INTERFACE_TABLE_TO_MAP_SEGUE NS_INTERFACE_TABLE_TO_MAP_SEGUE
if (aIID.Equals(kThisSimpleURIImplementationCID)) if (aIID.Equals(kThisSimpleURIImplementationCID))
@ -784,10 +784,6 @@ nsSimpleURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
} }
//----------------------------------------------------------------------------
// nsSimpleURI::nsIURIWithQuery
//----------------------------------------------------------------------------
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleURI::GetFilePath(nsACString& aFilePath) nsSimpleURI::GetFilePath(nsACString& aFilePath)
{ {

View file

@ -8,7 +8,6 @@
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIURIWithQuery.h"
#include "nsISerializable.h" #include "nsISerializable.h"
#include "nsString.h" #include "nsString.h"
#include "nsIClassInfo.h" #include "nsIClassInfo.h"
@ -28,7 +27,7 @@ namespace net {
} }
class nsSimpleURI class nsSimpleURI
: public nsIURIWithQuery : public nsIURI
, public nsISerializable , public nsISerializable
, public nsIClassInfo , public nsIClassInfo
, public nsIMutable , public nsIMutable
@ -41,7 +40,6 @@ protected:
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIURI NS_DECL_NSIURI
NS_DECL_NSIURIWITHQUERY
NS_DECL_NSISERIALIZABLE NS_DECL_NSISERIALIZABLE
NS_DECL_NSICLASSINFO NS_DECL_NSICLASSINFO
NS_DECL_NSIMUTABLE NS_DECL_NSIMUTABLE

View file

@ -1182,7 +1182,6 @@ NS_IMPL_RELEASE(nsStandardURL)
NS_INTERFACE_MAP_BEGIN(nsStandardURL) NS_INTERFACE_MAP_BEGIN(nsStandardURL)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStandardURL) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStandardURL)
NS_INTERFACE_MAP_ENTRY(nsIURI) NS_INTERFACE_MAP_ENTRY(nsIURI)
NS_INTERFACE_MAP_ENTRY(nsIURIWithQuery)
NS_INTERFACE_MAP_ENTRY(nsIURL) NS_INTERFACE_MAP_ENTRY(nsIURL)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFileURL, mSupportsFileURL) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFileURL, mSupportsFileURL)
NS_INTERFACE_MAP_ENTRY(nsIStandardURL) NS_INTERFACE_MAP_ENTRY(nsIStandardURL)

View file

@ -54,7 +54,6 @@ protected:
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIURI NS_DECL_NSIURI
NS_DECL_NSIURIWITHQUERY
NS_DECL_NSIURL NS_DECL_NSIURL
NS_DECL_NSIFILEURL NS_DECL_NSIFILEURL
NS_DECL_NSISTANDARDURL NS_DECL_NSISTANDARDURL