summaryrefslogtreecommitdiffstats
path: root/services/sync/modules
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-06 15:53:52 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-07-06 15:53:52 +0200
commit941e54654eabed0a3568f7fefe424a45aa02eddb (patch)
tree49aa02b174c428962d99142d8061267bfcd79e69 /services/sync/modules
parentad9ee72dcd7981bc47b3844a224d69fadfdfd8ef (diff)
parent0daa12376295d5d796256a116eb2a348a3a9273f (diff)
downloadUXP-941e54654eabed0a3568f7fefe424a45aa02eddb.tar
UXP-941e54654eabed0a3568f7fefe424a45aa02eddb.tar.gz
UXP-941e54654eabed0a3568f7fefe424a45aa02eddb.tar.lz
UXP-941e54654eabed0a3568f7fefe424a45aa02eddb.tar.xz
UXP-941e54654eabed0a3568f7fefe424a45aa02eddb.zip
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into _testBranch_test_1
Diffstat (limited to 'services/sync/modules')
-rw-r--r--services/sync/modules/main.js1
-rw-r--r--services/sync/modules/notifications.js131
-rw-r--r--services/sync/modules/record.js4
-rw-r--r--services/sync/modules/service.js49
4 files changed, 160 insertions, 25 deletions
diff --git a/services/sync/modules/main.js b/services/sync/modules/main.js
index af3399e7a..e8e705e72 100644
--- a/services/sync/modules/main.js
+++ b/services/sync/modules/main.js
@@ -8,6 +8,7 @@ this.Weave = {};
Components.utils.import("resource://services-sync/constants.js", Weave);
var lazies = {
"jpakeclient.js": ["JPAKEClient", "SendCredentialsController"],
+ "notifications.js": ["Notifications", "Notification", "NotificationButton"],
"service.js": ["Service"],
"status.js": ["Status"],
"util.js": ['Utils', 'Svc']
diff --git a/services/sync/modules/notifications.js b/services/sync/modules/notifications.js
new file mode 100644
index 000000000..72187a4ce
--- /dev/null
+++ b/services/sync/modules/notifications.js
@@ -0,0 +1,131 @@
+/* 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/. */
+
+this.EXPORTED_SYMBOLS = ["Notifications", "Notification", "NotificationButton"];
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cr = Components.results;
+var Cu = Components.utils;
+
+Cu.import("resource://services-common/observers.js");
+Cu.import("resource://gre/modules/Log.jsm");
+Cu.import("resource://services-sync/util.js");
+
+this.Notifications = {
+ // Match the referenced values in toolkit/content/widgets/notification.xml.
+ get PRIORITY_INFO() { return 1; }, // PRIORITY_INFO_LOW
+ get PRIORITY_WARNING() { return 4; }, // PRIORITY_WARNING_LOW
+ get PRIORITY_ERROR() { return 7; }, // PRIORITY_CRITICAL_LOW
+
+ // FIXME: instead of making this public, dress the Notifications object
+ // to behave like an iterator (using generators?) and have callers access
+ // this array through the Notifications object.
+ notifications: [],
+
+ _observers: [],
+
+ // XXX Should we have a helper method for adding a simple notification?
+ // I.e. something like |function notify(title, description, priority)|.
+
+ add: function Notifications_add(notification) {
+ this.notifications.push(notification);
+ Observers.notify("weave:notification:added", notification, null);
+ },
+
+ remove: function Notifications_remove(notification) {
+ let index = this.notifications.indexOf(notification);
+
+ if (index != -1) {
+ this.notifications.splice(index, 1);
+ Observers.notify("weave:notification:removed", notification, null);
+ }
+ },
+
+ /**
+ * Replace an existing notification.
+ */
+ replace: function Notifications_replace(oldNotification, newNotification) {
+ let index = this.notifications.indexOf(oldNotification);
+
+ if (index != -1)
+ this.notifications.splice(index, 1, newNotification);
+ else {
+ this.notifications.push(newNotification);
+ // XXX Should we throw because we didn't find the existing notification?
+ // XXX Should we notify observers about weave:notification:added?
+ }
+
+ // XXX Should we notify observers about weave:notification:replaced?
+ },
+
+ /**
+ * Remove all notifications that match a title. If no title is provided, all
+ * notifications are removed.
+ *
+ * @param title [optional]
+ * Title of notifications to remove; falsy value means remove all
+ */
+ removeAll: function Notifications_removeAll(title) {
+ this.notifications.filter(old => (old.title == title || !title)).
+ forEach(old => { this.remove(old); }, this);
+ },
+
+ // replaces all existing notifications with the same title as the new one
+ replaceTitle: function Notifications_replaceTitle(notification) {
+ this.removeAll(notification.title);
+ this.add(notification);
+ }
+};
+
+
+/**
+ * A basic notification. Subclass this to create more complex notifications.
+ */
+this.Notification =
+function Notification(title, description, iconURL, priority, buttons, link) {
+ this.title = title;
+ this.description = description;
+
+ if (iconURL)
+ this.iconURL = iconURL;
+
+ if (priority)
+ this.priority = priority;
+
+ if (buttons)
+ this.buttons = buttons;
+
+ if (link)
+ this.link = link;
+}
+
+// We set each prototype property individually instead of redefining
+// the entire prototype to avoid blowing away existing properties
+// of the prototype like the the "constructor" property, which we use
+// to bind notification objects to their XBL representations.
+Notification.prototype.priority = Notifications.PRIORITY_INFO;
+Notification.prototype.iconURL = null;
+Notification.prototype.buttons = [];
+
+/**
+ * A button to display in a notification.
+ */
+this.NotificationButton =
+ function NotificationButton(label, accessKey, callback) {
+ function callbackWrapper() {
+ try {
+ callback.apply(this, arguments);
+ } catch (e) {
+ let logger = Log.repository.getLogger("Sync.Notifications");
+ logger.error("An exception occurred: " + Utils.exceptionStr(e));
+ logger.info(Utils.stackTrace(e));
+ throw e;
+ }
+ }
+
+ this.label = label;
+ this.accessKey = accessKey;
+ this.callback = callbackWrapper;
+}
diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js
index 02f7f281a..f7a69d9ef 100644
--- a/services/sync/modules/record.js
+++ b/services/sync/modules/record.js
@@ -43,7 +43,7 @@ WBORecord.prototype = {
// Get thyself from your URI, then deserialize.
// Set thine 'response' field.
fetch: function fetch(resource) {
- if (!resource instanceof Resource) {
+ if (!(resource instanceof Resource)) {
throw new Error("First argument must be a Resource instance.");
}
@@ -56,7 +56,7 @@ WBORecord.prototype = {
},
upload: function upload(resource) {
- if (!resource instanceof Resource) {
+ if (!(resource instanceof Resource)) {
throw new Error("First argument must be a Resource instance.");
}
diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js
index b0eb0f41d..f8c64b0fa 100644
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -455,7 +455,7 @@ Sync11Service.prototype = {
this.clientsEngine = new ClientEngine(this);
for (let name of engines) {
- if (!name in ENGINE_MODULES) {
+ if (!(name in ENGINE_MODULES)) {
this._log.info("Do not know about engine: " + name);
continue;
}
@@ -1067,31 +1067,34 @@ Sync11Service.prototype = {
// Note: returns false if we failed for a reason other than the server not yet
// supporting the api.
_fetchServerConfiguration() {
- // This is similar to _fetchInfo, but with different error handling.
+ if (Svc.Prefs.get("APILevel") >= 2) {
+ // This is similar to _fetchInfo, but with different error handling.
+ // Only supported by later sync implementations.
- let infoURL = this.userBaseURL + "info/configuration";
- this._log.debug("Fetching server configuration", infoURL);
- let configResponse;
- try {
- configResponse = this.resource(infoURL).get();
- } catch (ex) {
- // This is probably a network or similar error.
- this._log.warn("Failed to fetch info/configuration", ex);
- this.errorHandler.checkServerError(ex);
- return false;
- }
+ let infoURL = this.userBaseURL + "info/configuration";
+ this._log.debug("Fetching server configuration", infoURL);
+ let configResponse;
+ try {
+ configResponse = this.resource(infoURL).get();
+ } catch (ex) {
+ // This is probably a network or similar error.
+ this._log.warn("Failed to fetch info/configuration", ex);
+ this.errorHandler.checkServerError(ex);
+ return false;
+ }
- if (configResponse.status == 404) {
- // This server doesn't support the URL yet - that's OK.
- this._log.debug("info/configuration returned 404 - using default upload semantics");
- } else if (configResponse.status != 200) {
- this._log.warn(`info/configuration returned ${configResponse.status} - using default configuration`);
- this.errorHandler.checkServerError(configResponse);
- return false;
- } else {
- this.serverConfiguration = configResponse.obj;
+ if (configResponse.status == 404) {
+ // This server doesn't support the URL yet - that's OK.
+ this._log.debug("info/configuration returned 404 - using default upload semantics");
+ } else if (configResponse.status != 200) {
+ this._log.warn(`info/configuration returned ${configResponse.status} - using default configuration`);
+ this.errorHandler.checkServerError(configResponse);
+ return false;
+ } else {
+ this.serverConfiguration = configResponse.obj;
+ }
+ this._log.trace("info/configuration for this server", this.serverConfiguration);
}
- this._log.trace("info/configuration for this server", this.serverConfiguration);
return true;
},