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

Feature: Add the capability of setting "allow list" content policy #376

Merged
merged 50 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2be223e
Add permission for contentSettings
mohdsayed Dec 30, 2023
46e8aa5
Clear contentSettings.cookies when browser window is opened
mohdsayed Dec 30, 2023
e672975
Add custom hook for allowed list
mohdsayed Dec 30, 2023
b0cd3ff
Create state for and handle classes in body row
mohdsayed Dec 30, 2023
4dca6d5
Merge branch 'develop' of github.com:GoogleChromeLabs/cookie-analysis…
mohdsayed Jan 9, 2024
7f7543f
Update TableProps and details component
mohdsayed Jan 9, 2024
47b3926
Add mock test data and test for bodyRow
mohdsayed Jan 9, 2024
fc16201
Add test for BodyRow
mohdsayed Jan 9, 2024
f9c80cd
Update useAllowedList hook to handle session storage
mohdsayed Jan 9, 2024
4821842
Add test data for cookie table body
mohdsayed Jan 9, 2024
8c1c285
Add method for adding domain to allow list
mohdsayed Jan 9, 2024
d662828
Add new clors to tailwind
mohdsayed Jan 9, 2024
7acbb32
Add condition before loopin through storage.allowList
mohdsayed Jan 9, 2024
28e2935
Refactor cdoe
mohdsayed Jan 12, 2024
0ce1f07
Refactor code
mohdsayed Jan 12, 2024
524e110
Refactor code
mohdsayed Jan 12, 2024
9503f4f
Add types
mohdsayed Jan 12, 2024
bcc05d3
Refactor code
mohdsayed Jan 12, 2024
4bc335f
Refactor code
mohdsayed Jan 12, 2024
c02df0a
Refactor code
mohdsayed Jan 12, 2024
006c217
Use async/await instead of promise then
mohdsayed Jan 12, 2024
5f7e096
Refactor code to move onClick function to a utility
mohdsayed Jan 14, 2024
0b81fda
Update details section for allowed cookies
mohdsayed Jan 14, 2024
3470d2a
Show green for an item that is not blocked and allow listed
mohdsayed Jan 14, 2024
39609f1
Show green border for allow listed items even if they are blocked
mohdsayed Jan 14, 2024
a68989a
Fix state update
mohdsayed Jan 14, 2024
9bc8352
Capitalize R in blocked reason
mohdsayed Jan 14, 2024
ef3aea8
Refactor: Add the capability of setting "allow list" content policy (…
mayan-000 Jan 16, 2024
ad32754
Merge develop and resolve conflicts
mohdsayed Jan 16, 2024
ba265b3
Merge develop and resolve conflicts
mohdsayed Jan 22, 2024
6d7ac37
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
mohdsayed Jan 22, 2024
3871f17
Add reloadCurrentTab to reload current tab
mohdsayed Jan 22, 2024
ec9b3b5
Reload page on adding domain to allowed list
mohdsayed Jan 22, 2024
7a6cba3
Fix url pattern issue
mohdsayed Jan 22, 2024
6bb2aa7
Fix styling for border left
mohdsayed Jan 23, 2024
5c292e5
Update message
mohdsayed Jan 23, 2024
f82b3a9
Update text for context menu
mohdsayed Jan 24, 2024
ff92e85
Allow cookies for domain with dot prefix
mohdsayed Jan 25, 2024
9d31a97
Refactor code
mohdsayed Jan 29, 2024
f37ecea
Merge develop and resolve conflicts
mohdsayed Jan 29, 2024
2a50da3
Fix tests
mohdsayed Jan 29, 2024
2eb3f9b
Remove condition for fixing remove allow list issue
mohdsayed Jan 29, 2024
3b1ee84
Remove unused code for useHighlighting
mohdsayed Jan 29, 2024
f42183f
Fix parent domain double click issue
mohdsayed Jan 29, 2024
b9b04e6
Code improvements and refactoring
mohdsayed Jan 29, 2024
05e6bbb
Fix test case
mohdsayed Jan 29, 2024
cf581e5
Add code improvements
mohdsayed Jan 29, 2024
74919ff
Fix test
mohdsayed Jan 29, 2024
322a543
ref: use domains list as prop
mayan-000 Jan 29, 2024
7713e39
test: fix test
mayan-000 Jan 29, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add types
  • Loading branch information
mohdsayed committed Jan 12, 2024
commit 9503f4ff652b8c2f5784aba2b6c394ec30304469
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
import { useRef, useEffect, useCallback, useState } from 'react';
import { CookieTableData } from '@ps-analysis-tool/common';
import { CookieStore } from '@ps-analysis-tool/extension/src/localStore';
import {
CookieStore,
type AllowedDomainObject,
} from '@ps-analysis-tool/extension/src/localStore';

/**
* Internal dependencies.
Expand Down Expand Up @@ -60,7 +63,7 @@ const useAllowedList = (
'/*';

const scope = isIncognito.current ? 'incognito_session_only' : 'regular';
const domainObject = {
const domainObject: AllowedDomainObject = {
primaryDomain: domainForAllowList,
primaryPattern,
secondaryPattern,
Expand All @@ -74,8 +77,8 @@ const useAllowedList = (

CookieStore.removeDomainFromAllowList(domainObject).then(() => {
// Set remaining settings after removing one setting.
CookieStore.getDomainsInAllowList().then((listOfDomainObject) => {
listOfDomainObject.forEach((domainObjectItem) => {
CookieStore.getDomainsInAllowList().then((allowedDomainObjects) => {
allowedDomainObjects.forEach((domainObjectItem) => {
chrome.contentSettings.cookies
.set({
primaryPattern: domainObjectItem.primaryPattern,
Expand All @@ -102,9 +105,9 @@ const useAllowedList = (
}

CookieStore.getDomainsInAllowList()
.then((listOfDomainObject) => {
console.log(listOfDomainObject, domainForAllowList);
listOfDomainObject.forEach((domainObjectItem) => {
.then((allowedDomainObjects) => {
console.log(allowedDomainObjects, domainForAllowList);
allowedDomainObjects.forEach((domainObjectItem) => {
// Check if more specific patterns was added to allow-list,
// and remove it as the general pattern will be applied.
if (
Expand All @@ -118,8 +121,8 @@ const useAllowedList = (
() => {
// Set remaining settings after removing one setting.
CookieStore.getDomainsInAllowList().then(
(newListOfDomainObject) => {
newListOfDomainObject.forEach((newDomainObjectItem) => {
(newallowedDomainObjects) => {
newallowedDomainObjects.forEach((newDomainObjectItem) => {
chrome.contentSettings.cookies
.set({
primaryPattern: newDomainObjectItem.primaryPattern,
Expand Down Expand Up @@ -232,26 +235,29 @@ const useAllowedList = (
);

// Set whether the domain is a subdomain match or the exact match.
allowListSessionStorage.then((listOfDomainObject) => {
let parentDomainValue = '';
const numberOfDomainsInAllowList = listOfDomainObject
? listOfDomainObject.length
: 0;
allowListSessionStorage.then(
(allowedDomainObjects: AllowedDomainObject[]) => {
let parentDomainValue = '';

for (let i = 0; i < numberOfDomainsInAllowList; i++) {
if (
domain.endsWith(listOfDomainObject[i].primaryDomain) &&
domain !== listOfDomainObject[i].primaryDomain
) {
parentDomainValue = listOfDomainObject[i].primaryDomain;
break;
if (!allowedDomainObjects || allowedDomainObjects?.length === 0) {
return;
}
}

if (parentDomain !== parentDomainValue) {
setParentDomain(parentDomainValue);
for (let i = 0; i < allowedDomainObjects.length; i++) {
if (
domain.endsWith(allowedDomainObjects[i].primaryDomain) &&
domain !== allowedDomainObjects[i].primaryDomain
) {
parentDomainValue = allowedDomainObjects[i].primaryDomain;
break;
}
}

if (parentDomain !== parentDomainValue) {
setParentDomain(parentDomainValue);
}
}
});
);
}, [
row,
domain,
Expand Down
24 changes: 13 additions & 11 deletions packages/extension/src/localStore/cookieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import type { Protocol } from 'devtools-protocol';
* Internal dependencies.
*/
import updateStorage from './utils/updateStorage';
import type { TabData } from './types';
import type {
TabData,
AllowedDomainObject,
AllowedDomainStorage,
} from './types';
import fetchTopicsTaxonomy from '../utils/fetchTopicsTaxonomy';
import updateCookieBadgeText from './utils/updateCookieBadgeText';
import getIndexForAllowListedItem, {
type AllowListedStorage,
} from './utils/getIndexForAllowListedItem';
import getIndexForAllowListedItem from './utils/getIndexForAllowListedItem';

const CookieStore = {
/**
Expand Down Expand Up @@ -347,17 +349,17 @@ const CookieStore = {

/**
* Add domain to allow-list.
* @param {Record<string, string>} domainObject The domain to be added to allow-list.
* @param {AllowedDomainObject} domainObject The domain to be added to allow-list.
*/
async addDomainToAllowList(domainObject: Record<string, string>) {
async addDomainToAllowList(domainObject: AllowedDomainObject) {
const storage = await chrome.storage.session.get();

if (!storage.allowList) {
storage.allowList = [];
}

const index = getIndexForAllowListedItem(
storage as AllowListedStorage,
storage as AllowedDomainStorage,
domainObject
);

Expand All @@ -370,17 +372,17 @@ const CookieStore = {

/**
* Remove domain from allow-list.
* @param {Record<string, string>} domainObject The domain to be removed from allow-list.
* @param {AllowedDomainObject} domainObject The domain to be removed from allow-list.
*/
async removeDomainFromAllowList(domainObject: Record<string, string>) {
async removeDomainFromAllowList(domainObject: AllowedDomainObject) {
const storage = await chrome.storage.session.get();

if (!storage?.allowList || storage?.allowList?.length === 0) {
return;
}

const indexToRemove = getIndexForAllowListedItem(
storage as AllowListedStorage,
storage as AllowedDomainStorage,
domainObject
);

Expand All @@ -395,7 +397,7 @@ const CookieStore = {
* Get domains in allow-list.
* @returns {Promise<Record<string, string>>} Set of domains in allow-list.
*/
async getDomainsInAllowList(): Promise<Record<string, string>[]> {
async getDomainsInAllowList(): Promise<AllowedDomainObject[] | []> {
const storage = await chrome.storage.session.get();

return storage.allowList ?? [];
Expand Down
11 changes: 11 additions & 0 deletions packages/extension/src/localStore/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ export type TabData = {
export type Storage = {
[tabId: string]: TabData;
};

export type AllowedDomainObject = {
primaryDomain: string;
primaryPattern: string;
secondaryPattern: string;
scope: string;
};

export type AllowedDomainStorage = {
allowList: AllowedDomainObject[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface AllowListedStorage {
allowList: Record<string, string>[];
}
/**
* Internal dependencies.
*/
import type { AllowedDomainObject, AllowedDomainStorage } from '../types';

const getIndexForAllowListedItem = (
storage: AllowListedStorage,
domainObject: Record<string, string>
storage: AllowedDomainStorage,
domainObject: AllowedDomainObject
): number => {
let index = -1;

Expand Down
Loading