From a17882a8cc9e326877f0efe32925b42db47e15a1 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 10 Feb 2015 14:24:04 -0700 Subject: [PATCH] Remove previous Safari overhead; cleanup workarounds from rest of code --- platform/chromium/vapi-client.js | 8 +------ platform/firefox/vapi-client.js | 6 ------ platform/safari/vapi-background.js | 34 +++++++++++++++--------------- platform/safari/vapi-client.js | 6 +----- src/js/contentscript-end.js | 5 ----- src/js/contentscript-start.js | 6 ------ 6 files changed, 19 insertions(+), 46 deletions(-) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 9fd6a6e89..4b0f56256 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -150,12 +150,6 @@ vAPI.messaging = { /******************************************************************************/ -vAPI.canExecuteContentScript = function() { - return true; -}; - -/******************************************************************************/ - })(); -/******************************************************************************/ \ No newline at end of file +/******************************************************************************/ diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index 58bb110ca..c9caa85d4 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -166,12 +166,6 @@ window.addEventListener('pageshow', vAPI.messaging.toggleListener, true); /******************************************************************************/ -vAPI.canExecuteContentScript = function() { - return true; -}; - -/******************************************************************************/ - })(this); /******************************************************************************/ diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index f57edb8cb..1a417a4c7 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -32,7 +32,6 @@ var vAPI = self.vAPI = self.vAPI || {}; vAPI.safari = true; - var noopFunc = function(){}; /******************************************************************************/ @@ -349,22 +348,23 @@ if(details.file) { var xhr = new XMLHttpRequest(); - xhr.overrideMimeType('application/x-javascript;charset=utf-8'); - xhr.open('GET', details.file, false); + xhr.open('GET', details.file, true); + xhr.addEventListener("readystatechange", function() { + if(this.readyState === 4) { + details.code = xhr.responseText; + tab.page.dispatchMessage('broadcast', { + channelName: 'vAPI', + msg: { + cmd: 'injectScript', + details: details + } + }); + if(typeof callback === 'function') { + setTimeout(callback, 13); + } + } + }); xhr.send(); - details.code = xhr.responseText; - } - - tab.page.dispatchMessage('broadcast', { - channelName: 'vAPI', - msg: { - cmd: 'injectScript', - details: details - } - }); - - if(typeof callback === 'function') { - setTimeout(callback, 13); } }; @@ -488,7 +488,7 @@ vAPI.messaging = { listeners: {}, defaultHandler: null, - NOOPFUNC: noopFunc, + NOOPFUNC: function() {}, UNHANDLED: 'vAPI.messaging.notHandled' }; diff --git a/platform/safari/vapi-client.js b/platform/safari/vapi-client.js index fb5dbc4b0..e12b5a821 100644 --- a/platform/safari/vapi-client.js +++ b/platform/safari/vapi-client.js @@ -86,7 +86,7 @@ this.channels['vAPI'] = { listener: function(msg) { if(msg.cmd === 'injectScript' && msg.details.code) { - Function(msg.details.code).call(self); + Function(msg.details.code).call(self); } } }; @@ -146,10 +146,6 @@ } }; - vAPI.canExecuteContentScript = function() { - return (/^https?:/.test(location.protocol) && typeof safari === "object"); - }; - // The following code should run only in content pages if(location.protocol === "safari-extension:" || typeof safari !== "object") { return; diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index 232604ed5..cc383238d 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -42,11 +42,6 @@ if ( !vAPI ) { return; } -if ( vAPI.canExecuteContentScript() !== true ) { - //console.debug('contentscript-end.js > can\'t execute'); - return; -} - // https://github.com/gorhill/uBlock/issues/587 // Pointless to execute without the start script having done its job. if ( !vAPI.contentscriptStartInjected ) { diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 1e9e4d3ef..996b749f4 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -46,12 +46,6 @@ if ( !vAPI ) { return; } -// Because Safari -if ( vAPI.canExecuteContentScript() !== true ) { - //console.debug('contentscript-start.js > can\'t execute'); - return; -} - // https://github.com/gorhill/uBlock/issues/456 // Already injected? if ( vAPI.contentscriptStartInjected ) {