From 7501447cace6832ee8b8423689ac989cc914bcdc Mon Sep 17 00:00:00 2001 From: Manuel Reimer Date: Thu, 8 Oct 2015 19:15:00 +0200 Subject: [PATCH] Added basic Thunderbird support --- platform/firefox/install.rdf | 9 +++++++++ platform/firefox/vapi-background.js | 26 ++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/platform/firefox/install.rdf b/platform/firefox/install.rdf index c0332ff3e..07b107fdf 100644 --- a/platform/firefox/install.rdf +++ b/platform/firefox/install.rdf @@ -59,5 +59,14 @@ 9.9 + + + + + {{3550f703-e582-4d05-9a08-453d09bdfdc6}} + 38.3 + 45.0 + + diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 8bc110b15..d8a528d11 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -40,6 +40,7 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null); var vAPI = self.vAPI = self.vAPI || {}; vAPI.firefox = true; vAPI.fennec = Services.appinfo.ID === '{aa3c5121-dab2-40e2-81ca-7ea25febc110}'; +vAPI.thunderbird = Services.appinfo.ID === '{3550f703-e582-4d05-9a08-453d09bdfdc6}'; /******************************************************************************/ @@ -524,7 +525,10 @@ vAPI.storage = (function() { /******************************************************************************/ var getTabBrowser = function(win) { - return vAPI.fennec && win.BrowserApp || win.gBrowser || null; + return vAPI.fennec && win.BrowserApp || + vAPI.thunderbird && win.document.getElementById('tabmail') || + win.gBrowser || + null; }; /******************************************************************************/ @@ -729,7 +733,7 @@ vAPI.tabs.open = function(details) { } } - var win = Services.wm.getMostRecentWindow('navigator:browser'); + var win = Services.wm.getMostRecentWindow(vAPI.thunderbird && 'mail:3pane' || 'navigator:browser'); var tabBrowser = getTabBrowser(win); if ( vAPI.fennec ) { @@ -750,6 +754,12 @@ vAPI.tabs.open = function(details) { return; } + if ( vAPI.thunderbird ) { + tabBrowser.openTab('contentTab', { contentPage: details.url, background: !details.active }); + // TODO: Should be possible to move tabs on Thunderbird + return; + } + if ( details.index === -1 ) { details.index = tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1; } @@ -876,6 +886,9 @@ var tabWatcher = (function() { var tabIdGenerator = 1; var indexFromBrowser = function(browser) { + if (vAPI.thunderbird) // TODO: Add support for this + return -1; + var win = getOwnerWindow(browser); if ( !win ) { return -1; @@ -966,13 +979,18 @@ var tabWatcher = (function() { }; var currentBrowser = function() { - var win = Services.wm.getMostRecentWindow('navigator:browser'); + var win = Services.wm.getMostRecentWindow(vAPI.thunderbird && 'mail:3pane' || 'navigator:browser'); // https://github.com/gorhill/uBlock/issues/399 // getTabBrowser() can return null at browser launch time. var tabBrowser = getTabBrowser(win); if ( tabBrowser === null ) { return null; } + if (vAPI.thunderbird) { + // Directly at startup the first tab may not be initialized + if (tabBrowser.tabInfo.length == 0) return null; + return tabBrowser.getBrowserForSelectedTab(); + } return browserFromTarget(tabBrowser.selectedTab); }; @@ -1186,7 +1204,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) { // If badge is undefined, then setIcon was called from the TabSelect event var win = badge === undefined ? iconStatus - : Services.wm.getMostRecentWindow('navigator:browser'); + : vAPI.thunderbird && Services.wm.getMostRecentWindow('mail:3pane') || Services.wm.getMostRecentWindow('navigator:browser'); var curTabId = tabWatcher.tabIdFromTarget(getTabBrowser(win).selectedTab); var tb = vAPI.toolbarButton;