Backed out changeset effbc83efa08 (bug 1279186)

This commit is contained in:
Iris Hsiao 2016-07-18 12:11:07 +08:00
parent acc7c12786
commit 296ca81daa
8 changed files with 46 additions and 321 deletions

View File

@ -7,11 +7,8 @@
#include "nsHostObjectProtocolHandler.h"
#include "DOMMediaStream.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/Exceptions.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/dom/MediaSource.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/ModuleUtils.h"
@ -41,79 +38,9 @@ struct DataInfo
static nsClassHashtable<nsCStringHashKey, DataInfo>* gDataTable;
static DataInfo*
GetDataInfo(const nsACString& aUri)
{
if (!gDataTable) {
return nullptr;
}
DataInfo* res;
// Let's remove any fragment and query from this URI.
int32_t hasFragmentPos = aUri.FindChar('#');
int32_t hasQueryPos = aUri.FindChar('?');
int32_t pos = -1;
if (hasFragmentPos >= 0 && hasQueryPos >= 0) {
pos = std::min(hasFragmentPos, hasQueryPos);
} else if (hasFragmentPos >= 0) {
pos = hasFragmentPos;
} else {
pos = hasQueryPos;
}
if (pos < 0) {
gDataTable->Get(aUri, &res);
} else {
gDataTable->Get(StringHead(aUri, pos), &res);
}
return res;
}
// Memory reporting for the hash table.
namespace mozilla {
void
BroadcastBlobURLRegistration(const nsACString& aURI,
BlobImpl* aBlobImpl,
nsIPrincipal* aPrincipal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aBlobImpl);
if (XRE_IsParentProcess()) {
ContentParent::BroadcastBlobURLRegistration(aURI, aBlobImpl,
aPrincipal);
return;
}
ContentChild* cc = ContentChild::GetSingleton();
BlobChild* actor = cc->GetOrCreateActorForBlobImpl(aBlobImpl);
if (NS_WARN_IF(!actor)) {
return;
}
NS_WARN_IF(!cc->SendStoreAndBroadcastBlobURLRegistration(nsCString(aURI), actor,
IPC::Principal(aPrincipal)));
}
void
BroadcastBlobURLUnregistration(const nsACString& aURI, DataInfo* aInfo)
{
MOZ_ASSERT(aInfo);
MOZ_ASSERT(NS_IsMainThread());
if (XRE_IsParentProcess()) {
ContentParent::BroadcastBlobURLUnregistration(aURI);
return;
}
ContentChild* cc = ContentChild::GetSingleton();
NS_WARN_IF(!cc->SendUnstoreAndBroadcastBlobURLUnregistration(nsCString(aURI)));
}
class HostObjectURLsReporter final : public nsIMemoryReporter
{
~HostObjectURLsReporter() {}
@ -394,14 +321,12 @@ nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
nsACString& aUri)
{
#ifdef DEBUG
{
nsCOMPtr<BlobImpl> blobImpl(do_QueryInterface(aObject));
nsCOMPtr<MediaSource> mediaSource(do_QueryInterface(aObject));
nsCOMPtr<DOMMediaStream> mediaStream(do_QueryInterface(aObject));
nsCOMPtr<BlobImpl> blobImpl(do_QueryInterface(aObject));
nsCOMPtr<MediaSource> mediaSource(do_QueryInterface(aObject));
nsCOMPtr<DOMMediaStream> mediaStream(do_QueryInterface(aObject));
// We support only these types.
MOZ_ASSERT(blobImpl || mediaSource || mediaStream);
}
// We support only these types.
MOZ_ASSERT(blobImpl || mediaSource || mediaStream);
#endif
Init();
@ -409,22 +334,6 @@ nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aScheme,
nsresult rv = GenerateURIString(aScheme, aPrincipal, aUri);
NS_ENSURE_SUCCESS(rv, rv);
rv = AddDataEntry(aUri, aObject, aPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(aObject);
if (blobImpl) {
BroadcastBlobURLRegistration(aUri, blobImpl, aPrincipal);
}
return NS_OK;
}
/* static */ nsresult
nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aURI,
nsISupports* aObject,
nsIPrincipal* aPrincipal)
{
if (!gDataTable) {
gDataTable = new nsClassHashtable<nsCStringHashKey, DataInfo>;
}
@ -435,62 +344,17 @@ nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aURI,
info->mPrincipal = aPrincipal;
mozilla::BlobURLsReporter::GetJSStackForBlob(info);
gDataTable->Put(aURI, info);
gDataTable->Put(aUri, info);
return NS_OK;
}
/* static */ bool
nsHostObjectProtocolHandler::GetAllBlobURLEntries(nsTArray<BlobURLRegistrationData>& aRegistrations,
ContentParent* aCP)
{
MOZ_ASSERT(aCP);
if (!gDataTable) {
return true;
}
for (auto iter = gDataTable->ConstIter(); !iter.Done(); iter.Next()) {
DataInfo* info = iter.UserData();
MOZ_ASSERT(info);
nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(info->mObject);
if (!blobImpl) {
continue;
}
PBlobParent* blobParent = aCP->GetOrCreateActorForBlobImpl(blobImpl);
if (!blobParent) {
return false;
}
aRegistrations.AppendElement(
BlobURLRegistrationData(nsCString(iter.Key()), blobParent, nullptr,
IPC::Principal(info->mPrincipal)));
}
return true;
}
void
nsHostObjectProtocolHandler::RemoveDataEntry(const nsACString& aUri,
bool aBroadcastToOtherProcesses)
nsHostObjectProtocolHandler::RemoveDataEntry(const nsACString& aUri)
{
if (!gDataTable) {
return;
}
DataInfo* info = GetDataInfo(aUri);
if (!info) {
return;
}
if (aBroadcastToOtherProcesses) {
nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(info->mObject);
if (blobImpl) {
BroadcastBlobURLUnregistration(aUri, info);
}
}
gDataTable->Remove(aUri);
if (gDataTable->Count() == 0) {
delete gDataTable;
@ -534,6 +398,37 @@ nsHostObjectProtocolHandler::GenerateURIString(const nsACString &aScheme,
return NS_OK;
}
static DataInfo*
GetDataInfo(const nsACString& aUri)
{
if (!gDataTable) {
return nullptr;
}
DataInfo* res;
// Let's remove any fragment and query from this URI.
int32_t hasFragmentPos = aUri.FindChar('#');
int32_t hasQueryPos = aUri.FindChar('?');
int32_t pos = -1;
if (hasFragmentPos >= 0 && hasQueryPos >= 0) {
pos = std::min(hasFragmentPos, hasQueryPos);
} else if (hasFragmentPos >= 0) {
pos = hasFragmentPos;
} else {
pos = hasQueryPos;
}
if (pos < 0) {
gDataTable->Get(aUri, &res);
} else {
gDataTable->Get(StringHead(aUri, pos), &res);
}
return res;
}
nsIPrincipal*
nsHostObjectProtocolHandler::GetDataEntryPrincipal(const nsACString& aUri)
{
@ -909,4 +804,3 @@ static const mozilla::Module kHostObjectProtocolHandlerModule = {
};
NSMODULE_DEFN(HostObjectProtocolHandler) = &kHostObjectProtocolHandlerModule;

View File

@ -12,7 +12,6 @@
#include "nsIURI.h"
#include "nsCOMPtr.h"
#include "nsIInputStream.h"
#include "nsTArray.h"
#define BLOBURI_SCHEME "blob"
#define MEDIASTREAMURI_SCHEME "mediastream"
@ -26,8 +25,6 @@ namespace mozilla {
class DOMMediaStream;
namespace dom {
class BlobImpl;
class BlobURLRegistrationData;
class ContentParent;
class MediaSource;
} // namespace dom
} // namespace mozilla
@ -58,19 +55,10 @@ public:
nsISupports* aObject,
nsIPrincipal* aPrincipal,
nsACString& aUri);
static void RemoveDataEntry(const nsACString& aUri,
bool aBroadcastToOTherProcesses = true);
static void RemoveDataEntry(const nsACString& aUri);
static nsIPrincipal* GetDataEntryPrincipal(const nsACString& aUri);
static void Traverse(const nsACString& aUri, nsCycleCollectionTraversalCallback& aCallback);
// IPC or internal use only
static nsresult AddDataEntry(const nsACString& aURI,
nsISupports* aObject,
nsIPrincipal* aPrincipal);
static bool
GetAllBlobURLEntries(nsTArray<mozilla::dom::BlobURLRegistrationData>& aRegistrations,
mozilla::dom::ContentParent* aCP);
protected:
virtual ~nsHostObjectProtocolHandler() {}

View File

@ -129,7 +129,6 @@
#include "mozilla/dom/PCycleCollectWithLogsChild.h"
#include "nsIScriptSecurityManager.h"
#include "nsHostObjectProtocolHandler.h"
#ifdef MOZ_WEBRTC
#include "signaling/src/peerconnection/WebrtcGlobalChild.h"
@ -2636,22 +2635,6 @@ ContentChild::RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig)
return true;
}
bool
ContentChild::RecvInitBlobURLs(nsTArray<BlobURLRegistrationData>&& aRegistrations)
{
for (uint32_t i = 0; i < aRegistrations.Length(); ++i) {
BlobURLRegistrationData& registration = aRegistrations[i];
RefPtr<BlobImpl> blobImpl =
static_cast<BlobChild*>(registration.blobChild())->GetBlobImpl();
MOZ_ASSERT(blobImpl);
nsHostObjectProtocolHandler::AddDataEntry(registration.url(), blobImpl,
registration.principal());
}
return true;
}
bool
ContentChild::RecvLastPrivateDocShellDestroyed()
{
@ -3390,25 +3373,6 @@ ContentChild::RecvNotifyPushSubscriptionModifiedObservers(const nsCString& aScop
return true;
}
bool
ContentChild::RecvBlobURLRegistration(const nsCString& aURI, PBlobChild* aBlobChild,
const IPC::Principal& aPrincipal)
{
RefPtr<BlobImpl> blobImpl = static_cast<BlobChild*>(aBlobChild)->GetBlobImpl();
MOZ_ASSERT(blobImpl);
nsHostObjectProtocolHandler::AddDataEntry(aURI, blobImpl, aPrincipal);
return true;
}
bool
ContentChild::RecvBlobURLUnregistration(const nsCString& aURI)
{
nsHostObjectProtocolHandler::RemoveDataEntry(aURI);
return true;
}
void
ContentChild::CreateGetFilesRequest(const nsAString& aDirectoryPath,
bool aRecursiveFlag,

View File

@ -462,9 +462,6 @@ public:
virtual bool
RecvInitServiceWorkers(const ServiceWorkerConfiguration& aConfig) override;
virtual bool
RecvInitBlobURLs(nsTArray<BlobURLRegistrationData>&& aRegistations) override;
virtual bool RecvLastPrivateDocShellDestroyed() override;
virtual bool RecvVolumes(InfallibleTArray<VolumeInfo>&& aVolumes) override;
@ -646,13 +643,6 @@ public:
RecvGetFilesResponse(const nsID& aUUID,
const GetFilesResponseResult& aResult) override;
virtual bool
RecvBlobURLRegistration(const nsCString& aURI, PBlobChild* aBlobChild,
const IPC::Principal& aPrincipal) override;
virtual bool
RecvBlobURLUnregistration(const nsCString& aURI) override;
private:
static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
void StartForceKillTimer();

View File

@ -191,7 +191,6 @@
#include "nsIBlocklistService.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"
#include "nsHostObjectProtocolHandler.h"
#include "nsIBidiKeyboard.h"
@ -2514,22 +2513,13 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
}
#endif
{
RefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
MOZ_ASSERT(swr);
RefPtr<ServiceWorkerRegistrar> swr = ServiceWorkerRegistrar::Get();
MOZ_ASSERT(swr);
nsTArray<ServiceWorkerRegistrationData> registrations;
swr->GetRegistrations(registrations);
Unused << SendInitServiceWorkers(ServiceWorkerConfiguration(registrations));
}
nsTArray<ServiceWorkerRegistrationData> registrations;
swr->GetRegistrations(registrations);
{
nsTArray<BlobURLRegistrationData> registrations;
if (nsHostObjectProtocolHandler::GetAllBlobURLEntries(registrations,
this)) {
Unused << SendInitBlobURLs(registrations);
}
}
Unused << SendInitServiceWorkers(ServiceWorkerConfiguration(registrations));
}
bool
@ -5706,63 +5696,6 @@ ContentParent::RecvNotifyLowMemory()
return true;
}
/* static */ void
ContentParent::BroadcastBlobURLRegistration(const nsACString& aURI,
BlobImpl* aBlobImpl,
nsIPrincipal* aPrincipal,
ContentParent* aIgnoreThisCP)
{
nsCString uri(aURI);
IPC::Principal principal(aPrincipal);
for (auto* cp : AllProcesses(eLive)) {
if (cp != aIgnoreThisCP) {
PBlobParent* blobParent = cp->GetOrCreateActorForBlobImpl(aBlobImpl);
if (blobParent) {
Unused << cp->SendBlobURLRegistration(uri, blobParent, principal);
}
}
}
}
/* static */ void
ContentParent::BroadcastBlobURLUnregistration(const nsACString& aURI,
ContentParent* aIgnoreThisCP)
{
nsCString uri(aURI);
for (auto* cp : AllProcesses(eLive)) {
if (cp != aIgnoreThisCP) {
Unused << cp->SendBlobURLUnregistration(uri);
}
}
}
bool
ContentParent::RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
PBlobParent* aBlobParent,
const Principal& aPrincipal)
{
RefPtr<BlobImpl> blobImpl =
static_cast<BlobParent*>(aBlobParent)->GetBlobImpl();
if (NS_WARN_IF(!blobImpl)) {
return false;
}
nsHostObjectProtocolHandler::AddDataEntry(aURI, blobImpl, aPrincipal);
BroadcastBlobURLRegistration(aURI, blobImpl, aPrincipal, this);
return true;
}
bool
ContentParent::RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI)
{
nsHostObjectProtocolHandler::RemoveDataEntry(aURI,
false /* Don't broadcast */);
BroadcastBlobURLUnregistration(aURI, this);
return true;
}
} // namespace dom
} // namespace mozilla

