Bug 1199855 - Add Matrix as a supported protocol: Part 2 - Add basic setup for a new Matrix protocol. r=clokep
authorFrédéric Wang <fred.wang@free.fr>
Thu, 02 Mar 2017 14:30:00 +0100
changeset 27722 b99d93143c49b92aaf252143ff1a64a8c38ec28b
parent 27721 bd5460ae6c1ca6be12e12fbe804ef8d5a12255d3
child 27723 f6a8a506a1c95767ae64e65101a83ea866dd5cdf
push id1918
push userclokep@gmail.com
push dateTue, 18 Apr 2017 16:38:40 +0000
treeherdercomm-beta@6b755b36d0c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1199855
Bug 1199855 - Add Matrix as a supported protocol: Part 2 - Add basic setup for a new Matrix protocol. r=clokep
chat/locales/en-US/matrix.properties
chat/locales/jar.mn
chat/moz.build
chat/protocols/matrix/icons/README
chat/protocols/matrix/icons/prpl-matrix-32.png
chat/protocols/matrix/icons/prpl-matrix-48.png
chat/protocols/matrix/icons/prpl-matrix.png
chat/protocols/matrix/jar.mn
chat/protocols/matrix/matrix-sdk.jsm
chat/protocols/matrix/matrix-sdk/moz.build
chat/protocols/matrix/matrix.js
chat/protocols/matrix/matrix.manifest
chat/protocols/matrix/moz.build
new file mode 100644
--- /dev/null
+++ b/chat/locales/en-US/matrix.properties
@@ -0,0 +1,9 @@
+# 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/.
+
+# LOCALIZATION NOTE (options.*):
+#   These are the protocol specific options shown in the account manager and
+#   account wizard windows.
+options.connectServer=Server
+options.connectPort=Port
--- a/chat/locales/jar.mn
+++ b/chat/locales/jar.mn
@@ -11,13 +11,14 @@
 	locale/@AB_CD@/chat/imtooltip.properties (%imtooltip.properties)
 	locale/@AB_CD@/chat/commands.properties (%commands.properties)
 	locale/@AB_CD@/chat/contacts.properties	(%contacts.properties)
 	locale/@AB_CD@/chat/conversations.properties (%conversations.properties)
 	locale/@AB_CD@/chat/dateFormat.properties (%dateFormat.properties)
 	locale/@AB_CD@/chat/facebook.properties	(%facebook.properties)
 	locale/@AB_CD@/chat/irc.properties	(%irc.properties)
 	locale/@AB_CD@/chat/logger.properties	(%logger.properties)
+	locale/@AB_CD@/chat/matrix.properties	(%matrix.properties)
 	locale/@AB_CD@/chat/skype.properties	(%skype.properties)
 	locale/@AB_CD@/chat/status.properties	(%status.properties)
 	locale/@AB_CD@/chat/twitter.properties	(%twitter.properties)
 	locale/@AB_CD@/chat/xmpp.properties	(%xmpp.properties)
 	locale/@AB_CD@/chat/yahoo.properties	(%yahoo.properties)
