Skip to content

Commit

Permalink
Merge pull request #181 from cowlicks/fix-compat
Browse files Browse the repository at this point in the history
Fix chrome to firefox compatibility. Update release process
  • Loading branch information
cowlicks authored Jul 10, 2019
2 parents 4ac38d5 + 9f079d1 commit ad7ee92
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 11 deletions.
49 changes: 43 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
test_node:
toplevel := $(shell git rev-parse --show-toplevel)
possum_pem := $(toplevel)/possum.pem
possum_zip := $(toplevel)/possum.zip
possum_crx := $(toplevel)/possum.crx

clean:
rm -rf src/js/node_modules
rm -f src/js/package-lock.json
rm -rf selenium/node_modules
rm -f selenium/package-lock.json
rm -f possum.zip
rm -f possum.crx

test_node: src/js/node_modules
./scripts/test.sh

test_selenium:
test_selenium: selenium/node_modules
./scripts/selenium_test.sh

npm_install_node:
Expand All @@ -10,10 +23,34 @@ npm_install_node:
npm_install_selenium:
./scripts/npm_install.sh selenium/.

psl:
psl:
./scripts/getpsl.py > src/js/domains/psl.js

release:
./scripts/release.sh
scripts/release.sh: scripts/source_me.sh

possum.zip: $(shell git ls-files src)
cd src/ && git ls-files | zip -q -9 -X $(possum_zip) -@

dev: src/js/node_modules selenium/node_modules
src/js/node_modules: src/js/package.json
cd src/js && npm install

selenium/node_modules: selenium/package.json
cd selenium && npm install

possum.crx: possum.zip src/js/node_modules $(shell git ls-files src)
src/js/node_modules/.bin/crx3-new $(possum_pem) < $(possum_zip) > $(possum_crx)

git_tag_release:
today=$$(date '+%Y.%-m.%-d'); \
manifest_version=$$(jq ".version" src/manifest.json); \
if [ $${manifest_version} != "\"$${today}\"" ]; then \
echo "bad version in manifest.json change $${manifest_version} to \"$${today}\""; \
exit 1;\
fi; \
echo "tagging version: \"$${today}\""; \
git tag $${today}

release: clean git_tag_release possum.zip possum.crx

.PHONY: test_node test_selenium npm_install_node npm_install_selenium psl release
.PHONY: clean test_node test_selenium npm_install_node npm_install_selenium psl release
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pushd ${src_dir} > /dev/null
trap "popd > /dev/null" EXIT

echo "packaging extension to: ${out_file}"
git ls-files | zip -q ${out_file} -@
git ls-files | zip -q -9 -X ${out_file} -@
24 changes: 24 additions & 0 deletions src/js/browser_compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

[(function(exports) {

const shim = require('./shim');

/*
* Firefox & Chrome now take different values in opt_extraInfoSpec
*/
function getOnBeforeRequestOptions({OnBeforeRequestOptions} = shim) {
return ["BLOCKING"].map(x => OnBeforeRequestOptions[x]).filter(x => x);
}

function getOnBeforeSendHeadersOptions({OnBeforeSendHeadersOptions} = shim) {
return ["BLOCKING", "REQUEST_HEADERS", "REQUESTHEADERS", "EXTRA_HEADERS"].map(x => OnBeforeSendHeadersOptions[x]).filter(x => x);
}

function getOnHeadersReceivedOptions({OnHeadersReceivedOptions} = shim) {
return ["BLOCKING", "RESPONSE_HEADERS", "RESPONSEHEADERS", "EXTRA_HEADERS"].map(x => OnHeadersReceivedOptions[x]).filter(x => x);
}

Object.assign(exports, {getOnBeforeRequestOptions, getOnBeforeSendHeadersOptions, getOnHeadersReceivedOptions});

})].map(func => typeof exports == 'undefined' ? define('/browser_compat', func) : func(exports));
1 change: 1 addition & 0 deletions src/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.1",
"crx3-utils": "0.0.3",
"eslint": "^4.19.1",
"jsdom": "^11.10.0",
"mocha": "^4.1.0",
Expand Down
9 changes: 9 additions & 0 deletions src/js/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ let shims = [
['onBeforeSendHeaders', 'chrome.webRequest.onBeforeSendHeaders', passThru, makeFakeMessages],
['onHeadersReceived', 'chrome.webRequest.onHeadersReceived', passThru, makeFakeMessages],
['onCompleted', 'chrome.webRequest.onCompleted', passThru, makeFakeMessages],
['OnBeforeRequestOptions', 'chrome.webRequest.OnBeforeRequestOptions', passThru, () => {
return {'BLOCKING': 'blocking'};
}],
['OnBeforeSendHeadersOptions', 'chrome.webRequest.OnBeforeSendHeadersOptions', passThru, () => {
return {'BLOCKING': 'blocking', 'REQUEST_HEADERS': "requestHeaders"};
}],
['OnHeadersReceivedOptions', 'chrome.webRequest.OnHeadersReceivedOptions', passThru, ()=> {
return {'BLOCKING': 'blocking', 'RESPONSE_HEADERS': "responseHeaders"};
}],
['onRemoved', 'chrome.tabs.onRemoved', passThru, makeFakeMessages],
['onActivated', 'chrome.tabs.onActivated', passThru, makeFakeMessages],
['onUpdated', 'chrome.tabs.onUpdated', passThru, makeFakeMessages],
Expand Down
9 changes: 6 additions & 3 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const shim = require('./shim'), {URL} = shim,
constants = require('./constants'),
{header_methods, request_methods} = constants,
{ON_BEFORE_REQUEST, ON_BEFORE_SEND_HEADERS, ON_HEADERS_RECEIVED} = request_methods,
{getOnBeforeRequestOptions, getOnBeforeSendHeadersOptions, getOnHeadersReceivedOptions} = require('./browser_compat'),
{Handler} = require('./reasons/handlers');

function annotateDetails(details, requestType) {
Expand All @@ -17,6 +18,7 @@ function annotateDetails(details, requestType) {
});
}


class WebRequest {
constructor(tabs, store, handler = new Handler(tabs, store)) {
Object.assign(this, {tabs, store, handler});
Expand All @@ -25,22 +27,23 @@ class WebRequest {
}

startListeners({onBeforeRequest, onBeforeSendHeaders, onHeadersReceived} = shim) {

onBeforeRequest.addListener(
this.onBeforeRequest.bind(this),
{urls: ["<all_urls>"]},
["blocking"],
getOnBeforeRequestOptions(),
);

onBeforeSendHeaders.addListener(
this.onBeforeSendHeaders.bind(this),
{urls: ["<all_urls>"]},
["blocking", "requestHeaders", "extraHeaders"],
getOnBeforeSendHeadersOptions(),
);

onHeadersReceived.addListener(
this.onHeadersReceived.bind(this),
{urls: ["<all_urls>"]},
["blocking", "responseHeaders", "extraHeaders"],
getOnHeadersReceivedOptions(),
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2018.8.31",
"version": "2019.7.8",
"name": "Privacy Possum",
"author": "[email protected]",
"manifest_version": 2,
Expand Down Expand Up @@ -64,6 +64,7 @@

"js/schemes.js",

"js/browser_compat.js",
"js/webrequest.js",
"js/store.js",
"js/popup.js",
Expand Down

0 comments on commit ad7ee92

Please sign in to comment.