Skip to content

Commit 2a43654

Browse files
committed
feat(api): add glide.containers
1 parent 772029a commit 2a43654

6 files changed

Lines changed: 155 additions & 0 deletions

File tree

@types/gecko.d.mts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,21 @@ declare var ReadableStream: {
496496
new<R = any>(underlyingSource?: UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
497497
};
498498

499+
declare var ContextualIdentityService: {
500+
create(name: string, icon: string, color: string): ContextualIdentityService.Container;
501+
remove(id: number): boolean;
502+
};
503+
504+
declare namespace ContextualIdentityService {
505+
export type Container = {
506+
userContextId: number;
507+
public: boolean;
508+
icon: string;
509+
color: string;
510+
name: string;
511+
};
512+
}
513+
499514
//////////////////////////////////////////
500515
////////////// typed actors //////////////
501516
//////////////////////////////////////////

src/glide/browser/base/content/browser-api.mts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,24 @@ export function make_glide_api(
466466
},
467467
},
468468

469+
containers: {
470+
create(props): glide.Container {
471+
const container = ContextualIdentityService.create(props.name, props.icon, props.color);
472+
return {
473+
icon: container.icon,
474+
name: container.name,
475+
id: container.userContextId,
476+
color: container.color,
477+
478+
// toolkit/components/extensions/parent/ext-toolkit.js::getCookieStoreIdForContainer
479+
cookie_store_id: `firefox-container-${container.userContextId}`,
480+
};
481+
},
482+
remove(id) {
483+
return ContextualIdentityService.remove(id);
484+
},
485+
},
486+
469487
addons: {
470488
async install(xpi_url, opts): Promise<glide.AddonInstall> {
471489
const cache = GlideBrowser.resolved_addons_cache_file;

src/glide/browser/base/content/glide.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,18 @@ declare global {
948948
}): Promise<void>;
949949
};
950950

