Bug 1567341 - Release EventDispatcher listeners on xpcom-shutdown. r=esawin

Differential Revision: https://phabricator.services.mozilla.com/D106204
This commit is contained in:
Agi Sferro 2021-03-24 21:49:35 +00:00
Родитель abb7600c37
Коммит 32e27b2a7c
6 изменённых файлов: 31 добавлений и 3 удалений

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

@ -213,6 +213,7 @@ class GeckoViewStartup {
"GeckoView:SetLocale",
]);
Services.obs.addObserver(this, "xpcom-shutdown");
Services.obs.notifyObservers(null, "geckoview-startup-complete");
break;
}
@ -224,6 +225,16 @@ class GeckoViewStartup {
Services.startup.trackStartupCrashEnd();
break;
}
case "xpcom-shutdown": {
Services.obs.removeObserver(this, "xpcom-shutdown");
EventDispatcher.instance.unregisterListener(this, [
"GeckoView:ResetUserPrefs",
"GeckoView:SetDefaultPrefs",
"GeckoView:SetLocale",
]);
EventDispatcher.instance.shutdown();
delete EventDispatcher.instance;
}
}
}

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

@ -125,7 +125,7 @@ public final class EventDispatcher extends JNIObject {
@WrapForJNI @Override // JNIObject
protected native void disposeNative();
@WrapForJNI(stubName = "Shutdown")
@WrapForJNI(stubName = "ShutdownFromJava", dispatchTo = "gecko")
protected native void shutdownNative();
@WrapForJNI private static final int DETACHED = 0;

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

@ -151,6 +151,10 @@ DispatcherDelegate.prototype = {
this._replies.clear();
},
shutdown() {
this._dispatcher.shutdown();
},
receiveMessage(aMsg) {
const { uuid, type } = aMsg.data;
const reply = this._replies.get(uuid);
@ -282,4 +286,12 @@ var EventDispatcher = {
if (IS_PARENT_PROCESS) {
Services.mm.addMessageListener("GeckoView:Messaging", EventDispatcher);
Services.ppmm.addMessageListener("GeckoView:Messaging", EventDispatcher);
function xpcomShutdown() {
Services.mm.removeMessageListener("GeckoView:Messaging", EventDispatcher);
Services.ppmm.removeMessageListener("GeckoView:Messaging", EventDispatcher);
Services.obs.removeObserver(xpcomShutdown, "xpcom-shutdown");
}
Services.obs.addObserver(xpcomShutdown, "xpcom-shutdown");
}

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

@ -949,9 +949,13 @@ void EventDispatcher::Attach(java::EventDispatcher::Param aDispatcher,
dispatcher->SetAttachedToGecko(java::EventDispatcher::ATTACHED);
}
void EventDispatcher::Shutdown() {
NS_IMETHODIMP
EventDispatcher::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());
mDispatcher = nullptr;
mDOMWindow = nullptr;
mListenersMap.Clear();
return NS_OK;
}
void EventDispatcher::Detach() {

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

@ -65,7 +65,7 @@ class EventDispatcher final
virtual ~EventDispatcher() {}
void Shutdown();
void ShutdownFromJava() { Shutdown(); }
struct ListenersList {
nsCOMArray<nsIAndroidEventListener> listeners{/* count */ 1};

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

@ -43,6 +43,7 @@ interface nsIAndroidEventDispatcher : nsISupports
[implicit_jscontext]
void unregisterListener(in nsIAndroidEventListener listener,
in jsval events);
void shutdown();
};
[scriptable, uuid(60a78a94-6117-432f-9d49-304913a931c5)]