forked from mirrors/gecko-dev
Bug 1874920 - [bidi] Avoid using internal user context id in bidi modules r=webdriver-reviewers,whimboo
Depends on D200182 Differential Revision: https://phabricator.services.mozilla.com/D200610
This commit is contained in:
parent
4620282750
commit
191a9767e8
6 changed files with 47 additions and 47 deletions
|
|
@ -13,6 +13,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||||
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
||||||
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
|
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
|
||||||
TabSession: "chrome://remote/content/cdp/sessions/TabSession.sys.mjs",
|
TabSession: "chrome://remote/content/cdp/sessions/TabSession.sys.mjs",
|
||||||
|
UserContextManager:
|
||||||
|
"chrome://remote/content/shared/UserContextManager.sys.mjs",
|
||||||
windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
|
windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -131,7 +133,9 @@ export class Target extends Domain {
|
||||||
const onTarget = targetList.once("target-created");
|
const onTarget = targetList.once("target-created");
|
||||||
const tab = await lazy.TabManager.addTab({
|
const tab = await lazy.TabManager.addTab({
|
||||||
focus: true,
|
focus: true,
|
||||||
userContextId: browserContextId,
|
userContextId:
|
||||||
|
// Bug 1878649: Use UserContextManager ids consistently in CDP.
|
||||||
|
lazy.UserContextManager.getIdByInternalId(browserContextId),
|
||||||
window,
|
window,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||||
EventPromise: "chrome://remote/content/shared/Sync.sys.mjs",
|
EventPromise: "chrome://remote/content/shared/Sync.sys.mjs",
|
||||||
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
||||||
MobileTabBrowser: "chrome://remote/content/shared/MobileTabBrowser.sys.mjs",
|
MobileTabBrowser: "chrome://remote/content/shared/MobileTabBrowser.sys.mjs",
|
||||||
|
UserContextManager:
|
||||||
|
"chrome://remote/content/shared/UserContextManager.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
class TabManagerClass {
|
class TabManagerClass {
|
||||||
|
|
@ -143,8 +145,8 @@ class TabManagerClass {
|
||||||
* The reference tab after which the new tab will be added. If no
|
* The reference tab after which the new tab will be added. If no
|
||||||
* reference tab is provided, the new tab will be added after all the
|
* reference tab is provided, the new tab will be added after all the
|
||||||
* other tabs.
|
* other tabs.
|
||||||
* @param {number} options.userContextId
|
* @param {string=} options.userContextId
|
||||||
* The user context (container) id.
|
* A user context id from UserContextManager.
|
||||||
* @param {window=} options.window
|
* @param {window=} options.window
|
||||||
* The window where the new tab will open. Defaults to Services.wm.getMostRecentWindow
|
* The window where the new tab will open. Defaults to Services.wm.getMostRecentWindow
|
||||||
* if no window is provided. Will be ignored if referenceTab is provided.
|
* if no window is provided. Will be ignored if referenceTab is provided.
|
||||||
|
|
@ -153,7 +155,7 @@ class TabManagerClass {
|
||||||
let {
|
let {
|
||||||
focus = false,
|
focus = false,
|
||||||
referenceTab = null,
|
referenceTab = null,
|
||||||
userContextId,
|
userContextId = null,
|
||||||
window = Services.wm.getMostRecentWindow(null),
|
window = Services.wm.getMostRecentWindow(null),
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
|
@ -169,10 +171,11 @@ class TabManagerClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabBrowser = this.getTabBrowser(window);
|
const tabBrowser = this.getTabBrowser(window);
|
||||||
|
|
||||||
const tab = await tabBrowser.addTab("about:blank", {
|
const tab = await tabBrowser.addTab("about:blank", {
|
||||||
index,
|
index,
|
||||||
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
||||||
userContextId,
|
userContextId: lazy.UserContextManager.getInternalIdById(userContextId),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (focus) {
|
if (focus) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||||
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const DEFAULT_CONTEXT_ID = "default";
|
||||||
|
const DEFAULT_INTERNAL_ID = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A UserContextManager instance keeps track of all public user contexts and
|
* A UserContextManager instance keeps track of all public user contexts and
|
||||||
* maps their internal platform.
|
* maps their internal platform.
|
||||||
|
|
@ -24,9 +27,6 @@ export class UserContextManagerClass {
|
||||||
#contextualIdentityListener;
|
#contextualIdentityListener;
|
||||||
#userContextIds;
|
#userContextIds;
|
||||||
|
|
||||||
DEFAULT_CONTEXT_ID = "default";
|
|
||||||
DEFAULT_INTERNAL_ID = 0;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Map from internal ids (numbers) from the ContextualIdentityService to
|
// Map from internal ids (numbers) from the ContextualIdentityService to
|
||||||
// opaque UUIDs (string).
|
// opaque UUIDs (string).
|
||||||
|
|
@ -34,7 +34,7 @@ export class UserContextManagerClass {
|
||||||
|
|
||||||
// The default user context is always using 0 as internal user context id
|
// The default user context is always using 0 as internal user context id
|
||||||
// and should be exposed as "default" instead of a randomly generated id.
|
// and should be exposed as "default" instead of a randomly generated id.
|
||||||
this.#userContextIds.set(this.DEFAULT_INTERNAL_ID, this.DEFAULT_CONTEXT_ID);
|
this.#userContextIds.set(DEFAULT_INTERNAL_ID, DEFAULT_CONTEXT_ID);
|
||||||
|
|
||||||
// Register other (non-default) public contexts.
|
// Register other (non-default) public contexts.
|
||||||
lazy.ContextualIdentityService.getPublicIdentities().forEach(identity =>
|
lazy.ContextualIdentityService.getPublicIdentities().forEach(identity =>
|
||||||
|
|
@ -55,6 +55,16 @@ export class UserContextManagerClass {
|
||||||
this.#userContextIds = null;
|
this.#userContextIds = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the user context id corresponding to the default user context.
|
||||||
|
*
|
||||||
|
* @returns {string}
|
||||||
|
* The default user context id.
|
||||||
|
*/
|
||||||
|
get defaultUserContextId() {
|
||||||
|
return DEFAULT_CONTEXT_ID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new user context.
|
* Creates a new user context.
|
||||||
*
|
*
|
||||||
|
|
@ -93,8 +103,14 @@ export class UserContextManagerClass {
|
||||||
* If `browsingContext` is not a CanonicalBrowsingContext instance.
|
* If `browsingContext` is not a CanonicalBrowsingContext instance.
|
||||||
*/
|
*/
|
||||||
getIdByBrowsingContext(browsingContext) {
|
getIdByBrowsingContext(browsingContext) {
|
||||||
|
if (!CanonicalBrowsingContext.isInstance(browsingContext)) {
|
||||||
|
throw new TypeError(
|
||||||
|
`Expected browsingContext to be a CanonicalBrowsingContext, got ${browsingContext}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return this.getIdByInternalId(
|
return this.getIdByInternalId(
|
||||||
this.getInternalIdByBrowsingContext(browsingContext)
|
browsingContext.originAttributes.userContextId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,29 +131,6 @@ export class UserContextManagerClass {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the internal user context id corresponding to the provided
|
|
||||||
* browsing context.
|
|
||||||
*
|
|
||||||
* @param {BrowsingContext} browsingContext
|
|
||||||
* The browsing context to get the internal user context id from.
|
|
||||||
*
|
|
||||||
* @returns {string}
|
|
||||||
* The corresponding internal user context id.
|
|
||||||
*
|
|
||||||
* @throws {TypeError}
|
|
||||||
* If `browsingContext` is not a CanonicalBrowsingContext instance.
|
|
||||||
*/
|
|
||||||
getInternalIdByBrowsingContext(browsingContext) {
|
|
||||||
if (!CanonicalBrowsingContext.isInstance(browsingContext)) {
|
|
||||||
throw new TypeError(
|
|
||||||
`Expected browsingContext to be a CanonicalBrowsingContext, got ${browsingContext}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return browsingContext.originAttributes.userContextId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the internal id corresponding to the provided user
|
* Retrieve the internal id corresponding to the provided user
|
||||||
* context id.
|
* context id.
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||||
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
generateUUID: "chrome://remote/content/shared/UUID.sys.mjs",
|
||||||
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
|
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
|
||||||
TimedPromise: "chrome://remote/content/marionette/sync.sys.mjs",
|
TimedPromise: "chrome://remote/content/marionette/sync.sys.mjs",
|
||||||
|
UserContextManager:
|
||||||
|
"chrome://remote/content/shared/UserContextManager.sys.mjs",
|
||||||
waitForObserverTopic: "chrome://remote/content/marionette/sync.sys.mjs",
|
waitForObserverTopic: "chrome://remote/content/marionette/sync.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -218,7 +220,8 @@ class WindowManager {
|
||||||
{
|
{
|
||||||
private: isPrivate,
|
private: isPrivate,
|
||||||
resolveOnContentBrowserCreated,
|
resolveOnContentBrowserCreated,
|
||||||
userContextId: userContextId !== null ? userContextId : undefined,
|
userContextId:
|
||||||
|
lazy.UserContextManager.getInternalIdById(userContextId),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class BrowserModule extends Module {
|
||||||
`Expected "userContext" to be a string, got ${userContextId}`
|
`Expected "userContext" to be a string, got ${userContextId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userContextId === lazy.UserContextManager.DEFAULT_CONTEXT_ID) {
|
if (userContextId === lazy.UserContextManager.defaultUserContextId) {
|
||||||
throw new lazy.error.InvalidArgumentError(
|
throw new lazy.error.InvalidArgumentError(
|
||||||
`Default user context cannot be removed`
|
`Default user context cannot be removed`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -488,12 +488,10 @@ class BrowsingContextModule extends Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let internalUserContextId = lazy.UserContextManager.DEFAULT_INTERNAL_ID;
|
let userContext = lazy.UserContextManager.defaultUserContextId;
|
||||||
if (referenceContext !== null) {
|
if (referenceContext !== null) {
|
||||||
internalUserContextId =
|
userContext =
|
||||||
lazy.UserContextManager.getInternalIdByBrowsingContext(
|
lazy.UserContextManager.getIdByBrowsingContext(referenceContext);
|
||||||
referenceContext
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userContextId !== null) {
|
if (userContextId !== null) {
|
||||||
|
|
@ -502,18 +500,17 @@ class BrowsingContextModule extends Module {
|
||||||
lazy.pprint`Expected "userContext" to be a string, got ${userContextId}`
|
lazy.pprint`Expected "userContext" to be a string, got ${userContextId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
internalUserContextId =
|
if (!lazy.UserContextManager.hasUserContextId(userContextId)) {
|
||||||
lazy.UserContextManager.getInternalIdById(userContextId);
|
|
||||||
|
|
||||||
if (internalUserContextId === null) {
|
|
||||||
throw new lazy.error.NoSuchUserContextError(
|
throw new lazy.error.NoSuchUserContextError(
|
||||||
`User Context with id ${userContextId} was not found`
|
`User Context with id ${userContextId} was not found`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userContext = userContextId;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
lazy.AppInfo.isAndroid &&
|
lazy.AppInfo.isAndroid &&
|
||||||
userContextId != lazy.UserContextManager.DEFAULT_CONTEXT_ID
|
userContext != lazy.UserContextManager.defaultUserContextId
|
||||||
) {
|
) {
|
||||||
throw new lazy.error.UnsupportedOperationError(
|
throw new lazy.error.UnsupportedOperationError(
|
||||||
`browsingContext.create with non-default "userContext" not supported for ${lazy.AppInfo.name}`
|
`browsingContext.create with non-default "userContext" not supported for ${lazy.AppInfo.name}`
|
||||||
|
|
@ -538,7 +535,7 @@ class BrowsingContextModule extends Module {
|
||||||
case "window":
|
case "window":
|
||||||
const newWindow = await lazy.windowManager.openBrowserWindow({
|
const newWindow = await lazy.windowManager.openBrowserWindow({
|
||||||
focus: !background,
|
focus: !background,
|
||||||
userContextId: internalUserContextId,
|
userContextId: userContext,
|
||||||
});
|
});
|
||||||
browser = lazy.TabManager.getTabBrowser(newWindow).selectedBrowser;
|
browser = lazy.TabManager.getTabBrowser(newWindow).selectedBrowser;
|
||||||
break;
|
break;
|
||||||
|
|
@ -559,7 +556,7 @@ class BrowsingContextModule extends Module {
|
||||||
const tab = await lazy.TabManager.addTab({
|
const tab = await lazy.TabManager.addTab({
|
||||||
focus: !background,
|
focus: !background,
|
||||||
referenceTab,
|
referenceTab,
|
||||||
userContextId: internalUserContextId,
|
userContextId: userContext,
|
||||||
});
|
});
|
||||||
browser = lazy.TabManager.getBrowserForTab(tab);
|
browser = lazy.TabManager.getBrowserForTab(tab);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue