2012-06-20 18:01:27 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["SocialService"];
|
2012-06-20 18:01:27 -07:00
|
|
|
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2012-06-26 19:03:32 -07:00
|
|
|
|
2012-06-20 18:01:27 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-07-05 14:01:38 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-02-26 14:50:24 -08:00
|
|
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
|
|
|
|
const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties";
|
|
|
|
const ADDON_TYPE_SERVICE = "service";
|
|
|
|
const ID_SUFFIX = "@services.mozilla.org";
|
|
|
|
const STRING_TYPE_NAME = "type.%ID%.name";
|
2012-07-16 08:43:50 -07:00
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "getFrameWorkerHandle", "resource://gre/modules/FrameWorker.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "WorkerAPI", "resource://gre/modules/WorkerAPI.jsm");
|
2012-08-13 08:20:29 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "MozSocialAPI", "resource://gre/modules/MozSocialAPI.jsm");
|
2012-12-07 20:13:27 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm");
|
2012-07-17 18:44:09 -07:00
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, 'bs',
|
|
|
|
"@mozilla.org/extensions/blocklist;1",
|
|
|
|
"nsIBlocklistService");
|
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
/**
|
|
|
|
* The SocialService is the public API to social providers - it tracks which
|
|
|
|
* providers are installed and enabled, and is the entry-point for access to
|
|
|
|
* the provider itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Internal helper methods and state
|
|
|
|
let SocialServiceInternal = {
|
|
|
|
enabled: Services.prefs.getBoolPref("social.enabled"),
|
|
|
|
get providerArray() {
|
|
|
|
return [p for ([, p] of Iterator(this.providers))];
|
2013-02-08 11:39:25 -08:00
|
|
|
},
|
|
|
|
get manifests() {
|
|
|
|
// Retrieve the builtin manifests from prefs
|
|
|
|
let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
|
|
|
|
let prefs = MANIFEST_PREFS.getChildList("", []);
|
|
|
|
for (let pref of prefs) {
|
|
|
|
try {
|
|
|
|
var manifest = JSON.parse(MANIFEST_PREFS.getCharPref(pref));
|
|
|
|
if (manifest && typeof(manifest) == "object" && manifest.origin)
|
|
|
|
yield manifest;
|
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("SocialService: failed to load manifest: " + pref +
|
|
|
|
", exception: " + err);
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
getManifestByOrigin: function(origin) {
|
|
|
|
for (let manifest of SocialServiceInternal.manifests) {
|
|
|
|
if (origin == manifest.origin) {
|
|
|
|
return manifest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
getManifestPrefname: function(origin) {
|
|
|
|
// Retrieve the prefname for a given origin/manifest.
|
|
|
|
// If no existing pref, return a generated prefname.
|
|
|
|
let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
|
|
|
|
let prefs = MANIFEST_PREFS.getChildList("", []);
|
|
|
|
for (let pref of prefs) {
|
|
|
|
try {
|
|
|
|
var manifest = JSON.parse(MANIFEST_PREFS.getCharPref(pref));
|
|
|
|
if (manifest.origin == origin) {
|
|
|
|
return pref;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("SocialService: failed to load manifest: " + pref +
|
|
|
|
", exception: " + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let originUri = Services.io.newURI(origin, null, null);
|
|
|
|
return originUri.hostPort.replace('.','-');
|
2012-07-18 11:40:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
let ActiveProviders = {
|
|
|
|
get _providers() {
|
|
|
|
delete this._providers;
|
|
|
|
this._providers = {};
|
|
|
|
try {
|
|
|
|
let pref = Services.prefs.getComplexValue("social.activeProviders",
|
|
|
|
Ci.nsISupportsString);
|
|
|
|
this._providers = JSON.parse(pref);
|
|
|
|
} catch(ex) {}
|
|
|
|
return this._providers;
|
|
|
|
},
|
|
|
|
|
|
|
|
has: function (origin) {
|
|
|
|
return (origin in this._providers);
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function (origin) {
|
|
|
|
this._providers[origin] = 1;
|
|
|
|
this._deferredTask.start();
|
|
|
|
},
|
|
|
|
|
|
|
|
delete: function (origin) {
|
|
|
|
delete this._providers[origin];
|
|
|
|
this._deferredTask.start();
|
|
|
|
},
|
|
|
|
|
|
|
|
flush: function () {
|
|
|
|
this._deferredTask.flush();
|
|
|
|
},
|
|
|
|
|
|
|
|
get _deferredTask() {
|
|
|
|
delete this._deferredTask;
|
|
|
|
return this._deferredTask = new DeferredTask(this._persist.bind(this), 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
_persist: function () {
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = JSON.stringify(this._providers);
|
|
|
|
Services.prefs.setComplexValue("social.activeProviders",
|
|
|
|
Ci.nsISupportsString, string);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
function migrateSettings() {
|
|
|
|
try {
|
|
|
|
// we don't care what the value is, if it is set, we've already migrated
|
|
|
|
Services.prefs.getCharPref("social.activeProviders");
|
|
|
|
return;
|
|
|
|
} catch(e) {
|
|
|
|
try {
|
|
|
|
let active = Services.prefs.getBoolPref("social.active");
|
|
|
|
if (active) {
|
|
|
|
for (let manifest of SocialServiceInternal.manifests) {
|
|
|
|
ActiveProviders.add(manifest.origin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
// not activated, nothing to see here.
|
|
|
|
}
|
2013-02-07 06:36:31 -08:00
|
|
|
}
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function initService() {
|
2012-07-18 11:40:05 -07:00
|
|
|
Services.obs.addObserver(function xpcomShutdown() {
|
2012-12-07 20:13:27 -08:00
|
|
|
ActiveProviders.flush();
|
|
|
|
SocialService._providerListeners = null;
|
2012-07-18 11:40:05 -07:00
|
|
|
Services.obs.removeObserver(xpcomShutdown, "xpcom-shutdown");
|
|
|
|
}, "xpcom-shutdown", false);
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
migrateSettings();
|
2012-07-13 13:51:35 -07:00
|
|
|
// Initialize the MozSocialAPI
|
2012-08-13 08:20:29 -07:00
|
|
|
if (SocialServiceInternal.enabled)
|
|
|
|
MozSocialAPI.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(SocialServiceInternal, "providers", function () {
|
|
|
|
initService();
|
2012-07-18 11:40:05 -07:00
|
|
|
let providers = {};
|
2013-02-08 11:39:25 -08:00
|
|
|
for (let manifest of this.manifests) {
|
2012-07-18 11:40:05 -07:00
|
|
|
try {
|
2013-02-08 11:39:25 -08:00
|
|
|
if (ActiveProviders.has(manifest.origin)) {
|
2012-12-07 20:13:27 -08:00
|
|
|
let provider = new SocialProvider(manifest);
|
2012-07-18 11:40:05 -07:00
|
|
|
providers[provider.origin] = provider;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2013-02-08 11:39:25 -08:00
|
|
|
Cu.reportError("SocialService: failed to load provider: " + manifest.origin +
|
2012-07-18 11:40:05 -07:00
|
|
|
", exception: " + err);
|
|
|
|
}
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
return providers;
|
|
|
|
});
|
|
|
|
|
|
|
|
function schedule(callback) {
|
|
|
|
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public API
|
2012-10-31 09:13:28 -07:00
|
|
|
this.SocialService = {
|
2012-07-18 11:40:05 -07:00
|
|
|
get enabled() {
|
|
|
|
return SocialServiceInternal.enabled;
|
|
|
|
},
|
|
|
|
set enabled(val) {
|
|
|
|
let enable = !!val;
|
2012-09-24 14:57:12 -07:00
|
|
|
|
|
|
|
// Allow setting to the same value when in safe mode so the
|
|
|
|
// feature can be force enabled.
|
|
|
|
if (enable == SocialServiceInternal.enabled &&
|
|
|
|
!Services.appinfo.inSafeMode)
|
2012-07-18 11:40:05 -07:00
|
|
|
return;
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
// if disabling, ensure all providers are actually disabled
|
2012-12-07 20:13:27 -08:00
|
|
|
if (!enable)
|
|
|
|
SocialServiceInternal.providerArray.forEach(function (p) p.enabled = false);
|
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
SocialServiceInternal.enabled = enable;
|
2012-07-13 13:51:35 -07:00
|
|
|
MozSocialAPI.enabled = enable;
|
2012-07-18 11:40:05 -07:00
|
|
|
Services.obs.notifyObservers(null, "social:pref-changed", enable ? "enabled" : "disabled");
|
2012-08-24 17:24:52 -07:00
|
|
|
Services.telemetry.getHistogramById("SOCIAL_TOGGLED").add(enable);
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
// Adds and activates a builtin provider. The provider may or may not have
|
|
|
|
// previously been added. onDone is always called - with null if no such
|
|
|
|
// provider exists, or the activated provider on success.
|
|
|
|
addBuiltinProvider: function addBuiltinProvider(origin, onDone) {
|
|
|
|
if (SocialServiceInternal.providers[origin]) {
|
|
|
|
schedule(function() {
|
|
|
|
onDone(SocialServiceInternal.providers[origin]);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
let manifest = SocialServiceInternal.getManifestByOrigin(origin);
|
|
|
|
if (manifest) {
|
|
|
|
let addon = new AddonWrapper(manifest);
|
|
|
|
AddonManagerPrivate.callAddonListeners("onEnabling", addon, false);
|
|
|
|
addon.pendingOperations |= AddonManager.PENDING_ENABLE;
|
|
|
|
this.addProvider(manifest, onDone);
|
|
|
|
addon.pendingOperations -= AddonManager.PENDING_ENABLE;
|
|
|
|
AddonManagerPrivate.callAddonListeners("onEnabled", addon);
|
|
|
|
return;
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
|
|
|
schedule(function() {
|
|
|
|
onDone(null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
// Adds a provider given a manifest, and returns the added provider.
|
|
|
|
addProvider: function addProvider(manifest, onDone) {
|
|
|
|
if (SocialServiceInternal.providers[manifest.origin])
|
|
|
|
throw new Error("SocialService.addProvider: provider with this origin already exists");
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
let provider = new SocialProvider(manifest);
|
2012-07-18 11:40:05 -07:00
|
|
|
SocialServiceInternal.providers[provider.origin] = provider;
|
2013-02-08 11:39:25 -08:00
|
|
|
ActiveProviders.add(provider.origin);
|
2012-07-18 11:40:05 -07:00
|
|
|
|
|
|
|
schedule(function () {
|
2012-12-07 20:13:27 -08:00
|
|
|
this._notifyProviderListeners("provider-added",
|
|
|
|
SocialServiceInternal.providerArray);
|
|
|
|
if (onDone)
|
|
|
|
onDone(provider);
|
|
|
|
}.bind(this));
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Removes a provider with the given origin, and notifies when the removal is
|
|
|
|
// complete.
|
|
|
|
removeProvider: function removeProvider(origin, onDone) {
|
|
|
|
if (!(origin in SocialServiceInternal.providers))
|
2013-02-26 14:50:24 -08:00
|
|
|
throw new Error("SocialService.removeProvider: no provider with origin " + origin + " exists!");
|
2012-07-18 11:40:05 -07:00
|
|
|
|
|
|
|
let provider = SocialServiceInternal.providers[origin];
|
2013-02-26 14:50:24 -08:00
|
|
|
let manifest = SocialServiceInternal.getManifestByOrigin(origin);
|
|
|
|
let addon = manifest && new AddonWrapper(manifest);
|
|
|
|
if (addon) {
|
|
|
|
AddonManagerPrivate.callAddonListeners("onDisabling", addon, false);
|
|
|
|
addon.pendingOperations |= AddonManager.PENDING_DISABLE;
|
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
provider.enabled = false;
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
ActiveProviders.delete(provider.origin);
|
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
delete SocialServiceInternal.providers[origin];
|
|
|
|
|
2013-02-26 14:50:24 -08:00
|
|
|
if (addon) {
|
|
|
|
// we have to do this now so the addon manager ui will update an uninstall
|
|
|
|
// correctly.
|
|
|
|
addon.pendingOperations -= AddonManager.PENDING_DISABLE;
|
|
|
|
AddonManagerPrivate.callAddonListeners("onDisabled", addon);
|
|
|
|
AddonManagerPrivate.notifyAddonChanged(addon.id, ADDON_TYPE_SERVICE, false);
|
|
|
|
}
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
schedule(function () {
|
|
|
|
this._notifyProviderListeners("provider-removed",
|
|
|
|
SocialServiceInternal.providerArray);
|
|
|
|
if (onDone)
|
|
|
|
onDone();
|
|
|
|
}.bind(this));
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
// Returns a single provider object with the specified origin. The provider
|
|
|
|
// must be "installed" (ie, in ActiveProviders)
|
2012-07-18 11:40:05 -07:00
|
|
|
getProvider: function getProvider(origin, onDone) {
|
|
|
|
schedule((function () {
|
|
|
|
onDone(SocialServiceInternal.providers[origin] || null);
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2013-02-08 11:39:25 -08:00
|
|
|
// Returns an array of installed providers.
|
2012-07-18 11:40:05 -07:00
|
|
|
getProviderList: function getProviderList(onDone) {
|
|
|
|
schedule(function () {
|
|
|
|
onDone(SocialServiceInternal.providerArray);
|
|
|
|
});
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
getOriginActivationType: function(origin) {
|
2013-02-08 11:39:25 -08:00
|
|
|
for (let manifest in SocialServiceInternal.manifests) {
|
|
|
|
if (manifest.origin == origin)
|
2013-03-05 11:24:30 -08:00
|
|
|
return 'builtin';
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
2013-03-05 11:24:30 -08:00
|
|
|
|
|
|
|
let whitelist = Services.prefs.getCharPref("social.whitelist").split(',');
|
|
|
|
if (whitelist.indexOf(origin) >= 0)
|
|
|
|
return 'whitelist';
|
|
|
|
|
|
|
|
let directories = Services.prefs.getCharPref("social.directories").split(',');
|
|
|
|
if (directories.indexOf(origin) >= 0)
|
|
|
|
return 'directory';
|
|
|
|
|
|
|
|
return 'foreign';
|
2013-02-08 11:39:25 -08:00
|
|
|
},
|
|
|
|
|
2012-12-07 20:13:27 -08:00
|
|
|
_providerListeners: new Map(),
|
|
|
|
registerProviderListener: function registerProviderListener(listener) {
|
|
|
|
this._providerListeners.set(listener, 1);
|
|
|
|
},
|
|
|
|
unregisterProviderListener: function unregisterProviderListener(listener) {
|
|
|
|
this._providerListeners.delete(listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
_notifyProviderListeners: function (topic, data) {
|
|
|
|
for (let [listener, ] of this._providerListeners) {
|
|
|
|
try {
|
|
|
|
listener(topic, data);
|
|
|
|
} catch (ex) {
|
|
|
|
Components.utils.reportError("SocialService: provider listener threw an exception: " + ex);
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_manifestFromData: function(type, data, principal) {
|
|
|
|
let sameOriginRequired = ['workerURL', 'sidebarURL'];
|
|
|
|
|
|
|
|
if (type == 'directory') {
|
|
|
|
// directory provided manifests must have origin in manifest, use that
|
|
|
|
if (!data['origin']) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData directory service provided manifest without origin.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let URI = Services.io.newURI(data.origin, null, null);
|
|
|
|
principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(URI);
|
|
|
|
}
|
|
|
|
// force/fixup origin
|
|
|
|
data.origin = principal.origin;
|
|
|
|
|
|
|
|
// workerURL, sidebarURL is required and must be same-origin
|
|
|
|
// iconURL and name are required
|
|
|
|
// iconURL may be a different origin (CDN or data url support) if this is
|
|
|
|
// a whitelisted or directory listed provider
|
|
|
|
if (!data['workerURL'] || !data['sidebarURL']) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData manifest missing required workerURL or sidebarURL.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!data['name'] || !data['iconURL']) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData manifest missing name or iconURL.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
for (let url of sameOriginRequired) {
|
|
|
|
if (data[url]) {
|
|
|
|
try {
|
|
|
|
data[url] = Services.io.newURI(principal.URI.resolve(data[url]), null, null).spec;
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData same-origin missmatch in manifest for " + principal.origin);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
|
|
|
installProvider: function(sourceURI, data, installCallback) {
|
|
|
|
let URI = Services.io.newURI(sourceURI, null, null);
|
|
|
|
let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(URI);
|
|
|
|
let installOrigin = principal.origin;
|
|
|
|
|
|
|
|
let id = getAddonIDFromOrigin(installOrigin);
|
|
|
|
if (bs.getAddonBlocklistState(id, data.version || "0") == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
throw new Error("installProvider: provider with origin [" +
|
|
|
|
installOrigin + "] is blocklisted");
|
|
|
|
|
|
|
|
let installType = this.getOriginActivationType(installOrigin);
|
|
|
|
let manifest;
|
|
|
|
if (data) {
|
|
|
|
// if we get data, we MUST have a valid manifest generated from the data
|
|
|
|
manifest = this._manifestFromData(installType, data, principal);
|
|
|
|
if (!manifest)
|
|
|
|
throw new Error("SocialService.installProvider: service configuration is invalid from " + sourceURI);
|
|
|
|
}
|
|
|
|
switch(installType) {
|
|
|
|
case "foreign":
|
|
|
|
if (!Services.prefs.getBoolPref("social.remote-install.enabled"))
|
|
|
|
throw new Error("Remote install of services is disabled");
|
|
|
|
if (!manifest)
|
|
|
|
throw new Error("Cannot install provider without manifest data");
|
|
|
|
let args = {};
|
|
|
|
args.url = this.url;
|
|
|
|
args.installs = [new AddonInstaller(sourceURI, manifest, installCallback)];
|
|
|
|
args.wrappedJSObject = args;
|
|
|
|
|
|
|
|
// Bug 836452, get something better than the scary addon dialog
|
|
|
|
Services.ww.openWindow(this.window, "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul",
|
|
|
|
null, "chrome,modal,centerscreen", args);
|
|
|
|
break;
|
|
|
|
case "builtin":
|
|
|
|
// for builtin, we already have a manifest, but it can be overridden
|
|
|
|
// we need to return the manifest in the installcallback, so fetch
|
|
|
|
// it if we have it. If there is no manifest data for the builtin,
|
|
|
|
// the install request MUST be from the provider, otherwise we have
|
|
|
|
// no way to know what provider we're trying to enable. This is
|
|
|
|
// primarily an issue for "version zero" providers that did not
|
|
|
|
// send the manifest with the dom event for activation.
|
|
|
|
if (!manifest)
|
|
|
|
manifest = SocialServiceInternal.getManifestByOrigin(installOrigin);
|
|
|
|
case "directory":
|
|
|
|
// a manifest is requried, and will have been vetted by reviewers
|
|
|
|
case "whitelist":
|
|
|
|
// a manifest is required, we'll catch a missing manifest below.
|
|
|
|
if (!manifest)
|
|
|
|
throw new Error("Cannot install provider without manifest data");
|
|
|
|
let installer = new AddonInstaller(sourceURI, manifest, installCallback);
|
|
|
|
installer.install();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("SocialService.installProvider: Invalid install type "+installType+"\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
uninstallProvider: function(origin) {
|
|
|
|
let manifest = SocialServiceInternal.getManifestByOrigin(origin);
|
|
|
|
let addon = new AddonWrapper(manifest);
|
|
|
|
addon.uninstall();
|
2012-07-18 11:40:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
/**
|
|
|
|
* The SocialProvider object represents a social provider, and allows
|
|
|
|
* access to its FrameWorker (if it has one).
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {jsobj} object representing the manifest file describing this provider
|
|
|
|
*/
|
2012-12-07 20:13:27 -08:00
|
|
|
function SocialProvider(input) {
|
2012-07-17 18:44:09 -07:00
|
|
|
if (!input.name)
|
|
|
|
throw new Error("SocialProvider must be passed a name");
|
|
|
|
if (!input.origin)
|
|
|
|
throw new Error("SocialProvider must be passed an origin");
|
|
|
|
|
2013-02-26 14:50:24 -08:00
|
|
|
let id = getAddonIDFromOrigin(input.origin);
|
|
|
|
if (bs.getAddonBlocklistState(id, input.version || "0") == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
throw new Error("SocialProvider: provider with origin [" +
|
|
|
|
input.origin + "] is blocklisted");
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
this.name = input.name;
|
|
|
|
this.iconURL = input.iconURL;
|
2013-02-19 05:32:49 -08:00
|
|
|
this.icon32URL = input.icon32URL;
|
|
|
|
this.icon64URL = input.icon64URL;
|
2012-07-17 18:44:09 -07:00
|
|
|
this.workerURL = input.workerURL;
|
2012-07-18 11:40:05 -07:00
|
|
|
this.sidebarURL = input.sidebarURL;
|
2012-07-17 18:44:09 -07:00
|
|
|
this.origin = input.origin;
|
2012-12-26 23:28:49 -08:00
|
|
|
let originUri = Services.io.newURI(input.origin, null, null);
|
|
|
|
this.principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(originUri);
|
2012-07-17 18:44:09 -07:00
|
|
|
this.ambientNotificationIcons = {};
|
2012-12-07 20:13:27 -08:00
|
|
|
this.errorState = null;
|
2012-07-17 18:44:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SocialProvider.prototype = {
|
|
|
|
// Provider enabled/disabled state. Disabled providers do not have active
|
|
|
|
// connections to their FrameWorkers.
|
2012-12-07 20:13:27 -08:00
|
|
|
_enabled: false,
|
2012-07-17 18:44:09 -07:00
|
|
|
get enabled() {
|
|
|
|
return this._enabled;
|
|
|
|
},
|
|
|
|
set enabled(val) {
|
|
|
|
let enable = !!val;
|
|
|
|
if (enable == this._enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._enabled = enable;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
this._activate();
|
|
|
|
} else {
|
|
|
|
this._terminate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Reference to a workerAPI object for this provider. Null if the provider has
|
|
|
|
// no FrameWorker, or is disabled.
|
|
|
|
workerAPI: null,
|
|
|
|
|
|
|
|
// Contains information related to the user's profile. Populated by the
|
2012-10-08 01:57:21 -07:00
|
|
|
// workerAPI via updateUserProfile.
|
2012-07-17 18:44:09 -07:00
|
|
|
// Properties:
|
|
|
|
// iconURL, portrait, userName, displayName, profileURL
|
|
|
|
// See https://github.com/mozilla/socialapi-dev/blob/develop/docs/socialAPI.md
|
2012-10-07 17:15:02 -07:00
|
|
|
// A value of null or an empty object means 'user not logged in'.
|
2012-10-08 01:57:21 -07:00
|
|
|
// A value of undefined means the service has not yet told us the status of
|
|
|
|
// the profile (ie, the service is still loading/initing, or the provider has
|
|
|
|
// no FrameWorker)
|
2012-10-07 17:15:02 -07:00
|
|
|
// This distinction might be used to cache certain data between runs - eg,
|
|
|
|
// browser-social.js caches the notification icons so they can be displayed
|
|
|
|
// quickly at startup without waiting for the provider to initialize -
|
|
|
|
// 'undefined' means 'ok to use cached values' versus 'null' meaning 'cached
|
|
|
|
// values aren't to be used as the user is logged out'.
|
|
|
|
profile: undefined,
|
2012-07-17 18:44:09 -07:00
|
|
|
|
2012-11-14 19:57:28 -08:00
|
|
|
// Contains the information necessary to support our "recommend" feature.
|
|
|
|
// null means no info yet provided (which includes the case of the provider
|
|
|
|
// not supporting the feature) or the provided data is invalid. Updated via
|
|
|
|
// the 'recommendInfo' setter and returned via the getter.
|
|
|
|
_recommendInfo: null,
|
|
|
|
get recommendInfo() {
|
|
|
|
return this._recommendInfo;
|
|
|
|
},
|
|
|
|
set recommendInfo(data) {
|
|
|
|
// Accept *and validate* the user-recommend-prompt-response message from
|
|
|
|
// the provider.
|
|
|
|
let promptImages = {};
|
|
|
|
let promptMessages = {};
|
|
|
|
function reportError(reason) {
|
|
|
|
Cu.reportError("Invalid recommend data from provider: " + reason + ": sharing is disabled for this provider");
|
|
|
|
// and we explicitly reset the recommend data to null to avoid stale
|
|
|
|
// data being used and notify our observers.
|
|
|
|
this._recommendInfo = null;
|
|
|
|
Services.obs.notifyObservers(null, "social:recommend-info-changed", this.origin);
|
|
|
|
}
|
|
|
|
if (!data ||
|
|
|
|
!data.images || typeof data.images != "object" ||
|
|
|
|
!data.messages || typeof data.messages != "object") {
|
|
|
|
reportError("data is missing valid 'images' or 'messages' elements");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let sub of ["share", "unshare"]) {
|
|
|
|
let url = data.images[sub];
|
|
|
|
if (!url || typeof url != "string" || url.length == 0) {
|
|
|
|
reportError('images["' + sub + '"] is missing or not a non-empty string');
|
|
|
|
return;
|
|
|
|
}
|
2012-12-26 23:28:49 -08:00
|
|
|
// resolve potentially relative URLs but there is no same-origin check
|
|
|
|
// for images to help providers utilize content delivery networks...
|
|
|
|
// Also note no scheme checks are necessary - even a javascript: URL
|
|
|
|
// is safe as gecko evaluates them in a sandbox.
|
|
|
|
let imgUri = this.resolveUri(url);
|
|
|
|
if (!imgUri) {
|
|
|
|
reportError('images["' + sub + '"] is an invalid URL');
|
2012-11-14 19:57:28 -08:00
|
|
|
return;
|
|
|
|
}
|
2012-12-26 23:28:49 -08:00
|
|
|
promptImages[sub] = imgUri.spec;
|
2012-11-14 19:57:28 -08:00
|
|
|
}
|
|
|
|
for (let sub of ["shareTooltip", "unshareTooltip",
|
|
|
|
"sharedLabel", "unsharedLabel", "unshareLabel",
|
|
|
|
"portraitLabel",
|
|
|
|
"unshareConfirmLabel", "unshareConfirmAccessKey",
|
|
|
|
"unshareCancelLabel", "unshareCancelAccessKey"]) {
|
|
|
|
if (typeof data.messages[sub] != "string" || data.messages[sub].length == 0) {
|
|
|
|
reportError('messages["' + sub + '"] is not a valid string');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
promptMessages[sub] = data.messages[sub];
|
|
|
|
}
|
|
|
|
this._recommendInfo = {images: promptImages, messages: promptMessages};
|
|
|
|
Services.obs.notifyObservers(null, "social:recommend-info-changed", this.origin);
|
|
|
|
},
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
// Map of objects describing the provider's notification icons, whose
|
|
|
|
// properties include:
|
|
|
|
// name, iconURL, counter, contentPanel
|
2012-10-07 17:15:02 -07:00
|
|
|
// See https://developer.mozilla.org/en-US/docs/Social_API
|
2012-07-17 18:44:09 -07:00
|
|
|
ambientNotificationIcons: null,
|
|
|
|
|
|
|
|
// Called by the workerAPI to update our profile information.
|
|
|
|
updateUserProfile: function(profile) {
|
2012-12-18 16:05:37 -08:00
|
|
|
if (!profile)
|
|
|
|
profile = {};
|
2012-07-17 18:44:09 -07:00
|
|
|
this.profile = profile;
|
|
|
|
|
2012-08-02 15:30:19 -07:00
|
|
|
// Sanitize the portrait from any potential script-injection.
|
|
|
|
if (profile.portrait) {
|
|
|
|
try {
|
|
|
|
let portraitUri = Services.io.newURI(profile.portrait, null, null);
|
|
|
|
|
|
|
|
let scheme = portraitUri ? portraitUri.scheme : "";
|
|
|
|
if (scheme != "data" && scheme != "http" && scheme != "https") {
|
|
|
|
profile.portrait = "";
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
profile.portrait = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
if (profile.iconURL)
|
|
|
|
this.iconURL = profile.iconURL;
|
|
|
|
|
|
|
|
if (!profile.displayName)
|
|
|
|
profile.displayName = profile.userName;
|
|
|
|
|
|
|
|
// if no userName, consider this a logged out state, emtpy the
|
|
|
|
// users ambient notifications. notify both profile and ambient
|
|
|
|
// changes to clear everything
|
|
|
|
if (!profile.userName) {
|
|
|
|
this.profile = {};
|
|
|
|
this.ambientNotificationIcons = {};
|
|
|
|
Services.obs.notifyObservers(null, "social:ambient-notification-changed", this.origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(null, "social:profile-changed", this.origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called by the workerAPI to add/update a notification icon.
|
|
|
|
setAmbientNotification: function(notification) {
|
|
|
|
if (!this.profile.userName)
|
|
|
|
throw new Error("unable to set notifications while logged out");
|
|
|
|
this.ambientNotificationIcons[notification.name] = notification;
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(null, "social:ambient-notification-changed", this.origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Internal helper methods
|
|
|
|
_activate: function _activate() {
|
|
|
|
// Initialize the workerAPI and its port first, so that its initialization
|
|
|
|
// occurs before any other messages are processed by other ports.
|
2012-09-11 19:48:38 -07:00
|
|
|
let workerAPIPort = this.getWorkerPort();
|
2012-07-17 18:44:09 -07:00
|
|
|
if (workerAPIPort)
|
|
|
|
this.workerAPI = new WorkerAPI(this, workerAPIPort);
|
|
|
|
},
|
|
|
|
|
|
|
|
_terminate: function _terminate() {
|
|
|
|
if (this.workerURL) {
|
|
|
|
try {
|
2012-12-07 20:13:27 -08:00
|
|
|
getFrameWorkerHandle(this.workerURL).terminate();
|
2012-07-17 18:44:09 -07:00
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("SocialProvider FrameWorker termination failed: " + e);
|
|
|
|
}
|
|
|
|
}
|
2012-09-11 19:48:38 -07:00
|
|
|
if (this.workerAPI) {
|
|
|
|
this.workerAPI.terminate();
|
|
|
|
}
|
2012-12-07 20:13:27 -08:00
|
|
|
this.errorState = null;
|
2012-07-17 18:44:09 -07:00
|
|
|
this.workerAPI = null;
|
2012-10-31 21:00:15 -07:00
|
|
|
this.profile = undefined;
|
2012-07-17 18:44:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a FrameWorker for the provider if one doesn't exist, and
|
|
|
|
* returns a reference to a new port to that FrameWorker.
|
|
|
|
*
|
|
|
|
* Returns null if this provider has no workerURL, or is disabled.
|
|
|
|
*
|
|
|
|
* @param {DOMWindow} window (optional)
|
|
|
|
*/
|
2012-09-11 19:48:38 -07:00
|
|
|
getWorkerPort: function getWorkerPort(window) {
|
2012-07-17 18:44:09 -07:00
|
|
|
if (!this.workerURL || !this.enabled)
|
|
|
|
return null;
|
2012-12-07 20:13:27 -08:00
|
|
|
return getFrameWorkerHandle(this.workerURL, window,
|
|
|
|
"SocialProvider:" + this.origin, this.origin).port;
|
2012-12-26 23:28:49 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given URI is of the same origin as the provider.
|
|
|
|
*
|
|
|
|
* Returns true or false.
|
|
|
|
*
|
|
|
|
* @param {URI or string} uri
|
|
|
|
*/
|
|
|
|
isSameOrigin: function isSameOrigin(uri, allowIfInheritsPrincipal) {
|
|
|
|
if (!uri)
|
|
|
|
return false;
|
|
|
|
if (typeof uri == "string") {
|
|
|
|
try {
|
|
|
|
uri = Services.io.newURI(uri, null, null);
|
|
|
|
} catch (ex) {
|
|
|
|
// an invalid URL can't be loaded!
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
this.principal.checkMayLoad(
|
|
|
|
uri, // the thing to check.
|
|
|
|
false, // reportError - we do our own reporting when necessary.
|
|
|
|
allowIfInheritsPrincipal
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
} catch (ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve partial URLs for a provider.
|
|
|
|
*
|
|
|
|
* Returns nsIURI object or null on failure
|
|
|
|
*
|
|
|
|
* @param {string} url
|
|
|
|
*/
|
|
|
|
resolveUri: function resolveUri(url) {
|
|
|
|
try {
|
|
|
|
let fullURL = this.principal.URI.resolve(url);
|
|
|
|
return Services.io.newURI(fullURL, null, null);
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("mozSocial: failed to resolve window URL: " + url + "; " + ex);
|
|
|
|
return null;
|
|
|
|
}
|
2012-07-17 18:44:09 -07:00
|
|
|
}
|
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
|
|
|
|
function getAddonIDFromOrigin(origin) {
|
|
|
|
let originUri = Services.io.newURI(origin, null, null);
|
|
|
|
return originUri.host + ID_SUFFIX;
|
|
|
|
}
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
function getPrefnameFromOrigin(origin) {
|
|
|
|
return "social.manifest." + SocialServiceInternal.getManifestPrefname(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddonInstaller(sourceURI, aManifest, installCallback) {
|
|
|
|
this.sourceURI = sourceURI;
|
|
|
|
this.install = function() {
|
|
|
|
let addon = this.addon;
|
|
|
|
AddonManagerPrivate.callInstallListeners("onExternalInstall", null, addon, null, false);
|
|
|
|
AddonManagerPrivate.callAddonListeners("onInstalling", addon, false);
|
|
|
|
Services.prefs.setCharPref(getPrefnameFromOrigin(aManifest.origin), JSON.stringify(aManifest));
|
|
|
|
AddonManagerPrivate.callAddonListeners("onInstalled", addon);
|
|
|
|
installCallback(aManifest);
|
|
|
|
};
|
|
|
|
this.cancel = function() {
|
|
|
|
Services.prefs.clearUserPref(getPrefnameFromOrigin(aManifest.origin))
|
|
|
|
},
|
|
|
|
this.addon = new AddonWrapper(aManifest);
|
|
|
|
};
|
|
|
|
|
2013-02-26 14:50:24 -08:00
|
|
|
var SocialAddonProvider = {
|
|
|
|
startup: function() {},
|
|
|
|
|
|
|
|
shutdown: function() {},
|
|
|
|
|
|
|
|
updateAddonAppDisabledStates: function() {
|
|
|
|
// we wont bother with "enabling" services that are released from blocklist
|
|
|
|
for (let manifest of SocialServiceInternal.manifests) {
|
|
|
|
try {
|
|
|
|
if (ActiveProviders.has(manifest.origin)) {
|
|
|
|
let id = getAddonIDFromOrigin(manifest.origin);
|
|
|
|
if (bs.getAddonBlocklistState(id, manifest.version || "0") != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
|
|
|
|
SocialService.removeProvider(manifest.origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getAddonByID: function(aId, aCallback) {
|
|
|
|
for (let manifest of SocialServiceInternal.manifests) {
|
|
|
|
if (aId == getAddonIDFromOrigin(manifest.origin)) {
|
|
|
|
aCallback(new AddonWrapper(manifest));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aCallback(null);
|
|
|
|
},
|
|
|
|
|
|
|
|
getAddonsByTypes: function(aTypes, aCallback) {
|
|
|
|
if (aTypes && aTypes.indexOf(ADDON_TYPE_SERVICE) == -1) {
|
|
|
|
aCallback([]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aCallback([new AddonWrapper(a) for each (a in SocialServiceInternal.manifests)]);
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
removeAddon: function(aAddon) {
|
|
|
|
AddonManagerPrivate.callAddonListeners("onUninstalling", aAddon, false);
|
|
|
|
aAddon.pendingOperations |= AddonManager.PENDING_UNINSTALL;
|
|
|
|
Services.prefs.clearUserPref(getPrefnameFromOrigin(aAddon.manifest.origin));
|
|
|
|
aAddon.pendingOperations -= AddonManager.PENDING_UNINSTALL;
|
|
|
|
AddonManagerPrivate.callAddonListeners("onUninstalled", aAddon);
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function AddonWrapper(aManifest) {
|
|
|
|
this.manifest = aManifest;
|
|
|
|
this.id = getAddonIDFromOrigin(this.manifest.origin);
|
|
|
|
this._pending = AddonManager.PENDING_NONE;
|
|
|
|
}
|
|
|
|
AddonWrapper.prototype = {
|
|
|
|
get type() {
|
|
|
|
return ADDON_TYPE_SERVICE;
|
|
|
|
},
|
|
|
|
|
|
|
|
get appDisabled() {
|
|
|
|
return this.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED;
|
|
|
|
},
|
|
|
|
|
|
|
|
set softDisabled(val) {
|
|
|
|
this.userDisabled = val;
|
|
|
|
},
|
|
|
|
|
|
|
|
get softDisabled() {
|
|
|
|
return this.userDisabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
get isCompatible() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
get isPlatformCompatible() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
get scope() {
|
|
|
|
return AddonManager.SCOPE_PROFILE;
|
|
|
|
},
|
|
|
|
|
|
|
|
get foreignInstall() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
isCompatibleWith: function(appVersion, platformVersion) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
get providesUpdatesSecurely() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
get blocklistState() {
|
|
|
|
return bs.getAddonBlocklistState(this.id, this.version || "0");
|
|
|
|
},
|
|
|
|
|
|
|
|
get blocklistURL() {
|
|
|
|
return bs.getAddonBlocklistURL(this.id, this.version || "0");
|
|
|
|
},
|
|
|
|
|
|
|
|
get screenshots() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
get pendingOperations() {
|
|
|
|
return this._pending || AddonManager.PENDING_NONE;
|
|
|
|
},
|
|
|
|
set pendingOperations(val) {
|
|
|
|
this._pending = val;
|
|
|
|
},
|
|
|
|
|
|
|
|
get operationsRequiringRestart() {
|
|
|
|
return AddonManager.OP_NEEDS_RESTART_NONE;
|
|
|
|
},
|
|
|
|
|
|
|
|
get size() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get permissions() {
|
|
|
|
let permissions = 0;
|
2013-03-05 11:24:30 -08:00
|
|
|
// any "user defined" manifest can be removed
|
|
|
|
if (Services.prefs.prefHasUserValue(getPrefnameFromOrigin(this.manifest.origin)))
|
|
|
|
permissions = AddonManager.PERM_CAN_UNINSTALL;
|
2013-02-26 14:50:24 -08:00
|
|
|
if (!this.appDisabled) {
|
|
|
|
if (this.userDisabled) {
|
|
|
|
permissions |= AddonManager.PERM_CAN_ENABLE;
|
|
|
|
} else {
|
|
|
|
permissions |= AddonManager.PERM_CAN_DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissions;
|
|
|
|
},
|
|
|
|
|
|
|
|
findUpdates: function(listener, reason, appVersion, platformVersion) {
|
|
|
|
if ("onNoCompatibilityUpdateAvailable" in listener)
|
|
|
|
listener.onNoCompatibilityUpdateAvailable(this);
|
|
|
|
if ("onNoUpdateAvailable" in listener)
|
|
|
|
listener.onNoUpdateAvailable(this);
|
|
|
|
if ("onUpdateFinished" in listener)
|
|
|
|
listener.onUpdateFinished(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
get isActive() {
|
|
|
|
return ActiveProviders.has(this.manifest.origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return this.manifest.name;
|
|
|
|
},
|
|
|
|
get version() {
|
|
|
|
return this.manifest.version ? this.manifest.version : "";
|
|
|
|
},
|
|
|
|
|
|
|
|
get iconURL() {
|
|
|
|
return this.manifest.icon32URL ? this.manifest.icon32URL : this.manifest.iconURL;
|
|
|
|
},
|
|
|
|
get icon64URL() {
|
|
|
|
return this.manifest.icon64URL;
|
|
|
|
},
|
|
|
|
get icons() {
|
|
|
|
let icons = {
|
|
|
|
16: this.manifest.iconURL
|
|
|
|
};
|
|
|
|
if (this.manifest.icon32URL)
|
|
|
|
icons[32] = this.manifest.icon32URL;
|
|
|
|
if (this.manifest.icon64URL)
|
|
|
|
icons[64] = this.manifest.icon64URL;
|
|
|
|
return icons;
|
|
|
|
},
|
|
|
|
|
|
|
|
get description() {
|
|
|
|
return this.manifest.description;
|
|
|
|
},
|
|
|
|
get homepageURL() {
|
|
|
|
return this.manifest.homepageURL;
|
|
|
|
},
|
|
|
|
get defaultLocale() {
|
|
|
|
return this.manifest.defaultLocale;
|
|
|
|
},
|
|
|
|
get selectedLocale() {
|
|
|
|
return this.manifest.selectedLocale;
|
|
|
|
},
|
|
|
|
|
|
|
|
get installDate() {
|
|
|
|
return this.manifest.installDate ? new Date(this.manifest.installDate) : null;
|
|
|
|
},
|
|
|
|
get updateDate() {
|
|
|
|
return this.manifest.updateDate ? new Date(this.manifest.updateDate) : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get creator() {
|
|
|
|
return new AddonManagerPrivate.AddonAuthor(this.manifest.author);
|
|
|
|
},
|
|
|
|
|
|
|
|
get userDisabled() {
|
|
|
|
return this.appDisabled || !ActiveProviders.has(this.manifest.origin);
|
|
|
|
},
|
|
|
|
|
|
|
|
set userDisabled(val) {
|
|
|
|
if (val == this.userDisabled)
|
|
|
|
return val;
|
|
|
|
if (val) {
|
|
|
|
SocialService.removeProvider(this.manifest.origin);
|
|
|
|
} else if (!this.appDisabled) {
|
|
|
|
SocialService.addBuiltinProvider(this.manifest.origin);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
|
|
|
|
uninstall: function() {
|
2013-03-05 11:24:30 -08:00
|
|
|
let prefName = getPrefnameFromOrigin(this.manifest.origin);
|
|
|
|
if (Services.prefs.prefHasUserValue(prefName)) {
|
|
|
|
if (ActiveProviders.has(this.manifest.origin)) {
|
|
|
|
SocialService.removeProvider(this.manifest.origin, function() {
|
|
|
|
SocialAddonProvider.removeAddon(this);
|
|
|
|
}.bind(this));
|
|
|
|
} else {
|
|
|
|
SocialAddonProvider.removeAddon(this);
|
|
|
|
}
|
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelUninstall: function() {
|
2013-03-05 11:24:30 -08:00
|
|
|
let prefName = getPrefnameFromOrigin(this.manifest.origin);
|
|
|
|
if (Services.prefs.prefHasUserValue(prefName))
|
|
|
|
throw new Error(this.manifest.name + " is not marked to be uninstalled");
|
|
|
|
// ensure we're set into prefs
|
|
|
|
Services.prefs.setCharPref(prefName, JSON.stringify(this.manifest));
|
|
|
|
this._pending -= AddonManager.PENDING_UNINSTALL;
|
|
|
|
AddonManagerPrivate.callAddonListeners("onOperationCancelled", this);
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AddonManagerPrivate.registerProvider(SocialAddonProvider, [
|
|
|
|
new AddonManagerPrivate.AddonType(ADDON_TYPE_SERVICE, URI_EXTENSION_STRINGS,
|
|
|
|
STRING_TYPE_NAME,
|
|
|
|
AddonManager.VIEW_TYPE_LIST, 10000)
|
|
|
|
]);
|