diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index eafc1a0a2..de7147293 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -46,6 +46,10 @@ vAPI.chrome = true; /******************************************************************************/ +vAPI.setTimeout = vAPI.setTimeout || self.setTimeout.bind(self); + +/******************************************************************************/ + vAPI.shutdown = (function() { var jobs = []; diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index d67f41996..0ddc7f486 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -30,10 +30,12 @@ 'use strict'; -self.vAPI = self.vAPI || {}; - +var vAPI = self.vAPI = self.vAPI || {}; var chrome = self.chrome; -var vAPI = self.vAPI; + +/******************************************************************************/ + +vAPI.setTimeout = vAPI.setTimeout || self.setTimeout.bind(self); /******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 96af96e79..ce7ce51b7 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -747,7 +747,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) { ); if ( typeof callback === 'function' ) { - setTimeout(callback, 13); + vAPI.setTimeout(callback, 13); } }; @@ -1568,7 +1568,7 @@ vAPI.toolbarButton.init = function() { } // Anonymous elements need some time to be reachable - setTimeout(this.updateBadgeStyle, 250); + vAPI.setTimeout(this.updateBadgeStyle, 250); }.bind(this.CUIEvents); // https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm#Listeners @@ -1602,7 +1602,7 @@ vAPI.toolbarButton.init = function() { this.onCreated = function(button) { button.setAttribute('badge', ''); - setTimeout(updateBadge, 250); + vAPI.setTimeout(updateBadge, 250); }; CustomizableUI.addListener(this.CUIEvents); @@ -1668,7 +1668,7 @@ vAPI.toolbarButton.onBeforeCreated = function(doc) { return; } - updateTimer = setTimeout(resizePopup, 10); + updateTimer = vAPI.setTimeout(resizePopup, 10); }; var resizePopup = function() { updateTimer = null; diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index f33234bf5..07e1ae65e 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -38,6 +38,12 @@ vAPI.sessionId = String.fromCharCode(Date.now() % 25 + 97) + /******************************************************************************/ +vAPI.setTimeout = vAPI.setTimeout || function(callback, delay) { + setTimeout(function() { callback(); }, delay); +}; + +/******************************************************************************/ + vAPI.shutdown = (function() { var jobs = []; diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index c84d2813e..fbd9cd75c 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -36,7 +36,13 @@ const {Services} = Components.utils.import( null ); -self.vAPI = self.vAPI || {}; +var vAPI = self.vAPI = self.vAPI || {}; + +/******************************************************************************/ + +vAPI.setTimeout = vAPI.setTimeout || function(callback, delay) { + setTimeout(function() { callback(); }, delay); +}; /******************************************************************************/ diff --git a/src/js/assets.js b/src/js/assets.js index d1ddb61b0..8a7e8a485 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -1352,7 +1352,7 @@ var scheduleUpdateDaemon = function() { if ( updateDaemonTimer !== null ) { clearTimeout(updateDaemonTimer); } - updateDaemonTimer = setTimeout( + updateDaemonTimer = vAPI.setTimeout( updateDaemon, exports.manualUpdate ? manualUpdateDaemonTimerPeriod : autoUpdateDaemonTimerPeriod ); diff --git a/src/js/async.js b/src/js/async.js index b30678c18..9debc58a2 100644 --- a/src/js/async.js +++ b/src/js/async.js @@ -88,7 +88,7 @@ AsyncJobManager.prototype.restartTimer = function() { if ( when < this.timerWhen ) { clearTimeout(this.timerId); this.timerWhen = when; - this.timerId = setTimeout(processJobs, Math.max(when - Date.now(), 10)); + this.timerId = vAPI.setTimeout(processJobs, Math.max(when - Date.now(), 10)); } }; @@ -198,6 +198,6 @@ return asyncJobManager; if ( vAPI.isBehindTheSceneTabId(tabId) ) { return; } - tabIdToTimer[tabId] = setTimeout(updateBadge.bind(this, tabId), 500); + tabIdToTimer[tabId] = vAPI.setTimeout(updateBadge.bind(this, tabId), 500); }; })(); diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 282056dcf..5ee01dff3 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -206,7 +206,7 @@ var uBlockCollapser = (function() { clearTimeout(timer); send(); } else if ( timer === null ) { - timer = setTimeout(send, delay || 20); + timer = vAPI.setTimeout(send, delay || 20); } }; @@ -599,7 +599,7 @@ var uBlockCollapser = (function() { if ( processHighHighGenericsTimer !== null ) { clearTimeout(processHighHighGenericsTimer); } - processHighHighGenericsTimer = setTimeout(processHighHighGenerics, 300); + processHighHighGenericsTimer = vAPI.setTimeout(processHighHighGenerics, 300); }; // Extract all ids: these will be passed to the cosmetic filtering @@ -739,7 +739,7 @@ var uBlockCollapser = (function() { // I arbitrarily chose 100 ms for now: // I have to compromise between the overhead of processing too few // nodes too often and the delay of many nodes less often. - addedNodeListsTimer = setTimeout(treeMutationObservedHandler, 100); + addedNodeListsTimer = vAPI.setTimeout(treeMutationObservedHandler, 100); } }; diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 47834d4a2..98abdd891 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -1012,7 +1012,7 @@ FilterContainer.prototype.triggerSelectorCachePruner = function() { } // Of interest: http://fitzgeraldnick.com/weblog/40/ // http://googlecode.blogspot.ca/2009/07/gmail-for-mobile-html5-series-using.html - this.selectorCacheTimer = setTimeout( + this.selectorCacheTimer = vAPI.setTimeout( this.pruneSelectorCacheAsync.bind(this), this.selectorCachePruneDelay ); diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index 2690762c9..b1890305f 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -460,7 +460,7 @@ var onLogBufferRead = function(response) { tbody.querySelector('tr') === null ); - setTimeout(readLogBuffer, 1200); + vAPI.setTimeout(readLogBuffer, 1200); }; /******************************************************************************/ @@ -640,7 +640,7 @@ var rowFilterer = (function() { if ( timer !== null ) { clearTimeout(timer); } - timer = setTimeout(commit, 750); + timer = vAPI.setTimeout(commit, 750); }; })(); diff --git a/src/js/logger.js b/src/js/logger.js index 937bacb04..2da5757d2 100644 --- a/src/js/logger.js +++ b/src/js/logger.js @@ -164,7 +164,7 @@ var janitor = function() { logBuffer = logBuffer.dispose(); } if ( logBuffer !== null ) { - setTimeout(janitor, logBufferObsoleteAfter); + vAPI.setTimeout(janitor, logBufferObsoleteAfter); } }; @@ -181,7 +181,7 @@ var writeOne = function() { var readAll = function() { if ( logBuffer === null ) { logBuffer = new LogBuffer(); - setTimeout(janitor, logBufferObsoleteAfter); + vAPI.setTimeout(janitor, logBufferObsoleteAfter); } return logBuffer.readAll(); }; diff --git a/src/js/mirrors.js b/src/js/mirrors.js index 515abac67..d574b1751 100644 --- a/src/js/mirrors.js +++ b/src/js/mirrors.js @@ -332,7 +332,7 @@ var updateMetadataNow = function() { var updateMetadataAsync = function() { if ( metadataPersistTimer === null ) { - metadataPersistTimer = setTimeout(updateMetadata, 60 * 1000); + metadataPersistTimer = vAPI.setTimeout(updateMetadata, 60 * 1000); } }; diff --git a/src/js/pagestore.js b/src/js/pagestore.js index a2378e30a..690f3da9e 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -200,7 +200,7 @@ NetFilteringResultCache.prototype.prune = function() { NetFilteringResultCache.prototype.pruneAsync = function() { if ( this.timer === null ) { - this.timer = setTimeout(this.boundPruneAsyncCallback, this.shelfLife * 2); + this.timer = vAPI.setTimeout(this.boundPruneAsyncCallback, this.shelfLife * 2); } }; diff --git a/src/js/popup.js b/src/js/popup.js index c5967ab29..0bbb8d216 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -744,7 +744,7 @@ var pollForContentChange = (function() { if ( pollTimer !== null ) { return; } - pollTimer = setTimeout(pollCallback, 1500); + pollTimer = vAPI.setTimeout(pollCallback, 1500); }; return poll; diff --git a/src/js/tab.js b/src/js/tab.js index c07ac0512..4a52634d3 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -165,7 +165,7 @@ housekeep itself. TabContext.prototype.onTab = function(tab) { if ( tab ) { - this.timer = setTimeout(this.onTimerCallback, gcPeriod); + this.timer = vAPI.setTimeout(this.onTimerCallback, gcPeriod); } else { this.destroy(); } @@ -188,7 +188,7 @@ housekeep itself. } this.onTabCallback = this.onTab.bind(this); this.onTimerCallback = this.onTimer.bind(this); - this.timer = setTimeout(this.onTimerCallback, gcPeriod); + this.timer = vAPI.setTimeout(this.onTimerCallback, gcPeriod); }; // Update just force all properties to be updated to match the most current @@ -593,7 +593,7 @@ vAPI.tabs.registerListeners(); return false; } tabIdToTryCount[tabId] = count - 1; - tabIdToTimer[tabId] = setTimeout(updateTitle.bind(µb, tabId), delay); + tabIdToTimer[tabId] = vAPI.setTimeout(updateTitle.bind(µb, tabId), delay); return true; }; @@ -624,7 +624,7 @@ vAPI.tabs.registerListeners(); if ( tabIdToTimer[tabId] ) { clearTimeout(tabIdToTimer[tabId]); } - tabIdToTimer[tabId] = setTimeout(updateTitle.bind(this, tabId), delay); + tabIdToTimer[tabId] = vAPI.setTimeout(updateTitle.bind(this, tabId), delay); tabIdToTryCount[tabId] = 5; }; })(); @@ -664,10 +664,10 @@ var pageStoreJanitor = function() { } pageStoreJanitorSampleAt = n; - setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); + vAPI.setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); }; -setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); +vAPI.setTimeout(pageStoreJanitor, pageStoreJanitorPeriod); /******************************************************************************/ diff --git a/src/js/ublock.js b/src/js/ublock.js index aa2c3f157..c8a4f31f8 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -372,7 +372,7 @@ var matchWhitelistDirective = function(url, hostname, directive) { if ( tabIdToTimerMap.hasOwnProperty(tabId) ) { return; } - tabIdToTimerMap[tabId] = setTimeout( + tabIdToTimerMap[tabId] = vAPI.setTimeout( injectNow.bind(null, tabId), 100 );