Skip to content
Snippets Groups Projects
Commit 8575705a authored by Agi Sferro's avatar Agi Sferro
Browse files

Bug 1703629 - Discard useless prompts. r=aklotz

parent fee5a53f
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,8 @@ class GeckoViewPrompter {
this._domWin,
] = GeckoViewUtils.getActiveDispatcherAndWindow();
}
this._innerWindowId = this._domWin?.browsingContext.currentWindowContext.innerWindowId;
}
get domWin() {
......@@ -95,6 +97,17 @@ class GeckoViewPrompter {
return result;
}
checkInnerWindow() {
// Checks that the innerWindow where this prompt was created still matches
// the current innerWindow.
// This checks will fail if the page navigates away, making this prompt
// obsolete.
return (
this._innerWindowId ===
this._domWin.browsingContext.currentWindowContext.innerWindowId
);
}
asyncShowPromptPromise(aMsg) {
return new Promise(resolve => {
this.asyncShowPrompt(aMsg, resolve);
......@@ -107,7 +120,12 @@ class GeckoViewPrompter {
if (handled) {
return;
}
aCallback(response);
if (!this.checkInnerWindow()) {
// Page has navigated away, let's dismiss the prompt
aCallback(null);
} else {
aCallback(response);
}
// This callback object is tied to the Java garbage collector because
// it is invoked from Java. Manually release the target callback
// here; otherwise we may hold onto resources for too long, because
......@@ -118,7 +136,7 @@ class GeckoViewPrompter {
handled = true;
};
if (!this._dispatcher) {
if (!this._dispatcher || !this.checkInnerWindow()) {
onResponse(null);
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment