Skip to content

Commit

Permalink
Bug 1501108 - [1.3] Add GeckoView Session Context ID support. r=snorp…
Browse files Browse the repository at this point in the history
…,baku,mayhemer

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Eugen Sawin committed Apr 16, 2019
1 parent bfcbc83 commit 2fd75d1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 2 deletions.
15 changes: 15 additions & 0 deletions caps/OriginAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
sanitizedFirstPartyDomain);
}

if (!mGeckoViewSessionContextId.IsEmpty()) {
nsAutoString sanitizedGeckoViewUserContextId(mGeckoViewSessionContextId);
sanitizedGeckoViewUserContextId.ReplaceChar(
dom::quota::QuotaManager::kReplaceChars, '+');

params.Set(NS_LITERAL_STRING("geckoViewUserContextId"),
sanitizedGeckoViewUserContextId);
}

aStr.Truncate();

params.Serialize(value);
Expand Down Expand Up @@ -258,6 +267,12 @@ class MOZ_STACK_CLASS PopulateFromSuffixIterator final
return true;
}

if (aName.EqualsLiteral("geckoViewUserContextId")) {
MOZ_RELEASE_ASSERT(mOriginAttributes->mGeckoViewSessionContextId.IsEmpty());
mOriginAttributes->mGeckoViewSessionContextId.Assign(aValue);
return true;
}

// No other attributes are supported.
return false;
}
Expand Down
16 changes: 14 additions & 2 deletions caps/OriginAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class OriginAttributes : public dom::OriginAttributesDictionary {
mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser &&
mUserContextId == aOther.mUserContextId &&
mPrivateBrowsingId == aOther.mPrivateBrowsingId &&
mFirstPartyDomain == aOther.mFirstPartyDomain;
mFirstPartyDomain == aOther.mFirstPartyDomain &&
mGeckoViewSessionContextId == aOther.mGeckoViewSessionContextId;
}

bool operator!=(const OriginAttributes& aOther) const {
Expand All @@ -61,7 +62,8 @@ class OriginAttributes : public dom::OriginAttributesDictionary {
return mAppId == aOther.mAppId &&
mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser &&
mUserContextId == aOther.mUserContextId &&
mPrivateBrowsingId == aOther.mPrivateBrowsingId;
mPrivateBrowsingId == aOther.mPrivateBrowsingId &&
mGeckoViewSessionContextId == aOther.mGeckoViewSessionContextId;
}

// Serializes/Deserializes non-default values into the suffix format, i.e.
Expand Down Expand Up @@ -153,6 +155,11 @@ class OriginAttributesPattern : public dom::OriginAttributesPatternDictionary {
return false;
}

if (mGeckoViewSessionContextId.WasPassed() &&
mGeckoViewSessionContextId.Value() != aAttrs.mGeckoViewSessionContextId) {
return false;
}

return true;
}

Expand Down Expand Up @@ -184,6 +191,11 @@ class OriginAttributesPattern : public dom::OriginAttributesPatternDictionary {
return false;
}

if (mGeckoViewSessionContextId.WasPassed() && aOther.mGeckoViewSessionContextId.WasPassed() &&
mGeckoViewSessionContextId.Value() != aOther.mGeckoViewSessionContextId.Value()) {
return false;
}

return true;
}
};
Expand Down
2 changes: 2 additions & 0 deletions dom/chrome-webidl/ChromeUtils.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,15 @@ dictionary OriginAttributesDictionary {
boolean inIsolatedMozBrowser = false;
unsigned long privateBrowsingId = 0;
DOMString firstPartyDomain = "";
DOMString geckoViewSessionContextId = "";
};
dictionary OriginAttributesPatternDictionary {
unsigned long appId;
unsigned long userContextId;
boolean inIsolatedMozBrowser;
unsigned long privateBrowsingId;
DOMString firstPartyDomain;
DOMString geckoViewSessionContextId;
};

dictionary CompileScriptOptionsDictionary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public Builder(final GeckoSessionSettings settings) {
return this;
}

/**
* Set the session context ID for this instance.
* Setting a context ID partitions the cookie jars based on the provided
* IDs. This isolates the browser storage like cookies and localStorage
* between sessions, only sessions that share the same ID share storage
* data.
*
* @param value The custom context ID.
* The default ID is null, which removes isolation for this
* instance.
*/
public @NonNull Builder contextId(final @Nullable String value) {
mSettings.setContextId(value);
return this;
}

/**
* Set whether multi-process support should be enabled.
*
Expand Down Expand Up @@ -213,6 +229,7 @@ public Builder(final GeckoSessionSettings settings) {
* width of 980 CSS px.
*/
public static final int VIEWPORT_MODE_MOBILE = 0;

/**
* All pages will be rendered using the special desktop mode viewport, which has a width of
* 980 CSS px, regardless of whether the page has a <meta> viewport tag specified or not.
Expand Down Expand Up @@ -314,6 +331,12 @@ public static class Key<T> {
private static final Key<Boolean> FULL_ACCESSIBILITY_TREE =
new Key<Boolean>("fullAccessibilityTree", /* initOnly */ false, /* values */ null);

/**
* Key to specify the session context ID.
*/
private static final Key<String> CONTEXT_ID =
new Key<String>("sessionContextId", /* initOnly */ true, /* values */ null);

private final GeckoSession mSession;
private final GeckoBundle mBundle;

Expand Down Expand Up @@ -347,6 +370,7 @@ public GeckoSessionSettings(final @NonNull GeckoSessionSettings settings) {
mBundle.putString(USER_AGENT_OVERRIDE.name, null);
mBundle.putInt(VIEWPORT_MODE.name, VIEWPORT_MODE_MOBILE);
mBundle.putInt(DISPLAY_MODE.name, DISPLAY_MODE_BROWSER);
mBundle.putString(CONTEXT_ID.name, null);
}

/**
Expand Down Expand Up @@ -439,6 +463,15 @@ public boolean getUsePrivateMode() {
return getBoolean(USE_PRIVATE_MODE);
}

/**
* The context ID for this session.
*
* @return The context ID for this session.
*/
public @Nullable String getContextId() {
return getString(CONTEXT_ID);
}

/**
* Whether multiprocess is enabled.
*
Expand Down Expand Up @@ -597,6 +630,10 @@ public void setUserAgentOverride(final @Nullable String value) {
setString(USER_AGENT_OVERRIDE, value);
}

private void setContextId(final @Nullable String value) {
setString(CONTEXT_ID, value);
}

private void setString(final Key<String> key, final String value) {
synchronized (mBundle) {
if (valueChangedLocked(key, value)) {
Expand Down
13 changes: 13 additions & 0 deletions mobile/android/modules/geckoview/GeckoViewNavigation.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
E10SUtils: "resource://gre/modules/sessionstore/Utils.jsm",
LoadURIDelegate: "resource://gre/modules/LoadURIDelegate.jsm",
Services: "resource://gre/modules/Services.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
});

// Handles navigation requests between Gecko and a GeckoView.
Expand All @@ -32,6 +33,8 @@ class GeckoViewNavigation extends GeckoViewModule {
}

onInit() {
debug `onInit`;

this.registerListener([
"GeckoView:GoBack",
"GeckoView:GoForward",
Expand All @@ -42,6 +45,16 @@ class GeckoViewNavigation extends GeckoViewModule {
]);

this.messageManager.addMessageListener("Browser:LoadURI", this);

debug `sessionContextId=${this.settings.sessionContextId}`;

if (this.settings.sessionContextId !== null) {
this.browser.webNavigation.setOriginAttributesBeforeLoading({
geckoViewSessionContextId: this.settings.sessionContextId,
privateBrowsingId:
PrivateBrowsingUtils.isBrowserPrivate(this.browser) ? 1 : 0,
});
}
}

// Bundle event handler.
Expand Down
10 changes: 10 additions & 0 deletions mobile/android/modules/geckoview/GeckoViewSettings.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class GeckoViewSettings extends GeckoViewModule {
debug `onInit`;
this._userAgentMode = USER_AGENT_MODE_MOBILE;
this._userAgentOverride = null;
this._sessionContextId = null;
// Required for safe browsing and tracking protection.

this.registerListener([
Expand All @@ -67,6 +68,7 @@ class GeckoViewSettings extends GeckoViewModule {
this.displayMode = settings.displayMode;
this.userAgentMode = settings.userAgentMode;
this.userAgentOverride = settings.userAgentOverride;
this.sessionContextId = settings.sessionContextId;
}

get useMultiprocess() {
Expand Down Expand Up @@ -112,6 +114,14 @@ class GeckoViewSettings extends GeckoViewModule {
set displayMode(aMode) {
this.window.docShell.displayMode = aMode;
}

set sessionContextId(aAttribute) {
this._sessionContextId = aAttribute;
}

get sessionContextId() {
return this._sessionContextId;
}
}

const {debug, warn} = GeckoViewSettings.initLogging("GeckoViewSettings"); // eslint-disable-line no-unused-vars
3 changes: 3 additions & 0 deletions netwerk/protocol/http/HttpBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3208,6 +3208,9 @@ already_AddRefed<nsILoadInfo> HttpBaseChannel::CloneLoadInfoForRedirect(
MOZ_ASSERT(
docShellAttrs.mPrivateBrowsingId == attrs.mPrivateBrowsingId,
"docshell and necko should have the same privateBrowsingId attribute.");
MOZ_ASSERT(
docShellAttrs.mGeckoViewSessionContextId == attrs.mGeckoViewSessionContextId,
"docshell and necko should have the same geckoViewSessionContextId attribute");

attrs = docShellAttrs;
attrs.SetFirstPartyDomain(true, newURI);
Expand Down

0 comments on commit 2fd75d1

Please sign in to comment.