Bug 1589337 - Use nsIClassInfoImpl in nsJARURI r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D90256
This commit is contained in:
Valentin Gosu 2020-09-29 11:40:58 +00:00
parent 2ba638de33
commit e05404b825
3 changed files with 18 additions and 58 deletions

View File

@ -8,6 +8,7 @@
#include "nsJARURI.h"
#include "nsNetUtil.h"
#include "nsIClassInfoImpl.h"
#include "nsIIOService.h"
#include "nsIStandardURL.h"
#include "nsCRT.h"
@ -24,6 +25,10 @@ static NS_DEFINE_CID(kJARURICID, NS_JARURI_CID);
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_CLASSINFO(nsJARURI, nullptr, nsIClassInfo::THREADSAFE, NS_JARURI_CID)
// Empty CI getter. We only need nsIClassInfo for Serialization
NS_IMPL_CI_INTERFACE_GETTER0(nsJARURI)
nsJARURI::nsJARURI() {}
nsJARURI::~nsJARURI() {}
@ -37,7 +42,7 @@ NS_INTERFACE_MAP_BEGIN(nsJARURI)
NS_INTERFACE_MAP_ENTRY(nsIURL)
NS_INTERFACE_MAP_ENTRY(nsIJARURI)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
NS_IMPL_QUERY_CLASSINFO(nsJARURI)
NS_INTERFACE_MAP_ENTRY(nsINestedURI)
NS_INTERFACE_MAP_ENTRY_CONCRETE(nsJARURI)
NS_INTERFACE_MAP_END
@ -128,52 +133,6 @@ nsJARURI::Write(nsIObjectOutputStream* aOutputStream) {
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIClassInfo methods:
NS_IMETHODIMP
nsJARURI::GetInterfaces(nsTArray<nsIID>& array) {
array.Clear();
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetScriptableHelper(nsIXPCScriptable** _retval) {
*_retval = nullptr;
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetContractID(nsACString& aContractID) {
aContractID.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetClassDescription(nsACString& aClassDescription) {
aClassDescription.SetIsVoid(true);
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetClassID(nsCID** aClassID) {
*aClassID = (nsCID*)moz_xmalloc(sizeof(nsCID));
return GetClassIDNoAlloc(*aClassID);
}
NS_IMETHODIMP
nsJARURI::GetFlags(uint32_t* aFlags) {
// XXX We implement THREADSAFE addref/release, but probably shouldn't.
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
return NS_OK;
}
NS_IMETHODIMP
nsJARURI::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
*aClassIDNoAlloc = kJARURICID;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIURI methods:

View File

@ -9,7 +9,6 @@
#include "nsIJARURI.h"
#include "nsISerializable.h"
#include "nsIClassInfo.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsINestedURI.h"
@ -38,7 +37,6 @@
class nsJARURI final : public nsIJARURI,
public nsISerializable,
public nsIClassInfo,
public nsINestedURI {
public:
NS_DECL_THREADSAFE_ISUPPORTS
@ -46,7 +44,6 @@ class nsJARURI final : public nsIJARURI,
NS_DECL_NSIURL
NS_DECL_NSIJARURI
NS_DECL_NSISERIALIZABLE
NS_DECL_NSICLASSINFO
NS_DECL_NSINESTEDURI
NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID)

View File

@ -1015,6 +1015,14 @@ add_task(function mainTest() {
});
});
function check_round_trip_serialization(spec) {
dump(`checking ${spec}\n`);
let uri = gIoService.newURI(spec);
let str = serialize_to_escaped_string(uri);
let other = deserialize_from_escaped_string(str).QueryInterface(Ci.nsIURI);
equal(other.spec, uri.spec);
}
add_task(function test_iconURI_serialization() {
// URIs taken from test_moz_icon_uri.js
@ -1026,13 +1034,9 @@ add_task(function test_iconURI_serialization() {
"moz-icon://file://foo.txt",
];
function check_round_trip_serialization(spec) {
dump(`checking ${spec}\n`);
let uri = gIoService.newURI(spec);
let str = serialize_to_escaped_string(uri);
let other = deserialize_from_escaped_string(str).QueryInterface(Ci.nsIURI);
equal(other.spec, uri.spec);
}
tests.forEach(str => check_round_trip_serialization(str));
});
add_task(function test_jarURI_serialization() {
check_round_trip_serialization("jar:http://example.com/bar.jar!/");
});