Bug 1580448 - nsIContent{Child, Parent}::getActor;r=nika

Differential Revision: https://phabricator.services.mozilla.com/D69784
This commit is contained in:
David Teller 2020-04-30 16:43:48 +00:00
Родитель 3da6e17db2
Коммит 47e9954cc6
5 изменённых файлов: 80 добавлений и 1 удалений

Просмотреть файл

@ -4202,6 +4202,42 @@ NS_IMETHODIMP ContentChild::GetChildID(uint64_t* aOut) {
return NS_OK;
}
NS_IMETHODIMP ContentChild::GetActor(const nsACString& aName,
JSProcessActorChild** retval) {
if (!CanSend()) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
RefPtr<JSProcessActorChild> actor(mProcessActors.Get(aName));
actor.forget(retval);
return NS_OK;
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ErrorResult result;
ConstructActor(aName, &obj, result);
if (result.Failed()) {
return result.StealNSResult();
}
// Unwrap our actor to a JSProcessActorChild object.
RefPtr<JSProcessActorChild> actor;
nsresult rv = UNWRAP_OBJECT(JSProcessActorChild, &obj, actor);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
actor.forget(retval);
return NS_OK;
}
IPCResult ContentChild::RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack) {

Просмотреть файл

@ -907,7 +907,6 @@ class ContentChild final
uint64_t mBrowsingContextFieldEpoch = 0;
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorChild> mProcessActors;
DISALLOW_EVIL_CONSTRUCTORS(ContentChild);
};

Просмотреть файл

@ -6483,6 +6483,42 @@ already_AddRefed<JSProcessActorParent> ContentParent::GetActor(
return actor.forget();
}
NS_IMETHODIMP ContentParent::GetActor(const nsACString& aName,
JSProcessActorParent** retval) {
if (!CanSend()) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
RefPtr<JSProcessActorParent> actor(mProcessActors.Get(aName));
actor.forget(retval);
return NS_OK;
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ErrorResult result;
ConstructActor(aName, &obj, result);
if (result.Failed()) {
return result.StealNSResult();
}
// Unwrap our actor to a JSProcessActorParent object.
RefPtr<JSProcessActorParent> actor;
nsresult rv = UNWRAP_OBJECT(JSProcessActorParent, &obj, actor);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
actor.forget(retval);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -1,7 +1,11 @@
#include "nsISupports.idl"
webidl JSProcessActorChild;
[scriptable, builtinclass, uuid(b0c6e5f3-02f1-4f11-a0af-336fc231f3bf)]
interface nsIContentChild: nsISupports {
// Internal ID of the process.
readonly attribute unsigned long long childID;
JSProcessActorChild getActor(in ACString name);
};

Просмотреть файл

@ -1,7 +1,11 @@
#include "nsISupports.idl"
webidl JSProcessActorParent;
[scriptable, builtinclass, uuid(81fc08b9-c901-471f-ab0d-876362eba770)]
interface nsIContentParent: nsISupports {
// Internal ID of the process.
readonly attribute unsigned long long childID;
JSProcessActorParent getActor(in ACString name);
};