--- a/chat/moz.build
+++ b/chat/moz.build
@@ -8,16 +8,17 @@ DIRS += [
     'components/src',
     'modules',
     'content',
     'themes',
     'locales',
     'protocols/facebook',
     'protocols/gtalk',
     'protocols/irc',
+    'protocols/matrix',
     'protocols/odnoklassniki',
     'protocols/skype',
     'protocols/twitter',
     'protocols/xmpp',
     'protocols/yahoo',
 ]
 
 if CONFIG['MOZ_DEBUG']:
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/icons/README
@@ -0,0 +1,5 @@
+These icons have been generated from
+
+https://github.com/matrix-org/matrix.to/blob/master/img/matrix-logo.svg
+
+and are licensed under the Apache License Version 2.
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..09c8f4b531018bc03414374d94ea369f6173df56
GIT binary patch
literal 693
zc$@*X0!safP)<h;3K|Lk000e1NJLTq001BW001Be0ssI2{21+{00006VoOIv0RI60
z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru;R6B{8z!Bz{~!PW0zyed
zK~zY`?Uui5>QEHNPvQ?^ENH+Xn?tCji_M^<h*D7pi%^S8hay;~wyTrUv44c!#1KKD
zIw`1wlarx{(k^NjJ0wuVNyMV(4Jq$O-y7awhJxSa!sT#2hwt~^%OwyI^b`p?YX{f?
zz5&26pU-)o-`m^UdTT{d?(XhLkH^EZtRAzoEbH-jwqw!b<Ktv9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%`EX7WqAsj$Z!;#Vf<Z~8yL>2?-
zO(4veJtgA-kRe&(8c`CQpH@<ySd_|8US6)3nU`IhoLG>mmtT}V`<;yxP|;dX7sn8b
z-m{nO`5YZ3SU$|RH@}c!;<eVI{haQKtLqjxs4o=bQ+OoBHBqC*twgD^|B%>;?kBdr
zna^hDq;0yNBc`^(yWgsfHN@b&K!Jnl{DVK*{&Pztb{YCbENYeQd!g1^68B6rY0JgK
zveG6S`O=q$=U?Kg{$j{c)z<pl`)R<xZA>xD_nGfA9rwKcf9H`$?RE-W#Vxw$9OIkz
r)mGf|^65Sz6#UShDQi>x^JC2CY?bmP>bf+54rlOm^>bP0l+XkKGzf0s
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/jar.mn
@@ -0,0 +1,9 @@
+# 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/.
+
+chat.jar:
+% skin prpl-matrix classic/1.0 %skin/classic/prpl/matrix/
+	skin/classic/prpl/matrix/icon32.png	(icons/prpl-matrix-32.png)
+	skin/classic/prpl/matrix/icon48.png	(icons/prpl-matrix-48.png)
+	skin/classic/prpl/matrix/icon.png	(icons/prpl-matrix.png)
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/matrix-sdk.jsm
@@ -0,0 +1,110 @@
+/* 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/. */
+
+var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/Console.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Timer.jsm");
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
+const { Loader, Require, Module } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
+
+this.EXPORTED_SYMBOLS = ["MatrixSDK"];
+
+// Set-up loading so require works properly in CommonJS modules.
+let matrixPath = "resource:///modules/matrix/";
+let loader = Loader({
+  paths: {
+      "": matrixPath,
+      "../../utils": matrixPath + "utils.js",
+      "../content-repo": matrixPath + "content-repo.js",
+      "../deviceinfo": matrixPath + "crypto/deviceinfo.js",
+      "../models/event": matrixPath + "models/event.js",
+      "../models/room": matrixPath + "models/room.js",
+      "../models/user": matrixPath + "models/user.js",
+      "../olmlib": matrixPath + "crypto/olmlib.js",
+      "../utils": matrixPath + "utils.js",
+      "./../../utils": matrixPath + "utils.js",
+      "./OlmDevice": matrixPath + "crypto/OlmDevice.js",
+      "./algorithms": matrixPath + "crypto/algorithms/index.js",
+      "./base": matrixPath + "crypto/algorithms/base.js",
+      "./base-apis": matrixPath + "base-apis.js",
+      "./client": matrixPath + "client.js",
+      "./content-repo": matrixPath + "content-repo.js",
+      "./crypto": matrixPath + "crypto/index.js",
+      "./decode": matrixPath + "browserify/querystring/decode.js",
+      "./deviceinfo": matrixPath + "crypto/deviceinfo.js",
+      "./encode": matrixPath + "browserify/querystring/encode.js",
+      "./event": matrixPath + "models/event.js",
+      "./event-context": matrixPath + "models/event-content.js",
+      "./event-timeline": matrixPath + "models/event-timeline.js",
+      "./event-timeline-set": matrixPath + "models/event-timeline-set.js",
+      "./filter": matrixPath + "filter.js",
+      "./filter-component": matrixPath + "filter-component.js",
+      "./http-api": matrixPath + "http-api.js",
+      "./interactive-auth": matrixPath + "interactive-auth.js",
+      "./megolm": matrixPath + "crypto/algorithms/megolm.js",
+      "./models/event": matrixPath + "models/event.js",
+      "./models/event-timeline": matrixPath + "models/event-timeline.js",
+      "./models/event-timeline-set": matrixPath + "models/event-timeline-set.js",
+      "./models/room": matrixPath + "models/room.js",
+      "./models/room-member": matrixPath + "models/room-member.js",
+      "./models/room-state": matrixPath + "models/room-state.js",
+      "./models/search-result": matrixPath + "models/search-result.js",
+      "./models/user": matrixPath + "models/user.js",
+      "./olm": matrixPath + "crypto/algorithms/olm.js",
+      "./olmlib": matrixPath + "crypto/olmlib.js",
+      "./pushprocessor": matrixPath + "pushprocessor.js",
+      "./q": matrixPath + "q/q.js",
+      "./realtime-callbacks": matrixPath + "realtime-callbacks.js",
+      "./room-member": matrixPath + "models/room-member.js",
+      "./room-state": matrixPath + "models/room-state.js",
+      "./room-summary": matrixPath + "models/room-summary.js",
+      "./scheduler": matrixPath + "scheduler.js",
+      "./store/memory": matrixPath + "store/memory.js",
+      "./store/session/webstorage": matrixPath + "store/session/webstorage.js",
+      "./store/stub": matrixPath + "store/stub.js",
+      "./store/webstorage": matrixPath + "store/webstorage.js",
+      "./sync": matrixPath + "sync.js",
+      "./timeline-window": matrixPath + "timeline-window.js",
+      "./utils": matrixPath + "utils.js",
+      "./webrtc/call": matrixPath + "webrtc/call.js",
+      "OlmDevice": matrixPath + "crypto/OlmDevice.js",
+      "algorithms": matrixPath + "crypto/algorithms/index.js",
+      "another-json": matrixPath + "another_json/another-json.js",
+      "base": matrixPath + "crypto/algorithms/base.js",
+      "browser-request": matrixPath + "browser_request/index.js",
+      "crypto": matrixPath + "crypto/index.js",
+      "decode": matrixPath + "browserify/querystring/decode.js",
+      "deviceinfo": matrixPath + "crypto/deviceinfo.js",
+      "encode": matrixPath + "browserify/querystring/encode.js",
+      "events": matrixPath + "browserify/events.js",
+      "megolm": matrixPath + "crypto/algorithms/megolm.js",
+      "olm": matrixPath + "crypto/algorithms/olm.js",
+      "olmlib": matrixPath + "crypto/olmlib.js",
+      "punycode": matrixPath + "browserify/punycode.js",
+      "q": matrixPath + "q/q.js",
+      "querystring": matrixPath + "browserify/querystring/index.js",
+      "url": matrixPath + "browserify/url.js",
+  },
+  globals: {
+    global: {
+      setInterval: setInterval,
+      clearInterval: clearInterval,
+      setTimeout: setTimeout,
+      clearTimeout: clearTimeout,
+    },
+    console: console,
+    XMLHttpRequest: XMLHttpRequest,
+    setTimeout: setTimeout,
+    clearTimeout: clearTimeout,
+    location: { href: "" }, // workaround for browser-request's is_crossDomain
+  }
+})
+
+let requirer = Module("matrix-module", "");
+let require = Require(loader, requirer);
+MatrixSDK = require("matrix.js");
+MatrixSDK.request(require("browser-request"));
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/matrix-sdk/moz.build
@@ -0,0 +1,87 @@
+# vim: set filetype=python:
+# 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/.
+
+EXTRA_JS_MODULES.matrix += [
+    'base-apis.js',
+    'client.js',
+    'content-repo.js',
+    'filter-component.js',
+    'filter.js',
+    'http-api.js',
+    'interactive-auth.js',
+    'matrix.js',
+    'pushprocessor.js',
+    'realtime-callbacks.js',
+    'scheduler.js',
+    'sync.js',
+    'timeline-window.js',
+    'utils.js',
+]
+
+EXTRA_JS_MODULES.matrix.another_json += [
+    'another-json/another-json.js',
+]
+
+EXTRA_JS_MODULES.matrix.browserify += [
+    'browserify/events.js',
+    'browserify/punycode.js',
+    'browserify/url.js',
+]
+
+EXTRA_JS_MODULES.matrix.browserify.querystring += [
+    'browserify/querystring/decode.js',
+    'browserify/querystring/encode.js',
+    'browserify/querystring/index.js',
+]
+
+EXTRA_JS_MODULES.matrix.browser_request += [
+    'browser-request/index.js',
+]
+
+EXTRA_JS_MODULES.matrix.crypto += [
+    'crypto/deviceinfo.js',
+    'crypto/index.js',
+    'crypto/OlmDevice.js',
+    'crypto/olmlib.js',
+]
+
+EXTRA_JS_MODULES.matrix.crypto.algorithms += [
+    'crypto/algorithms/base.js',
+    'crypto/algorithms/index.js',
+    'crypto/algorithms/megolm.js',
+    'crypto/algorithms/olm.js',
+]
+
+EXTRA_JS_MODULES.matrix.models += [
+    'models/event-context.js',
+    'models/event-timeline-set.js',
+    'models/event-timeline.js',
+    'models/event.js',
+    'models/room-member.js',
+    'models/room-state.js',
+    'models/room-summary.js',
+    'models/room.js',
+    'models/search-result.js',
+    'models/user.js',
+]
+
+EXTRA_JS_MODULES.matrix.q += [
+    'q/q.js',
+    'q/queue.js',
+]
+
+EXTRA_JS_MODULES.matrix.store += [
+    'store/memory.js',
+    'store/stub.js',
+    'store/webstorage.js',
+]
+
+EXTRA_JS_MODULES.matrix.store.session += [
+    'store/session/webstorage.js',
+]
+
+EXTRA_JS_MODULES.matrix.webrtc += [
+    'webrtc/call.js',
+]
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/matrix.js
@@ -0,0 +1,49 @@
+/* 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/. */
+
+var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+Cu.import("resource:///modules/imXPCOMUtils.jsm");
+Cu.import("resource:///modules/jsProtoHelper.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "_", () =>
+  l10nHelper("chrome://chat/locale/matrix.properties")
+);
+
+XPCOMUtils.defineLazyModuleGetter(this, "MatrixSDK",
+                                  "resource:///modules/matrix-sdk.jsm"
+);
+
+function MatrixAccount(aProtocol, aImAccount)
+{
+  this._init(aProtocol, aImAccount);
+}
+MatrixAccount.prototype = {
+  __proto__: GenericAccountPrototype,
+}
+
+function MatrixProtocol() {
+}
+MatrixProtocol.prototype = {
+  __proto__: GenericProtocolPrototype,
+  get normalizedName() { return "matrix"; },
+  get name() { return "Matrix"; },
+  get iconBaseURI() { return "chrome://prpl-matrix/skin/"; },
+  getAccount: function(aImAccount) { return new MatrixAccount(this, aImAccount); },
+
+  options: {
+    server: {
+      get label() { return _("options.connectServer"); },
+      default: "https://"
+    },
+    port: {
+      get label() { return _("options.connectPort"); },
+      default: 443
+    }
+  },
+
+  classID: Components.ID("{e9653ac6-a671-11e6-bf84-60a44c717042}")
+};
+
+var NSGetFactory = XPCOMUtils.generateNSGetFactory([MatrixProtocol]);
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/matrix.manifest
@@ -0,0 +1,4 @@
+component {e9653ac6-a671-11e6-bf84-60a44c717042} matrix.js
+contract @mozilla.org/chat/matrix;1 {e9653ac6-a671-11e6-bf84-60a44c717042}
+category im-protocol-plugin prpl-matrix @mozilla.org/chat/matrix;1
+
new file mode 100644
--- /dev/null
+++ b/chat/protocols/matrix/moz.build
@@ -0,0 +1,23 @@
+# vim: set filetype=python:
+# 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/.
+
+# XPCSHELL_TESTS_MANIFESTS += []
+
+DIRS += [
+    'matrix-sdk',
+]
+
+EXTRA_COMPONENTS += [
+    'matrix.js',
+    'matrix.manifest',
+]
+
+EXTRA_JS_MODULES += [
+    'matrix-sdk.jsm',
+]
+
+JAR_MANIFESTS += [
+    'jar.mn',
+]