Update library

This commit is contained in:
YUKI Hiroshi 2016-09-07 15:57:00 +09:00
parent 92dd8adf82
commit 88cf5df47f

View File

@ -1,47 +1,23 @@
/* /**
Uninstallation Listener Library * @fileOverview Uninstallation Listener Library
* @author YUKI "Piro" Hiroshi
Usage: * @version 3
new window['piro.sakura.ne.jp'].UninstallationListener({ *
id : 'test@exmaple.com', * @license
onuninstalled : function() { ... }, * The MIT License, Copyright (c) 2009-2016 YUKI "Piro" Hiroshi.
ondisabled : function() { ... } * https://github.com/piroor/fxaddonlib-uninstallation-listener/blob/master/license.txt
}); * @url https://github.com/piroor/fxaddonlib-uninstallation-listener
*
license: The MIT License, Copyright (c) 2009-2011 YUKI "Piro" Hiroshi * Usage:
http://github.com/piroor/fxaddonlibs/blob/master/license.txt * new UninstallationListener({
original: * id : 'test@exmaple.com',
http://github.com/piroor/fxaddonlibs/blob/master/UninstallationListener.js * onuninstalled : function() { ... },
* ondisabled : function() { ... }
* });
*/ */
/* To work as a JS Code Module */ var EXPORTED_SYMBOLS = ['UninstallationListener'];
if (typeof window == 'undefined' ||
(window && typeof window.constructor == 'function')) {
this.EXPORTED_SYMBOLS = ['UninstallationListener'];
// 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://my-modules/namespace.jsm', ns);
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
}
catch(e) {
window = {};
}
}
(function() {
const currentRevision = 2;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
var loadedRevision = 'UninstallationListener' in window['piro.sakura.ne.jp'] ?
window['piro.sakura.ne.jp'].UninstallationListener.prototype.revision :
0 ;
if (loadedRevision && loadedRevision > currentRevision) {
return;
}
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -49,61 +25,12 @@ if (typeof window == 'undefined' ||
const ObserverService = Cc['@mozilla.org/observer-service;1'] const ObserverService = Cc['@mozilla.org/observer-service;1']
.getService(Ci.nsIObserverService); .getService(Ci.nsIObserverService);
var AddonManager; var { AddonManager } = Components.utils.import('resource://gre/modules/AddonManager.jsm', {});
try {
let ns = {};
Components.utils.import('resource://gre/modules/AddonManager.jsm', ns);
AddonManager = ns.AddonManager;
}
catch(e) {
}
window['piro.sakura.ne.jp'].UninstallationListener = function(aArguments) { var UninstallationListener = function(aArguments) {
this.init(aArguments); this.init(aArguments);
}; };
window['piro.sakura.ne.jp'].UninstallationListener.prototype = { UninstallationListener.prototype = {
revision : currentRevision,
// for Firefox 3.6 or older
observe : function(aSubject, aTopic, aData)
{
switch (aTopic)
{
case 'em-action-requested':
switch (aData)
{
case 'item-uninstalled':
if (this.isTargetExtension(aSubject))
this.toBeUninstalled = true;
break;
case 'item-cancel-action':
if (this.isTargetExtension(aSubject)) {
this.toBeUninstalled = false;
this.toBeDisabled = false;
}
break;
case 'item-disabled':
if (this.isTargetExtension(aSubject))
this.toBeDisabled = true;
break;
case 'item-enabled':
if (this.isTargetExtension(aSubject))
this.toBeDisabled = false;
break;
}
return;
case 'quit-application-granted':
this.destroy();
return;
}
},
isTargetExtension : function(aSubject)
{
return (aSubject instanceof Ci.nsIUpdateItem) && (aSubject.id == this.id);
},
// for Firefox 4 or later
onEnabling : function(aAddon, aRestartRequired) {}, onEnabling : function(aAddon, aRestartRequired) {},
onEnabled : function(aAddon) {}, onEnabled : function(aAddon) {},
onDisabling : function(aAddon, aRestartRequired) { onDisabling : function(aAddon, aRestartRequired) {
@ -154,12 +81,7 @@ if (typeof window == 'undefined' ||
this.ondisabled = aArguments.ondisabled; this.ondisabled = aArguments.ondisabled;
} }
if (AddonManager) { // Firefox 4 or later
AddonManager.addAddonListener(this); AddonManager.addAddonListener(this);
}
else {
ObserverService.addObserver(this, 'em-action-requested', false);
}
ObserverService.addObserver(this, 'quit-application-granted', false); ObserverService.addObserver(this, 'quit-application-granted', false);
}, },
@ -173,17 +95,18 @@ if (typeof window == 'undefined' ||
this.ondisabled(); this.ondisabled();
delete this.ondisabled; delete this.ondisabled;
if (AddonManager) { // Firefox 4 or later
AddonManager.removeAddonListener(this); AddonManager.removeAddonListener(this);
}
else {
ObserverService.removeObserver(this, 'em-action-requested');
}
ObserverService.removeObserver(this, 'quit-application-granted'); ObserverService.removeObserver(this, 'quit-application-granted');
},
observe : function(aSubject, aTopic, aData)
{
switch (aTopic)
{
case 'quit-application-granted':
this.destroy();
return;
}
} }
}; };
})();
if (window != this) { // work as a JS Code Module
this.UninstallationListener = window['piro.sakura.ne.jp'].UninstallationListener;
}