Update library
This commit is contained in:
parent
4c4b5da0fd
commit
2186ecbaf0
@ -2,7 +2,6 @@
|
||||
Extensions Compatibility Library
|
||||
|
||||
Usage:
|
||||
Asynchronus:
|
||||
var extensions = window['piro.sakura.ne.jp'].extensions;
|
||||
extensions.isAvailable('my.extension.id@example.com', {
|
||||
ok : function() { extensions.goToOptions('my.extension.id@example.com'); },
|
||||
@ -14,16 +13,9 @@
|
||||
}
|
||||
});
|
||||
|
||||
Synchronus: (DEPRECATED)
|
||||
if (extensions.isAvailable('my.extension.id@example.com'))
|
||||
extensions.goToOptions('my.extension.id@example.com');
|
||||
var dir = extensions.getInstalledLocation('my.extension.id@example.com'); // nsILocalFile
|
||||
|
||||
license: The MIT License, Copyright (c) 2009-2010 YUKI "Piro" Hiroshi
|
||||
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
||||
license: The MIT License, Copyright (c) 2009-2016 YUKI "Piro" Hiroshi
|
||||
original:
|
||||
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/extensions.js
|
||||
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/extensions.test.js
|
||||
http://github.com/piroor/fxaddonlib-extensions
|
||||
*/
|
||||
|
||||
/* To work as a JS Code Module */
|
||||
@ -32,7 +24,7 @@ if (typeof window == 'undefined' ||
|
||||
this.EXPORTED_SYMBOLS = ['extensions'];
|
||||
|
||||
// If namespace.jsm is available, export symbols to the shared namespace.
|
||||
// See: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm
|
||||
// See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm
|
||||
try {
|
||||
let ns = {};
|
||||
Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm', ns);
|
||||
@ -44,7 +36,7 @@ if (typeof window == 'undefined' ||
|
||||
}
|
||||
|
||||
(function() {
|
||||
const currentRevision = 11;
|
||||
const currentRevision = 13;
|
||||
|
||||
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
||||
|
||||
@ -58,30 +50,11 @@ if (typeof window == 'undefined' ||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
// Firefox 3.7 or later
|
||||
var AM = {};
|
||||
if ('@mozilla.org/addons/integration;1' in Cc)
|
||||
Components.utils.import('resource://gre/modules/AddonManager.jsm', AM);
|
||||
var { AddonManager } = Components.utils.import('resource://gre/modules/AddonManager.jsm', {});
|
||||
|
||||
window['piro.sakura.ne.jp'].extensions = {
|
||||
revision : currentRevision,
|
||||
|
||||
// Firefox 3.7 or later
|
||||
_getInstalledAddonNow : function(aId)
|
||||
{
|
||||
var addon;
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
addon = aAddon;
|
||||
});
|
||||
var thread = Cc['@mozilla.org/thread-manager;1']
|
||||
.getService()
|
||||
.mainThread;
|
||||
while (addon === void(0)) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
return addon;
|
||||
},
|
||||
|
||||
_formatCallbacks : function(aOKCallback, aNGCallback)
|
||||
{
|
||||
var callbacks = {
|
||||
@ -99,18 +72,6 @@ if (typeof window == 'undefined' ||
|
||||
return callbacks;
|
||||
},
|
||||
|
||||
// Firefox 3.6 or older
|
||||
_ExtensionManager : ('@mozilla.org/extensions/manager;1' in Cc) ?
|
||||
Cc['@mozilla.org/extensions/manager;1']
|
||||
.getService(Ci.nsIExtensionManager) :
|
||||
null,
|
||||
_RDF : Cc['@mozilla.org/rdf/rdf-service;1']
|
||||
.getService(Ci.nsIRDFService),
|
||||
_WindowMediator : Cc['@mozilla.org/appshell/window-mediator;1']
|
||||
.getService(Ci.nsIWindowMediator),
|
||||
_Prefs : Cc['@mozilla.org/preferences;1']
|
||||
.getService(Ci.nsIPrefBranch),
|
||||
|
||||
|
||||
isAvailable : function(aId, aOKCallback, aNGCallback)
|
||||
{
|
||||
@ -120,149 +81,37 @@ if (typeof window == 'undefined' ||
|
||||
|
||||
isInstalled : function(aId, aOKCallback, aNGCallback)
|
||||
{
|
||||
if (!aOKCallback)
|
||||
return this._ExtensionManager ? this._isInstalled_EM(aId) : this._isInstalled_AM(aId) ;
|
||||
|
||||
var callbacks = this._formatCallbacks(aOKCallback, aNGCallback);
|
||||
if (this._ExtensionManager) {
|
||||
callbacks[this._isInstalled_EM(aId) ? 'ok' : 'ng']();
|
||||
}
|
||||
else {
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
callbacks[aAddon ? 'ok' : 'ng']();
|
||||
});
|
||||
}
|
||||
},
|
||||
_isInstalled_EM : function(aId)
|
||||
{
|
||||
return this._ExtensionManager.getInstallLocation(aId) ? true : false ;
|
||||
},
|
||||
_isInstalled_AM : function(aId)
|
||||
{
|
||||
return this._getInstalledAddonNow(aId) ? true : false ;
|
||||
AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
callbacks[aAddon ? 'ok' : 'ng']();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
isEnabled : function(aId, aOKCallback, aNGCallback)
|
||||
{
|
||||
if (!aOKCallback)
|
||||
return this._ExtensionManager ? this._isEnabled_EM(aId) : this._isEnabled_AM(aId) ;
|
||||
|
||||
var callbacks = this._formatCallbacks(aOKCallback, aNGCallback);
|
||||
if (this._ExtensionManager) {
|
||||
callbacks[this._isEnabled_EM(aId) ? 'ok' : 'ng']();
|
||||
}
|
||||
else {
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
callbacks[aAddon && aAddon.isActive ? 'ok' : 'ng']();
|
||||
});
|
||||
}
|
||||
},
|
||||
_isEnabled_EM : function(aId)
|
||||
{
|
||||
if (!this._isInstalled_EM(aId))
|
||||
return false;
|
||||
|
||||
var res = this._RDF.GetResource('urn:mozilla:item:'+aId);
|
||||
var appDisabled = false;
|
||||
try {
|
||||
appDisabled = this._ExtensionManager.datasource.GetTarget(
|
||||
res,
|
||||
this._RDF.GetResource('http://www.mozilla.org/2004/em-rdf#appDisabled'),
|
||||
true
|
||||
).QueryInterface(Ci.nsIRDFLiteral)
|
||||
.Value == 'true';
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
var userDisabled = false;
|
||||
try {
|
||||
userDisabled = this._ExtensionManager.datasource.GetTarget(
|
||||
res,
|
||||
this._RDF.GetResource('http://www.mozilla.org/2004/em-rdf#userDisabled'),
|
||||
true
|
||||
).QueryInterface(Ci.nsIRDFLiteral)
|
||||
.Value == 'true';
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
|
||||
return !appDisabled && !userDisabled;
|
||||
},
|
||||
_isEnabled_AM : function(aId)
|
||||
{
|
||||
var addon = this._getInstalledAddonNow(aId);
|
||||
return addon ? addon.isActive : false ;
|
||||
AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
callbacks[aAddon && aAddon.isActive ? 'ok' : 'ng']();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
getInstalledLocation : function(aId, aCallback)
|
||||
{
|
||||
if (!aCallback)
|
||||
return this._ExtensionManager ? this._getInstalledLocation_EM(aId) : this._getInstalledLocation_AM(aId) ;
|
||||
|
||||
if (this._ExtensionManager) {
|
||||
aCallback(this._getInstalledLocation_EM(aId));
|
||||
}
|
||||
else {
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
var location = null;
|
||||
if (aAddon)
|
||||
location = aAddon.getResourceURI('/').QueryInterface(Ci.nsIFileURL).file.clone();
|
||||
aCallback(location);
|
||||
});
|
||||
}
|
||||
},
|
||||
_getInstalledLocation_EM : function(aId)
|
||||
{
|
||||
var addon = this._ExtensionManager.getInstallLocation(aId);
|
||||
if (!addon) return null;
|
||||
return addon.getItemFile(aId, '').clone();
|
||||
},
|
||||
_getInstalledLocation_AM : function(aId)
|
||||
{
|
||||
var addon = this._getInstalledAddonNow(aId);
|
||||
if (!addon) return null;
|
||||
return addon.getResourceURI('/').QueryInterface(Ci.nsIFileURL).file.clone();
|
||||
AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
var location = null;
|
||||
if (aAddon)
|
||||
location = aAddon.getResourceURI('/').QueryInterface(Ci.nsIFileURL).file.clone();
|
||||
aCallback(location);
|
||||
});
|
||||
},
|
||||
|
||||
getVersion : function(aId, aCallback)
|
||||
{
|
||||
if (!aCallback)
|
||||
return this._ExtensionManager ? this._getVersion_EM(aId) : this._getVersion_AM(aId) ;
|
||||
|
||||
if (this._ExtensionManager) {
|
||||
aCallback(this._getVersion_EM(aId));
|
||||
}
|
||||
else {
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
aCallback(aAddon ? aAddon.version : null );
|
||||
});
|
||||
}
|
||||
},
|
||||
_getVersion_EM : function(aId)
|
||||
{
|
||||
if (!this._isInstalled_EM(aId))
|
||||
return null;
|
||||
|
||||
var res = this._RDF.GetResource('urn:mozilla:item:'+aId);
|
||||
var version = null;
|
||||
try {
|
||||
version = this._ExtensionManager.datasource.GetTarget(
|
||||
res,
|
||||
this._RDF.GetResource('http://www.mozilla.org/2004/em-rdf#version'),
|
||||
true
|
||||
).QueryInterface(Ci.nsIRDFLiteral)
|
||||
.Value;
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
return version;
|
||||
},
|
||||
_getVersion_AM : function(aId)
|
||||
{
|
||||
var addon = this._getInstalledAddonNow(aId);
|
||||
return addon ? addon.version : null ;
|
||||
AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
aCallback(aAddon ? aAddon.version : null );
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -272,46 +121,10 @@ if (typeof window == 'undefined' ||
|
||||
var callback = function(aURI) {
|
||||
self.goToOptionsInternal(aURI, aOwnerWindow);
|
||||
};
|
||||
return this._ExtensionManager ? this._getOptionsURI_EM(aId, callback) : this._getOptionsURI_AM(aId, callback);
|
||||
AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
callback(aAddon && aAddon.isActive ? aAddon.optionsURL : null );
|
||||
});
|
||||
},
|
||||
_getOptionsURI_EM : function(aId, aCallback)
|
||||
{
|
||||
var res = this._RDF.GetResource('urn:mozilla:item:'+aId);
|
||||
var uri = null;
|
||||
try {
|
||||
uri = this._ExtensionManager.datasource.GetTarget(
|
||||
res,
|
||||
this._RDF.GetResource('http://www.mozilla.org/2004/em-rdf#optionsURL'),
|
||||
true
|
||||
).QueryInterface(Ci.nsIRDFLiteral)
|
||||
.Value;
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
return aCallback ? aCallback(uri) : uri ;
|
||||
},
|
||||
_getOptionsURI_AM : function(aId, aCallback)
|
||||
{
|
||||
if (aCallback) {
|
||||
AM.AddonManager.getAddonByID(aId, function(aAddon) {
|
||||
aCallback(aAddon && aAddon.isActive ? aAddon.optionsURL : null );
|
||||
});
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
var addon = this._getInstalledAddonNow(aId);
|
||||
return (addon && addon.isActive) ? addon.optionsURL : null ;
|
||||
}
|
||||
},
|
||||
|
||||
goToOptionsNow : function(aId, aOwnerWindow)
|
||||
{
|
||||
this.goToOptionsInternal(
|
||||
(this._ExtensionManager ? this._getOptionsURI_EM(aId) : this._getOptionsURI_AM(aId) ),
|
||||
aOwnerWindow
|
||||
);
|
||||
},
|
||||
|
||||
goToOptionsInternal : function(aURI, aOwnerWindow)
|
||||
{
|
||||
if (!aURI) return;
|
||||
@ -320,7 +133,7 @@ if (typeof window == 'undefined' ||
|
||||
while (windows.hasMoreElements())
|
||||
{
|
||||
let win = windows.getNext();
|
||||
if (win.location.href == uri) {
|
||||
if (win.location.href == aURI) {
|
||||
win.focus();
|
||||
return;
|
||||
}
|
||||
@ -332,7 +145,7 @@ if (typeof window == 'undefined' ||
|
||||
catch(e) {
|
||||
}
|
||||
(aOwnerWindow || window).openDialog(
|
||||
uri,
|
||||
aURI,
|
||||
'',
|
||||
'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' )
|
||||
);
|
||||
@ -343,3 +156,4 @@ if (typeof window == 'undefined' ||
|
||||
if (window != this) { // work as a JS Code Module
|
||||
this.extensions = window['piro.sakura.ne.jp'].extensions;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user