mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 06:22:20 +00:00
Bug 1420954 - Make nsIURIMutator setters return nsIURIMutator so we can chain setters r=bagder
MozReview-Commit-ID: 53BD91hB2yi --HG-- extra : rebase_source : 45594a92e1a9f18f2f4b5bb2824b5f8ced584eab
This commit is contained in:
parent
c528f7e479
commit
f903a38639
@ -58,7 +58,7 @@ public:
|
||||
, public BaseURIMutator<NullPrincipalURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
|
||||
NS_IMETHOD Deserialize(const mozilla::ipc::URIParams& aParams) override
|
||||
{
|
||||
@ -76,8 +76,9 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec) override
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec, nsIURIMutator** aMutator) override
|
||||
{
|
||||
NS_ADDREF(*aMutator = this);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
, public BaseURIMutator<nsHostObjectURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
, public BaseURIMutator<nsJSURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
, public BaseURIMutator<nsMozIconURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
|
||||
NS_IMETHOD Deserialize(const mozilla::ipc::URIParams& aParams) override
|
||||
{
|
||||
@ -69,7 +69,8 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec) override {
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec, nsIURIMutator** aMutator) override {
|
||||
NS_ADDREF(*aMutator = this);
|
||||
return InitFromSpec(aSpec);
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
, public BaseURIMutator<nsJARURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "nsISupports.idl"
|
||||
interface nsIURI;
|
||||
interface nsIObjectInputStream;
|
||||
interface nsIURIMutator;
|
||||
|
||||
%{C++
|
||||
#include "nsStringGlue.h"
|
||||
@ -87,9 +88,8 @@ protected:
|
||||
{ return InitFromInputStream(aStream); } \
|
||||
NS_IMETHOD Finalize(nsIURI** aURI) override \
|
||||
{ mURI.forget(aURI); return NS_OK; } \
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec) override \
|
||||
{ return InitFromSpec(aSpec); }
|
||||
|
||||
NS_IMETHOD SetSpec(const nsACString & aSpec, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return InitFromSpec(aSpec); }
|
||||
%}
|
||||
|
||||
[ptr] native Encoding(const mozilla::Encoding);
|
||||
@ -104,27 +104,70 @@ interface nsIURISetSpec : nsISupports
|
||||
* to define it separately, while the rest of the setters may be simply
|
||||
* forwarded to the mutable URI.
|
||||
*/
|
||||
void setSpec(in AUTF8String aSpec);
|
||||
nsIURIMutator setSpec(in AUTF8String aSpec);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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();
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(5403a6ec-99d7-405e-8b45-9f805bbdfcef)]
|
||||
interface nsIURISetters : nsIURISetSpec
|
||||
{
|
||||
void setScheme(in AUTF8String aScheme);
|
||||
void setUserPass(in AUTF8String aUserPass);
|
||||
void setUsername(in AUTF8String aUsername);
|
||||
void setPassword(in AUTF8String aPassword);
|
||||
void setHostPort(in AUTF8String aHostPort);
|
||||
void setHostAndPort(in AUTF8String aHostAndPort);
|
||||
void setHost(in AUTF8String aHost);
|
||||
void setPort(in long aPort);
|
||||
void setPathQueryRef(in AUTF8String aPathQueryRef);
|
||||
void setRef(in AUTF8String aRef);
|
||||
void setFilePath(in AUTF8String aFilePath);
|
||||
void setQuery(in AUTF8String aQuery);
|
||||
[noscript] void setQueryWithEncoding(in AUTF8String query, in Encoding encoding);
|
||||
nsIURIMutator setScheme(in AUTF8String aScheme);
|
||||
nsIURIMutator setUserPass(in AUTF8String aUserPass);
|
||||
nsIURIMutator setUsername(in AUTF8String aUsername);
|
||||
nsIURIMutator setPassword(in AUTF8String aPassword);
|
||||
nsIURIMutator setHostPort(in AUTF8String aHostPort);
|
||||
nsIURIMutator setHostAndPort(in AUTF8String aHostAndPort);
|
||||
nsIURIMutator setHost(in AUTF8String aHost);
|
||||
nsIURIMutator setPort(in long aPort);
|
||||
nsIURIMutator setPathQueryRef(in AUTF8String aPathQueryRef);
|
||||
nsIURIMutator setRef(in AUTF8String aRef);
|
||||
nsIURIMutator setFilePath(in AUTF8String aFilePath);
|
||||
nsIURIMutator setQuery(in AUTF8String aQuery);
|
||||
[noscript] nsIURIMutator setQueryWithEncoding(in AUTF8String query, in Encoding encoding);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
// Using this macro instead of NS_FORWARD_SAFE_NSIURISETTERS makes chaining
|
||||
// setter operations possible.
|
||||
#define NS_FORWARD_SAFE_NSIURISETTERS_RET(_to) \
|
||||
NS_IMETHOD SetScheme(const nsACString & aScheme, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetScheme(aScheme); } \
|
||||
NS_IMETHOD SetUserPass(const nsACString & aUserPass, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetUserPass(aUserPass); } \
|
||||
NS_IMETHOD SetUsername(const nsACString & aUsername, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetUsername(aUsername); } \
|
||||
NS_IMETHOD SetPassword(const nsACString & aPassword, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetPassword(aPassword); } \
|
||||
NS_IMETHOD SetHostPort(const nsACString & aHostPort, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostPort(aHostPort); } \
|
||||
NS_IMETHOD SetHostAndPort(const nsACString & aHostAndPort, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostAndPort(aHostAndPort); } \
|
||||
NS_IMETHOD SetHost(const nsACString & aHost, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetHost(aHost); } \
|
||||
NS_IMETHOD SetPort(int32_t aPort, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetPort(aPort); } \
|
||||
NS_IMETHOD SetPathQueryRef(const nsACString & aPathQueryRef, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetPathQueryRef(aPathQueryRef); } \
|
||||
NS_IMETHOD SetRef(const nsACString & aRef, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetRef(aRef); } \
|
||||
NS_IMETHOD SetFilePath(const nsACString & aFilePath, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetFilePath(aFilePath); } \
|
||||
NS_IMETHOD SetQuery(const nsACString & aQuery, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetQuery(aQuery); } \
|
||||
NS_IMETHOD SetQueryWithEncoding(const nsACString & query, const mozilla::Encoding *encoding, nsIURIMutator** aMutator) override \
|
||||
{ NS_ADDREF(*aMutator = this); return !_to ? NS_ERROR_NULL_POINTER : _to->SetQueryWithEncoding(query, encoding); }
|
||||
|
||||
%}
|
||||
|
||||
[scriptable, builtinclass, uuid(4d1f3103-1c44-4dcd-b717-5d22a697a7d9)]
|
||||
interface nsIURIMutator : nsIURISetters
|
||||
{
|
||||
|
@ -77,8 +77,8 @@ public:
|
||||
, public BaseURIMutator<nsSimpleNestedURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
|
||||
explicit Mutator() { }
|
||||
private:
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
, public BaseURIMutator<nsSimpleURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
@ -318,7 +318,7 @@ public:
|
||||
, public BaseURIMutator<nsStandardURL>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
, public BaseURIMutator<nsNestedAboutURI>
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_SAFE_NSIURISETTERS(mURI)
|
||||
NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
|
||||
NS_DEFINE_NSIMUTATOR_COMMON
|
||||
|
||||
explicit Mutator() { }
|
||||
|
23
netwerk/test/unit/test_uri_mutator.js
Normal file
23
netwerk/test/unit/test_uri_mutator.js
Normal file
@ -0,0 +1,23 @@
|
||||
/* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
|
||||
|
||||
"use strict";
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
function standardMutator()
|
||||
{
|
||||
return Cc['@mozilla.org/network/standard-url-mutator;1']
|
||||
.createInstance(Ci.nsIURIMutator);
|
||||
}
|
||||
|
||||
add_task(async function test_simple_setter_chaining() {
|
||||
let uri = standardMutator()
|
||||
.setSpec("http://example.com/")
|
||||
.setQuery("hello")
|
||||
.setRef("bla")
|
||||
.setScheme("ftp")
|
||||
.finalize();
|
||||
equal(uri.spec, "ftp://example.com/?hello#bla");
|
||||
});
|
@ -405,3 +405,4 @@ skip-if = os == "android"
|
||||
[test_bug1378385_http1.js]
|
||||
[test_tls_flags_separate_connections.js]
|
||||
[test_tls_flags.js]
|
||||
[test_uri_mutator.js]
|
||||
|
Loading…
x
Reference in New Issue
Block a user