2009-07-21 00:03:33 -04:00
|
|
|
/*
|
|
|
|
Extensions Compatibility Library
|
|
|
|
|
|
|
|
Usage:
|
2010-07-02 04:39:24 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-07 02:32:39 -04:00
|
|
|
license: The MIT License, Copyright (c) 2009-2016 YUKI "Piro" Hiroshi
|
2009-07-21 00:03:33 -04:00
|
|
|
original:
|
2016-09-07 02:32:39 -04:00
|
|
|
http://github.com/piroor/fxaddonlib-extensions
|
2009-07-21 00:03:33 -04:00
|
|
|
*/
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
/* To work as a JS Code Module */
|
2010-08-27 05:58:57 -04:00
|
|
|
if (typeof window == 'undefined' ||
|
|
|
|
(window && typeof window.constructor == 'function')) {
|
2010-06-22 21:32:31 -04:00
|
|
|
this.EXPORTED_SYMBOLS = ['extensions'];
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-26 11:13:11 -04:00
|
|
|
// If namespace.jsm is available, export symbols to the shared namespace.
|
2016-09-07 02:32:39 -04:00
|
|
|
// See: http://github.com/piroor/fxaddonlibs/blob/master/namespace.jsm
|
2010-06-26 11:13:11 -04:00
|
|
|
try {
|
|
|
|
let ns = {};
|
2010-12-06 07:04:52 -05:00
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm', ns);
|
2010-06-26 11:13:11 -04:00
|
|
|
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
window = {};
|
|
|
|
}
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|
|
|
|
|
2009-07-21 00:03:33 -04:00
|
|
|
(function() {
|
2016-09-07 02:32:39 -04:00
|
|
|
const currentRevision = 13;
|
2009-07-21 00:03:33 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-05-02 00:06:54 -04:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2016-09-07 02:32:39 -04:00
|
|
|
var { AddonManager } = Components.utils.import('resource://gre/modules/AddonManager.jsm', {});
|
2010-05-02 00:06:54 -04:00
|
|
|
|
2009-07-21 00:03:33 -04:00
|
|
|
window['piro.sakura.ne.jp'].extensions = {
|
|
|
|
revision : currentRevision,
|
|
|
|
|
2010-07-02 04:56:28 -04:00
|
|
|
_formatCallbacks : function(aOKCallback, aNGCallback)
|
2010-07-02 04:39:24 -04:00
|
|
|
{
|
|
|
|
var callbacks = {
|
|
|
|
ok : aOKCallback,
|
|
|
|
ng : aNGCallback
|
|
|
|
};
|
|
|
|
if (typeof aOKCallback != 'function')
|
|
|
|
callbacks = aOKCallback;
|
2010-07-02 04:51:07 -04:00
|
|
|
|
|
|
|
if (!('ok' in callbacks) || typeof callbacks.ok != 'function')
|
|
|
|
callbacks.ok = function() {};
|
|
|
|
if (!('ng' in callbacks) || typeof callbacks.ng != 'function')
|
|
|
|
callbacks.ng = function() {};
|
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
return callbacks;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
isAvailable : function(aId, aOKCallback, aNGCallback)
|
2009-07-21 00:18:37 -04:00
|
|
|
{
|
2010-08-11 12:55:28 -04:00
|
|
|
return this.isEnabled(aId, aOKCallback, aNGCallback);
|
2009-07-21 00:18:37 -04:00
|
|
|
},
|
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
|
|
|
|
isInstalled : function(aId, aOKCallback, aNGCallback)
|
2009-07-21 00:03:33 -04:00
|
|
|
{
|
2010-07-02 04:39:24 -04:00
|
|
|
var callbacks = this._formatCallbacks(aOKCallback, aNGCallback);
|
2016-09-07 02:32:39 -04:00
|
|
|
AddonManager.getAddonByID(aId, function(aAddon) {
|
|
|
|
callbacks[aAddon ? 'ok' : 'ng']();
|
|
|
|
});
|
2009-07-21 00:03:33 -04:00
|
|
|
},
|
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
|
|
|
|
isEnabled : function(aId, aOKCallback, aNGCallback)
|
2010-05-02 00:06:54 -04:00
|
|
|
{
|
2010-07-02 04:39:24 -04:00
|
|
|
var callbacks = this._formatCallbacks(aOKCallback, aNGCallback);
|
2016-09-07 02:32:39 -04:00
|
|
|
AddonManager.getAddonByID(aId, function(aAddon) {
|
|
|
|
callbacks[aAddon && aAddon.isActive ? 'ok' : 'ng']();
|
|
|
|
});
|
2010-05-02 00:06:54 -04:00
|
|
|
},
|
2009-07-21 00:03:33 -04:00
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
|
|
|
|
getInstalledLocation : function(aId, aCallback)
|
|
|
|
{
|
2016-09-07 02:32:39 -04:00
|
|
|
AddonManager.getAddonByID(aId, function(aAddon) {
|
|
|
|
var location = null;
|
|
|
|
if (aAddon)
|
|
|
|
location = aAddon.getResourceURI('/').QueryInterface(Ci.nsIFileURL).file.clone();
|
|
|
|
aCallback(location);
|
|
|
|
});
|
2010-07-02 04:39:24 -04:00
|
|
|
},
|
|
|
|
|
2010-08-11 12:55:28 -04:00
|
|
|
getVersion : function(aId, aCallback)
|
|
|
|
{
|
2016-09-07 02:32:39 -04:00
|
|
|
AddonManager.getAddonByID(aId, function(aAddon) {
|
|
|
|
aCallback(aAddon ? aAddon.version : null );
|
|
|
|
});
|
2010-08-11 12:55:28 -04:00
|
|
|
},
|
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
|
2010-06-22 14:00:16 -04:00
|
|
|
goToOptions : function(aId, aOwnerWindow)
|
2009-07-21 00:03:33 -04:00
|
|
|
{
|
2010-07-02 04:39:24 -04:00
|
|
|
var self = this;
|
|
|
|
var callback = function(aURI) {
|
|
|
|
self.goToOptionsInternal(aURI, aOwnerWindow);
|
|
|
|
};
|
2016-09-07 02:32:39 -04:00
|
|
|
AddonManager.getAddonByID(aId, function(aAddon) {
|
|
|
|
callback(aAddon && aAddon.isActive ? aAddon.optionsURL : null );
|
|
|
|
});
|
2010-07-02 04:39:24 -04:00
|
|
|
},
|
|
|
|
goToOptionsInternal : function(aURI, aOwnerWindow)
|
|
|
|
{
|
|
|
|
if (!aURI) return;
|
2009-07-21 00:03:33 -04:00
|
|
|
|
2010-07-02 04:39:24 -04:00
|
|
|
var windows = this._WindowMediator.getEnumerator(null);
|
2009-07-21 00:03:33 -04:00
|
|
|
while (windows.hasMoreElements())
|
|
|
|
{
|
|
|
|
let win = windows.getNext();
|
2016-09-07 02:32:39 -04:00
|
|
|
if (win.location.href == aURI) {
|
2009-07-21 00:03:33 -04:00
|
|
|
win.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var instantApply = false;
|
|
|
|
try {
|
2016-09-07 02:41:23 -04:00
|
|
|
instantApply = Cc['@mozilla.org/preferences;1']
|
|
|
|
.getService(Ci.nsIPrefBranch)
|
|
|
|
.getBoolPref('browser.preferences.instantApply');
|
2009-07-21 00:03:33 -04:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
2010-06-22 14:00:16 -04:00
|
|
|
(aOwnerWindow || window).openDialog(
|
2016-09-07 02:32:39 -04:00
|
|
|
aURI,
|
2009-07-21 00:03:33 -04:00
|
|
|
'',
|
|
|
|
'chrome,titlebar,toolbar,centerscreen,' + (instantApply ? 'dialog=no' : 'modal' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
2010-06-22 19:46:51 -04:00
|
|
|
|
|
|
|
if (window != this) { // work as a JS Code Module
|
2010-06-22 21:32:31 -04:00
|
|
|
this.extensions = window['piro.sakura.ne.jp'].extensions;
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|
2016-09-07 02:32:39 -04:00
|
|
|
|