Commit 862a2e28 authored by Agi Sferro's avatar Agi Sferro
Browse files

Bug 1703629 - Discard useless prompts. r=aklotz, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D111474
parent c767f016
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment