-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
399 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isFirstParty } from '@cookie-analysis-tool/common'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import { createCookieObject } from '../worker/createCookieObject'; | ||
import { fetchDictionary, type CookieDatabase } from './fetchCookieDictionary'; | ||
import findAnalyticsMatch from '../worker/findAnalyticsMatch'; | ||
import { CookieStore, type CookieData } from '../localStore'; | ||
|
||
interface ProcessAndStoreDucmentCookiesProps { | ||
tabUrlResult: string; | ||
tabId: string; | ||
documentCookies: string[]; | ||
dictionary: CookieDatabase; | ||
isException: object; | ||
} | ||
|
||
const processAndStoreDocumentCookies = async ({ | ||
tabUrlResult, | ||
tabId, | ||
documentCookies, | ||
dictionary, | ||
isException, | ||
}: ProcessAndStoreDucmentCookiesProps) => { | ||
if (!isException && typeof tabUrlResult === 'string') { | ||
const tabUrl = tabUrlResult; | ||
|
||
const frames = await chrome.webNavigation.getAllFrames({ | ||
tabId: Number(tabId), | ||
}); | ||
|
||
const outerMostFrame = frames?.filter( | ||
(frame) => frame.frameType === 'outermost_frame' | ||
); | ||
|
||
const parsedCookieData: CookieData[] = await Promise.all( | ||
documentCookies.map(async (singleCookie: string) => { | ||
const cookieValue = singleCookie.split('=')[1]?.trim(); | ||
const cookieName = singleCookie.split('=')[0]?.trim(); | ||
let analytics; | ||
|
||
const parsedCookie = await createCookieObject( | ||
{ | ||
name: cookieName, | ||
value: cookieValue, | ||
}, | ||
tabUrl | ||
); | ||
|
||
if (dictionary) { | ||
analytics = findAnalyticsMatch(parsedCookie.name, dictionary); | ||
} | ||
|
||
const isFirstPartyCookie = isFirstParty( | ||
parsedCookie.domain || '', | ||
tabUrl | ||
); | ||
|
||
return Promise.resolve({ | ||
parsedCookie, | ||
analytics: | ||
analytics && Object.keys(analytics).length > 0 ? analytics : null, | ||
url: tabUrl, | ||
headerType: 'javascript', // @todo Update headerType name. | ||
isFirstParty: isFirstPartyCookie || null, | ||
frameIdList: [ | ||
outerMostFrame && outerMostFrame[0] | ||
? outerMostFrame[0]?.frameId | ||
: 0, | ||
], | ||
}); | ||
}) | ||
); | ||
|
||
await CookieStore.update(tabId, parsedCookieData); | ||
} | ||
}; | ||
|
||
/** | ||
* Utility function to get the cookies from result and send it for processing. | ||
* @param result the evaluated value of array of string. | ||
* @param exceptionGenerated Boolean value which specifies if an exception was generated during evaluating the javascript. | ||
* @param tabId Tab ID from which the JS cookies have to be read. | ||
* @param dictionary JSON object which is used to classify cookie based on their use. | ||
*/ | ||
const getJSCookiesForProcessing = ( | ||
result: string[], | ||
exceptionGenerated: object, | ||
tabId: string, | ||
dictionary: CookieDatabase | ||
) => { | ||
let documentCookies: string[] = []; | ||
|
||
if (!exceptionGenerated && result.length > 1) { | ||
documentCookies = result; | ||
|
||
chrome.devtools.inspectedWindow.eval( | ||
'window.location.href', | ||
(tabUrlResult: string, isException) => | ||
processAndStoreDocumentCookies({ | ||
tabUrlResult, | ||
tabId, | ||
documentCookies, | ||
dictionary, | ||
isException, | ||
}) | ||
); | ||
} else { | ||
return; | ||
} | ||
}; | ||
|
||
/** | ||
* Adds the cookies set via document.cookie. | ||
* @param tabId Id of the tab being listened to. | ||
*/ | ||
async function setDocumentCookies(tabId: string) { | ||
if (!tabId) { | ||
return; | ||
} | ||
|
||
const dictionary = await fetchDictionary(); | ||
|
||
chrome.devtools.inspectedWindow.eval( | ||
'document.cookie.split(";")', | ||
(result: string[], isException) => | ||
getJSCookiesForProcessing(result, isException, tabId, dictionary) | ||
); | ||
} | ||
export default setDocumentCookies; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
.../extension/src/view/design-system/components/circlePieChart/tests/emptyCirclePieChart.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.