951+
containers: {
952+
/**
953+
* Create a new container.
954+
*/
955+
create(props: { name: string; icon: glide.ContainerIcon; color: glide.ContainerColor }): glide.Container;
956+
957+
/**
958+
* Remove a container.
959+
*/
960+
remove(id: number): boolean;
961+
};
962+
951963
messengers: {
952964
/**
953965
* Create a {@link glide.ParentMessenger} that can be used to communicate with the content process.
@@ -1846,6 +1858,44 @@ declare global {
18461858
path: string | undefined;
18471859
size: number | undefined;
18481860
};
1861+
1862+
export type Container = {
1863+
id: number;
1864+
1865+
name: string;
1866+
icon: string;
1867+
color: string;
1868+
1869+
cookie_store_id: string;
1870+
};
1871+
1872+
// browser/components/preferences/dialogs/containers.js::gContainersManager.icons
1873+
export type ContainerIcon =
1874+
| "fingerprint"
1875+
| "briefcase"
1876+
| "dollar"
1877+
| "cart"
1878+
| "vacation"
1879+
| "gift"
1880+
| "food"
1881+
| "fruit"
1882+
| "pet"
1883+
| "tree"
1884+
| "chill"
1885+
| "circle"
1886+
| "fence";
1887+
1888+
// browser/components/preferences/dialogs/containers.js::gContainersManager.colors
1889+
export type ContainerColor =
1890+
| "blue"
1891+
| "turquoise"
1892+
| "green"
1893+
| "yellow"
1894+
| "orange"
1895+
| "red"
1896+
| "pink"
1897+
| "purple"
1898+
| "toolbar";
18491899
}
18501900

18511901
type TabID = number;

src/glide/browser/base/content/test/config/browser.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ https_first_disabled = true
1414
["dist/browser_sandbox.js"]
1515
https_first_disabled = true
1616

17+
["dist/browser_containers.js"]
18+
https_first_disabled = true
19+
1720
["dist/browser_document_mirror.js"]
1821
https_first_disabled = true
1922

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use strict";
6+
7+
add_task(async function test_containers() {
8+
await GlideTestUtils.reload_config(function _() {
9+
glide.keymaps.set("normal", "~", () => {
10+
glide.g.value = glide.containers.create({
11+
name: "my-test",
12+
color: "red",
13+
icon: "tree",
14+
});
15+
});
16+
17+
glide.keymaps.set("normal", "Z", () => {
18+
glide.g.value = glide.containers.remove((glide.g.value as glide.Container).id);
19+
});
20+
});
21+
22+
await keys("~");
23+
24+
const container = glide.g.value as glide.Container;
25+
ok(container);
26+
is(typeof container.id, "number");
27+
is(container.name, "my-test");
28+
is(container.icon, "tree");
29+
is(container.color, "red");
30+
is(container.cookie_store_id, `firefox-container-${container.id}`);
31+
32+
await keys("Z");
33+
34+
is(glide.g.value, true);
35+
});

src/glide/docs/api.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ text-decoration: none;
139139
[`glide.fs.exists()`](#glide.fs.exists)\
140140
[`glide.fs.stat()`](#glide.fs.stat)\
141141
[`glide.fs.mkdir()`](#glide.fs.mkdir)\
142+
[`glide.containers`](#glide.containers)\
143+
[`glide.containers.create()`](#glide.containers.create)\
144+
[`glide.containers.remove()`](#glide.containers.remove)\
142145
[`glide.messengers`](#glide.messengers)\
143146
[`glide.messengers.create()`](#glide.messengers.create)\
144147
[`glide.modes`](#glide.modes)\
@@ -175,6 +178,9 @@ text-decoration: none;
175178
[`glide.CommandLineShowOpts`](#glide.CommandLineShowOpts)\
176179
[`glide.CommandLineCustomOption`](#glide.CommandLineCustomOption)\
177180
[`glide.FileInfo`](#glide.FileInfo)\
181+
[`glide.Container`](#glide.Container)\
182+
[`glide.ContainerIcon`](#glide.ContainerIcon)\
183+
[`glide.ContainerColor`](#glide.ContainerColor)\
178184
[`DOM.create_element()`](#DOM.create_element)
179185

180186
{% html %}
@@ -1078,6 +1084,20 @@ Parent directories are created by default, if desired you can turn this off with
10781084
By default this will _not_ error if the `path` already exists, if you would like it
10791085
to do so, pass `ts:glide.fs.mkdir('...', { exists_ok: false })`
10801086

1087+
## `glide.containers` {% id="glide.containers" %}
1088+
1089+
{% api-heading id="glide.containers.create" %}
1090+
glide.containers.create(props): glide.Container
1091+
{% /api-heading %}
1092+
1093+
Create a new container.
1094+
1095+
{% api-heading id="glide.containers.remove" %}
1096+
glide.containers.remove(id): boolean
1097+
{% /api-heading %}
1098+
1099+
Remove a container.
1100+
10811101
## `glide.messengers` {% id="glide.messengers" %}
10821102

10831103
{% api-heading id="glide.messengers.create" %}
@@ -1583,6 +1603,20 @@ path: string | undefined;
15831603
size: number | undefined;
15841604
```
15851605

1606+
## • `glide.Container` {% id="glide.Container" %}
1607+
1608+
```typescript {% highlight_prefix="type x = {" %}
1609+
id: number;
1610+
name: string;
1611+
icon: string;
1612+
color: string;
1613+
cookie_store_id: string;
1614+
```
1615+
1616+
## • `glide.ContainerIcon: "fingerprint" | "briefcase" | "dollar" | "cart" | "vacation" | "gift" | "food" | "fruit" | "pet" | "tree" | "chill" | "circle" | "fence"` {% id="glide.ContainerIcon" %}
1617+
1618+
## • `glide.ContainerColor: "blue" | "turquoise" | "green" | "yellow" | "orange" | "red" | "pink" | "purple" | "toolbar"` {% id="glide.ContainerColor" %}
1619+
15861620
# `DOM` {% id="DOM" %}
15871621

15881622
Helper functions for interacting with the DOM.

0 commit comments

Comments
 (0)