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