Bug 1432187 - Add nsIStandardURLMutator interface r=mayhemer

MozReview-Commit-ID: 4IbdO2gMwox

--HG--
extra : rebase_source : 4f64f44bc1f8e8ee4538c7624f00ab76cc914fae
This commit is contained in:
Valentin Gosu 2018-01-23 23:13:04 +01:00
parent f7be53e152
commit 358af2c859
3 changed files with 58 additions and 7 deletions

View File

@ -6,6 +6,7 @@
#include "nsIMutable.idl"
interface nsIURI;
interface nsIURIMutator;
/**
* nsIStandardURL defines the interface to an URL with the standard
@ -40,6 +41,18 @@ interface nsIStandardURL : nsIMutable
*/
const unsigned long URLTYPE_NO_AUTHORITY = 3;
void init(in unsigned long aUrlType,
in long aDefaultPort,
in AUTF8String aSpec,
in string aOriginCharset,
in nsIURI aBaseURI);
void setDefaultPort(in long aNewDefaultPort);
};
[scriptable, builtinclass, uuid(fc894e98-23a1-43cd-a7fe-72876f8ea2ee)]
interface nsIStandardURLMutator : nsISupports
{
/**
* Initialize a standard URL.
*
@ -60,11 +73,11 @@ interface nsIStandardURL : nsIMutable
* otherwise, aSpec will be resolved relative
* to aBaseURI.
*/
void init(in unsigned long aUrlType,
in long aDefaultPort,
in AUTF8String aSpec,
in string aOriginCharset,
in nsIURI aBaseURI);
nsIURIMutator init(in unsigned long aUrlType,
in long aDefaultPort,
in AUTF8String aSpec,
in string aOriginCharset,
in nsIURI aBaseURI);
/**
* Set the default port.
@ -76,5 +89,5 @@ interface nsIStandardURL : nsIMutable
* matches this default, then we won't include a
* port number in the canonical form of the URL.
*/
void setDefaultPort(in long aNewDefaultPort);
nsIURIMutator setDefaultPort(in long aNewDefaultPort);
};

View File

@ -2226,7 +2226,7 @@ nsStandardURL::SetPathQueryRef(const nsACString &input)
return NS_OK;
}
NS_IMPL_ISUPPORTS(nsStandardURL::Mutator, nsIURISetters, nsIURIMutator)
NS_IMPL_ISUPPORTS(nsStandardURL::Mutator, nsIURISetters, nsIURIMutator, nsIStandardURLMutator)
NS_IMETHODIMP
nsStandardURL::Mutate(nsIURIMutator** aMutator)

View File

@ -316,11 +316,49 @@ public:
class Mutator
: public nsIURIMutator
, public BaseURIMutator<nsStandardURL>
, public nsIStandardURLMutator
{
NS_DECL_ISUPPORTS
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
NS_DEFINE_NSIMUTATOR_COMMON
MOZ_MUST_USE NS_IMETHOD
Init(uint32_t aURLType, int32_t aDefaultPort,
const nsACString& aSpec, const char* aCharset, nsIURI* aBaseURI,
nsIURIMutator** aMutator) override
{
if (aMutator) {
nsCOMPtr<nsIURIMutator> mutator = this;
mutator.forget(aMutator);
}
RefPtr<nsStandardURL> uri;
if (mURI) {
// We don't need to instantiate a new object we already have one
mURI.swap(uri);
} else {
uri = new nsStandardURL();
}
nsresult rv = uri->Init(aURLType, aDefaultPort, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) {
return rv;
}
mURI = uri;
return NS_OK;
}
MOZ_MUST_USE NS_IMETHODIMP
SetDefaultPort(int32_t aNewDefaultPort, nsIURIMutator** aMutator) override
{
if (!mURI) {
return NS_ERROR_NULL_POINTER;
}
if (aMutator) {
nsCOMPtr<nsIURIMutator> mutator = this;
mutator.forget(aMutator);
}
return mURI->SetDefaultPort(aNewDefaultPort);
}
explicit Mutator() { }
private:
virtual ~Mutator() { }