View File

@ -575,24 +575,6 @@ public:
static bool AllocateLayerTreeId(TabParent* aTabParent, uint64_t* aId);
static void
BroadcastBlobURLRegistration(const nsACString& aURI,
BlobImpl* aBlobImpl,
nsIPrincipal* aPrincipal,
ContentParent* aIgnoreThisCP = nullptr);
static void
BroadcastBlobURLUnregistration(const nsACString& aURI,
ContentParent* aIgnoreThisCP = nullptr);
virtual bool
RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
PBlobParent* aBlobParent,
const Principal& aPrincipal) override;
virtual bool
RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI) override;
protected:
void OnChannelConnected(int32_t pid) override;

View File

@ -373,13 +373,6 @@ union GetFilesResponseResult
GetFilesResponseFailure;
};
struct BlobURLRegistrationData
{
nsCString url;
PBlob blob;
Principal principal;
};
prio(normal upto urgent) sync protocol PContent
{
parent spawns PPluginModule;
@ -554,11 +547,6 @@ child:
*/
async InitServiceWorkers(ServiceWorkerConfiguration aConfig);
/**
* Send BlobURLRegistrationData to child process.
*/
async InitBlobURLs(BlobURLRegistrationData[] registrations);
// Notify child that last-pb-context-exited notification was observed
async LastPrivateDocShellDestroyed();
@ -688,11 +676,6 @@ child:
async GetFilesResponse(nsID aID, GetFilesResponseResult aResult);
async BlobURLRegistration(nsCString aURI, PBlob aBlob,
Principal aPrincipal);
async BlobURLUnregistration(nsCString aURI);
parent:
/**
* Tell the content process some attributes of itself. This is
@ -1205,11 +1188,6 @@ parent:
async GetFilesRequest(nsID aID, nsString aDirectory, bool aRecursiveFlag);
async DeleteGetFilesRequest(nsID aID);
async StoreAndBroadcastBlobURLRegistration(nsCString url, PBlob blob,
Principal principal);
async UnstoreAndBroadcastBlobURLUnregistration(nsCString url);
both:
async AsyncMessage(nsString aMessage, CpowEntry[] aCpows,
Principal aPrincipal, ClonedMessageData aData);

View File

@ -28,13 +28,9 @@ public:
operator nsIPrincipal*() const { return mPrincipal.get(); }
Principal& operator=(const Principal& aOther)
{
mPrincipal = aOther.mPrincipal;
return *this;
}
private:
// Unimplemented
Principal& operator=(Principal&);
nsCOMPtr<nsIPrincipal> mPrincipal;
};