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");
|
2013-05-11 10:54:31 -07:00
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
2013-02-26 14:50:24 -08:00
|
|
|
|
|
|
|
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");
|
2013-08-15 15:30:02 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "closeAllChatWindows", "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-05-11 10:54:31 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "etld",
|
|
|
|
"@mozilla.org/network/effective-tld-service;1",
|
|
|
|
"nsIEffectiveTLDService");
|
|
|
|
|
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
|
2015-09-15 11:19:45 -07:00
|
|
|
var SocialServiceInternal = {
|
2015-09-24 04:32:23 -07:00
|
|
|
get enabled() {
|
|
|
|
return this.providerArray.length > 0;
|
|
|
|
},
|
2013-08-21 11:32:46 -07:00
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
get providerArray() {
|
|
|
|
return [p for ([, p] of Iterator(this.providers))];
|
2013-02-08 11:39:25 -08:00
|
|
|
},
|
|
|
|
get manifests() {
|
2013-04-03 20:39:37 -07:00
|
|
|
// Retrieve the manifests of installed providers from prefs
|
2013-02-08 11:39:25 -08:00
|
|
|
let MANIFEST_PREFS = Services.prefs.getBranch("social.manifest.");
|
|
|
|
let prefs = MANIFEST_PREFS.getChildList("", []);
|
|
|
|
for (let pref of prefs) {
|
2013-04-03 20:39:37 -07:00
|
|
|
// we only consider manifests in user level prefs to be *installed*
|
|
|
|
if (!MANIFEST_PREFS.prefHasUserValue(pref))
|
|
|
|
continue;
|
2013-02-08 11:39:25 -08:00
|
|
|
try {
|
2013-04-01 16:27:13 -07:00
|
|
|
var manifest = JSON.parse(MANIFEST_PREFS.getComplexValue(pref, Ci.nsISupportsString).data);
|
2013-02-08 11:39:25 -08:00
|
|
|
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
|
|
|
},
|
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 {
|
2013-04-03 20:39:37 -07:00
|
|
|
var manifest = JSON.parse(MANIFEST_PREFS.getComplexValue(pref, Ci.nsISupportsString).data);
|
2013-03-05 11:24:30 -08:00
|
|
|
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('.','-');
|
2013-05-11 10:54:31 -07:00
|
|
|
},
|
|
|
|
orderedProviders: function(aCallback) {
|
|
|
|
if (SocialServiceInternal.providerArray.length < 2) {
|
|
|
|
schedule(function () {
|
|
|
|
aCallback(SocialServiceInternal.providerArray);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// query moz_hosts for frecency. since some providers may not have a
|
|
|
|
// frecency entry, we need to later sort on our own. We use the providers
|
|
|
|
// object below as an easy way to later record the frecency on the provider
|
|
|
|
// object from the query results.
|
|
|
|
let hosts = [];
|
|
|
|
let providers = {};
|
|
|
|
|
2013-07-11 07:52:30 -07:00
|
|
|
for (let p of SocialServiceInternal.providerArray) {
|
2013-05-11 10:54:31 -07:00
|
|
|
p.frecency = 0;
|
|
|
|
providers[p.domain] = p;
|
|
|
|
hosts.push(p.domain);
|
|
|
|
};
|
|
|
|
|
|
|
|
// cannot bind an array to stmt.params so we have to build the string
|
|
|
|
let stmt = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
|
|
|
.DBConnection.createAsyncStatement(
|
|
|
|
"SELECT host, frecency FROM moz_hosts WHERE host IN (" +
|
|
|
|
[ '"' + host + '"' for each (host in hosts) ].join(",") + ") "
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
stmt.executeAsync({
|
|
|
|
handleResult: function(aResultSet) {
|
|
|
|
let row;
|
|
|
|
while ((row = aResultSet.getNextRow())) {
|
|
|
|
let rh = row.getResultByName("host");
|
|
|
|
let frecency = row.getResultByName("frecency");
|
|
|
|
providers[rh].frecency = parseInt(frecency) || 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleError: function(aError) {
|
|
|
|
Cu.reportError(aError.message + " (Result = " + aError.result + ")");
|
|
|
|
},
|
|
|
|
handleCompletion: function(aReason) {
|
|
|
|
// the query may not have returned all our providers, so we have
|
|
|
|
// stamped the frecency on the provider and sort here. This makes sure
|
|
|
|
// all enabled providers get sorted even with frecency zero.
|
|
|
|
let providerList = SocialServiceInternal.providerArray;
|
|
|
|
// reverse sort
|
2015-09-24 04:32:23 -07:00
|
|
|
aCallback(providerList.sort((a, b) => b.frecency - a.frecency));
|
2013-05-11 10:54:31 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
stmt.finalize();
|
|
|
|
}
|
2012-07-18 11:40:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-17 14:25:06 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(SocialServiceInternal, "providers", function () {
|
|
|
|
initService();
|
|
|
|
let providers = {};
|
|
|
|
for (let manifest of this.manifests) {
|
|
|
|
try {
|
|
|
|
if (ActiveProviders.has(manifest.origin)) {
|
2014-03-11 19:25:45 -07:00
|
|
|
// enable the api when a provider is enabled
|
|
|
|
MozSocialAPI.enabled = true;
|
2013-06-26 15:20:35 -07:00
|
|
|
let provider = new SocialProvider(manifest);
|
2013-06-17 14:25:06 -07:00
|
|
|
providers[provider.origin] = provider;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("SocialService: failed to load provider: " + manifest.origin +
|
|
|
|
", exception: " + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return providers;
|
|
|
|
});
|
|
|
|
|
|
|
|
function getOriginActivationType(origin) {
|
2014-07-18 10:27:52 -07:00
|
|
|
// if this is an about uri, treat it as a directory
|
2014-10-09 12:02:21 -07:00
|
|
|
let URI = Services.io.newURI(origin, null, null);
|
2015-08-18 00:01:42 -07:00
|
|
|
let principal = Services.scriptSecurityManager.createCodebasePrincipal(URI, {});
|
2014-10-09 12:02:21 -07:00
|
|
|
if (Services.scriptSecurityManager.isSystemPrincipal(principal) || origin == "moz-safe-about:home") {
|
2014-07-18 10:27:52 -07:00
|
|
|
return "internal";
|
2014-07-08 16:48:12 -07:00
|
|
|
}
|
2013-06-17 14:25:06 -07:00
|
|
|
|
|
|
|
let directories = Services.prefs.getCharPref("social.directories").split(',');
|
|
|
|
if (directories.indexOf(origin) >= 0)
|
2015-02-19 11:27:27 -08:00
|
|
|
return "directory";
|
2013-06-17 14:25:06 -07:00
|
|
|
|
2015-02-19 11:27:27 -08:00
|
|
|
return "foreign";
|
2013-06-17 14:25:06 -07:00
|
|
|
}
|
|
|
|
|
2015-09-15 11:19:45 -07:00
|
|
|
var ActiveProviders = {
|
2012-12-07 20:13:27 -08:00
|
|
|
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;
|
2013-12-03 04:21:08 -08:00
|
|
|
this._deferredTask.arm();
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
delete: function (origin) {
|
|
|
|
delete this._providers[origin];
|
2013-12-03 04:21:08 -08:00
|
|
|
this._deferredTask.arm();
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
flush: function () {
|
2013-12-03 04:21:08 -08:00
|
|
|
this._deferredTask.disarm();
|
|
|
|
this._persist();
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
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() {
|
2014-03-11 19:25:45 -07:00
|
|
|
let activeProviders, enabled;
|
2013-02-08 11:39:25 -08:00
|
|
|
try {
|
2013-04-03 20:39:37 -07:00
|
|
|
activeProviders = Services.prefs.getCharPref("social.activeProviders");
|
2013-02-08 11:39:25 -08:00
|
|
|
} catch(e) {
|
2013-04-11 15:43:40 -07:00
|
|
|
// not set, we'll check if we need to migrate older prefs
|
2013-04-03 20:39:37 -07:00
|
|
|
}
|
2014-03-11 19:25:45 -07:00
|
|
|
if (Services.prefs.prefHasUserValue("social.enabled")) {
|
|
|
|
enabled = Services.prefs.getBoolPref("social.enabled");
|
|
|
|
}
|
2013-04-03 20:39:37 -07:00
|
|
|
if (activeProviders) {
|
|
|
|
// migration from fx21 to fx22 or later
|
|
|
|
// ensure any *builtin* provider in activeproviders is in user level prefs
|
|
|
|
for (let origin in ActiveProviders._providers) {
|
2013-04-11 15:43:40 -07:00
|
|
|
let prefname;
|
2013-04-29 13:09:10 -07:00
|
|
|
let manifest;
|
2013-05-06 23:02:58 -07:00
|
|
|
let defaultManifest;
|
2013-04-11 15:43:40 -07:00
|
|
|
try {
|
|
|
|
prefname = getPrefnameFromOrigin(origin);
|
2013-04-29 13:09:10 -07:00
|
|
|
manifest = JSON.parse(Services.prefs.getComplexValue(prefname, Ci.nsISupportsString).data);
|
2013-04-11 15:43:40 -07:00
|
|
|
} catch(e) {
|
|
|
|
// Our preference is missing or bad, remove from ActiveProviders and
|
|
|
|
// continue. This is primarily an error-case and should only be
|
|
|
|
// reached by either messing with preferences or hitting the one or
|
|
|
|
// two days of nightly that ran into it, so we'll flush right away.
|
|
|
|
ActiveProviders.delete(origin);
|
|
|
|
ActiveProviders.flush();
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-06 23:02:58 -07:00
|
|
|
let needsUpdate = !manifest.updateDate;
|
|
|
|
// fx23 may have built-ins with shareURL
|
|
|
|
try {
|
|
|
|
defaultManifest = Services.prefs.getDefaultBranch(null)
|
|
|
|
.getComplexValue(prefname, Ci.nsISupportsString).data;
|
|
|
|
defaultManifest = JSON.parse(defaultManifest);
|
2014-02-28 15:07:44 -08:00
|
|
|
} catch(e) {
|
|
|
|
// not a built-in, continue
|
|
|
|
}
|
|
|
|
if (defaultManifest) {
|
2013-05-06 23:02:58 -07:00
|
|
|
if (defaultManifest.shareURL && !manifest.shareURL) {
|
|
|
|
manifest.shareURL = defaultManifest.shareURL;
|
|
|
|
needsUpdate = true;
|
|
|
|
}
|
2014-02-28 15:07:44 -08:00
|
|
|
if (defaultManifest.version && (!manifest.version || defaultManifest.version > manifest.version)) {
|
|
|
|
manifest = defaultManifest;
|
|
|
|
needsUpdate = true;
|
|
|
|
}
|
2013-05-06 23:02:58 -07:00
|
|
|
}
|
|
|
|
if (needsUpdate) {
|
2013-04-29 13:09:10 -07:00
|
|
|
// the provider was installed with an older build, so we will update the
|
|
|
|
// timestamp and ensure the manifest is in user prefs
|
2013-04-05 19:14:41 -07:00
|
|
|
delete manifest.builtin;
|
2013-05-06 23:02:58 -07:00
|
|
|
// we're potentially updating for share, so always mark the updateDate
|
|
|
|
manifest.updateDate = Date.now();
|
|
|
|
if (!manifest.installDate)
|
2013-04-29 13:09:10 -07:00
|
|
|
manifest.installDate = 0; // we don't know when it was installed
|
2013-04-03 20:39:37 -07:00
|
|
|
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = JSON.stringify(manifest);
|
|
|
|
Services.prefs.setComplexValue(prefname, Ci.nsISupportsString, string);
|
|
|
|
}
|
2014-03-11 19:25:45 -07:00
|
|
|
// as of fx 29, we no longer rely on social.enabled. migration from prior
|
|
|
|
// versions should disable all service addons if social.enabled=false
|
|
|
|
if (enabled === false) {
|
|
|
|
ActiveProviders.delete(origin);
|
|
|
|
}
|
2013-04-03 20:39:37 -07:00
|
|
|
}
|
2014-03-11 19:25:45 -07:00
|
|
|
ActiveProviders.flush();
|
|
|
|
Services.prefs.clearUserPref("social.enabled");
|
2013-04-03 20:39:37 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// primary migration from pre-fx21
|
|
|
|
let active;
|
|
|
|
try {
|
|
|
|
active = Services.prefs.getBoolPref("social.active");
|
|
|
|
} catch(e) {}
|
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// primary difference from SocialServiceInternal.manifests is that we
|
|
|
|
// only read the default branch here.
|
|
|
|
let manifestPrefs = Services.prefs.getDefaultBranch("social.manifest.");
|
|
|
|
let prefs = manifestPrefs.getChildList("", []);
|
|
|
|
for (let pref of prefs) {
|
2013-02-08 11:39:25 -08:00
|
|
|
try {
|
2013-04-11 15:43:40 -07:00
|
|
|
let manifest;
|
|
|
|
try {
|
|
|
|
manifest = JSON.parse(manifestPrefs.getComplexValue(pref, Ci.nsISupportsString).data);
|
|
|
|
} catch(e) {
|
|
|
|
// bad or missing preference, we wont update this one.
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-03 20:39:37 -07:00
|
|
|
if (manifest && typeof(manifest) == "object" && manifest.origin) {
|
2013-04-05 19:14:41 -07:00
|
|
|
// our default manifests have been updated with the builtin flags as of
|
|
|
|
// fx22, delete it so we can set the user-pref
|
|
|
|
delete manifest.builtin;
|
2013-04-29 13:09:10 -07:00
|
|
|
if (!manifest.updateDate) {
|
|
|
|
manifest.updateDate = Date.now();
|
|
|
|
manifest.installDate = 0; // we don't know when it was installed
|
|
|
|
}
|
2013-04-05 19:14:41 -07:00
|
|
|
|
2013-04-03 20:39:37 -07:00
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = JSON.stringify(manifest);
|
2013-04-05 19:14:41 -07:00
|
|
|
// pref here is just the branch name, set the full pref name
|
|
|
|
Services.prefs.setComplexValue("social.manifest." + pref, Ci.nsISupportsString, string);
|
2013-04-03 20:39:37 -07:00
|
|
|
ActiveProviders.add(manifest.origin);
|
|
|
|
ActiveProviders.flush();
|
|
|
|
// social.active was used at a time that there was only one
|
|
|
|
// builtin, we'll assume that is still the case
|
|
|
|
return;
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
2013-04-03 20:39:37 -07:00
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError("SocialService: failed to load manifest: " + pref + ", exception: " + err);
|
2013-02-08 11:39:25 -08:00
|
|
|
}
|
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-04-11 15:43:40 -07:00
|
|
|
try {
|
|
|
|
migrateSettings();
|
|
|
|
} catch(e) {
|
|
|
|
// no matter what, if migration fails we do not want to render social
|
|
|
|
// unusable. Worst case scenario is that, when upgrading Firefox, previously
|
|
|
|
// enabled providers are not migrated.
|
|
|
|
Cu.reportError("Error migrating social settings: " + e);
|
|
|
|
}
|
2012-08-13 08:20:29 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 11:40:05 -07:00
|
|
|
function schedule(callback) {
|
|
|
|
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public API
|
2012-10-31 09:13:28 -07:00
|
|
|
this.SocialService = {
|
2013-08-30 11:11:20 -07:00
|
|
|
get hasEnabledProviders() {
|
|
|
|
// used as an optimization during startup, can be used to check if further
|
|
|
|
// initialization should be done (e.g. creating the instances of
|
|
|
|
// SocialProvider and turning on UI). ActiveProviders may have changed and
|
|
|
|
// not yet flushed so we check the active providers array
|
|
|
|
for (let p in ActiveProviders._providers) {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
return false;
|
|
|
|
},
|
2012-07-18 11:40:05 -07:00
|
|
|
get enabled() {
|
|
|
|
return SocialServiceInternal.enabled;
|
|
|
|
},
|
|
|
|
set enabled(val) {
|
2014-03-11 19:25:45 -07:00
|
|
|
throw new Error("not allowed to set SocialService.enabled");
|
2012-07-18 11:40:05 -07:00
|
|
|
},
|
|
|
|
|
2014-07-18 10:27:52 -07:00
|
|
|
// Enables a provider, the manifest must already exist in prefs. 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.
|
|
|
|
enableProvider: function enableProvider(origin, onDone) {
|
2013-02-08 11:39:25 -08:00
|
|
|
if (SocialServiceInternal.providers[origin]) {
|
|
|
|
schedule(function() {
|
|
|
|
onDone(SocialServiceInternal.providers[origin]);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2013-09-04 10:01:38 -07:00
|
|
|
let manifest = SocialService.getManifestByOrigin(origin);
|
2013-02-26 14:50:24 -08:00
|
|
|
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");
|
|
|
|
|
2014-03-11 19:25:45 -07:00
|
|
|
// enable the api when a provider is enabled
|
|
|
|
MozSocialAPI.enabled = true;
|
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
|
|
|
|
2013-05-11 10:54:31 -07:00
|
|
|
this.getOrderedProviderList(function (providers) {
|
2013-09-04 10:01:38 -07:00
|
|
|
this._notifyProviderListeners("provider-enabled", provider.origin, providers);
|
2012-12-07 20:13:27 -08:00
|
|
|
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.
|
2014-07-18 10:27:52 -07:00
|
|
|
disableProvider: function disableProvider(origin, onDone) {
|
2012-07-18 11:40:05 -07:00
|
|
|
if (!(origin in SocialServiceInternal.providers))
|
2014-07-18 10:27:52 -07:00
|
|
|
throw new Error("SocialService.disableProvider: no provider with origin " + origin + " exists!");
|
2012-07-18 11:40:05 -07:00
|
|
|
|
|
|
|
let provider = SocialServiceInternal.providers[origin];
|
2013-09-04 10:01:38 -07:00
|
|
|
let manifest = SocialService.getManifestByOrigin(origin);
|
2013-02-26 14:50:24 -08:00
|
|
|
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];
|
2014-03-11 19:25:45 -07:00
|
|
|
// disable the api if we have no enabled providers
|
|
|
|
MozSocialAPI.enabled = SocialServiceInternal.enabled;
|
2012-07-18 11:40:05 -07:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-11 10:54:31 -07:00
|
|
|
this.getOrderedProviderList(function (providers) {
|
2013-09-04 10:01:38 -07:00
|
|
|
this._notifyProviderListeners("provider-disabled", origin, providers);
|
2012-12-07 20:13:27 -08:00
|
|
|
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-05-11 10:54:31 -07:00
|
|
|
// Returns an unordered array of installed providers
|
|
|
|
getProviderList: function(onDone) {
|
2012-07-18 11:40:05 -07:00
|
|
|
schedule(function () {
|
|
|
|
onDone(SocialServiceInternal.providerArray);
|
|
|
|
});
|
2012-12-07 20:13:27 -08:00
|
|
|
},
|
|
|
|
|
2013-09-04 10:01:38 -07:00
|
|
|
getManifestByOrigin: function(origin) {
|
|
|
|
for (let manifest of SocialServiceInternal.manifests) {
|
|
|
|
if (origin == manifest.origin) {
|
|
|
|
return manifest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-05-11 10:54:31 -07:00
|
|
|
// Returns an array of installed providers, sorted by frecency
|
|
|
|
getOrderedProviderList: function(onDone) {
|
|
|
|
SocialServiceInternal.orderedProviders(onDone);
|
|
|
|
},
|
|
|
|
|
2013-06-17 14:25:06 -07:00
|
|
|
getOriginActivationType: function (origin) {
|
|
|
|
return getOriginActivationType(origin);
|
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);
|
|
|
|
},
|
|
|
|
|
2013-09-04 10:01:38 -07:00
|
|
|
_notifyProviderListeners: function (topic, origin, providers) {
|
2012-12-07 20:13:27 -08:00
|
|
|
for (let [listener, ] of this._providerListeners) {
|
|
|
|
try {
|
2013-09-04 10:01:38 -07:00
|
|
|
listener(topic, origin, providers);
|
2012-12-07 20:13:27 -08:00
|
|
|
} catch (ex) {
|
|
|
|
Components.utils.reportError("SocialService: provider listener threw an exception: " + ex);
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
_manifestFromData: function(type, data, installOrigin) {
|
2014-04-30 12:08:23 -07:00
|
|
|
let featureURLs = ['workerURL', 'sidebarURL', 'shareURL', 'statusURL', 'markURL'];
|
|
|
|
let resolveURLs = featureURLs.concat(['postActivationURL']);
|
2013-03-05 11:24:30 -08:00
|
|
|
|
2014-07-08 16:48:12 -07:00
|
|
|
if (type == 'directory' || type == 'internal') {
|
2013-03-05 11:24:30 -08:00
|
|
|
// 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;
|
|
|
|
}
|
2014-11-05 17:22:27 -08:00
|
|
|
installOrigin = data.origin;
|
2013-03-05 11:24:30 -08:00
|
|
|
}
|
|
|
|
// force/fixup origin
|
2014-11-05 17:22:27 -08:00
|
|
|
let URI = Services.io.newURI(installOrigin, null, null);
|
2015-08-18 00:01:42 -07:00
|
|
|
principal = Services.scriptSecurityManager.createCodebasePrincipal(URI, {});
|
2013-03-05 11:24:30 -08:00
|
|
|
data.origin = principal.origin;
|
|
|
|
|
|
|
|
// iconURL and name are required
|
2014-04-30 12:08:23 -07:00
|
|
|
let providerHasFeatures = [url for (url of featureURLs) if (data[url])].length > 0;
|
2013-09-04 10:01:38 -07:00
|
|
|
if (!providerHasFeatures) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData manifest missing required urls.");
|
2013-03-05 11:24:30 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!data['name'] || !data['iconURL']) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData manifest missing name or iconURL.");
|
|
|
|
return null;
|
|
|
|
}
|
2014-04-30 12:08:23 -07:00
|
|
|
for (let url of resolveURLs) {
|
2013-03-05 11:24:30 -08:00
|
|
|
if (data[url]) {
|
|
|
|
try {
|
2014-04-30 12:08:23 -07:00
|
|
|
let resolved = Services.io.newURI(principal.URI.resolve(data[url]), null, null);
|
|
|
|
if (!(resolved.schemeIs("http") || resolved.schemeIs("https"))) {
|
|
|
|
Cu.reportError("SocialService.manifestFromData unsupported scheme '" + resolved.scheme + "' for " + principal.origin);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
data[url] = resolved.spec;
|
2013-03-05 11:24:30 -08:00
|
|
|
} catch(e) {
|
2014-04-30 12:08:23 -07:00
|
|
|
Cu.reportError("SocialService.manifestFromData unable to resolve '" + url + "' for " + principal.origin);
|
2013-03-05 11:24:30 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
_showInstallNotification: function(data, aAddonInstaller) {
|
2013-04-02 16:28:30 -07:00
|
|
|
let brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
|
2015-02-19 11:27:27 -08:00
|
|
|
// internal/directory activations need to use the manifest origin, any other
|
|
|
|
// use the domain activation is occurring on
|
|
|
|
let url = data.url;
|
|
|
|
if (data.installType == "internal" || data.installType == "directory") {
|
|
|
|
url = data.manifest.origin;
|
|
|
|
}
|
|
|
|
let requestingURI = Services.io.newURI(url, null, null);
|
2013-04-02 16:28:30 -07:00
|
|
|
let productName = brandBundle.GetStringFromName("brandShortName");
|
|
|
|
|
|
|
|
let message = browserBundle.formatStringFromName("service.install.description",
|
2014-09-30 17:08:42 -07:00
|
|
|
[requestingURI.host, productName], 2);
|
2013-04-02 16:28:30 -07:00
|
|
|
|
|
|
|
let action = {
|
|
|
|
label: browserBundle.GetStringFromName("service.install.ok.label"),
|
|
|
|
accessKey: browserBundle.GetStringFromName("service.install.ok.accesskey"),
|
|
|
|
callback: function() {
|
|
|
|
aAddonInstaller.install();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-02-18 19:05:34 -08:00
|
|
|
let options = {
|
|
|
|
learnMoreURL: Services.urlFormatter.formatURLPref("app.support.baseURL") + "social-api",
|
|
|
|
};
|
2013-04-02 16:28:30 -07:00
|
|
|
let anchor = "servicesInstall-notification-icon";
|
|
|
|
let notificationid = "servicesInstall";
|
2014-11-05 17:22:27 -08:00
|
|
|
data.window.PopupNotifications.show(data.window.gBrowser.selectedBrowser,
|
|
|
|
notificationid, message, anchor,
|
|
|
|
action, [], options);
|
2013-04-02 16:28:30 -07:00
|
|
|
},
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
installProvider: function(data, installCallback, options={}) {
|
|
|
|
data.installType = getOriginActivationType(data.origin);
|
2014-10-09 12:02:21 -07:00
|
|
|
// if we get data, we MUST have a valid manifest generated from the data
|
2014-11-05 17:22:27 -08:00
|
|
|
let manifest = this._manifestFromData(data.installType, data.manifest, data.origin);
|
2014-10-09 12:02:21 -07:00
|
|
|
if (!manifest)
|
2014-11-05 17:22:27 -08:00
|
|
|
throw new Error("SocialService.installProvider: service configuration is invalid from " + data.url);
|
2014-10-09 12:02:21 -07:00
|
|
|
|
|
|
|
let addon = new AddonWrapper(manifest);
|
|
|
|
if (addon && addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
|
|
|
|
throw new Error("installProvider: provider with origin [" +
|
2014-11-05 17:22:27 -08:00
|
|
|
data.origin + "] is blocklisted");
|
2014-10-09 12:02:21 -07:00
|
|
|
// manifestFromData call above will enforce correct origin. To support
|
|
|
|
// activation from about: uris, we need to be sure to use the updated
|
|
|
|
// origin on the manifest.
|
2014-11-05 17:22:27 -08:00
|
|
|
data.manifest = manifest;
|
|
|
|
let id = getAddonIDFromOrigin(manifest.origin);
|
2013-05-09 12:59:57 -07:00
|
|
|
AddonManager.getAddonByID(id, function(aAddon) {
|
|
|
|
if (aAddon && aAddon.userDisabled) {
|
|
|
|
aAddon.cancelUninstall();
|
|
|
|
aAddon.userDisabled = false;
|
|
|
|
}
|
|
|
|
schedule(function () {
|
2015-03-09 11:24:12 -07:00
|
|
|
try {
|
|
|
|
this._installProvider(data, options, aManifest => {
|
|
|
|
this._notifyProviderListeners("provider-installed", aManifest.origin);
|
|
|
|
installCallback(aManifest);
|
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
Cu.reportError("Activation failed: " + e);
|
|
|
|
installCallback(null);
|
|
|
|
}
|
2013-05-09 12:59:57 -07:00
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
_installProvider: function(data, options, installCallback) {
|
|
|
|
if (!data.manifest)
|
2014-10-09 12:02:21 -07:00
|
|
|
throw new Error("Cannot install provider without manifest data");
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
if (data.installType == "foreign" && !Services.prefs.getBoolPref("social.remote-install.enabled"))
|
2014-10-09 12:02:21 -07:00
|
|
|
throw new Error("Remote install of services is disabled");
|
|
|
|
|
2015-03-09 11:24:12 -07:00
|
|
|
// if installing from any website, the install must happen over https.
|
|
|
|
// "internal" are installs from about:home or similar
|
|
|
|
if (data.installType != "internal" && !Services.io.newURI(data.origin, null, null).schemeIs("https")) {
|
|
|
|
throw new Error("attempt to activate provider over unsecured channel: " + data.origin);
|
|
|
|
}
|
|
|
|
|
2014-11-05 17:22:27 -08:00
|
|
|
let installer = new AddonInstaller(data.url, data.manifest, installCallback);
|
2014-10-09 12:02:21 -07:00
|
|
|
let bypassPanel = options.bypassInstallPanel ||
|
2014-11-05 17:22:27 -08:00
|
|
|
(data.installType == "internal" && data.manifest.oneclick);
|
2014-10-09 12:02:21 -07:00
|
|
|
if (bypassPanel)
|
|
|
|
installer.install();
|
|
|
|
else
|
2014-11-05 17:22:27 -08:00
|
|
|
this._showInstallNotification(data, installer);
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
|
2014-01-06 00:46:32 -08:00
|
|
|
createWrapper: function(manifest) {
|
|
|
|
return new AddonWrapper(manifest);
|
|
|
|
},
|
|
|
|
|
2013-07-03 10:24:16 -07:00
|
|
|
/**
|
|
|
|
* updateProvider is used from the worker to self-update. Since we do not
|
|
|
|
* have knowledge of the currently selected provider here, we will notify
|
|
|
|
* the front end to deal with any reload.
|
|
|
|
*/
|
2013-09-04 10:01:38 -07:00
|
|
|
updateProvider: function(aUpdateOrigin, aManifest) {
|
2013-08-28 16:45:58 -07:00
|
|
|
let installType = this.getOriginActivationType(aUpdateOrigin);
|
2013-07-03 10:24:16 -07:00
|
|
|
// if we get data, we MUST have a valid manifest generated from the data
|
2014-11-05 17:22:27 -08:00
|
|
|
let manifest = this._manifestFromData(installType, aManifest, aUpdateOrigin);
|
2013-07-03 10:24:16 -07:00
|
|
|
if (!manifest)
|
2013-08-28 16:45:58 -07:00
|
|
|
throw new Error("SocialService.installProvider: service configuration is invalid from " + aUpdateOrigin);
|
2013-07-03 10:24:16 -07:00
|
|
|
|
|
|
|
// overwrite the preference
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = JSON.stringify(manifest);
|
|
|
|
Services.prefs.setComplexValue(getPrefnameFromOrigin(manifest.origin), Ci.nsISupportsString, string);
|
|
|
|
|
|
|
|
// overwrite the existing provider then notify the front end so it can
|
|
|
|
// handle any reload that might be necessary.
|
|
|
|
if (ActiveProviders.has(manifest.origin)) {
|
2014-08-27 16:11:36 -07:00
|
|
|
// unload the worker prior to replacing the provider instance, also
|
|
|
|
// ensures the workerapi instance is terminated.
|
|
|
|
let provider = SocialServiceInternal.providers[manifest.origin];
|
|
|
|
provider.enabled = false;
|
|
|
|
provider = new SocialProvider(manifest);
|
2013-07-03 10:24:16 -07:00
|
|
|
SocialServiceInternal.providers[provider.origin] = provider;
|
|
|
|
// update the cache and ui, reload provider if necessary
|
2013-09-04 10:01:38 -07:00
|
|
|
this.getOrderedProviderList(providers => {
|
|
|
|
this._notifyProviderListeners("provider-update", provider.origin, providers);
|
|
|
|
});
|
2013-07-03 10:24:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-27 09:18:35 -07:00
|
|
|
uninstallProvider: function(origin, aCallback) {
|
2013-09-04 10:01:38 -07:00
|
|
|
let manifest = SocialService.getManifestByOrigin(origin);
|
2013-03-05 11:24:30 -08:00
|
|
|
let addon = new AddonWrapper(manifest);
|
2013-08-27 09:18:35 -07:00
|
|
|
addon.uninstall(aCallback);
|
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
|
2013-06-17 14:25:06 -07:00
|
|
|
* @param {bool} boolean indicating whether this provider is "built in"
|
2012-07-17 18:44:09 -07:00
|
|
|
*/
|
2013-06-26 15:20:35 -07: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");
|
|
|
|
|
2014-01-06 00:46:32 -08:00
|
|
|
let addon = new AddonWrapper(input);
|
|
|
|
if (addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED)
|
2013-02-26 14:50:24 -08:00
|
|
|
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;
|
2013-05-06 23:02:58 -07:00
|
|
|
this.shareURL = input.shareURL;
|
2013-09-04 10:01:38 -07:00
|
|
|
this.statusURL = input.statusURL;
|
2013-09-06 10:56:01 -07:00
|
|
|
this.markURL = input.markURL;
|
|
|
|
this.markedIcon = input.markedIcon;
|
|
|
|
this.unmarkedIcon = input.unmarkedIcon;
|
2014-04-30 12:08:23 -07:00
|
|
|
this.postActivationURL = input.postActivationURL;
|
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);
|
2015-08-18 00:01:42 -07:00
|
|
|
this.principal = Services.scriptSecurityManager.createCodebasePrincipal(originUri, {});
|
2012-07-17 18:44:09 -07:00
|
|
|
this.ambientNotificationIcons = {};
|
2012-12-07 20:13:27 -08:00
|
|
|
this.errorState = null;
|
2013-05-11 10:54:31 -07:00
|
|
|
this.frecency = 0;
|
2013-06-26 15:20:35 -07:00
|
|
|
|
2014-07-18 10:27:52 -07:00
|
|
|
// this provider has localStorage access in the worker if listed in the
|
|
|
|
// whitelist
|
|
|
|
let whitelist = Services.prefs.getCharPref("social.whitelist").split(',');
|
|
|
|
this.blessed = whitelist.indexOf(this.origin) >= 0;
|
2013-06-26 15:20:35 -07:00
|
|
|
|
2013-05-11 10:54:31 -07:00
|
|
|
try {
|
|
|
|
this.domain = etld.getBaseDomainFromHost(originUri.host);
|
|
|
|
} catch(e) {
|
|
|
|
this.domain = originUri.host;
|
|
|
|
}
|
2012-07-17 18:44:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SocialProvider.prototype = {
|
2013-08-21 11:32:46 -07:00
|
|
|
reload: function() {
|
2014-08-27 16:11:36 -07:00
|
|
|
// calling terminate/activate does not set the enabled state whereas setting
|
|
|
|
// enabled will call terminate/activate
|
|
|
|
this.enabled = false;
|
|
|
|
this.enabled = true;
|
2013-08-21 11:32:46 -07:00
|
|
|
Services.obs.notifyObservers(null, "social:provider-reload", this.origin);
|
|
|
|
},
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-03 10:24:16 -07:00
|
|
|
get manifest() {
|
2013-09-04 10:01:38 -07:00
|
|
|
return SocialService.getManifestByOrigin(this.origin);
|
2013-07-03 10:24:16 -07:00
|
|
|
},
|
|
|
|
|
2014-05-13 11:10:47 -07:00
|
|
|
getPageSize: function(name) {
|
|
|
|
let manifest = this.manifest;
|
|
|
|
if (manifest && manifest.pageSize)
|
|
|
|
return manifest.pageSize[name];
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
// 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
|
|
|
|
|
|
|
// 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 = {};
|
2013-08-15 15:30:02 -07:00
|
|
|
let accountChanged = !this.profile || this.profile.userName != profile.userName;
|
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);
|
2013-08-15 15:30:02 -07:00
|
|
|
if (accountChanged)
|
|
|
|
closeAllChatWindows(this);
|
2012-07-17 18:44:09 -07:00
|
|
|
},
|
|
|
|
|
2013-08-21 11:32:46 -07:00
|
|
|
haveLoggedInUser: function () {
|
|
|
|
return !!(this.profile && this.profile.userName);
|
|
|
|
},
|
|
|
|
|
2012-07-17 18:44:09 -07:00
|
|
|
// 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");
|
2013-05-09 17:10:14 -07:00
|
|
|
if (!this.ambientNotificationIcons[notification.name] &&
|
|
|
|
Object.keys(this.ambientNotificationIcons).length >= 3) {
|
|
|
|
throw new Error("ambient notification limit reached");
|
|
|
|
}
|
2012-07-17 18:44:09 -07:00
|
|
|
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() {
|
2013-08-15 15:34:37 -07:00
|
|
|
closeAllChatWindows(this);
|
2012-07-17 18:44:09 -07:00
|
|
|
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;
|
2013-06-17 14:25:06 -07:00
|
|
|
// Only allow localStorage in the frameworker for blessed providers
|
|
|
|
let allowLocalStorage = this.blessed;
|
|
|
|
let handle = getFrameWorkerHandle(this.workerURL, window,
|
|
|
|
"SocialProvider:" + this.origin, this.origin,
|
|
|
|
allowLocalStorage);
|
|
|
|
return handle.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) {
|
2013-04-29 13:09:10 -07:00
|
|
|
aManifest.updateDate = Date.now();
|
|
|
|
// get the existing manifest for installDate
|
2013-09-04 10:01:38 -07:00
|
|
|
let manifest = SocialService.getManifestByOrigin(aManifest.origin);
|
2013-05-09 12:59:57 -07:00
|
|
|
let isNewInstall = !manifest;
|
2013-04-29 13:09:10 -07:00
|
|
|
if (manifest && manifest.installDate)
|
|
|
|
aManifest.installDate = manifest.installDate;
|
|
|
|
else
|
|
|
|
aManifest.installDate = aManifest.updateDate;
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
this.sourceURI = sourceURI;
|
|
|
|
this.install = function() {
|
|
|
|
let addon = this.addon;
|
2013-05-09 12:59:57 -07:00
|
|
|
if (isNewInstall) {
|
|
|
|
AddonManagerPrivate.callInstallListeners("onExternalInstall", null, addon, null, false);
|
|
|
|
AddonManagerPrivate.callAddonListeners("onInstalling", addon, false);
|
|
|
|
}
|
2013-04-01 16:27:13 -07:00
|
|
|
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = JSON.stringify(aManifest);
|
|
|
|
Services.prefs.setComplexValue(getPrefnameFromOrigin(aManifest.origin), Ci.nsISupportsString, string);
|
|
|
|
|
2013-05-09 12:59:57 -07:00
|
|
|
if (isNewInstall) {
|
|
|
|
AddonManagerPrivate.callAddonListeners("onInstalled", addon);
|
|
|
|
}
|
2013-03-05 11:24:30 -08:00
|
|
|
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)) {
|
2014-01-06 00:46:32 -08:00
|
|
|
let addon = new AddonWrapper(manifest);
|
|
|
|
if (addon.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
|
2014-07-18 10:27:52 -07:00
|
|
|
SocialService.disableProvider(manifest.origin);
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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
|
|
|
},
|
|
|
|
|
2013-08-27 09:18:35 -07:00
|
|
|
removeAddon: function(aAddon, aCallback) {
|
2013-03-05 11:24:30 -08:00
|
|
|
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-09-04 10:01:38 -07:00
|
|
|
SocialService._notifyProviderListeners("provider-uninstalled", aAddon.manifest.origin);
|
2013-08-27 09:18:35 -07:00
|
|
|
if (aCallback)
|
|
|
|
schedule(aCallback);
|
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() {
|
2014-01-06 00:46:32 -08:00
|
|
|
return Services.blocklist.getAddonBlocklistState(this);
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
get blocklistURL() {
|
2014-01-06 00:46:32 -08:00
|
|
|
return Services.blocklist.getAddonBlocklistURL(this);
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2014-07-18 10:27:52 -07:00
|
|
|
SocialService.disableProvider(this.manifest.origin);
|
2013-02-26 14:50:24 -08:00
|
|
|
} else if (!this.appDisabled) {
|
2014-07-18 10:27:52 -07:00
|
|
|
SocialService.enableProvider(this.manifest.origin);
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
|
2013-08-27 09:18:35 -07:00
|
|
|
uninstall: function(aCallback) {
|
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)) {
|
2014-07-18 10:27:52 -07:00
|
|
|
SocialService.disableProvider(this.manifest.origin, function() {
|
2013-08-27 09:18:35 -07:00
|
|
|
SocialAddonProvider.removeAddon(this, aCallback);
|
2013-03-05 11:24:30 -08:00
|
|
|
}.bind(this));
|
|
|
|
} else {
|
2013-08-27 09:18:35 -07:00
|
|
|
SocialAddonProvider.removeAddon(this, aCallback);
|
2013-03-05 11:24:30 -08:00
|
|
|
}
|
2013-08-27 09:18:35 -07:00
|
|
|
} else {
|
|
|
|
schedule(aCallback);
|
2013-03-05 11:24:30 -08:00
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
cancelUninstall: function() {
|
2013-03-05 11:24:30 -08:00
|
|
|
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)
|
|
|
|
]);
|