mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1416791 - Eliminate mutability from nsHostObjectURI by removing nsIURIWithBlobImpl r=baku
* blobImpl references are now only kept in nsHostObjectProtocolHandler * removes nsHostObjectProtocolHandler.idl * Makes nsHostObjectURI no longer inherit from nsSupportsWeakReference MozReview-Commit-ID: AC1klrfsMnn --HG-- extra : rebase_source : 142802f9a6fa6aae5611dccf117d88f96a9985a6
This commit is contained in:
parent
fda9fc4c79
commit
ed088d0c3e
@ -76,9 +76,6 @@ struct DataInfo
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
nsCString mStack;
|
||||
|
||||
// WeakReferences of nsHostObjectURI objects.
|
||||
nsTArray<nsWeakPtr> mURIs;
|
||||
|
||||
// When a blobURL is revoked, we keep it alive for RELEASING_TIMER
|
||||
// milliseconds in order to support pending operations such as navigation,
|
||||
// download and so on.
|
||||
@ -123,7 +120,7 @@ GetDataInfo(const nsACString& aUri, bool aAlsoIfRevoked = false)
|
||||
}
|
||||
|
||||
static DataInfo*
|
||||
GetDataInfoFromURI(nsIURI* aURI)
|
||||
GetDataInfoFromURI(nsIURI* aURI, bool aAlsoIfRevoked = false)
|
||||
{
|
||||
if (!aURI) {
|
||||
return nullptr;
|
||||
@ -135,7 +132,7 @@ GetDataInfoFromURI(nsIURI* aURI)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetDataInfo(spec);
|
||||
return GetDataInfo(spec, aAlsoIfRevoked);
|
||||
}
|
||||
|
||||
// Memory reporting for the hash table.
|
||||
@ -540,13 +537,6 @@ private:
|
||||
|
||||
MOZ_ASSERT(info->mRevoked);
|
||||
|
||||
for (uint32_t i = 0; i < info->mURIs.Length(); ++i) {
|
||||
nsCOMPtr<nsIURI> uri = do_QueryReferent(info->mURIs[i]);
|
||||
if (uri) {
|
||||
static_cast<nsHostObjectURI*>(uri.get())->ForgetBlobImpl();
|
||||
}
|
||||
}
|
||||
|
||||
gDataTable->Remove(mURI);
|
||||
if (gDataTable->Count() == 0) {
|
||||
delete gDataTable;
|
||||
@ -900,17 +890,12 @@ nsHostObjectProtocolHandler::NewURI(const nsACString& aSpec,
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_MutateURI(new nsHostObjectURI::Mutator())
|
||||
.SetSpec(aSpec)
|
||||
.Apply(NS_MutatorMethod(&nsIBlobURIMutator::SetBlobImpl, blob))
|
||||
.Apply(NS_MutatorMethod(&nsIPrincipalURIMutator::SetPrincipal, principal))
|
||||
.Finalize(uri);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uri.forget(aResult);
|
||||
|
||||
if (info && info->mObjectType == DataInfo::eBlobImpl) {
|
||||
info->mURIs.AppendElement(do_GetWeakReference(*aResult));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -921,14 +906,8 @@ nsHostObjectProtocolHandler::NewChannel2(nsIURI* uri,
|
||||
{
|
||||
*result = nullptr;
|
||||
|
||||
nsCOMPtr<nsIURIWithBlobImpl> uriBlobImpl = do_QueryInterface(uri);
|
||||
if (!uriBlobImpl) {
|
||||
return NS_ERROR_DOM_BAD_URI;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> tmp;
|
||||
MOZ_ALWAYS_SUCCEEDS(uriBlobImpl->GetBlobImpl(getter_AddRefs(tmp)));
|
||||
nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(tmp);
|
||||
RefPtr<BlobImpl> blobImpl;
|
||||
NS_GetBlobForBlobURI(uri, getter_AddRefs(blobImpl), true);
|
||||
if (!blobImpl) {
|
||||
return NS_ERROR_DOM_BAD_URI;
|
||||
}
|
||||
@ -942,6 +921,10 @@ nsHostObjectProtocolHandler::NewChannel2(nsIURI* uri,
|
||||
nsresult rv = uriPrinc->GetPrincipal(getter_AddRefs(principal));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!principal) {
|
||||
return NS_ERROR_DOM_BAD_URI;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Info can be null, in case this blob URL has been revoked already.
|
||||
DataInfo* info = GetDataInfoFromURI(uri);
|
||||
@ -1042,24 +1025,12 @@ nsFontTableProtocolHandler::GetScheme(nsACString &result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsHostObjectProtocolHandler::StoreClonedURI(const nsACString& aSpec,
|
||||
nsIURI* aURI)
|
||||
{
|
||||
MOZ_ASSERT(aURI);
|
||||
|
||||
DataInfo* info = GetDataInfo(aSpec);
|
||||
if (info) {
|
||||
info->mURIs.AppendElement(do_GetWeakReference(aURI));
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_GetBlobForBlobURI(nsIURI* aURI, BlobImpl** aBlob)
|
||||
NS_GetBlobForBlobURI(nsIURI* aURI, BlobImpl** aBlob, bool aAlsoIfRevoked)
|
||||
{
|
||||
*aBlob = nullptr;
|
||||
|
||||
DataInfo* info = GetDataInfoFromURI(aURI);
|
||||
DataInfo* info = GetDataInfoFromURI(aURI, aAlsoIfRevoked);
|
||||
if (!info || info->mObjectType != DataInfo::eBlobImpl) {
|
||||
return NS_ERROR_DOM_BAD_URI;
|
||||
}
|
||||
|
@ -88,9 +88,6 @@ public:
|
||||
GetAllBlobURLEntries(nsTArray<mozilla::dom::BlobURLRegistrationData>& aRegistrations,
|
||||
mozilla::dom::ContentParent* aCP);
|
||||
|
||||
// This is for nsHostObjectURI.
|
||||
static void StoreClonedURI(const nsACString& aSpec, nsIURI* aURI);
|
||||
|
||||
protected:
|
||||
virtual ~nsHostObjectProtocolHandler() {}
|
||||
|
||||
@ -133,7 +130,7 @@ inline bool IsFontTableURI(nsIURI* aUri)
|
||||
}
|
||||
|
||||
extern nsresult
|
||||
NS_GetBlobForBlobURI(nsIURI* aURI, mozilla::dom::BlobImpl** aBlob);
|
||||
NS_GetBlobForBlobURI(nsIURI* aURI, mozilla::dom::BlobImpl** aBlob, bool aAlsoIfRevoked = false);
|
||||
|
||||
extern nsresult
|
||||
NS_GetBlobForBlobURISpec(const nsACString& aSpec, mozilla::dom::BlobImpl** aBlob);
|
||||
|
@ -22,9 +22,7 @@ NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, mozilla::net::nsSimpleURI)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, mozilla::net::nsSimpleURI)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsHostObjectURI)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIURIWithBlobImpl)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIURIWithPrincipal)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
if (aIID.Equals(kHOSTOBJECTURICID))
|
||||
foundInterface = static_cast<nsIURI*>(this);
|
||||
else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
|
||||
@ -37,16 +35,6 @@ NS_INTERFACE_MAP_BEGIN(nsHostObjectURI)
|
||||
else
|
||||
NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI)
|
||||
|
||||
// nsIURIWithBlobImpl methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHostObjectURI::GetBlobImpl(nsISupports** aBlobImpl)
|
||||
{
|
||||
RefPtr<mozilla::dom::BlobImpl> blobImpl(mBlobImpl);
|
||||
blobImpl.forget(aBlobImpl);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIURIWithPrincipal methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -149,10 +137,6 @@ nsHostObjectURI::Deserialize(const mozilla::ipc::URIParams& aParams)
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this fails, we still want to complete the operation. Probably this
|
||||
// blobURL has been revoked in the meantime.
|
||||
NS_GetBlobForBlobURI(this, getter_AddRefs(mBlobImpl));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -185,9 +169,6 @@ nsHostObjectURI::CloneInternal(mozilla::net::nsSimpleURI::RefHandlingEnum aRefHa
|
||||
nsHostObjectURI* u = static_cast<nsHostObjectURI*>(simpleClone.get());
|
||||
|
||||
u->mPrincipal = mPrincipal;
|
||||
u->mBlobImpl = mBlobImpl;
|
||||
|
||||
nsHostObjectProtocolHandler::StoreClonedURI(newRef, simpleClone);
|
||||
|
||||
simpleClone.forget(aClone);
|
||||
return NS_OK;
|
||||
@ -216,10 +197,6 @@ nsHostObjectURI::EqualsInternal(nsIURI* aOther,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Compare the piece of additional member data that we add to base class,
|
||||
// but we cannot compare BlobImpl. This should not be a problem, because we
|
||||
// don't support changing the underlying mBlobImpl.
|
||||
|
||||
if (mPrincipal && otherUri->mPrincipal) {
|
||||
// Both of us have mPrincipals. Compare them.
|
||||
return mPrincipal->Equals(otherUri->mPrincipal, aResult);
|
||||
@ -233,7 +210,6 @@ nsHostObjectURI::EqualsInternal(nsIURI* aOther,
|
||||
NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsHostObjectURI::Mutator,
|
||||
nsIURISetters,
|
||||
nsIURIMutator,
|
||||
nsIBlobURIMutator,
|
||||
nsIPrincipalURIMutator,
|
||||
nsISerializable)
|
||||
|
||||
@ -305,10 +281,3 @@ nsHostObjectURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||
*aClassIDNoAlloc = kHOSTOBJECTURICID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHostObjectURI::ForgetBlobImpl()
|
||||
{
|
||||
MOZ_ASSERT(mBlobImpl);
|
||||
mBlobImpl = nullptr;
|
||||
}
|
||||
|
@ -13,11 +13,9 @@
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsISerializable.h"
|
||||
#include "nsIURIWithBlobImpl.h"
|
||||
#include "nsIURIWithPrincipal.h"
|
||||
#include "nsSimpleURI.h"
|
||||
#include "nsIIPCSerializableURI.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -28,23 +26,20 @@
|
||||
class nsHostObjectURI final
|
||||
: public mozilla::net::nsSimpleURI
|
||||
, public nsIURIWithPrincipal
|
||||
, public nsIURIWithBlobImpl
|
||||
, public nsSupportsWeakReference
|
||||
{
|
||||
private:
|
||||
nsHostObjectURI(nsIPrincipal* aPrincipal,
|
||||
mozilla::dom::BlobImpl* aBlobImpl)
|
||||
explicit nsHostObjectURI(nsIPrincipal* aPrincipal)
|
||||
: mozilla::net::nsSimpleURI()
|
||||
, mPrincipal(aPrincipal)
|
||||
, mBlobImpl(aBlobImpl)
|
||||
{}
|
||||
|
||||
// For use only from deserialization
|
||||
nsHostObjectURI() : mozilla::net::nsSimpleURI() {}
|
||||
explicit nsHostObjectURI()
|
||||
: mozilla::net::nsSimpleURI()
|
||||
{}
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIURIWITHBLOBIMPL
|
||||
NS_DECL_NSIURIWITHPRINCIPAL
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_DECL_NSICLASSINFO
|
||||
@ -69,10 +64,7 @@ public:
|
||||
|
||||
NS_IMETHOD Mutate(nsIURIMutator * *_retval) override;
|
||||
|
||||
void ForgetBlobImpl();
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
RefPtr<mozilla::dom::BlobImpl> mBlobImpl;
|
||||
|
||||
protected:
|
||||
virtual ~nsHostObjectURI() {}
|
||||
@ -84,7 +76,6 @@ public:
|
||||
class Mutator final
|
||||
: public nsIURIMutator
|
||||
, public BaseURIMutator<nsHostObjectURI>
|
||||
, public nsIBlobURIMutator
|
||||
, public nsIPrincipalURIMutator
|
||||
, public nsISerializable
|
||||
{
|
||||
@ -104,16 +95,6 @@ public:
|
||||
return InitFromInputStream(aStream);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE NS_IMETHOD
|
||||
SetBlobImpl(mozilla::dom::BlobImpl *aBlobImpl) override
|
||||
{
|
||||
if (!mURI) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
mURI->mBlobImpl = aBlobImpl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_MUST_USE NS_IMETHOD
|
||||
SetPrincipal(nsIPrincipal *aPrincipal) override
|
||||
{
|
||||
|
@ -127,7 +127,6 @@ XPIDL_SOURCES += [
|
||||
'nsIURI.idl',
|
||||
'nsIURIClassifier.idl',
|
||||
'nsIURIMutator.idl',
|
||||
'nsIURIWithBlobImpl.idl',
|
||||
'nsIURIWithPrincipal.idl',
|
||||
'nsIURL.idl',
|
||||
'nsIURLParser.idl',
|
||||
|
@ -1,40 +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 "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
|
||||
%{C++
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class BlobImpl;
|
||||
}}
|
||||
%}
|
||||
|
||||
[ptr] native BlobImplPtr(mozilla::dom::BlobImpl);
|
||||
|
||||
/**
|
||||
* nsIURIWithBlobImpl is implemented by URIs which are associated with a
|
||||
* specific BlobImpl.
|
||||
*/
|
||||
[builtinclass, builtinclass, uuid(331b41d3-3506-4ab5-bef9-aab41e3202a3)]
|
||||
interface nsIURIWithBlobImpl : nsISupports
|
||||
{
|
||||
/**
|
||||
* The BlobImpl associated with the resource returned when loading this uri.
|
||||
*/
|
||||
readonly attribute nsISupports blobImpl;
|
||||
};
|
||||
|
||||
[builtinclass, uuid(d3e8c9fa-ff07-47cc-90dc-0cc5445ddb59)]
|
||||
interface nsIBlobURIMutator : nsISupports
|
||||
{
|
||||
/**
|
||||
* Associates a blobImpl to the mutated URI.
|
||||
* Would normally return nsIURIMutator, but since it only gets called
|
||||
* from C++, there is no need for that.
|
||||
*/
|
||||
[must_use, noscript] void setBlobImpl(in BlobImplPtr blobImpl);
|
||||
};
|
Loading…
Reference in New Issue
Block a user