From 2cb98eb3f83dae2d0b09bc1ff0353b0e142b683d Mon Sep 17 00:00:00 2001 From: piro Date: Sun, 2 May 2010 03:57:59 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=83=89=E3=82=AA=E3=83=B3=E3=83=9E?= =?UTF-8?q?=E3=83=8D=E3=83=BC=E3=82=B8=E3=83=A3=E3=81=AE=E4=BB=95=E6=A7=98?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=AB=E8=BF=BD=E5=BE=93=EF=BC=88=20https:?= =?UTF-8?q?//bugzilla.mozilla.org/show=5Fbug.cgi=3Fid=3D550048=20=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6646 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/res/extensions.js | 93 +++++++++++++++++++++----- 1 file changed, 77 insertions(+), 16 deletions(-) diff --git a/content/treestyletab/res/extensions.js b/content/treestyletab/res/extensions.js index d38c7f20..535d827f 100644 --- a/content/treestyletab/res/extensions.js +++ b/content/treestyletab/res/extensions.js @@ -9,13 +9,13 @@ // window['piro.sakura.ne.jp'].extensions.isEnabled('my.extension.id@example.com')) // window['piro.sakura.ne.jp'].extensions.goToOptions('my.extension.id@example.com'); - lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi + lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt original: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/extensions.js */ (function() { - const currentRevision = 2; + const currentRevision = 3; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; @@ -26,11 +26,35 @@ return; } + // Firefox 3.7 or later + var AM = {}; + if ('@mozilla.org/addons/integration;1' in Components.classes) + Components.utils.import('resource://gre/modules/AddonManager.jsm', AM); + window['piro.sakura.ne.jp'].extensions = { revision : currentRevision, - ExtensionManager : Components.classes['@mozilla.org/extensions/manager;1'] - .getService(Components.interfaces.nsIExtensionManager), + // Firefox 3.7 or later + getInstalledAddon : function(aId) + { + var addon; + AM.AddonManager.getAddonByID(aId, function(aAddon) { + addon = aAddon; + }); + var thread = Components.classes['@mozilla.org/thread-manager;1'] + .getService() + .mainThread; + while (addon === void(0)) { + thread.processNextEvent(true); + } + return addon; + }, + + // Firefox 3.6 or older + ExtensionManager : ('@mozilla.org/extensions/manager;1' in Components.classes) ? + Components.classes['@mozilla.org/extensions/manager;1'] + .getService(Components.interfaces.nsIExtensionManager) : + null, RDF : Components.classes['@mozilla.org/rdf/rdf-service;1'] .getService(Components.interfaces.nsIRDFService), WindowMediator : Components.classes['@mozilla.org/appshell/window-mediator;1'] @@ -39,16 +63,38 @@ .getService(Components.interfaces.nsIPrefBranch), isAvailable : function(aId) + { + return this.ExtensionManager ? this.isAvailable_EM(aId) : this.isAvailable_AM(aId) ; + }, + isAvailable_EM : function(aId) { return this.isInstalled(aId) && this.isEnabled(aId); }, + isAvailable_AM : function(aId) + { + var addon = this.getInstalledAddon(aId); + if (!addon) return false; + return addon.isActive; + }, isInstalled : function(aId) + { + return this.ExtensionManager ? this.isInstalled_EM(aId) : this.isInstalled_AM(aId) ; + }, + isInstalled_EM : function(aId) { return this.ExtensionManager.getInstallLocation(aId); }, + isInstalled_AM : function(aId) + { + return this.getInstalledAddon(aId); + }, isEnabled : function(aId) + { + return this.ExtensionManager ? this.isEnabled_EM(aId) : this.isEnabled_AM(aId) ; + }, + isEnabled_EM : function(aId) { var res = this.RDF.GetResource('urn:mozilla:item:'+aId); var appDisabled = false; @@ -76,21 +122,14 @@ return !appDisabled && !userDisabled; }, + isEnabled_AM : function(aId) + { + return false; + }, goToOptions : function(aId) { - var res = this.RDF.GetResource('urn:mozilla:item:'+aId); - var uri; - try { - uri = this.ExtensionManager.datasource.GetTarget( - res, - this.RDF.GetResource('http://www.mozilla.org/2004/em-rdf#optionsURL'), - true - ).QueryInterface(Components.interfaces.nsIRDFLiteral) - .Value; - } - catch(e) { - } + var uri = this.ExtensionManager ? this.getOptionsURI_EM(aId) : this.getOptionsURI_AM(aId) ; if (!uri) return; var windows = this.WindowMediator.getEnumerator(null); @@ -113,6 +152,28 @@ '', 'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' ) ); + }, + getOptionsURI_EM : function(aId) + { + var res = this.RDF.GetResource('urn:mozilla:item:'+aId); + var uri; + try { + uri = this.ExtensionManager.datasource.GetTarget( + res, + this.RDF.GetResource('http://www.mozilla.org/2004/em-rdf#optionsURL'), + true + ).QueryInterface(Components.interfaces.nsIRDFLiteral) + .Value; + } + catch(e) { + } + return uri; + }, + getOptionsURI_AM : function(aId) + { + var addon = this.getInstalledAddon(aId); + if (!addon || !addon.isActive) return null; + return addon.optionsURL; } }; })();