зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1622500 - Implement cookieStoreId parameter for tabs.create. r=geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D71817
This commit is contained in:
Родитель
08cecbdc20
Коммит
7c5d0ed09c
|
@ -309,6 +309,7 @@ this.tabs = class extends ExtensionAPI {
|
|||
|
||||
async create({
|
||||
active,
|
||||
cookieStoreId,
|
||||
discarded,
|
||||
index,
|
||||
openInReaderMode,
|
||||
|
@ -334,6 +335,7 @@ this.tabs = class extends ExtensionAPI {
|
|||
extensionId: context.extension.id,
|
||||
createProperties: {
|
||||
active,
|
||||
cookieStoreId,
|
||||
discarded,
|
||||
index,
|
||||
openInReaderMode,
|
||||
|
|
|
@ -317,7 +317,8 @@ class Tab extends TabBase {
|
|||
}
|
||||
|
||||
get cookieStoreId() {
|
||||
return getCookieStoreIdForTab(this, this.nativeTab);
|
||||
// Expose the same session context ID that the GeckoView app is sending to us.
|
||||
return this.window.moduleManager.settings.unsafeSessionContextId;
|
||||
}
|
||||
|
||||
get height() {
|
||||
|
|
|
@ -17,7 +17,7 @@ add_task(async function() {
|
|||
useAddonManager: "permanent",
|
||||
manifest: {
|
||||
"applications": { "gecko": { "id": "tabs-create@tests.mozilla.org" } },
|
||||
"permissions": ["tabs"],
|
||||
"permissions": ["tabs", "cookies"],
|
||||
|
||||
"background": {"page": "bg/background.html"},
|
||||
},
|
||||
|
@ -59,6 +59,22 @@ add_task(async function() {
|
|||
create: {active: true},
|
||||
result: {active: true},
|
||||
},
|
||||
{
|
||||
create: {cookieStoreId: null},
|
||||
result: {cookieStoreId: null},
|
||||
},
|
||||
{
|
||||
create: {cookieStoreId: "firefox-container-1"},
|
||||
result: {cookieStoreId: "firefox-container-1"},
|
||||
},
|
||||
{
|
||||
create: {cookieStoreId: "😅"},
|
||||
result: {cookieStoreId: "😅"},
|
||||
},
|
||||
{
|
||||
create: {cookieStoreId: "漢字"},
|
||||
result: {cookieStoreId: "漢字"},
|
||||
},
|
||||
];
|
||||
|
||||
async function nextTest() {
|
||||
|
|
|
@ -1476,6 +1476,7 @@ package org.mozilla.geckoview {
|
|||
public static class WebExtension.CreateTabDetails {
|
||||
ctor protected CreateTabDetails();
|
||||
field @Nullable public final Boolean active;
|
||||
field @Nullable public final String cookieStoreId;
|
||||
field @Nullable public final Boolean discarded;
|
||||
field @Nullable public final Integer index;
|
||||
field @Nullable public final Boolean openInReaderMode;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
browser.tabs.create({
|
||||
url: "https://www.mozilla.org/en-US/",
|
||||
cookieStoreId: "1",
|
||||
});
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "messaging",
|
||||
"version": "1.0",
|
||||
"description": "Creates a tab with a contextual identity.",
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "tabs-create-2@tests.mozilla.org"
|
||||
}
|
||||
},
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"cookies"
|
||||
]
|
||||
}
|
|
@ -323,7 +323,14 @@ public class TestRunnerActivity extends Activity {
|
|||
@Override
|
||||
public GeckoResult<GeckoSession> onNewTab(WebExtension source,
|
||||
WebExtension.CreateTabDetails details) {
|
||||
GeckoSession newSession = createSession();
|
||||
GeckoSessionSettings settings = null;
|
||||
if (details.cookieStoreId != null) {
|
||||
settings = new GeckoSessionSettings.Builder()
|
||||
.contextId(details.cookieStoreId)
|
||||
.build();
|
||||
}
|
||||
|
||||
GeckoSession newSession = createSession(settings);
|
||||
if (details.active == Boolean.TRUE) {
|
||||
webExtensionController().setTabActive(mActiveSession, false);
|
||||
mActiveSession = newSession;
|
||||
|
|
|
@ -32,6 +32,8 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
companion object {
|
||||
private const val TABS_CREATE_BACKGROUND: String =
|
||||
"resource://android/assets/web_extensions/tabs-create/"
|
||||
private const val TABS_CREATE_2_BACKGROUND: String =
|
||||
"resource://android/assets/web_extensions/tabs-create-2/"
|
||||
private const val TABS_CREATE_REMOVE_BACKGROUND: String =
|
||||
"resource://android/assets/web_extensions/tabs-create-remove/"
|
||||
private const val TABS_ACTIVATE_REMOVE_BACKGROUND: String =
|
||||
|
@ -534,6 +536,34 @@ class WebExtensionTest : BaseSessionTest() {
|
|||
sessionRule.waitForResult(controller.uninstall(tabsExtension))
|
||||
}
|
||||
|
||||
// This test
|
||||
// - Listen for a new tab request from a web extension
|
||||
// - Registers a web extension
|
||||
// - Extension requests creation of new tab with a cookie store id.
|
||||
// - Waits for onNewTab request
|
||||
// - Verify that request came from right extension
|
||||
@Test
|
||||
fun testBrowserTabsCreateWithCookieStoreId() {
|
||||
val tabsCreateResult = GeckoResult<Void>()
|
||||
var tabsExtension: WebExtension? = null
|
||||
val tabDelegate = object : WebExtension.TabDelegate {
|
||||
override fun onNewTab(source: WebExtension, details: WebExtension.CreateTabDetails): GeckoResult<GeckoSession> {
|
||||
assertEquals(details.url, "https://www.mozilla.org/en-US/")
|
||||
assertEquals(details.active, true)
|
||||
assertEquals(details.cookieStoreId, "1")
|
||||
assertEquals(tabsExtension!!, source)
|
||||
tabsCreateResult.complete(null)
|
||||
return GeckoResult.fromValue(null)
|
||||
}
|
||||
}
|
||||
|
||||
tabsExtension = sessionRule.waitForResult(controller.installBuiltIn(TABS_CREATE_2_BACKGROUND))
|
||||
tabsExtension.setTabDelegate(tabDelegate)
|
||||
sessionRule.waitForResult(tabsCreateResult)
|
||||
|
||||
sessionRule.waitForResult(controller.uninstall(tabsExtension))
|
||||
}
|
||||
|
||||
// This test
|
||||
// - Create and assign WebExtension TabDelegate to handle creation and closing of tabs
|
||||
// - Registers a WebExtension
|
||||
|
|
|
@ -545,6 +545,12 @@ public class WebExtension {
|
|||
*/
|
||||
@Nullable
|
||||
public final Boolean active;
|
||||
/**
|
||||
* The CookieStoreId used for the tab. This option is only
|
||||
* available if the extension has the "cookies" permission.
|
||||
*/
|
||||
@Nullable
|
||||
public final String cookieStoreId;
|
||||
/**
|
||||
* Whether the tab is created and made visible in the tab bar
|
||||
* without any content loaded into memory, a state known as
|
||||
|
@ -581,6 +587,7 @@ public class WebExtension {
|
|||
/** For testing. */
|
||||
protected CreateTabDetails() {
|
||||
active = null;
|
||||
cookieStoreId = null;
|
||||
discarded = null;
|
||||
index = null;
|
||||
openInReaderMode = null;
|
||||
|
@ -590,6 +597,7 @@ public class WebExtension {
|
|||
|
||||
/* package */ CreateTabDetails(final GeckoBundle bundle) {
|
||||
active = bundle.getBooleanObject("active");
|
||||
cookieStoreId = bundle.getString("cookieStoreId");
|
||||
discarded = bundle.getBooleanObject("discarded");
|
||||
index = bundle.getInteger("index");
|
||||
openInReaderMode = bundle.getBooleanObject("openInReaderMode");
|
||||
|
|
|
@ -22,9 +22,14 @@ exclude: true
|
|||
enabling dynamic first party isolation; this will block tracking cookies and
|
||||
isolate all other third party cookies by keying them based on the first party
|
||||
from which they are accessed.
|
||||
- Added `cookieStoreId` field to [`WebExtension.CreateTabDetails`][78.3]. This adds the optional
|
||||
ability to create a tab with a given cookie store ID for its [`contextual identity`][78.4].
|
||||
([bug 1622500]({{bugzilla}}1622500))
|
||||
|
||||
[78.1]: {{javadoc_uri}}/WebExtensionController.html#installBuiltIn-java.lang.String-
|
||||
[78.2]: {{javadoc_uri}}/ContentBlocking.CookieBehavior.html#ACCEPT_FIRST_PARTY_AND_ISOLATE_OTHERS
|
||||
[78.3]: {{javadoc_uri}}/WebExtension.CreateTabDetails.html
|
||||
[78.4]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/contextualIdentities
|
||||
|
||||
## v77
|
||||
- Added [`GeckoRuntime.appendAppNotesToCrashReport`][77.1] For adding app notes to the crash report.
|
||||
|
@ -688,4 +693,4 @@ exclude: true
|
|||
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
|
||||
[65.25]: {{javadoc_uri}}/GeckoResult.html
|
||||
|
||||
[api-version]: 901bd3fab4e89390ffe1d0487f7156b687aec71a
|
||||
[api-version]: 5460cbfe03322d19964ce94082ac2ae99af6d791
|
||||
|
|
|
@ -427,7 +427,7 @@ public class GeckoViewActivity
|
|||
|
||||
@Override
|
||||
public TabSession openNewTab(WebExtension.CreateTabDetails details) {
|
||||
final TabSession newSession = createSession();
|
||||
final TabSession newSession = createSession(details.cookieStoreId);
|
||||
mToolbarView.updateTabCount();
|
||||
if (details.active == Boolean.TRUE) {
|
||||
setGeckoViewSession(newSession, false);
|
||||
|
@ -812,8 +812,9 @@ public class GeckoViewActivity
|
|||
}
|
||||
}
|
||||
|
||||
private TabSession createSession() {
|
||||
TabSession session = mTabSessionManager.newSession(new GeckoSessionSettings.Builder()
|
||||
private TabSession createSession(final @Nullable String cookieStoreId) {
|
||||
GeckoSessionSettings.Builder settingsBuilder = new GeckoSessionSettings.Builder();
|
||||
settingsBuilder
|
||||
.usePrivateMode(mUsePrivateBrowsing)
|
||||
.fullAccessibilityTree(mFullAccessibilityTree)
|
||||
.userAgentOverride(mUserAgentOverride)
|
||||
|
@ -823,13 +824,22 @@ public class GeckoViewActivity
|
|||
.userAgentMode(mDesktopMode
|
||||
? GeckoSessionSettings.USER_AGENT_MODE_DESKTOP
|
||||
: GeckoSessionSettings.USER_AGENT_MODE_MOBILE)
|
||||
.useTrackingProtection(mUseTrackingProtection)
|
||||
.build());
|
||||
.useTrackingProtection(mUseTrackingProtection);
|
||||
|
||||
if (cookieStoreId != null) {
|
||||
settingsBuilder.contextId(cookieStoreId);
|
||||
}
|
||||
|
||||
TabSession session = mTabSessionManager.newSession(settingsBuilder.build());
|
||||
connectSession(session);
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
private TabSession createSession() {
|
||||
return createSession(null);
|
||||
}
|
||||
|
||||
private void connectSession(GeckoSession session) {
|
||||
session.setContentDelegate(new ExampleContentDelegate());
|
||||
session.setHistoryDelegate(new ExampleHistoryDelegate());
|
||||
|
|
|
@ -70,6 +70,7 @@ class GeckoViewSettings extends GeckoViewModule {
|
|||
debug`onSettingsUpdate: ${settings}`;
|
||||
|
||||
this.displayMode = settings.displayMode;
|
||||
this.unsafeSessionContextId = settings.unsafeSessionContextId;
|
||||
this.userAgentMode = settings.userAgentMode;
|
||||
this.userAgentOverride = settings.userAgentOverride;
|
||||
this.sessionContextId = settings.sessionContextId;
|
||||
|
|
Загрузка…
Ссылка в новой задаче