diff options
author | Jesús <heckyel@hyperbola.info> | 2019-12-30 15:55:13 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-12-30 15:55:13 -0500 |
commit | 288df6a7bf8b933e2dc499e38f4915fcf974c14b (patch) | |
tree | 77bba994f260c064d3ee7f76c427ddfaa4f91710 /js/vapi-background.js | |
parent | a2c9deaa145b780722e93b3899600f287c8094a4 (diff) | |
download | ematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.tar.lz ematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.tar.xz ematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.zip |
backport
- Flush caches on upgrade
- Properly handle FrameModule's unloading
- Use the new module and remove the old implementation
Diffstat (limited to 'js/vapi-background.js')
-rw-r--r-- | js/vapi-background.js | 112 |
1 files changed, 20 insertions, 92 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js index 7686bc9..e5e6998 100644 --- a/js/vapi-background.js +++ b/js/vapi-background.js @@ -22,7 +22,7 @@ */ /* jshint bitwise: false, esnext: true */ -/* global self, Components, punycode */ +/* global self, Components */ // For background page @@ -31,7 +31,9 @@ /******************************************************************************/ (function () { - Cu.import('chrome://ematrix/content/HttpRequestHeaders.jsm'); + Cu.import('chrome://ematrix/content/lib/HttpRequestHeaders.jsm'); + Cu.import('chrome://ematrix/content/lib/PendingRequests.jsm'); + Cu.import('chrome://ematrix/content/lib/Punycode.jsm'); // Icon-related stuff vAPI.setIcon = function (tabId, iconId, badge) { @@ -134,8 +136,6 @@ return this.QueryInterface(iid); }, register: function () { - this.pendingRingBufferInit(); - Services.obs.addObserver(this, 'http-on-modify-request', true); Services.obs.addObserver(this, 'http-on-examine-response', true); Services.obs.addObserver(this, 'http-on-examine-cached-response', true); @@ -174,82 +174,6 @@ this.contractID, false); }, - PendingRequest: function () { - this.rawType = 0; - this.tabId = 0; - this._key = ''; // key is url, from URI.spec - }, - // If all work fine, this map should not grow indefinitely. It - // can have stale items in it, but these will be taken care of - // when entries in the ring buffer are overwritten. - pendingURLToIndex: new Map(), - pendingWritePointer: 0, - pendingRingBuffer: new Array(256), - pendingRingBufferInit: function () { - // Use and reuse pre-allocated PendingRequest objects = - // less memory churning. - for (let i=this.pendingRingBuffer.length-1; i>=0; --i) { - this.pendingRingBuffer[i] = new this.PendingRequest(); - } - }, - createPendingRequest: function (url) { - // Pending request ring buffer: - // +-------+-------+-------+-------+-------+-------+------- - // |0 |1 |2 |3 |4 |5 |... - // +-------+-------+-------+-------+-------+-------+------- - // - // URL to ring buffer index map: - // { k = URL, s = ring buffer indices } - // - // s is a string which character codes map to ring buffer - // indices -- for when the same URL is received multiple times - // by shouldLoadListener() before the existing one is serviced - // by the network request observer. I believe the use of a - // string in lieu of an array reduces memory churning. - let bucket; - let i = this.pendingWritePointer; - this.pendingWritePointer = i + 1 & 255; - - let preq = this.pendingRingBuffer[i]; - let si = String.fromCharCode(i); - - // Cleanup unserviced pending request - if (preq._key !== '') { - bucket = this.pendingURLToIndex.get(preq._key); - if (bucket.length === 1) { - this.pendingURLToIndex.delete(preq._key); - } else { - let pos = bucket.indexOf(si); - this.pendingURLToIndex.set(preq._key, - bucket.slice(0, pos) - + bucket.slice(pos + 1)); - } - } - - bucket = this.pendingURLToIndex.get(url); - this.pendingURLToIndex.set(url, bucket === undefined - ? si - : bucket + si); - preq._key = url; - return preq; - }, - lookupPendingRequest: function (url) { - let bucket = this.pendingURLToIndex.get(url); - if (bucket === undefined) { - return null; - } - - let i = bucket.charCodeAt(0); - if (bucket.length === 1) { - this.pendingURLToIndex.delete(url); - } else { - this.pendingURLToIndex.set(url, bucket.slice(1)); - } - - let preq = this.pendingRingBuffer[i]; - preq._key = ''; // mark as "serviced" - return preq; - }, handleRequest: function (channel, URI, tabId, rawType) { let type = this.typeMap[rawType] || 'other'; @@ -460,7 +384,8 @@ // The channel was never serviced. let tabId; - let pendingRequest = this.lookupPendingRequest(URI.asciiSpec); + let pendingRequest = + PendingRequestBuffer.lookupRequest(URI.asciiSpec); let rawType = 1; let loadInfo = channel.loadInfo; @@ -540,12 +465,7 @@ codePath: '' }; - // Non-Fennec: common code paths. (function () { - if (vAPI.fennec) { - return; - } - let tbb = vAPI.toolbarButton; let popupCommittedWidth = 0; let popupCommittedHeight = 0; @@ -571,8 +491,16 @@ button.setAttribute('badge', icon && icon.badge || ''); button.classList.toggle('off', !icon || !icon.img); - let iconId = icon && icon.img ? icon.img : 'off'; - icon = 'url(' + vAPI.getURL('img/browsericons/icon19-' + iconId + '.png') + ')'; + let iconId = (ηMatrix.userSettings.disableUpdateIcon) ? + icon && icon.img ? '19' : 'off' : + icon && icon.img ? icon.img : 'off'; + + icon = 'url(' + + vAPI.getURL('img/browsericons/icon19-' + + iconId + + '.png') + + ')'; + button.style.listStyleImage = icon; }; @@ -814,12 +742,12 @@ // Found our button on this toolbar - but where on it? let before = null; - for (let i = index+1; i<currentset.length; ++i) { + for (let i=index+1; i<currentset.length; ++i) { // The [id=...] notation doesn't work on // space elements as they get a random ID each session // (or something like that) - // https://libregit.org/heckyel/ematrix/issues/5 - // https://libregit.org/heckyel/ematrix/issues/6 + // https://gitlab.com/vannilla/ematrix/issues/5 + // https://gitlab.com/vannilla/ematrix/issues/6 // Based on JustOff's snippet from the Pale Moon // forum. It was reorganized because I find it @@ -1246,7 +1174,7 @@ // Likelihood is that we do not have to punycode: given punycode overhead, // it's faster to check and skip than do it unconditionally all the time. - var punycodeHostname = punycode.toASCII; + var punycodeHostname = Punycode.toASCII; var isNotASCII = /[^\x21-\x7F]/; vAPI.punycodeHostname = function (hostname) { |