aboutsummaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2018-09-02 00:15:48 +0200
committerhackademix <giorgio@maone.net>2018-09-02 00:15:48 +0200
commit35daafa5e5f7d094698933816e812d666c739982 (patch)
tree03280a9297394d35ecdd2ab66d9ce7e480fd44fb /content
parentf6bf59a4ed44ec7323a76b11317f715c929a69b4 (diff)
Fixed weblabels not being checked in whitelisted documents unless they precede scripts.
Diffstat (limited to 'content')
-rw-r--r--content/externalLicenseChecker.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/content/externalLicenseChecker.js b/content/externalLicenseChecker.js
index f150cea..be09ef1 100644
--- a/content/externalLicenseChecker.js
+++ b/content/externalLicenseChecker.js
@@ -22,12 +22,12 @@
{
let licensedScripts = null;
- let fetchWebLabels = async (map = new Map()) => {
+ let fetchWebLabels = async args => {
// see https://www.gnu.org/software/librejs/free-your-javascript.html#step3
-
+ let {map, cache} = args;
let link = document.querySelector(`link[rel="jslicense"], link[data-jslicense="1"], a[rel="jslicense"], a[data-jslicense="1"]`);
- if (link) try {
- let baseURL = link.href;
+ let baseURL = link ? link.href : cache.webLabels && new URL(cache.webLabels.href, document.baseURI);
+ if (baseURL) try {
let response = await fetch(baseURL);
if (!response.ok) throw `${response.status} ${response.statusText}`;
let doc = new DOMParser().parseFromString(
@@ -55,16 +55,16 @@
return map;
}
- let fetchLicenseInfo = async () => {
+ let fetchLicenseInfo = async cache => {
let map = new Map();
-
+ let args = {map, cache};
// in the fetchXxx methods we add to a map whatever license(s)
// URLs and source code references we can find in various formats
// (WebLabels is currently the only implementation), keyed by script URLs.
await Promise.all([
- fetchWebLabels(map),
- // fetchXmlSpdx(),
- // fetchTxtSpdx(),
+ fetchWebLabels(args),
+ // fetchXmlSpdx(args),
+ // fetchTxtSpdx(args),
// ...
]);
return map;
@@ -72,8 +72,8 @@
let handlers = {
async checkLicensedScript(m) {
- let {url} = m;
- if (!licensedScripts) licensedScripts = await fetchLicenseInfo();
+ let {url, cache} = m;
+ if (!licensedScripts) licensedScripts = await fetchLicenseInfo(cache);
return licensedScripts.get(url);
}
}
@@ -82,7 +82,6 @@
if (m.action in handlers) try {
debug("Received message", m);
let result = await handlers[m.action](m);
- console.debug("Returning", result);
return result;
} catch (e) {
console.error(e);