Skip to content

Commit

Permalink
Enumerate permitted content script messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Sep 24, 2019
1 parent a1bacb9 commit b7e9aea
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 140 deletions.
1 change: 0 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rules:
- error
- 2
- outerIIFEBody: 0
SwitchCase: 1
keyword-spacing: error
linebreak-style:
- error
Expand Down
5 changes: 4 additions & 1 deletion src/js/contentscripts/clobbercookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ if (window.top == window) {
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({ checkLocation: window.FRAME_URL }, function (blocked) {
chrome.runtime.sendMessage({
type: "checkLocation",
frameUrl: window.FRAME_URL
}, function (blocked) {
if (blocked) {
var code = '('+ function() {
document.__defineSetter__("cookie", function(/*value*/) { });
Expand Down
5 changes: 4 additions & 1 deletion src/js/contentscripts/clobberlocalstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ if (window.top == window) {
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({ checkLocation: window.FRAME_URL }, function (blocked) {
chrome.runtime.sendMessage({
type: "checkLocation",
frameUrl: window.FRAME_URL
}, function (blocked) {
if (blocked) {
// https://stackoverflow.com/questions/49092423/how-to-break-on-localstorage-changes
var code =
Expand Down
2 changes: 1 addition & 1 deletion src/js/contentscripts/dnt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (document instanceof HTMLDocument === false && (

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
checkDNT: true
type: "checkDNT"
}, function (enabled) {
if (enabled) {
window.injectScript(getPageScript());
Expand Down
43 changes: 22 additions & 21 deletions src/js/contentscripts/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,29 @@ if (document instanceof HTMLDocument === false && (
}

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
if (!enabled) {
return;
}
/**
* Communicating to webrequest.js
*/
var event_id = Math.random();

// listen for messages from the script we are about to insert
document.addEventListener(event_id, function (e) {
// pass these on to the background page
chrome.runtime.sendMessage({
fpReport: e.detail
});
chrome.runtime.sendMessage({
type: "checkEnabled"
}, function (enabled) {
if (!enabled) {
return;
}
/**
* Communicating to webrequest.js
*/
var event_id = Math.random();

// listen for messages from the script we are about to insert
document.addEventListener(event_id, function (e) {
// pass these on to the background page
chrome.runtime.sendMessage({
type: "fpReport",
data: e.detail
});
});

window.injectScript(getFpPageScript(), {
event_id: event_id
});
}
);
window.injectScript(getFpPageScript(), {
event_id: event_id
});
});

}());
15 changes: 9 additions & 6 deletions src/js/contentscripts/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ function createReplacementButtonImage(tracker, trackerElem, callback) {
// don't have image data cached yet, get it from the background page
buttonData.loading = true;
chrome.runtime.sendMessage({
getReplacementButton: buttonData.imagePath
type: "getReplacementButton",
imagePath: buttonData.imagePath
}, function (response) {
buttonData.buttonUrl = response; // cache image data
_createReplacementButtonImageCallback(tracker, trackerElem, callback);
Expand Down Expand Up @@ -416,7 +417,9 @@ function replaceIndividualButton(tracker) {
* replaced
*/
function getTrackerData(callback) {
chrome.runtime.sendMessage({checkReplaceButton: true}, function(response) {
chrome.runtime.sendMessage({
type: "checkReplaceButton"
}, function (response) {
if (response) {
for (const key in response.translations) {
TRANSLATIONS[key] = response.translations[key];
Expand All @@ -435,7 +438,7 @@ function getTrackerData(callback) {
*/
function unblockTracker(buttonUrls, callback) {
let request = {
unblockWidget: true,
type: "unblockWidget",
buttonUrls: buttonUrls
};
chrome.runtime.sendMessage(request, callback);
Expand All @@ -455,9 +458,9 @@ if (document instanceof HTMLDocument === false && (
}

chrome.runtime.sendMessage({
checkWidgetReplacementEnabled: true
}, function (checkWidgetReplacementEnabled) {
if (!checkWidgetReplacementEnabled) {
type: "checkWidgetReplacementEnabled"
}, function (enabled) {
if (!enabled) {
return;
}
initialize();
Expand Down
6 changes: 4 additions & 2 deletions src/js/contentscripts/supercookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ if (window.top == window) {
// could then remove test workarounds like
// https://github.com/EFForg/privacybadger/commit/39d5d0899e22d1c451d429e44553c5f9cad7fc46
chrome.runtime.sendMessage({
checkEnabledAndThirdParty: window.FRAME_URL
type: "checkEnabledAndThirdParty",
frameUrl: window.FRAME_URL
}, function (enabledAndThirdParty) {
if (!enabledAndThirdParty) {
return;
Expand All @@ -132,7 +133,8 @@ chrome.runtime.sendMessage({
document.addEventListener(event_id_super_cookie, function (e) {
// pass these on to the background page (handled by webrequest.js)
chrome.runtime.sendMessage({
superCookieReport: e.detail,
type: "supercookieReport",
data: e.detail,
frameUrl: window.FRAME_URL
});
});
Expand Down
28 changes: 14 additions & 14 deletions src/js/firstparties/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ function cleanLink(a) {
a.addEventListener("mouseover", function (e) { e.stopImmediatePropagation(); }, true);
}

//TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
if (!enabled) {
return;
}
// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
type: "checkEnabled"
}, function (enabled) {
if (!enabled) {
return;
}

// unwrap wrapped links in the original page
findInAllFrames(fb_wrapped_link).forEach((link) => {
cleanLink(link);
});
// unwrap wrapped links in the original page
findInAllFrames(fb_wrapped_link).forEach((link) => {
cleanLink(link);
});

// Execute redirect unwrapping each time new content is added to the page
observeMutations(fb_wrapped_link, cleanLink);
}
);
// Execute redirect unwrapping each time new content is added to the page
observeMutations(fb_wrapped_link, cleanLink);
});
27 changes: 13 additions & 14 deletions src/js/firstparties/google-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ function cleanLink(a) {
a.addEventListener("mousedown", function (e) { e.stopImmediatePropagation(); }, true);
}

//TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
if (!enabled) {
return;
}

// since the page is rendered all at once, no need to set up a
// mutationObserver or setInterval
findInAllFrames(trap_link).forEach((link) => {
cleanLink(link);
});

// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
type: "checkEnabled"
}, function (enabled) {
if (!enabled) {
return;
}
);

// since the page is rendered all at once, no need to set up a
// mutationObserver or setInterval
findInAllFrames(trap_link).forEach((link) => {
cleanLink(link);
});
});
18 changes: 9 additions & 9 deletions src/js/firstparties/google-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ function unwrapAll() {
});
}

//TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
if (!enabled) {
return;
}
unwrapAll();
setInterval(unwrapAll, 2000);
// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
type: "checkEnabled"
}, function (enabled) {
if (!enabled) {
return;
}
);
unwrapAll();
setInterval(unwrapAll, 2000);
});
20 changes: 10 additions & 10 deletions src/js/firstparties/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ function unwrapSpecialTwitterURLs() {
});
}

//TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({checkEnabled: true},
function (enabled) {
if (!enabled) {
return;
}
unwrapSpecialTwitterURLs();
unwrapTwitterURLsInTimeline();
setInterval(unwrapTwitterURLsInTimeline, 2000);
// TODO race condition; fix waiting on https://crbug.com/478183
chrome.runtime.sendMessage({
type: "checkEnabled",
}, function (enabled) {
if (!enabled) {
return;
}
);
unwrapSpecialTwitterURLs();
unwrapTwitterURLsInTimeline();
setInterval(unwrapTwitterURLsInTimeline, 2000);
});
28 changes: 14 additions & 14 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,20 @@ BadgerPen.prototype = {

function getScore(action) {
switch (action) {
case constants.NO_TRACKING:
return 0;
case constants.ALLOW:
return 1;
case constants.BLOCK:
return 2;
case constants.COOKIEBLOCK:
return 3;
case constants.DNT:
return 4;
case constants.USER_ALLOW:
case constants.USER_BLOCK:
case constants.USER_COOKIE_BLOCK:
return 5;
case constants.NO_TRACKING:
return 0;
case constants.ALLOW:
return 1;
case constants.BLOCK:
return 2;
case constants.COOKIEBLOCK:
return 3;
case constants.DNT:
return 4;
case constants.USER_ALLOW:
case constants.USER_BLOCK:
case constants.USER_COOKIE_BLOCK:
return 5;
}
}

Expand Down
Loading

0 comments on commit b7e9aea

Please sign in to comment.