From f17ad2f1a5e5245ac8f94f51965f4695d3b9da76 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Tue, 16 Dec 2014 22:31:03 +0100 Subject: [PATCH] Firefox: implement vAPI.tabs.injectScript --- platform/firefox/vapi-background.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 5814d50..92ff9d5 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -390,6 +390,11 @@ vAPI.tabs.get = function(tabId, callback) { } } + // for internal use + if (tab && callback === undefined) { + return tab; + } + if (!tab) { callback(); return; @@ -538,7 +543,27 @@ vAPI.tabs.close = function(tabIds) { /******************************************************************************/ vAPI.tabs.injectScript = function(tabId, details, callback) { + var tab = vAPI.tabs.get(tabId); + + if (!tab) { + return; + } + tab.linkedBrowser.messageManager.sendAsyncMessage( + vAPI.app.cleanName + ':broadcast', + JSON.stringify({ + broadcast: true, + portName: 'vAPI', + msg: { + cmd: 'injectScript', + details: details + } + }) + ); + + if (typeof callback === 'function') { + setTimeout(callback, 13); + } }; /******************************************************************************/ @@ -566,7 +591,8 @@ vAPI.setIcon = function(tabId, img, badge) { var button = curWin.document.getElementById(vAPI.toolbarButton.widgetId); var icon = vAPI.tabIcons[tabId]; button.setAttribute('badge', icon && icon.badge || ''); - button.style.listStyleImage = 'url(' + vAPI.getURL(icon && icon.img || 'img/browsericons/icon16-off.svg') + ')'; + icon = vAPI.getURL(icon && icon.img || 'img/browsericons/icon16-off.svg'); + button.style.listStyleImage = 'url(' + icon + ')'; }; /******************************************************************************/