From b4fe1f1fa6064162adfa7b6eee5f397f190ae8bf Mon Sep 17 00:00:00 2001 From: ispedals Date: Sat, 18 Jun 2016 19:42:00 -0400 Subject: Add polyfills for Gecko's WebExtension implementation Gecko currently does not support chrome.storage.sync and chrome.runtime.onInstalled. Use chrome.storage.local instead of sync and ignore calls to onInstalled. The implication of not having runtime.onInstalled is that the options page is not shown on first-run. --- ext/bg/js/polyfill-gecko.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ext/bg/js/polyfill-gecko.js (limited to 'ext/bg/js') diff --git a/ext/bg/js/polyfill-gecko.js b/ext/bg/js/polyfill-gecko.js new file mode 100644 index 00000000..8c7cc403 --- /dev/null +++ b/ext/bg/js/polyfill-gecko.js @@ -0,0 +1,15 @@ +// Gecko does not currently support chrome.storage.sync, use storage.local instead +// https://bugzilla.mozilla.org/show_bug.cgi?id=1220494 +if (!chrome.storage.sync) { + chrome.storage.sync = chrome.storage.local; +} + +// Gecko does not currently support chrome.runtime.onInstalled, just ignore calls to it +// (https://bugzilla.mozilla.org/show_bug.cgi?id=1252871) +if (!chrome.runtime.onInstalled) { + chrome.runtime.onInstalled = { + 'addListener' : function(){}, + 'hasListener' : function(){}, + 'removeListener' : function(){} + }; +} \ No newline at end of file -- cgit v1.2.3 From 5e0ac4e8ea32c3e33de38db02d7dcbebfdd05cda Mon Sep 17 00:00:00 2001 From: ispedals Date: Sat, 18 Jun 2016 18:33:51 -0400 Subject: Workaround spidermonkey bug so dictionary data loads We need to make a copy of the iteration variable in the for-of loop so that the distinct values are available in the callback. --- ext/bg/js/translator.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ext/bg/js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index bf1538e2..261196d2 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -46,8 +46,17 @@ class Translator { const pendingLoads = []; for (let key of files) { + /* + Spidermonkey does not implement lexical bindings for for-of loop + (see https://bugzilla.mozilla.org/show_bug.cgi?id=449811) + so we need to manually make a new declaration for key. + Otherwise key will always remain the same in the callback to loadData + and the dictionary data will not be set correctly + */ + let key_ = key; pendingLoads.push(key); Translator.loadData(this.paths[key], (response) => { + let key = key_ switch (key) { case 'rules': this.deinflector.setRules(JSON.parse(response)); -- cgit v1.2.3 From 28de6a4d6ecac9dade41f511c426fc16a443c537 Mon Sep 17 00:00:00 2001 From: ispedals Date: Sat, 18 Jun 2016 18:29:49 -0400 Subject: Add mimetype to XHR call This silences warnings about the JSON files being ill-formed --- ext/bg/js/translator.js | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/bg/js') diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 261196d2..d79ec6d1 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -237,6 +237,7 @@ class Translator { static loadData(url, callback) { const xhr = new XMLHttpRequest(); + xhr.overrideMimeType("application/json"); xhr.addEventListener('load', () => callback(xhr.responseText)); xhr.open('GET', chrome.extension.getURL(url), true); xhr.send(); -- cgit v1.2.3