tor-browser

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

commit 9372f2ecaaaefaa44777900e5efe2fb5ac974bb2
parent 11c3429a0c2944c22dfaaff3f29b461ce7dacdf3
Author: Alexandra Borovova <aborovova@mozilla.com>
Date:   Wed, 22 Oct 2025 07:06:58 +0000

Bug 1988725 - [bidi] Update "emulation.setLocaleOverride" and "emulation.setTimezoneOverride" commands reset behavior. r=webdriver-reviewers,whimboo

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

Diffstat:
Mremote/webdriver-bidi/modules/root/emulation.sys.mjs | 200++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mremote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs | 38++++++++++++++++++++++++++++++++++++--
2 files changed, 169 insertions(+), 69 deletions(-)

diff --git a/remote/webdriver-bidi/modules/root/emulation.sys.mjs b/remote/webdriver-bidi/modules/root/emulation.sys.mjs @@ -454,31 +454,39 @@ class EmulationModule extends RootBiDiModule { } const sessionDataItems = []; + // In case of resetting the override, remove existing session data items + // for the required context descriptors. + const onlyRemoveSessionDataItem = locale === ""; + if (userContextIds !== null) { for (const userContext of userContexts) { - sessionDataItems.push({ - category: "locale-override", - moduleName: "_configuration", - values: [locale], - contextDescriptor: { - type: lazy.ContextDescriptorType.UserContext, - id: userContext, - }, - method: lazy.SessionDataMethod.Add, - }); + sessionDataItems.push( + ...this.messageHandler.sessionData.generateSessionDataItemUpdate( + "_configuration", + "locale-override", + { + type: lazy.ContextDescriptorType.UserContext, + id: userContext, + }, + onlyRemoveSessionDataItem, + locale + ) + ); } } else { for (const navigable of navigables) { - sessionDataItems.push({ - category: "locale-override", - moduleName: "_configuration", - values: [locale], - contextDescriptor: { - type: lazy.ContextDescriptorType.TopBrowsingContext, - id: navigable.browserId, - }, - method: lazy.SessionDataMethod.Add, - }); + sessionDataItems.push( + ...this.messageHandler.sessionData.generateSessionDataItemUpdate( + "_configuration", + "locale-override", + { + type: lazy.ContextDescriptorType.TopBrowsingContext, + id: navigable.browserId, + }, + onlyRemoveSessionDataItem, + locale + ) + ); } } @@ -492,8 +500,23 @@ class EmulationModule extends RootBiDiModule { const commands = []; for (const navigable of navigables) { + const overrideValue = this.#getOverrideValue({ + category: "locale-override", + context: navigable, + contextIds, + userContextIds, + value: locale, + }); + + if (overrideValue === null) { + continue; + } + commands.push( - this._setLocaleForBrowsingContext({ locale, context: navigable }) + this._setLocaleForBrowsingContext({ + locale: overrideValue, + context: navigable, + }) ); } @@ -807,31 +830,39 @@ class EmulationModule extends RootBiDiModule { } const sessionDataItems = []; + // In case of resetting the override, remove existing session data items + // for the required context descriptors. + const onlyRemoveSessionDataItem = timezone === ""; + if (userContextIds !== null) { for (const userContext of userContexts) { - sessionDataItems.push({ - category: "timezone-override", - moduleName: "_configuration", - values: [timezone], - contextDescriptor: { - type: lazy.ContextDescriptorType.UserContext, - id: userContext, - }, - method: lazy.SessionDataMethod.Add, - }); + sessionDataItems.push( + ...this.messageHandler.sessionData.generateSessionDataItemUpdate( + "_configuration", + "timezone-override", + { + type: lazy.ContextDescriptorType.UserContext, + id: userContext, + }, + onlyRemoveSessionDataItem, + timezone + ) + ); } } else { for (const navigable of navigables) { - sessionDataItems.push({ - category: "timezone-override", - moduleName: "_configuration", - values: [timezone], - contextDescriptor: { - type: lazy.ContextDescriptorType.TopBrowsingContext, - id: navigable.browserId, - }, - method: lazy.SessionDataMethod.Add, - }); + sessionDataItems.push( + ...this.messageHandler.sessionData.generateSessionDataItemUpdate( + "_configuration", + "timezone-override", + { + type: lazy.ContextDescriptorType.TopBrowsingContext, + id: navigable.browserId, + }, + onlyRemoveSessionDataItem, + timezone + ) + ); } } @@ -845,8 +876,23 @@ class EmulationModule extends RootBiDiModule { const commands = []; for (const navigable of navigables) { + const overrideValue = this.#getOverrideValue({ + category: "timezone-override", + context: navigable, + contextIds, + userContextIds, + value: timezone, + }); + + if (overrideValue === null) { + continue; + } + commands.push( - this._setTimezoneOverride({ context: navigable, timezone }) + this._setTimezoneOverride({ + context: navigable, + timezone: overrideValue, + }) ); } @@ -1017,35 +1063,22 @@ class EmulationModule extends RootBiDiModule { } for (const navigable of navigables) { - const [overridePerContext, overridePerUserContext, overrideGlobal] = - this.#findExistingOverrideForContext("user-agent-override", navigable); - - if (contextIds) { - if (userAgent === "") { - // In case of resetting an override for navigable, - // if there is an existing override for user context or global, - // we should apply it to browsing context. - userAgent = overridePerUserContext || overrideGlobal || ""; - } - } else if (userContextIds) { - // No need to do anything if there is an override - // for the browsing context. - if (overridePerContext) { - continue; - } + const overrideValue = this.#getOverrideValue({ + category: "user-agent-override", + context: navigable, + contextIds, + userContextIds, + value: userAgent, + }); - // In case of resetting an override for user context, - // apply a global override if it exists - if (userAgent === "" && overrideGlobal) { - userAgent = overrideGlobal; - } - } else if (overridePerContext || overridePerUserContext) { - // No need to do anything if there is an override - // for the browsing or user context. + if (overrideValue === null) { continue; } - this._setUserAgentOverride({ context: navigable, userAgent }); + this._setUserAgentOverride({ + context: navigable, + userAgent: overrideValue, + }); } } @@ -1162,6 +1195,39 @@ class EmulationModule extends RootBiDiModule { } } + #getOverrideValue(params) { + const { category, context, contextIds, userContextIds, value } = params; + const [overridePerContext, overridePerUserContext, overrideGlobal] = + this.#findExistingOverrideForContext(category, context); + + if (contextIds) { + if (value === "") { + // In case of resetting an override for navigable, + // if there is an existing override for user context or global, + // we should apply it to browsing context. + return overridePerUserContext || overrideGlobal || ""; + } + } else if (userContextIds) { + // No need to do anything if there is an override + // for the browsing context. + if (overridePerContext) { + return null; + } + + // In case of resetting an override for user context, + // apply a global override if it exists + if (value === "" && overrideGlobal) { + return overrideGlobal; + } + } else if (overridePerContext || overridePerUserContext) { + // No need to do anything if there is an override + // for the browsing or user context. + return null; + } + + return value; + } + /** * Find the existing overrides for a given category and context. * diff --git a/remote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs @@ -214,6 +214,12 @@ class _ConfigurationModule extends WindowGlobalBiDiModule { } } + let localeOverridePerContext = null; + let localeOverridePerUserContext = null; + + let timezoneOverridePerContext = null; + let timezoneOverridePerUserContext = null; + let userAgentOverrideGlobal = null; let userAgentOverridePerUserContext = null; let userAgentOverridePerContext = null; @@ -252,7 +258,16 @@ class _ConfigurationModule extends WindowGlobalBiDiModule { break; } case "locale-override": { - this.#localeOverride = value; + switch (contextDescriptor.type) { + case lazy.ContextDescriptorType.TopBrowsingContext: { + localeOverridePerContext = value; + break; + } + case lazy.ContextDescriptorType.UserContext: { + localeOverridePerUserContext = value; + break; + } + } break; } case "screen-orientation-override": { @@ -260,7 +275,16 @@ class _ConfigurationModule extends WindowGlobalBiDiModule { break; } case "timezone-override": { - this.#timezoneOverride = value; + switch (contextDescriptor.type) { + case lazy.ContextDescriptorType.TopBrowsingContext: { + timezoneOverridePerContext = value; + break; + } + case lazy.ContextDescriptorType.UserContext: { + timezoneOverridePerUserContext = value; + break; + } + } break; } case "user-agent-override": { @@ -283,6 +307,16 @@ class _ConfigurationModule extends WindowGlobalBiDiModule { } } + this.#localeOverride = this.#findCorrectOverrideValue( + localeOverridePerContext, + localeOverridePerUserContext + ); + + this.#timezoneOverride = this.#findCorrectOverrideValue( + timezoneOverridePerContext, + timezoneOverridePerUserContext + ); + this.#userAgentOverride = this.#findCorrectOverrideValue( userAgentOverridePerContext, userAgentOverridePerUserContext,