From 5d06019b197cfa9ce3644d710f8ac18fa1d20289 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 7 Apr 2015 03:22:10 -0600 Subject: [PATCH] Add support for Chrome 22; fixes #1174 --- platform/chromium/manifest.json | 5 +---- platform/chromium/vapi-background.js | 26 ++++++++++++++++++++++++++ platform/chromium/vapi-client.js | 14 ++++++++++++++ src/js/profiler.js | 3 +++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 7a27c63ae..11dcb1182 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -12,10 +12,7 @@ }, "browser_action": { - "default_icon": { - "19": "img/browsericons/icon19-off.png", - "38": "img/browsericons/icon38-off.png" - }, + "default_icon": "img/browsericons/icon19-off.png", "default_title": "uBlock", "default_popup": "popup.html" }, diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index d0059477a..9b0399d9c 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -49,6 +49,20 @@ vAPI.app = { /******************************************************************************/ +if (!chrome.runtime) { + // Chrome 20-21 + chrome.runtime = chrome.extension; +} +else if(!chrome.runtime.onMessage) { + // Chrome 22-25 + chrome.runtime.onMessage = chrome.extension.onMessage; + chrome.runtime.sendMessage = chrome.extension.sendMessage; + chrome.runtime.onConnect = chrome.extension.onConnect; + chrome.runtime.connect = chrome.extension.connect; +} + +/******************************************************************************/ + vAPI.app.restart = function() { chrome.runtime.reload(); }; @@ -711,6 +725,18 @@ vAPI.onLoadAllCompleted = function() { } }; + var iconPaths = { '19': 'img/browsericons/icon19-off.png', + '38': 'img/browsericons/icon38-off.png' }; + try { + chrome.browserAction.setIcon({ path: iconPaths }); // Hello? Is this a recent version of Chrome? + } + catch(e) { + chrome.browserAction._setIcon = chrome.browserAction.setIcon; // Nope; looks like older than v23 + chrome.browserAction.setIcon = function(x, clbk){ // Shim + this._setIcon({path: x.path[19]}, clbk); + }; + chrome.browserAction.setIcon({ path: iconPaths }); /* maybe this time... I'll win! */ + }; chrome.tabs.query({ url: 'http://*/*' }, bindToTabs); chrome.tabs.query({ url: 'https://*/*' }, bindToTabs); }; diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index b8b46e311..aaba74777 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -48,6 +48,20 @@ vAPI.chrome = true; /******************************************************************************/ +if (!chrome.runtime) { + // Chrome 20-21 + chrome.runtime = chrome.extension; +} +else if(!chrome.runtime.onMessage) { + // Chrome 22-25 + chrome.runtime.onMessage = chrome.extension.onMessage; + chrome.runtime.sendMessage = chrome.extension.sendMessage; + chrome.runtime.onConnect = chrome.extension.onConnect; + chrome.runtime.connect = chrome.extension.connect; +} + +/******************************************************************************/ + var messagingConnector = function(response) { if ( !response ) { return; diff --git a/src/js/profiler.js b/src/js/profiler.js index 7b5a634df..968288aa0 100644 --- a/src/js/profiler.js +++ b/src/js/profiler.js @@ -27,6 +27,9 @@ var quickProfiler = (function() { 'use strict'; var timer = window.performance || Date; + if(typeof timer.now === "undefined") { + timer.now = timer.webkitNow; + } var time = 0; var count = 0; var tstart = 0;