mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1616353 - Part 3: Use an attribute to set geckoViewUserContextId on a browser, r=geckoview-reviewers,esawin
This is necessary to avoid the use of setOriginAttributesBeforeLoading, which is being removed in this patch set. Differential Revision: https://phabricator.services.mozilla.com/D67042 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
524bd71dde
commit
e1bf02fc4f
@ -1167,12 +1167,12 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
|
|||||||
// usercontextid attribute before comparing our originAttributes with the
|
// usercontextid attribute before comparing our originAttributes with the
|
||||||
// other one.
|
// other one.
|
||||||
OriginAttributes ourOriginAttributes = browserParent->OriginAttributesRef();
|
OriginAttributes ourOriginAttributes = browserParent->OriginAttributesRef();
|
||||||
rv = PopulateUserContextIdFromAttribute(ourOriginAttributes);
|
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
OriginAttributes otherOriginAttributes =
|
OriginAttributes otherOriginAttributes =
|
||||||
otherBrowserParent->OriginAttributesRef();
|
otherBrowserParent->OriginAttributesRef();
|
||||||
rv = aOther->PopulateUserContextIdFromAttribute(otherOriginAttributes);
|
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (ourOriginAttributes != otherOriginAttributes) {
|
if (ourOriginAttributes != otherOriginAttributes) {
|
||||||
@ -1597,11 +1597,11 @@ nsresult nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
|
|||||||
// usercontextid attribute before comparing our originAttributes with the
|
// usercontextid attribute before comparing our originAttributes with the
|
||||||
// other one.
|
// other one.
|
||||||
OriginAttributes ourOriginAttributes = ourDocshell->GetOriginAttributes();
|
OriginAttributes ourOriginAttributes = ourDocshell->GetOriginAttributes();
|
||||||
rv = PopulateUserContextIdFromAttribute(ourOriginAttributes);
|
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
OriginAttributes otherOriginAttributes = otherDocshell->GetOriginAttributes();
|
OriginAttributes otherOriginAttributes = otherDocshell->GetOriginAttributes();
|
||||||
rv = aOther->PopulateUserContextIdFromAttribute(otherOriginAttributes);
|
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (ourOriginAttributes != otherOriginAttributes) {
|
if (ourOriginAttributes != otherOriginAttributes) {
|
||||||
@ -2186,7 +2186,7 @@ nsresult nsFrameLoader::MaybeCreateDocShell() {
|
|||||||
ApplySandboxFlags(sandboxFlags);
|
ApplySandboxFlags(sandboxFlags);
|
||||||
|
|
||||||
// Grab the userContextId from owner
|
// Grab the userContextId from owner
|
||||||
nsresult rv = PopulateUserContextIdFromAttribute(attrs);
|
nsresult rv = PopulateOriginContextIdsFromAttributes(attrs);
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -3416,7 +3416,7 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
|
|||||||
|
|
||||||
// set the userContextId on the attrs before we pass them into
|
// set the userContextId on the attrs before we pass them into
|
||||||
// the tab context
|
// the tab context
|
||||||
rv = PopulateUserContextIdFromAttribute(attrs);
|
rv = PopulateOriginContextIdsFromAttributes(attrs);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsAutoString presentationURLStr;
|
nsAutoString presentationURLStr;
|
||||||
@ -3457,21 +3457,32 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsFrameLoader::PopulateUserContextIdFromAttribute(
|
nsresult nsFrameLoader::PopulateOriginContextIdsFromAttributes(
|
||||||
OriginAttributes& aAttr) {
|
OriginAttributes& aAttr) {
|
||||||
|
// Only XUL or mozbrowser frames are allowed to set context IDs
|
||||||
|
uint32_t namespaceID = mOwnerContent->GetNameSpaceID();
|
||||||
|
if (namespaceID != kNameSpaceID_XUL && !OwnerIsMozBrowserFrame()) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoString attributeValue;
|
||||||
if (aAttr.mUserContextId ==
|
if (aAttr.mUserContextId ==
|
||||||
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
|
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID &&
|
||||||
// Grab the userContextId from owner if XUL or mozbrowser frame
|
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid,
|
||||||
nsAutoString userContextIdStr;
|
attributeValue) &&
|
||||||
int32_t namespaceID = mOwnerContent->GetNameSpaceID();
|
!attributeValue.IsEmpty()) {
|
||||||
if ((namespaceID == kNameSpaceID_XUL || OwnerIsMozBrowserFrame()) &&
|
nsresult rv;
|
||||||
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid,
|
aAttr.mUserContextId = attributeValue.ToInteger(&rv);
|
||||||
userContextIdStr) &&
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
!userContextIdStr.IsEmpty()) {
|
}
|
||||||
nsresult rv;
|
|
||||||
aAttr.mUserContextId = userContextIdStr.ToInteger(&rv);
|
if (aAttr.mGeckoViewSessionContextId.IsEmpty() &&
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
mOwnerContent->GetAttr(kNameSpaceID_None,
|
||||||
}
|
nsGkAtoms::geckoViewSessionContextId,
|
||||||
|
attributeValue) &&
|
||||||
|
!attributeValue.IsEmpty()) {
|
||||||
|
// XXX: Should we check the format from `GeckoViewNavigation.jsm` here?
|
||||||
|
aAttr.mGeckoViewSessionContextId = attributeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -467,7 +467,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
|
|||||||
enum BrowserParentChange { eBrowserParentRemoved, eBrowserParentChanged };
|
enum BrowserParentChange { eBrowserParentRemoved, eBrowserParentChanged };
|
||||||
void MaybeUpdatePrimaryBrowserParent(BrowserParentChange aChange);
|
void MaybeUpdatePrimaryBrowserParent(BrowserParentChange aChange);
|
||||||
|
|
||||||
nsresult PopulateUserContextIdFromAttribute(mozilla::OriginAttributes& aAttr);
|
nsresult PopulateOriginContextIdsFromAttributes(
|
||||||
|
mozilla::OriginAttributes& aAttr);
|
||||||
|
|
||||||
RefPtr<mozilla::dom::BrowsingContext> mPendingBrowsingContext;
|
RefPtr<mozilla::dom::BrowsingContext> mPendingBrowsingContext;
|
||||||
nsCOMPtr<nsIURI> mURIToLoad;
|
nsCOMPtr<nsIURI> mURIToLoad;
|
||||||
|
@ -17,7 +17,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||||||
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
|
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
|
||||||
LoadURIDelegate: "resource://gre/modules/LoadURIDelegate.jsm",
|
LoadURIDelegate: "resource://gre/modules/LoadURIDelegate.jsm",
|
||||||
Services: "resource://gre/modules/Services.jsm",
|
Services: "resource://gre/modules/Services.jsm",
|
||||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
|
XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
|
||||||
@ -78,6 +77,21 @@ class GeckoViewNavigation extends GeckoViewModule {
|
|||||||
onInitBrowser() {
|
onInitBrowser() {
|
||||||
this.window.browserDOMWindow = this;
|
this.window.browserDOMWindow = this;
|
||||||
|
|
||||||
|
debug`sessionContextId=${this.settings.sessionContextId}`;
|
||||||
|
|
||||||
|
if (this.settings.sessionContextId !== null) {
|
||||||
|
// Gecko may have issues with strings containing special characters,
|
||||||
|
// so we restrict the string format to a specific pattern.
|
||||||
|
if (!/^gvctx(-)?([a-f0-9]+)$/.test(this.settings.sessionContextId)) {
|
||||||
|
throw new Error("sessionContextId has illegal format");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.browser.setAttribute(
|
||||||
|
"geckoViewSessionContextId",
|
||||||
|
this.settings.sessionContextId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// There may be a GeckoViewNavigation module in another window waiting for
|
// There may be a GeckoViewNavigation module in another window waiting for
|
||||||
// us to create a browser so it can call presetOpenerWindow(), so allow them
|
// us to create a browser so it can call presetOpenerWindow(), so allow them
|
||||||
// to do that now.
|
// to do that now.
|
||||||
@ -98,22 +112,6 @@ class GeckoViewNavigation extends GeckoViewModule {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
this._initialAboutBlank = true;
|
this._initialAboutBlank = true;
|
||||||
|
|
||||||
debug`sessionContextId=${this.settings.sessionContextId}`;
|
|
||||||
|
|
||||||
if (this.settings.sessionContextId !== null) {
|
|
||||||
// Gecko may have issues with strings containing special characters,
|
|
||||||
// so we restrict the string format to a specific pattern.
|
|
||||||
if (!/^gvctx(-)?([a-f0-9]+)$/.test(this.settings.sessionContextId)) {
|
|
||||||
throw new Error("sessionContextId has illegal format");
|
|
||||||
}
|
|
||||||
this.browser.webNavigation.setOriginAttributesBeforeLoading({
|
|
||||||
geckoViewSessionContextId: this.settings.sessionContextId,
|
|
||||||
privateBrowsingId: PrivateBrowsingUtils.isBrowserPrivate(this.browser)
|
|
||||||
? 1
|
|
||||||
: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bundle event handler.
|
// Bundle event handler.
|
||||||
|
@ -2383,6 +2383,7 @@ STATIC_ATOMS = [
|
|||||||
|
|
||||||
# Contextual Identity / Containers
|
# Contextual Identity / Containers
|
||||||
Atom("usercontextid", "usercontextid"),
|
Atom("usercontextid", "usercontextid"),
|
||||||
|
Atom("geckoViewSessionContextId", "geckoViewSessionContextId"),
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
Atom("nsuri_xmlns", "http://www.w3.org/2000/xmlns/"),
|
Atom("nsuri_xmlns", "http://www.w3.org/2000/xmlns/"),
|
||||||
|
Loading…
Reference in New Issue
Block a user