Skip to content

Commit 4d2979e

Browse files
authored
Merge pull request #345 from ezzak/css_verif_refac
Cleanups post CSS support
2 parents 75670cb + 7db98ac commit 4d2979e

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

src/js/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const ORIGIN_TYPE = Object.freeze({
8888
export type Origin = keyof typeof ORIGIN_TYPE;
8989

9090
// Firefox and Safari currently do not support CompressionStream/showSaveFilePicker
91-
export const DOWNLOAD_JS_ENABLED =
91+
export const DOWNLOAD_SRC_ENABLED =
9292
'CompressionStream' in window && 'showSaveFilePicker' in window;
9393

9494
export const MANIFEST_TIMEOUT = 45000;

src/js/content.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {
99
MESSAGE_TYPE,
10-
DOWNLOAD_JS_ENABLED,
10+
DOWNLOAD_SRC_ENABLED,
1111
STATES,
1212
Origin,
1313
ORIGIN_TYPE,
@@ -179,7 +179,7 @@ function handleManifestNode(manifestNode: HTMLScriptElement): void {
179179
}
180180

181181
sendMessageToBackground(messagePayload, response => {
182-
// then start processing of it's JS
182+
// then start processing its JS/CSS
183183
if (response.valid) {
184184
if (manifestTimeoutID !== '') {
185185
clearTimeout(manifestTimeoutID);
@@ -225,16 +225,12 @@ export const processFoundElements = async (version: string): Promise<void> => {
225225
updateCurrentState(STATES.VALID);
226226
}
227227
} else {
228-
if (response.type === 'EXTENSION') {
229-
updateCurrentState(STATES.RISK);
230-
} else {
231-
updateCurrentState(STATES.INVALID, `Invalid Tag ${tagIdentifier}`);
232-
}
228+
updateCurrentState(STATES.INVALID, `Invalid Tag ${tagIdentifier}`);
233229
}
234230
sendMessageToBackground({
235231
type: MESSAGE_TYPE.DEBUG,
236232
log:
237-
'processed JS with SRC response is ' +
233+
'processed SRC response is ' +
238234
JSON.stringify(response).substring(0, 500),
239235
src: tagIdentifier,
240236
});
@@ -324,7 +320,7 @@ export function storeFoundElement(element: HTMLElement): void {
324320
updateCurrentState(STATES.INVALID, 'blob: src');
325321
return;
326322
}
327-
if (script.src !== '' || script.innerHTML !== '') {
323+
if (script.src !== '') {
328324
handleScriptNode(script);
329325
}
330326
} else if (element.nodeName.toLowerCase() === 'style') {
@@ -458,7 +454,7 @@ export function startFor(origin: Origin, config: ContentScriptConfig): void {
458454
}
459455

460456
chrome.runtime.onMessage.addListener(request => {
461-
if (request.greeting === 'downloadSource' && DOWNLOAD_JS_ENABLED) {
457+
if (request.greeting === 'downloadSource' && DOWNLOAD_SRC_ENABLED) {
462458
downloadSrc();
463459
} else if (request.greeting === 'nocacheHeaderFound') {
464460
updateCurrentState(

src/js/content/contentUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import alertBackgroundOfImminentFetch from './alertBackgroundOfImminentFetch';
99

1010
import {TagDetails} from '../content';
11-
import {DOWNLOAD_JS_ENABLED, MESSAGE_TYPE} from '../config';
11+
import {DOWNLOAD_SRC_ENABLED, MESSAGE_TYPE} from '../config';
1212
import genSourceText from './genSourceText';
1313
import {sendMessageToBackground} from '../shared/sendMessageToBackground';
1414
import {getCurrentOrigin} from './updateCurrentState';
15-
import downloadJSArchive from './downloadJSArchive';
15+
import downloadArchive from './downloadArchive';
1616

1717
const SOURCE_SCRIPTS_AND_STYLES = new Map();
1818

@@ -40,7 +40,7 @@ async function processSrc(
4040
// If this is missing it will cause a cache miss, resulting in invalidation.
4141
headers: isServiceWorker ? {'Service-Worker': 'script'} : undefined,
4242
});
43-
if (DOWNLOAD_JS_ENABLED) {
43+
if (DOWNLOAD_SRC_ENABLED) {
4444
const fileNameArr = url.split('/');
4545
const fileName = fileNameArr[fileNameArr.length - 1].split('?')[0];
4646
const responseBody = sourceResponse.clone().body;
@@ -90,7 +90,7 @@ async function processSrc(
9090
}
9191

9292
function downloadSrc(): void {
93-
downloadJSArchive(SOURCE_SCRIPTS_AND_STYLES);
93+
downloadArchive(SOURCE_SCRIPTS_AND_STYLES);
9494
}
9595

9696
export {processSrc, downloadSrc};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export default async function downloadJSArchive(
8+
export default async function downloadArchive(
99
sourceScripts: Map<string, ReadableStream>,
1010
): Promise<void> {
1111
const fileHandle = await window.showSaveFilePicker({

src/js/popup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import {
9-
DOWNLOAD_JS_ENABLED,
9+
DOWNLOAD_SRC_ENABLED,
1010
MESSAGE_TYPE,
1111
ORIGIN_TYPE,
1212
STATES,
@@ -105,7 +105,7 @@ function attachListeners(origin: string | null): void {
105105
)[0];
106106
const downloadSrcButton = document.getElementById('i18nDownloadSourceButton');
107107

108-
if (DOWNLOAD_JS_ENABLED) {
108+
if (DOWNLOAD_SRC_ENABLED) {
109109
const downloadPageSourceMenuItem = menuRowList[1];
110110
downloadPageSourceMenuItem.addEventListener('click', () =>
111111
updateDisplay('download'),

0 commit comments

Comments
 (0)