diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-10-17 18:10:23 +0200 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-10-17 18:10:23 +0200 |
commit | ea0c3f8ecde7d6e418ddfc8c6f58cb2bbf1e84c7 (patch) | |
tree | f5f542e168df6b8da261ee0d95476a254fff9139 /platform/firefox/vapi-client.js | |
parent | 2a260e13033aa80f474f3c7ca2f7f4ca4aec2f54 (diff) | |
parent | 230639d959468fc67c7ca5cf0249009eee0853b8 (diff) | |
download | uBlock-ea0c3f8ecde7d6e418ddfc8c6f58cb2bbf1e84c7.zip uBlock-ea0c3f8ecde7d6e418ddfc8c6f58cb2bbf1e84c7.tar.gz uBlock-ea0c3f8ecde7d6e418ddfc8c6f58cb2bbf1e84c7.tar.bz2 |
Merge branch 'upstream'
Diffstat (limited to 'platform/firefox/vapi-client.js')
-rw-r--r-- | platform/firefox/vapi-client.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index bd6facd..b8715e8 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -31,6 +31,13 @@ /******************************************************************************/ +// Not all sandboxes are given an rpc function, so assign a dummy one if it is +// missing -- this avoids the need for testing before use. + +self.rpc = self.rpc || function(){}; + +/******************************************************************************/ + var vAPI = self.vAPI = self.vAPI || {}; vAPI.firefox = true; vAPI.sessionId = String.fromCharCode(Date.now() % 26 + 97) + @@ -67,6 +74,30 @@ vAPI.shutdown = (function() { /******************************************************************************/ +(function() { + var hostname = location.hostname; + if ( !hostname ) { + return; + } + var filters = self.rpc({ + fnName: 'getScriptTagFilters', + url: location.href, + hostname: hostname + }); + if ( typeof filters !== 'string' || filters === '' ) { + return; + } + var reFilters = new RegExp(filters); + document.addEventListener('beforescriptexecute', function(ev) { + if ( reFilters.test(ev.target.textContent) ) { + ev.preventDefault(); + ev.stopPropagation(); + } + }); +})(); + +/******************************************************************************/ + vAPI.messaging = { channels: {}, pending: {}, @@ -254,6 +285,12 @@ MessagingChannel.prototype.send = function(message, callback) { MessagingChannel.prototype.sendTo = function(message, toTabId, toChannel, callback) { var messaging = vAPI.messaging; + if ( !messaging ) { + if ( typeof callback === 'function' ) { + callback(); + } + return; + } // Too large a gap between the last request and the last response means // the main process is no longer reachable: memory leaks and bad // performance become a risk -- especially for long-lived, dynamic |