зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
dcd10aa59f
Коммит
c22ef89c64
|
@ -51,3 +51,12 @@ JSWindowActorChild implements JSWindowActor;
|
|||
callback interface MozObserverCallback {
|
||||
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());
|
||||
}
|
||||
|
||||
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() {
|
||||
// Take our queries out, in case somehow rejecting promises can trigger
|
||||
// additions or removals.
|
||||
|
|
|
@ -39,6 +39,7 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
|
|||
JSWindowActor();
|
||||
|
||||
enum class Type { Parent, Child };
|
||||
enum class DestroyCallbackFunction { WillDestroy, DidDestroy };
|
||||
|
||||
const nsString& Name() const { return mName; }
|
||||
|
||||
|
@ -71,6 +72,12 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
|
|||
|
||||
void SetName(const nsAString& aName);
|
||||
|
||||
void StartDestroy();
|
||||
|
||||
void AfterDestroy();
|
||||
|
||||
void DestroyCallback(DestroyCallbackFunction willDestroy);
|
||||
|
||||
private:
|
||||
void ReceiveMessageOrQuery(JSContext* aCx,
|
||||
const JSWindowActorMessageMeta& aMetadata,
|
||||
|
|
|
@ -115,10 +115,12 @@ Nullable<WindowProxyHolder> JSWindowActorChild::GetContentWindow(
|
|||
}
|
||||
|
||||
void JSWindowActorChild::StartDestroy() {
|
||||
JSWindowActor::StartDestroy();
|
||||
mCanSend = false;
|
||||
}
|
||||
|
||||
void JSWindowActorChild::AfterDestroy() {
|
||||
JSWindowActor::AfterDestroy();
|
||||
mManager = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,10 +86,12 @@ void JSWindowActorParent::SendRawMessage(const JSWindowActorMessageMeta& aMeta,
|
|||
}
|
||||
|
||||
void JSWindowActorParent::StartDestroy() {
|
||||
JSWindowActor::StartDestroy();
|
||||
mCanSend = false;
|
||||
}
|
||||
|
||||
void JSWindowActorParent::AfterDestroy() {
|
||||
JSWindowActor::AfterDestroy();
|
||||
mManager = nullptr;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче