michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * SmsProtocolHandle.js michael@0: * michael@0: * This file implements the URLs for SMS michael@0: * https://www.rfc-editor.org/rfc/rfc5724.txt michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: Cu.import('resource://gre/modules/XPCOMUtils.jsm'); michael@0: Cu.import("resource:///modules/TelURIParser.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "cpmm", michael@0: "@mozilla.org/childprocessmessagemanager;1", michael@0: "nsIMessageSender"); michael@0: michael@0: function SmsProtocolHandler() { michael@0: } michael@0: michael@0: SmsProtocolHandler.prototype = { michael@0: michael@0: scheme: "sms", michael@0: defaultPort: -1, michael@0: protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | michael@0: Ci.nsIProtocolHandler.URI_NOAUTH | michael@0: Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE | michael@0: Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA, michael@0: allowPort: function() false, michael@0: michael@0: newURI: function Proto_newURI(aSpec, aOriginCharset) { michael@0: let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); michael@0: uri.spec = aSpec; michael@0: return uri; michael@0: }, michael@0: michael@0: newChannel: function Proto_newChannel(aURI) { michael@0: let number = TelURIParser.parseURI('sms', aURI.spec); michael@0: let body = ""; michael@0: let query = aURI.spec.split("?")[1]; michael@0: michael@0: if (query) { michael@0: let params = query.split("&"); michael@0: params.forEach(function(aParam) { michael@0: let [name, value] = aParam.split("="); michael@0: if (name === "body") { michael@0: body = decodeURIComponent(value); michael@0: } michael@0: }) michael@0: } michael@0: michael@0: if (number || body) { michael@0: cpmm.sendAsyncMessage("sms-handler", { michael@0: number: number || "", michael@0: type: "websms/sms", michael@0: body: body }); michael@0: } michael@0: michael@0: throw Components.results.NS_ERROR_ILLEGAL_VALUE; michael@0: }, michael@0: michael@0: classID: Components.ID("{81ca20cb-0dad-4e32-8566-979c8998bd73}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]) michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SmsProtocolHandler]);