diff --git a/content/treestyletab/windowHelperHacks.js b/content/treestyletab/windowHelperHacks.js index 2df40006..f8c971a7 100644 --- a/content/treestyletab/windowHelperHacks.js +++ b/content/treestyletab/windowHelperHacks.js @@ -100,6 +100,7 @@ TreeStyleTabWindowHelper.overrideExtensionsBeforeBrowserInit = function TSTWH_ov TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_overrideExtensionsAfterBrowserInit() { var sv = this.service; + var { AddonManager } = Component.utils.import('resource://gre/modules/AddonManager.jsm', {}); // Selection Links // https://addons.mozilla.org/firefox/addon/selection-links/ @@ -244,11 +245,12 @@ TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_ove // Focus Last Selected Tab 0.9.5.x // http://www.gozer.org/mozilla/extensions/ if (TreeStyleTabUtils.getTreePref('compatibility.FocusLastSelectedTab')) { - sv.extensions.isAvailable('focuslastselectedtab@gozer.org', { ok : function() { - TreeStyleTabService.registerTabFocusAllowance(function(aTabBrowser) { - return !aTabBrowser.selectedTab.hasAttribute('lastselected'); - }); - }}); + AddonManager.getAddonById('focuslastselectedtab@gozer.org', function(aAddon) { + if (aAddon && aAddon.isAvailable) + TreeStyleTabService.registerTabFocusAllowance(function(aTabBrowser) { + return !aTabBrowser.selectedTab.hasAttribute('lastselected'); + }); + }); } // LastTab @@ -443,9 +445,10 @@ TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_ove // Remove New Tab Button // https://addons.mozilla.org/firefox/addon/remove-new-tab-button/ if (TreeStyleTabUtils.getTreePref('compatibility.RemoveNewTabButton')) { - sv.extensions.isAvailable('remove-new-tab-button@forerunnerdesigns.com', { ok : function() { - document.documentElement.setAttribute(TreeStyleTabService.kHIDE_NEWTAB, true); - }}); + AddonManager.getAddonById('remove-new-tab-button@forerunnerdesigns.com', function(aAddon) { + if (aAddon && aAddon.isAvailable) + document.documentElement.setAttribute(TreeStyleTabService.kHIDE_NEWTAB, true); + }); } // InstaClick @@ -554,13 +557,6 @@ TreeStyleTabWindowHelper.overrideExtensionsDelayed = function TSTWH_overrideExte var t = gBrowser.treeStyleTab.getFirstTab(gBrowser); gBrowser.treeStyleTab.initTabAttributes(t); gBrowser.treeStyleTab.initTabContentsOrder(t); - - gBrowser.__treestyletab__openInverseLink = gBrowser.openInverseLink; - gBrowser.openInverseLink = function(...aArgs) { - TreeStyleTabService.readyToOpenChildTabNow(gBrowser); - return this.__treestyletab__openInverseLink(...aArgs); - }; - gBrowser.treeStyleTab.internallyTabMovingCount--; } diff --git a/modules/base.js b/modules/base.js index 86ffed2e..0f50f59b 100644 --- a/modules/base.js +++ b/modules/base.js @@ -54,10 +54,6 @@ XPCOMUtils.defineLazyGetter(this, 'prefs', function() { Cu.import('resource://treestyletab-modules/lib/prefs.js'); return window['piro.sakura.ne.jp'].prefs; }); -XPCOMUtils.defineLazyGetter(this, 'extensions', function() { - Cu.import('resource://treestyletab-modules/lib/extensions.js', {}); - return window['piro.sakura.ne.jp'].extensions; -}); XPCOMUtils.defineLazyGetter(this, 'animationManager', function() { Cu.import('resource://treestyletab-modules/lib/animationManager.js', {}); return window['piro.sakura.ne.jp'].animationManager; @@ -117,7 +113,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { return SessionStore; }, - get extensions() { return extensions; }, get animationManager() { return animationManager; }, get autoScroll() { return autoScroll; }, get AeroPeek() { return AeroPeek; }, // for Windows diff --git a/modules/browser.js b/modules/browser.js index fe5f4712..da4980f5 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -50,6 +50,7 @@ Cu.import('resource://treestyletab-modules/ReferenceCounter.js'); XPCOMUtils.defineLazyModuleGetter(this, 'Services', 'resource://gre/modules/Services.jsm'); XPCOMUtils.defineLazyModuleGetter(this, 'Promise', 'resource://gre/modules/Promise.jsm'); +XPCOMUtils.defineLazyModuleGetter(this, 'AddonManager', 'resource://gre/modules/AddonManager.jsm'); XPCOMUtils.defineLazyModuleGetter(this, 'utils', 'resource://treestyletab-modules/utils.js', 'TreeStyleTabUtils'); XPCOMUtils.defineLazyModuleGetter(this, 'FullTooltipManager', 'resource://treestyletab-modules/fullTooltip.js'); XPCOMUtils.defineLazyModuleGetter(this, 'TabbarDNDObserver', 'resource://treestyletab-modules/tabbarDNDObserver.js'); @@ -2970,16 +2971,15 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { prefs.getPref('extensions.informationaltab.thumbnail.enabled') && prefs.getPref('extensions.informationaltab.thumbnail.position') < 100 ) { - let self = this; - this.extensions.isAvailable('informationaltab@piro.sakura.ne.jp', { - ok : function() { + AddonManager.getAddonByID('informationaltab@piro.sakura.ne.jp', (function(aAddon) { + if (aAddon) { aStyle = 'retro'; - self.setTabbrowserAttribute(self.kTWISTY_STYLE, aStyle); - }, - ng : function() { - self.setTabbrowserAttribute(self.kTWISTY_STYLE, aStyle); + this.setTabbrowserAttribute(this.kTWISTY_STYLE, aStyle); } - }); + else { + this.setTabbrowserAttribute(this.kTWISTY_STYLE, aStyle); + } + }).bind(this)); return; } diff --git a/modules/lib/extensions.js b/modules/lib/extensions.js deleted file mode 100644 index f06effa2..00000000 --- a/modules/lib/extensions.js +++ /dev/null @@ -1,161 +0,0 @@ -/* - Extensions Compatibility Library - - Usage: - var extensions = window['piro.sakura.ne.jp'].extensions; - extensions.isAvailable('my.extension.id@example.com', { - ok : function() { extensions.goToOptions('my.extension.id@example.com'); }, - ng : function() { alert('NOT INSTALLED'); } - }); - extensions.isInstalled('my.extension.id@example.com', { - ok : function(aDir) { - var dir = aDir; // nsILocalFile - } - }); - - license: The MIT License, Copyright (c) 2009-2016 YUKI "Piro" Hiroshi - original: - http://github.com/piroor/fxaddonlib-extensions -*/ - -/* To work as a JS Code Module */ -if (typeof window == 'undefined' || - (window && typeof window.constructor == 'function')) { - this.EXPORTED_SYMBOLS = ['extensions']; - - // If namespace.jsm is available, export symbols to the shared namespace. - // See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm - try { - let ns = {}; - Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm', ns); - /* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp'); - } - catch(e) { - window = {}; - } -} - -(function() { - const currentRevision = 13; - - if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; - - var loadedRevision = 'extensions' in window['piro.sakura.ne.jp'] ? - window['piro.sakura.ne.jp'].extensions.revision : - 0 ; - if (loadedRevision && loadedRevision > currentRevision) { - return; - } - - const Cc = Components.classes; - const Ci = Components.interfaces; - - var { AddonManager } = Components.utils.import('resource://gre/modules/AddonManager.jsm', {}); - - window['piro.sakura.ne.jp'].extensions = { - revision : currentRevision, - - _formatCallbacks : function(aOKCallback, aNGCallback) - { - var callbacks = { - ok : aOKCallback, - ng : aNGCallback - }; - if (typeof aOKCallback != 'function') - callbacks = aOKCallback; - - if (!('ok' in callbacks) || typeof callbacks.ok != 'function') - callbacks.ok = function() {}; - if (!('ng' in callbacks) || typeof callbacks.ng != 'function') - callbacks.ng = function() {}; - - return callbacks; - }, - - - isAvailable : function(aId, aOKCallback, aNGCallback) - { - return this.isEnabled(aId, aOKCallback, aNGCallback); - }, - - - isInstalled : function(aId, aOKCallback, aNGCallback) - { - var callbacks = this._formatCallbacks(aOKCallback, aNGCallback); - AddonManager.getAddonByID(aId, function(aAddon) { - callbacks[aAddon ? 'ok' : 'ng'](); - }); - }, - - - isEnabled : function(aId, aOKCallback, aNGCallback) - { - var callbacks = this._formatCallbacks(aOKCallback, aNGCallback); - AddonManager.getAddonByID(aId, function(aAddon) { - callbacks[aAddon && aAddon.isActive ? 'ok' : 'ng'](); - }); - }, - - - getInstalledLocation : function(aId, aCallback) - { - AddonManager.getAddonByID(aId, function(aAddon) { - var location = null; - if (aAddon) - location = aAddon.getResourceURI('/').QueryInterface(Ci.nsIFileURL).file.clone(); - aCallback(location); - }); - }, - - getVersion : function(aId, aCallback) - { - AddonManager.getAddonByID(aId, function(aAddon) { - aCallback(aAddon ? aAddon.version : null ); - }); - }, - - - goToOptions : function(aId, aOwnerWindow) - { - var self = this; - var callback = function(aURI) { - self.goToOptionsInternal(aURI, aOwnerWindow); - }; - AddonManager.getAddonByID(aId, function(aAddon) { - callback(aAddon && aAddon.isActive ? aAddon.optionsURL : null ); - }); - }, - goToOptionsInternal : function(aURI, aOwnerWindow) - { - if (!aURI) return; - - var windows = this._WindowMediator.getEnumerator(null); - while (windows.hasMoreElements()) - { - let win = windows.getNext(); - if (win.location.href == aURI) { - win.focus(); - return; - } - } - var instantApply = false; - try { - instantApply = Cc['@mozilla.org/preferences;1'] - .getService(Ci.nsIPrefBranch) - .getBoolPref('browser.preferences.instantApply'); - } - catch(e) { - } - (aOwnerWindow || window).openDialog( - aURI, - '', - 'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' ) - ); - } - }; -})(); - -if (window != this) { // work as a JS Code Module - this.extensions = window['piro.sakura.ne.jp'].extensions; -} -