2017-11-20 15:10:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "nsISupports.idl"
|
|
|
|
interface nsIURI;
|
2017-11-20 16:11:30 +00:00
|
|
|
interface nsIObjectInputStream;
|
2017-12-05 01:35:21 +00:00
|
|
|
interface nsIURIMutator;
|
2017-11-20 15:10:03 +00:00
|
|
|
|
|
|
|
%{C++
|
2017-12-07 00:52:51 +00:00
|
|
|
#include "nsString.h"
|
2017-12-05 16:17:02 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2017-11-20 15:10:03 +00:00
|
|
|
|
|
|
|
#undef SetPort // XXX Windows!
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class Encoding;
|
|
|
|
}
|
2017-11-20 16:11:30 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
class URIParams;
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class BaseURIMutator
|
|
|
|
{
|
|
|
|
// This is the base class that can be extended by implementors of nsIURIMutator
|
|
|
|
// in order to avoid code duplication
|
|
|
|
// Class type T should be the type of the class that implements nsIURI
|
|
|
|
protected:
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult InitFromURI(T* aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> clone;
|
|
|
|
nsresult rv = aURI->Clone(getter_AddRefs(clone));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2017-11-20 16:11:30 +00:00
|
|
|
}
|
2017-12-19 01:16:36 +00:00
|
|
|
mURI = static_cast<T*>(clone.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-11-20 16:11:30 +00:00
|
|
|
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult InitFromInputStream(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
RefPtr<T> uri = new T();
|
|
|
|
nsresult rv = uri->Read(aStream);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2017-11-20 16:11:30 +00:00
|
|
|
}
|
2017-12-19 01:16:36 +00:00
|
|
|
mURI = uri;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-11-20 16:11:30 +00:00
|
|
|
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult InitFromIPCParams(const mozilla::ipc::URIParams& aParams)
|
|
|
|
{
|
|
|
|
RefPtr<T> uri = new T();
|
|
|
|
bool ret = uri->Deserialize(aParams);
|
|
|
|
if (!ret) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2017-11-20 16:11:30 +00:00
|
|
|
}
|
2017-12-19 01:16:36 +00:00
|
|
|
mURI = uri;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-11-20 16:11:30 +00:00
|
|
|
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult InitFromSpec(const nsACString& aSpec)
|
|
|
|
{
|
2018-01-08 10:23:59 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
RefPtr<T> uri;
|
|
|
|
if (mURI) {
|
|
|
|
// This only works because all other Init methods create a new object
|
|
|
|
mURI.swap(uri);
|
|
|
|
} else {
|
|
|
|
uri = new T();
|
|
|
|
}
|
|
|
|
|
2018-01-19 14:26:07 +00:00
|
|
|
rv = uri->SetSpecInternal(aSpec);
|
2017-12-19 01:16:36 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2017-11-20 16:11:30 +00:00
|
|
|
}
|
2017-12-19 01:16:36 +00:00
|
|
|
mURI = uri;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-11-20 16:11:30 +00:00
|
|
|
|
2017-12-19 01:16:36 +00:00
|
|
|
RefPtr<T> mURI;
|
2017-11-20 16:11:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Since most implementations of nsIURIMutator would extend BaseURIMutator,
|
|
|
|
// some methods would have the same implementation. We provide a useful macro
|
|
|
|
// to avoid code duplication.
|
|
|
|
#define NS_DEFINE_NSIMUTATOR_COMMON \
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
Deserialize(const mozilla::ipc::URIParams& aParams) override \
|
|
|
|
{ \
|
|
|
|
return InitFromIPCParams(aParams); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
Read(nsIObjectInputStream* aStream) override \
|
|
|
|
{ \
|
|
|
|
return InitFromInputStream(aStream); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
Finalize(nsIURI** aURI) override \
|
|
|
|
{ \
|
|
|
|
mURI.forget(aURI); return NS_OK; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return InitFromSpec(aSpec); \
|
|
|
|
} \
|
2017-11-20 15:10:03 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
[ptr] native Encoding(const mozilla::Encoding);
|
2017-11-20 16:11:30 +00:00
|
|
|
[ref] native const_URIParams_ref(const mozilla::ipc::URIParams);
|
2017-11-20 15:10:03 +00:00
|
|
|
|
2017-11-20 16:11:30 +00:00
|
|
|
[scriptable, builtinclass, uuid(1fc53257-898b-4c5e-b69c-05bc84b4cd8f)]
|
|
|
|
interface nsIURISetSpec : nsISupports
|
2017-11-20 15:10:03 +00:00
|
|
|
{
|
2017-11-20 16:11:30 +00:00
|
|
|
/**
|
|
|
|
* This setter is different from all other setters because it may be used to
|
|
|
|
* initialize the object. We define it separately allowing mutator implementors
|
|
|
|
* to define it separately, while the rest of the setters may be simply
|
|
|
|
* forwarded to the mutable URI.
|
|
|
|
*/
|
2017-12-19 01:16:36 +00:00
|
|
|
[must_use] nsIURIMutator setSpec(in AUTF8String aSpec);
|
2017-11-20 16:11:30 +00:00
|
|
|
};
|
|
|
|
|
2017-12-05 01:35:21 +00:00
|
|
|
/**
|
|
|
|
* These methods allow the mutator to change various parts of the URI.
|
|
|
|
* They return the same nsIURIMutator so that we may chain setter operations:
|
|
|
|
* Example:
|
|
|
|
* let newURI = uri.mutate()
|
|
|
|
* .setSpec("http://example.com")
|
|
|
|
* .setQuery("hello")
|
|
|
|
* .finalize();
|
|
|
|
*/
|
2017-11-20 16:11:30 +00:00
|
|
|
[scriptable, builtinclass, uuid(5403a6ec-99d7-405e-8b45-9f805bbdfcef)]
|
|
|
|
interface nsIURISetters : nsIURISetSpec
|
|
|
|
{
|
2017-12-19 01:16:36 +00:00
|
|
|
[must_use] nsIURIMutator setScheme(in AUTF8String aScheme);
|
|
|
|
[must_use] nsIURIMutator setUserPass(in AUTF8String aUserPass);
|
|
|
|
[must_use] nsIURIMutator setUsername(in AUTF8String aUsername);
|
|
|
|
[must_use] nsIURIMutator setPassword(in AUTF8String aPassword);
|
|
|
|
[must_use] nsIURIMutator setHostPort(in AUTF8String aHostPort);
|
|
|
|
[must_use] nsIURIMutator setHostAndPort(in AUTF8String aHostAndPort);
|
|
|
|
[must_use] nsIURIMutator setHost(in AUTF8String aHost);
|
|
|
|
[must_use] nsIURIMutator setPort(in long aPort);
|
|
|
|
[must_use] nsIURIMutator setPathQueryRef(in AUTF8String aPathQueryRef);
|
|
|
|
[must_use] nsIURIMutator setRef(in AUTF8String aRef);
|
|
|
|
[must_use] nsIURIMutator setFilePath(in AUTF8String aFilePath);
|
|
|
|
[must_use] nsIURIMutator setQuery(in AUTF8String aQuery);
|
|
|
|
[must_use, noscript] nsIURIMutator setQueryWithEncoding(in AUTF8String query, in Encoding encoding);
|
2017-11-20 15:10:03 +00:00
|
|
|
};
|
|
|
|
|
2017-12-05 01:35:21 +00:00
|
|
|
%{C++
|
|
|
|
|
|
|
|
// Using this macro instead of NS_FORWARD_SAFE_NSIURISETTERS makes chaining
|
|
|
|
// setter operations possible.
|
2017-12-19 01:16:36 +00:00
|
|
|
#define NS_FORWARD_SAFE_NSIURISETTERS_RET(_to) \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetScheme(const nsACString& aScheme, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetScheme(aScheme); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetUserPass(const nsACString& aUserPass, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetUserPass(aUserPass); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetUsername(const nsACString& aUsername, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetUsername(aUsername); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetPassword(const nsACString& aPassword, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPassword(aPassword); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetHostPort(const nsACString& aHostPort, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostPort(aHostPort); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetHostAndPort(const nsACString& aHostAndPort, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostAndPort(aHostAndPort); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetHost(const nsACString& aHost, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetHost(aHost); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetPort(int32_t aPort, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPort(aPort); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPathQueryRef(aPathQueryRef); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetRef(const nsACString& aRef, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetRef(aRef); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetFilePath(const nsACString& aFilePath, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetFilePath(aFilePath); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetQuery(const nsACString& aQuery, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetQuery(aQuery); \
|
|
|
|
} \
|
|
|
|
MOZ_MUST_USE NS_IMETHOD \
|
|
|
|
SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding *encoding, nsIURIMutator** aMutator) override \
|
|
|
|
{ \
|
|
|
|
if (aMutator) NS_ADDREF(*aMutator = this); \
|
|
|
|
return !_to ? NS_ERROR_NULL_POINTER : _to->SetQueryWithEncoding(query, encoding); \
|
|
|
|
} \
|
2017-12-05 01:35:21 +00:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
2017-11-20 15:10:03 +00:00
|
|
|
[scriptable, builtinclass, uuid(4d1f3103-1c44-4dcd-b717-5d22a697a7d9)]
|
|
|
|
interface nsIURIMutator : nsIURISetters
|
|
|
|
{
|
2017-11-20 16:11:30 +00:00
|
|
|
/**
|
|
|
|
* Initializes the URI by reading from the input stream.
|
|
|
|
* The input stream must contain the serialization of the same object type.
|
|
|
|
* See nsISerializable.
|
|
|
|
*/
|
2017-12-19 01:16:36 +00:00
|
|
|
[must_use]
|
2017-11-20 16:11:30 +00:00
|
|
|
void read(in nsIObjectInputStream aInputStream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initalizes the URI by reading IPC URIParams.
|
|
|
|
* See nsIIPCSerializableURI.
|
|
|
|
*/
|
2017-12-19 01:16:36 +00:00
|
|
|
[noscript, notxpcom, must_use]
|
2017-11-20 16:11:30 +00:00
|
|
|
nsresult deserialize(in const_URIParams_ref aParams);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finishes changing or constructing the URI and returns an immutable URI.
|
|
|
|
*/
|
2017-12-19 01:16:36 +00:00
|
|
|
[must_use]
|
2017-11-20 15:10:03 +00:00
|
|
|
nsIURI finalize();
|
|
|
|
};
|
2017-11-20 16:11:30 +00:00
|
|
|
|
2017-12-05 16:17:02 +00:00
|
|
|
%{C++
|
|
|
|
|
|
|
|
// This class provides a useful helper that allows chaining of setter operations
|
|
|
|
class MOZ_STACK_CLASS NS_MutateURI
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit NS_MutateURI(nsIURI* aURI);
|
|
|
|
explicit NS_MutateURI(const char * aContractID);
|
|
|
|
|
2018-01-19 14:19:42 +00:00
|
|
|
explicit NS_MutateURI(nsIURIMutator* m)
|
|
|
|
{
|
|
|
|
mStatus = m ? NS_OK : NS_ERROR_NULL_POINTER;
|
|
|
|
mMutator = m;
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:17:02 +00:00
|
|
|
NS_MutateURI& SetSpec(const nsACString& aSpec)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetSpec(aSpec, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetScheme(const nsACString& aScheme)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetScheme(aScheme, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetUserPass(const nsACString& aUserPass)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetUserPass(aUserPass, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetUsername(const nsACString& aUsername)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetUsername(aUsername, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetPassword(const nsACString& aPassword)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetPassword(aPassword, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetHostPort(const nsACString& aHostPort)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetHostPort(aHostPort, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetHostAndPort(const nsACString& aHostAndPort)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetHostAndPort(aHostAndPort, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetHost(const nsACString& aHost)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetHost(aHost, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetPort(int32_t aPort)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetPort(aPort, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetPathQueryRef(const nsACString& aPathQueryRef)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetPathQueryRef(aPathQueryRef, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetRef(const nsACString& aRef)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetRef(aRef, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetFilePath(const nsACString& aFilePath)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetFilePath(aFilePath, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetQuery(const nsACString& aQuery)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetQuery(aQuery, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
NS_MutateURI& SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding *encoding)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = mMutator->SetQueryWithEncoding(query, encoding, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-12-08 16:37:41 +00:00
|
|
|
|
2018-01-22 14:52:37 +00:00
|
|
|
/**
|
|
|
|
* This method allows consumers to call the methods declared in other
|
|
|
|
* interfaces implemented by the mutator object.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* nsCOMPtr<nsIURI> uri;
|
|
|
|
* nsresult rv = NS_MutateURI(new URIClass::Mutator())
|
|
|
|
* .SetSpec(aSpec)
|
|
|
|
* .Apply<SomeInterface>(&SomeInterface::Method, arg1, arg2)
|
|
|
|
* .Finalize(uri);
|
|
|
|
*
|
|
|
|
* If mMutator does not implement SomeInterface, do_QueryInterface will fail
|
|
|
|
* and the method will not be called.
|
|
|
|
* If aMethod does not exist, or if there is a mismatch between argument
|
|
|
|
* types, or the number of arguments, then there will be a compile error.
|
|
|
|
*/
|
|
|
|
template <typename Interface, typename Method, typename... Args>
|
|
|
|
NS_MutateURI& Apply(Method aMethod, Args ...aArgs)
|
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
nsCOMPtr<Interface> target = do_QueryInterface(mMutator, &mStatus);
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, *this);
|
|
|
|
mStatus = (target->*aMethod)(aArgs...);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-12-08 16:37:41 +00:00
|
|
|
template <class C>
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult Finalize(nsCOMPtr<C>& aURI)
|
2017-12-05 16:17:02 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
2017-12-08 16:37:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mStatus = mMutator->Finalize(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
|
|
|
aURI = do_QueryInterface(uri, &mStatus);
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
2017-12-19 01:06:45 +00:00
|
|
|
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
|
2017-12-08 16:37:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overload for nsIURI to avoid query interface.
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult Finalize(nsCOMPtr<nsIURI>& aURI)
|
2017-12-08 16:37:41 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
mStatus = mMutator->Finalize(getter_AddRefs(aURI));
|
2017-12-19 01:06:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
|
|
|
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
|
|
|
|
return NS_OK;
|
2017-12-05 16:17:02 +00:00
|
|
|
}
|
2017-12-08 16:37:41 +00:00
|
|
|
|
2017-12-19 01:04:40 +00:00
|
|
|
template <class C>
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult Finalize(C** aURI)
|
2017-12-19 01:04:40 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
2017-12-19 01:06:45 +00:00
|
|
|
|
2017-12-19 01:04:40 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mStatus = mMutator->Finalize(getter_AddRefs(uri));
|
2017-12-19 01:06:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
2017-12-19 01:04:40 +00:00
|
|
|
nsCOMPtr<C> result = do_QueryInterface(uri, &mStatus);
|
2017-12-19 01:06:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
2017-12-19 01:04:40 +00:00
|
|
|
result.forget(aURI);
|
2017-12-19 01:06:45 +00:00
|
|
|
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
|
|
|
|
return NS_OK;
|
2017-12-19 01:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 01:16:36 +00:00
|
|
|
MOZ_MUST_USE nsresult Finalize(nsIURI** aURI)
|
2017-12-19 01:04:40 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
mStatus = mMutator->Finalize(aURI);
|
2017-12-19 01:06:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(mStatus, mStatus);
|
|
|
|
|
|
|
|
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
|
|
|
|
return NS_OK;
|
2017-12-19 01:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:17:02 +00:00
|
|
|
nsresult GetStatus() { return mStatus; }
|
|
|
|
private:
|
|
|
|
nsresult mStatus;
|
2017-12-08 16:37:41 +00:00
|
|
|
nsCOMPtr<nsIURIMutator> mMutator;
|
2017-12-05 16:17:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
%}
|