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:
Nika Layzell 2020-04-07 21:39:04 +00:00
Родитель dd58bf3df5
Коммит dd1ef62596
4 изменённых файлов: 48 добавлений и 37 удалений

Просмотреть файл

@ -1167,12 +1167,12 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
// usercontextid attribute before comparing our originAttributes with the
// other one.
OriginAttributes ourOriginAttributes = browserParent->OriginAttributesRef();
rv = PopulateUserContextIdFromAttribute(ourOriginAttributes);
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
OriginAttributes otherOriginAttributes =
otherBrowserParent->OriginAttributesRef();
rv = aOther->PopulateUserContextIdFromAttribute(otherOriginAttributes);
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
if (ourOriginAttributes != otherOriginAttributes) {
@ -1597,11 +1597,11 @@ nsresult nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
// usercontextid attribute before comparing our originAttributes with the
// other one.
OriginAttributes ourOriginAttributes = ourDocshell->GetOriginAttributes();
rv = PopulateUserContextIdFromAttribute(ourOriginAttributes);
rv = PopulateOriginContextIdsFromAttributes(ourOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
OriginAttributes otherOriginAttributes = otherDocshell->GetOriginAttributes();
rv = aOther->PopulateUserContextIdFromAttribute(otherOriginAttributes);
rv = aOther->PopulateOriginContextIdsFromAttributes(otherOriginAttributes);
NS_ENSURE_SUCCESS(rv, rv);
if (ourOriginAttributes != otherOriginAttributes) {
@ -2186,7 +2186,7 @@ nsresult nsFrameLoader::MaybeCreateDocShell() {
ApplySandboxFlags(sandboxFlags);
// Grab the userContextId from owner
nsresult rv = PopulateUserContextIdFromAttribute(attrs);
nsresult rv = PopulateOriginContextIdsFromAttributes(attrs);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -3399,7 +3399,7 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
// set the userContextId on the attrs before we pass them into
// the tab context
rv = PopulateUserContextIdFromAttribute(attrs);
rv = PopulateOriginContextIdsFromAttributes(attrs);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString presentationURLStr;
@ -3440,21 +3440,32 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
return NS_OK;
}
nsresult nsFrameLoader::PopulateUserContextIdFromAttribute(
nsresult nsFrameLoader::PopulateOriginContextIdsFromAttributes(
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 ==
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
// Grab the userContextId from owner if XUL or mozbrowser frame
nsAutoString userContextIdStr;
int32_t namespaceID = mOwnerContent->GetNameSpaceID();
if ((namespaceID == kNameSpaceID_XUL || OwnerIsMozBrowserFrame()) &&
nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID &&
mOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usercontextid,
userContextIdStr) &&
!userContextIdStr.IsEmpty()) {
attributeValue) &&
!attributeValue.IsEmpty()) {
nsresult rv;
aAttr.mUserContextId = userContextIdStr.ToInteger(&rv);
aAttr.mUserContextId = attributeValue.ToInteger(&rv);
NS_ENSURE_SUCCESS(rv, rv);
}
if (aAttr.mGeckoViewSessionContextId.IsEmpty() &&
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;

Просмотреть файл

@ -467,7 +467,8 @@ class nsFrameLoader final : public nsStubMutationObserver,
enum BrowserParentChange { eBrowserParentRemoved, eBrowserParentChanged };
void MaybeUpdatePrimaryBrowserParent(BrowserParentChange aChange);
nsresult PopulateUserContextIdFromAttribute(mozilla::OriginAttributes& aAttr);
nsresult PopulateOriginContextIdsFromAttributes(
mozilla::OriginAttributes& aAttr);
RefPtr<mozilla::dom::BrowsingContext> mPendingBrowsingContext;
nsCOMPtr<nsIURI> mURIToLoad;

Просмотреть файл

@ -17,7 +17,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
LoadURIDelegate: "resource://gre/modules/LoadURIDelegate.jsm",
Services: "resource://gre/modules/Services.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
});
XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
@ -78,6 +77,21 @@ class GeckoViewNavigation extends GeckoViewModule {
onInitBrowser() {
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
// us to create a browser so it can call presetOpenerWindow(), so allow them
// to do that now.
@ -98,22 +112,6 @@ class GeckoViewNavigation extends GeckoViewModule {
]);
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.

Просмотреть файл

@ -2389,6 +2389,7 @@ STATIC_ATOMS = [
# Contextual Identity / Containers
Atom("usercontextid", "usercontextid"),
Atom("geckoViewSessionContextId", "geckoViewSessionContextId"),
# Namespaces
Atom("nsuri_xmlns", "http://www.w3.org/2000/xmlns/"),