Bug 1538979 - Part 2: Add WillDestroy and DidDestroy lifecycle methods on JSWindowActor; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D30196

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Dai 2019-05-10 09:19:30 +00:00
Родитель dcd10aa59f
Коммит c22ef89c64
5 изменённых файлов: 51 добавлений и 0 удалений

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

@ -51,3 +51,12 @@ JSWindowActorChild implements JSWindowActor;
callback interface MozObserverCallback { callback interface MozObserverCallback {
void observe(nsISupports subject, ByteString topic, DOMString? data); void observe(nsISupports subject, ByteString topic, DOMString? data);
}; };
// WebIDL callback interface calling the `willDestroy` and `didDestroy`
// method on JSWindowActors.
callback MozActorDestroyCallback = void();
dictionary MozActorDestroyCallbacks {
[ChromeOnly] MozActorDestroyCallback willDestroy;
[ChromeOnly] MozActorDestroyCallback didDestroy;
};

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

@ -39,6 +39,37 @@ nsIGlobalObject* JSWindowActor::GetParentObject() const {
return xpc::NativeGlobal(xpc::PrivilegedJunkScope()); return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
} }
void JSWindowActor::StartDestroy() {
DestroyCallback(DestroyCallbackFunction::WillDestroy);
}
void JSWindowActor::AfterDestroy() {
DestroyCallback(DestroyCallbackFunction::DidDestroy);
}
void JSWindowActor::DestroyCallback(DestroyCallbackFunction callback) {
AutoEntryScript aes(xpc::PrivilegedJunkScope(),
"JSWindowActor destroy callback");
JSContext* cx = aes.cx();
MozActorDestroyCallbacks callbacksHolder;
NS_ENSURE_TRUE_VOID(GetWrapper());
JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*GetWrapper()));
if (NS_WARN_IF(!callbacksHolder.Init(cx, val))) {
return;
}
// Destroy callback is optional.
if (callback == DestroyCallbackFunction::WillDestroy) {
if (callbacksHolder.mWillDestroy.WasPassed()) {
callbacksHolder.mWillDestroy.Value()->Call();
}
} else {
if (callbacksHolder.mDidDestroy.WasPassed()) {
callbacksHolder.mDidDestroy.Value()->Call();
}
}
}
void JSWindowActor::RejectPendingQueries() { void JSWindowActor::RejectPendingQueries() {
// Take our queries out, in case somehow rejecting promises can trigger // Take our queries out, in case somehow rejecting promises can trigger
// additions or removals. // additions or removals.

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

@ -39,6 +39,7 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
JSWindowActor(); JSWindowActor();
enum class Type { Parent, Child }; enum class Type { Parent, Child };
enum class DestroyCallbackFunction { WillDestroy, DidDestroy };
const nsString& Name() const { return mName; } const nsString& Name() const { return mName; }
@ -71,6 +72,12 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
void SetName(const nsAString& aName); void SetName(const nsAString& aName);
void StartDestroy();
void AfterDestroy();
void DestroyCallback(DestroyCallbackFunction willDestroy);
private: private:
void ReceiveMessageOrQuery(JSContext* aCx, void ReceiveMessageOrQuery(JSContext* aCx,
const JSWindowActorMessageMeta& aMetadata, const JSWindowActorMessageMeta& aMetadata,

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

@ -115,10 +115,12 @@ Nullable<WindowProxyHolder> JSWindowActorChild::GetContentWindow(
} }
void JSWindowActorChild::StartDestroy() { void JSWindowActorChild::StartDestroy() {
JSWindowActor::StartDestroy();
mCanSend = false; mCanSend = false;
} }
void JSWindowActorChild::AfterDestroy() { void JSWindowActorChild::AfterDestroy() {
JSWindowActor::AfterDestroy();
mManager = nullptr; mManager = nullptr;
} }

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

@ -86,10 +86,12 @@ void JSWindowActorParent::SendRawMessage(const JSWindowActorMessageMeta& aMeta,
} }
void JSWindowActorParent::StartDestroy() { void JSWindowActorParent::StartDestroy() {
JSWindowActor::StartDestroy();
mCanSend = false; mCanSend = false;
} }
void JSWindowActorParent::AfterDestroy() { void JSWindowActorParent::AfterDestroy() {
JSWindowActor::AfterDestroy();
mManager = nullptr; mManager = nullptr;
} }