Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow an isolated tab to inherit its color or icon from its parent #624

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53,900 changes: 28,929 additions & 24,971 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"npm-check-updates": "^6.0.1",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"parcel": "^2.0.0-nightly.228",
"parcel": "^2.8.3",
"prettier": "2.0.5",
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
Expand Down
6 changes: 6 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"optionsGeneralContainerRandomColor": {
"message": "Random Container Color"
},
"optionsGeneralContainerInheritColor": {
"message": "Inherit color after isolation"
},
"optionsGeneralContainerIcon": {
"message": "Container Icon"
},
Expand Down Expand Up @@ -101,6 +104,9 @@
"optionsGeneralContainerIconRandom": {
"message": "Random Container Icon"
},
"optionsGeneralContainerInheritIcon": {
"message": "Inherit icon after isolation"
},
"optionsGeneralContainerNumber": {
"message": "Container Number"
},
Expand Down
31 changes: 31 additions & 0 deletions src/background/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Container {
deletesHistory = false,
macConfirmPage = false,
openerTab,
inheritContainerOptions,
}: TmpTabOptions): Promise<Tab | undefined> {
if (request && request.requestId) {
// we saw that request already
Expand All @@ -86,10 +87,24 @@ export class Container {
});
}

let inheritedContainerOptions;
if (tab && inheritContainerOptions) {
if (this.tabs.containerMap.has(tab.id)) {
inheritedContainerOptions = this.storage.local.tempContainers[
tab.cookieStoreId
];
} else {
inheritedContainerOptions = await browser.contextualIdentities.get(
tab.cookieStoreId
);
}
}

const contextualIdentity = await this.createTempContainer({
url,
request,
deletesHistory,
inheritedContainerOptions,
});

return this.createTab({
Expand All @@ -107,10 +122,14 @@ export class Container {
url,
request,
deletesHistory,
inheritedContainerOptions,
}: {
url?: string;
request?: false | WebRequestOnBeforeRequestDetails;
deletesHistory?: boolean;
inheritedContainerOptions?:
| ContainerOptions
| browser.contextualIdentities.ContextualIdentity;
}): Promise<browser.contextualIdentities.ContextualIdentity> {
const containerOptions = this.generateContainerNameIconColor(
(request && request.url) || url
Expand All @@ -120,6 +139,15 @@ export class Container {
this.storage.local.tempContainersNumbers.push(containerOptions.number);
}

if (inheritedContainerOptions) {
if (this.pref.container.colorInherit) {
containerOptions.color = inheritedContainerOptions.color;
}
if (this.pref.container.iconInherit) {
containerOptions.icon = inheritedContainerOptions.icon;
}
}

if (deletesHistory) {
if (this.permissions.history) {
containerOptions.name += '-deletes-history';
Expand Down Expand Up @@ -276,6 +304,7 @@ export class Container {
request,
macConfirmPage,
dontPin = true,
inheritContainerOptions,
}: {
tab?: Tab;
url?: string;
Expand All @@ -284,6 +313,7 @@ export class Container {
request?: WebRequestOnBeforeRequestDetails;
macConfirmPage?: boolean;
dontPin?: boolean;
inheritContainerOptions?: boolean;
}): Promise<undefined | Tab> {
const newTab = await this.createTabInTempContainer({
tab,
Expand All @@ -293,6 +323,7 @@ export class Container {
deletesHistory,
request,
macConfirmPage,
inheritContainerOptions,
});
if (!tab) {
return newTab;
Expand Down
2 changes: 2 additions & 0 deletions src/background/isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ export class Isolation {
request,
deletesHistory:
this.pref.deletesHistory.containerIsolation === 'automatic',
inheritContainerOptions:
this.pref.container.colorInherit || this.pref.container.iconInherit,
};

let reload = false;
Expand Down
2 changes: 2 additions & 0 deletions src/background/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export class Preferences {
color: 'toolbar',
colorRandom: false,
colorRandomExcluded: [],
colorInherit: false,
icon: 'circle',
iconRandom: false,
iconRandomExcluded: [],
iconInherit: false,
numberMode: 'keep',
removal: 900000, // ms
},
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface TmpTabOptions {
deletesHistory?: boolean;
macConfirmPage?: boolean;
openerTab?: Tab;
inheritContainerOptions?: boolean;
}

export type IsolationAction =
Expand Down Expand Up @@ -156,9 +157,11 @@ export interface PreferencesSchema {
color: ContainerColor;
colorRandom: boolean;
colorRandomExcluded: ContainerColor[];
colorInherit: boolean;
icon: ContainerIcon;
iconRandom: boolean;
iconRandomExcluded: ContainerIcon[];
iconInherit: boolean;
numberMode: 'keep' | 'keepuntilrestart' | 'reuse' | 'hide';
removal: Milliseconds;
};
Expand Down
12 changes: 12 additions & 0 deletions src/ui/components/general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ export default mixins(mixin).extend({
<label>{{ t('optionsGeneralContainerRandomColor') }}</label>
</div>
</div>
<div v-show="preferences.container.colorRandom" class="field">
<div class="ui checkbox">
<input v-model="preferences.container.colorInherit" type="checkbox" />
<label>{{ t('optionsGeneralContainerInheritColor') }}</label>
</div>
</div>
<div id="containerIcon" class="field">
<label v-if="!preferences.container.iconRandom">
{{ t('optionsGeneralContainerIcon') }}
Expand Down Expand Up @@ -255,6 +261,12 @@ export default mixins(mixin).extend({
<label>{{ t('optionsGeneralContainerIconRandom') }}</label>
</div>
</div>
<div v-show="preferences.container.iconRandom" class="field">
<div class="ui checkbox">
<input v-model="preferences.container.iconInherit" type="checkbox" />
<label>{{ t('optionsGeneralContainerInheritIcon') }}</label>
</div>
</div>
<div class="field">
<label>{{ t('optionsGeneralContainerNumber') }}</label>
<select
Expand Down