tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit ff08bedebcc87d1d005d8f01588b9a62bb970837
parent fc11ba2f78f97a71f9900f7a3934ef4fbe6b8e5e
Author: Alexandra Borovova <aborovova@mozilla.com>
Date:   Tue, 23 Dec 2025 12:51:16 +0000

Bug 1964905 - [webdriver-bidi] Use "owningBrowsingContext" to handle prompts. r=whimboo

Differential Revision: https://phabricator.services.mozilla.com/D276821

Diffstat:
Mremote/shared/NavigationManager.sys.mjs | 23+++++++++++++++--------
Mremote/shared/listeners/PromptListener.sys.mjs | 27++++++++-------------------
Mremote/webdriver-bidi/modules/root/browsingContext.sys.mjs | 25+++++++++++++++++++------
Mtesting/web-platform/meta/webdriver/tests/bidi/browsing_context/navigate/navigate_beforeunload.py.ini | 16++++++++++------
Mtesting/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_closed/user_prompt_closed.py.ini | 6++++--
Mtesting/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_opened/user_prompt_opened.py.ini | 5+++--
6 files changed, 59 insertions(+), 43 deletions(-)

diff --git a/remote/shared/NavigationManager.sys.mjs b/remote/shared/NavigationManager.sys.mjs @@ -7,6 +7,7 @@ import { EventEmitter } from "resource://gre/modules/EventEmitter.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { + AppInfo: "chrome://remote/content/shared/AppInfo.sys.mjs", BrowsingContextListener: "chrome://remote/content/shared/listeners/BrowsingContextListener.sys.mjs", DownloadListener: @@ -828,15 +829,18 @@ class NavigationRegistry extends EventEmitter { #onPromptClosed = (eventName, data) => { const { contentBrowser, detail } = data; - const { accepted, promptType } = detail; + const { accepted, browsingContext, promptType } = detail; // Send navigation failed event if beforeunload prompt was rejected. if (promptType === "beforeunload" && accepted === false) { - const browsingContext = contentBrowser.browsingContext; - + // TODO: Bug 2007385. We can remove this fallback + // when we have support for browsing context property in event details on Android. + const context = lazy.AppInfo.isAndroid + ? contentBrowser.browsingContext + : browsingContext; notifyNavigationFailed({ contextDetails: { - context: browsingContext, + context, }, errorName: "Beforeunload prompt was rejected", // Bug 1908952. Add support for the "url" field. @@ -845,16 +849,19 @@ class NavigationRegistry extends EventEmitter { }; #onPromptOpened = (eventName, data) => { - const { contentBrowser, prompt } = data; + const { browsingContext, contentBrowser, prompt } = data; const { promptType } = prompt; // We should start the navigation when beforeunload prompt is open. if (promptType === "beforeunload") { - const browsingContext = contentBrowser.browsingContext; - + // TODO: Bug 2007385. We can remove this fallback + // when we have support for browsing context property in event details on Android. + const context = lazy.AppInfo.isAndroid + ? contentBrowser.browsingContext + : browsingContext; notifyNavigationStarted({ contextDetails: { - context: browsingContext, + context, }, // Bug 1908952. Add support for the "url" field. }); diff --git a/remote/shared/listeners/PromptListener.sys.mjs b/remote/shared/listeners/PromptListener.sys.mjs @@ -112,7 +112,8 @@ export class PromptListener { // At the moment the event details are present for GeckoView and on desktop // only for Services.prompt.MODAL_TYPE_CONTENT prompts. if (event.detail) { - const { areLeaving, promptType, value } = event.detail; + const { areLeaving, owningBrowsingContext, promptType, value } = + event.detail; // `areLeaving` returns undefined for alerts, for confirms and prompts // it returns true if a user prompt was accepted and false if it was dismissed. detail.accepted = areLeaving === undefined ? true : areLeaving; @@ -120,6 +121,7 @@ export class PromptListener { if (value) { detail.userText = value; } + detail.browsingContext = owningBrowsingContext; } this.emit("closed", { @@ -134,10 +136,12 @@ export class PromptListener { * `domwindowopened` - when a new chrome window opened, * `geckoview-prompt-show` - when a modal dialog opened on Android. */ - async observe(subject, topic) { + observe(subject, topic) { let curBrowser = this.#curBrowserFn && this.#curBrowserFn(); switch (topic) { case "common-dialog-loaded": { + const browsingContext = subject.args.owningBrowsingContext; + if (curBrowser) { if ( !this.#hasCommonDialog( @@ -149,26 +153,11 @@ export class PromptListener { return; } } else { - const chromeWin = subject.opener - ? subject.opener.ownerGlobal - : subject.ownerGlobal; - - for (const tab of lazy.TabManager.getTabsForWindow(chromeWin)) { - const contentBrowser = lazy.TabManager.getBrowserForTab(tab); - const window = lazy.TabManager.getWindowForTab(tab); - - if (this.#hasCommonDialog(contentBrowser, window, subject)) { - curBrowser = { - contentBrowser, - window, - }; - - break; - } - } + curBrowser = { contentBrowser: browsingContext.embedderElement }; } this.emit("opened", { + browsingContext, contentBrowser: curBrowser.contentBrowser, prompt: new lazy.modal.Dialog(subject), }); diff --git a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs @@ -2205,14 +2205,20 @@ class BrowsingContextModule extends RootBiDiModule { #onPromptClosed = (eventName, data) => { if (this.#subscribedEvents.has("browsingContext.userPromptClosed")) { const { contentBrowser, detail } = data; - const navigableId = lazy.NavigableManager.getIdForBrowser(contentBrowser); + // TODO: Bug 2007385. Use only browsingContext from event details when the support for Android is added. + const browsingContext = lazy.AppInfo.isAndroid + ? contentBrowser.browsingContext + : detail.browsingContext; + + const navigableId = + lazy.NavigableManager.getIdForBrowsingContext(browsingContext); if (navigableId === null) { return; } lazy.logger.trace( - `[${contentBrowser.browsingContext.id}] Prompt closed (type: "${ + `[${browsingContext.id}] Prompt closed (type: "${ detail.promptType }", accepted: "${detail.accepted}")` ); @@ -2225,7 +2231,7 @@ class BrowsingContextModule extends RootBiDiModule { }; this.#emitContextEventForBrowsingContext( - contentBrowser.browsingContext.id, + browsingContext.id, "browsingContext.userPromptClosed", params ); @@ -2237,12 +2243,18 @@ class BrowsingContextModule extends RootBiDiModule { const { contentBrowser, prompt } = data; const type = prompt.promptType; + // TODO: Bug 2007385. We can remove this fallback + // when we have support for browsing context property on Android. + const browsingContext = lazy.AppInfo.isAndroid + ? contentBrowser.browsingContext + : data.browsingContext; + prompt.getText().then(text => { // We need the text to identify a user prompt when it gets // randomly opened. Because on Android the text is asynchronously // retrieved lets delay the logging without making the handler async. lazy.logger.trace( - `[${contentBrowser.browsingContext.id}] Prompt opened (type: "${ + `[${browsingContext.id}] Prompt opened (type: "${ prompt.promptType }", text: "${text}")` ); @@ -2254,7 +2266,8 @@ class BrowsingContextModule extends RootBiDiModule { return; } - const navigableId = lazy.NavigableManager.getIdForBrowser(contentBrowser); + const navigableId = + lazy.NavigableManager.getIdForBrowsingContext(browsingContext); const session = lazy.getWebDriverSessionById( this.messageHandler.sessionId @@ -2273,7 +2286,7 @@ class BrowsingContextModule extends RootBiDiModule { } this.#emitContextEventForBrowsingContext( - contentBrowser.browsingContext.id, + browsingContext.id, "browsingContext.userPromptOpened", eventPayload ); diff --git a/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/navigate/navigate_beforeunload.py.ini b/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/navigate/navigate_beforeunload.py.ini @@ -3,14 +3,18 @@ if os == "android": bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1879324 expected: if (os == "mac") and not debug: [OK, TIMEOUT] + [test_navigate_with_beforeunload_prompt_in_iframe[False-none\]] - bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1908951 - expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2007385 + expected: + if (os == "android"): FAIL [test_navigate_with_beforeunload_prompt_in_iframe[False-interactive\]] - bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1908951 - expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2007385 + expected: + if (os == "android"): FAIL [test_navigate_with_beforeunload_prompt_in_iframe[False-complete\]] - bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1908951 - expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2007385 + expected: + if (os == "android"): FAIL diff --git a/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_closed/user_prompt_closed.py.ini b/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_closed/user_prompt_closed.py.ini @@ -1,6 +1,8 @@ [user_prompt_closed.py] expected: if (os == "mac") and not debug: [OK, TIMEOUT] + [test_iframe] - bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1964905 - expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2007385 + expected: + if (os == "android"): FAIL diff --git a/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_opened/user_prompt_opened.py.ini b/testing/web-platform/meta/webdriver/tests/bidi/browsing_context/user_prompt_opened/user_prompt_opened.py.ini @@ -2,8 +2,9 @@ expected: if (os == "mac") and not debug: [OK, TIMEOUT] [test_iframe] - bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1964905 - expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=2007385 + expected: + if (os == "android"): FAIL [test_two_prompts[tab\]] expected: