|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /** |
|
6 * SmsProtocolHandle.js |
|
7 * |
|
8 * This file implements the URLs for SMS |
|
9 * https://www.rfc-editor.org/rfc/rfc5724.txt |
|
10 */ |
|
11 |
|
12 "use strict"; |
|
13 |
|
14 |
|
15 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
16 |
|
17 Cu.import('resource://gre/modules/XPCOMUtils.jsm'); |
|
18 Cu.import("resource:///modules/TelURIParser.jsm"); |
|
19 |
|
20 XPCOMUtils.defineLazyServiceGetter(this, "cpmm", |
|
21 "@mozilla.org/childprocessmessagemanager;1", |
|
22 "nsIMessageSender"); |
|
23 |
|
24 function SmsProtocolHandler() { |
|
25 } |
|
26 |
|
27 SmsProtocolHandler.prototype = { |
|
28 |
|
29 scheme: "sms", |
|
30 defaultPort: -1, |
|
31 protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | |
|
32 Ci.nsIProtocolHandler.URI_NOAUTH | |
|
33 Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE | |
|
34 Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA, |
|
35 allowPort: function() false, |
|
36 |
|
37 newURI: function Proto_newURI(aSpec, aOriginCharset) { |
|
38 let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); |
|
39 uri.spec = aSpec; |
|
40 return uri; |
|
41 }, |
|
42 |
|
43 newChannel: function Proto_newChannel(aURI) { |
|
44 let number = TelURIParser.parseURI('sms', aURI.spec); |
|
45 let body = ""; |
|
46 let query = aURI.spec.split("?")[1]; |
|
47 |
|
48 if (query) { |
|
49 let params = query.split("&"); |
|
50 params.forEach(function(aParam) { |
|
51 let [name, value] = aParam.split("="); |
|
52 if (name === "body") { |
|
53 body = decodeURIComponent(value); |
|
54 } |
|
55 }) |
|
56 } |
|
57 |
|
58 if (number || body) { |
|
59 cpmm.sendAsyncMessage("sms-handler", { |
|
60 number: number || "", |
|
61 type: "websms/sms", |
|
62 body: body }); |
|
63 } |
|
64 |
|
65 throw Components.results.NS_ERROR_ILLEGAL_VALUE; |
|
66 }, |
|
67 |
|
68 classID: Components.ID("{81ca20cb-0dad-4e32-8566-979c8998bd73}"), |
|
69 QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]) |
|
70 }; |
|
71 |
|
72 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SmsProtocolHandler]); |