Bug 1465480 - Allow GeckoView modules to clean up when window closes r=jchen
MozReview-Commit-ID: 2erYZpnBTnq
--- a/mobile/android/chrome/geckoview/geckoview.js
+++ b/mobile/android/chrome/geckoview/geckoview.js
@@ -58,16 +58,25 @@ var ModuleManager = {
]);
this.messageManager.addMessageListener("GeckoView:ContentModuleLoaded",
this);
this.forEach(module => {
module.onInit();
});
+
+ window.addEventListener("unload", () => {
+ this.forEach(module => {
+ module.enabled = false;
+ module.onDestroy();
+ });
+
+ this._modules.clear();
+ });
},
get window() {
return window;
},
get browser() {
return this._browser;
@@ -195,16 +204,22 @@ class ModuleInfo {
this._impl.onSettingsUpdate();
}
this._loadPhase(this._onInitPhase);
this._onInitPhase = null;
this.enabled = this._enabledOnInit;
}
+ onDestroy() {
+ if (this._impl) {
+ this._impl.onDestroy();
+ }
+ }
+
/**
* Load resources according to a phase object that contains possible keys,
*
* "resource": specify the JSM resource to load for this module.
* "frameScript": specify a content JS frame script to load for this module.
*/
_loadPhase(aPhase) {
if (!aPhase) {
--- a/mobile/android/modules/geckoview/GeckoViewModule.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewModule.jsm
@@ -50,16 +50,19 @@ class GeckoViewModule {
}
// Override to initialize the browser before it is bound to the window.
onInitBrowser() {}
// Override to initialize module.
onInit() {}
+ // Override to cleanup when the window is closed
+ onDestroy() {}
+
// Override to detect settings change. Access settings via this.settings.
onSettingsUpdate() {}
// Override to enable module after setting a Java delegate.
onEnable() {}
// Override to disable module after clearing the Java delegate.
onDisable() {}