Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 | * TelProtocolHandle.js |
michael@0 | 7 | * |
michael@0 | 8 | * This file implements the URLs for Telephone Calls |
michael@0 | 9 | * https://www.ietf.org/rfc/rfc2806.txt |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | "use strict"; |
michael@0 | 13 | |
michael@0 | 14 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 15 | |
michael@0 | 16 | Cu.import('resource://gre/modules/XPCOMUtils.jsm'); |
michael@0 | 17 | Cu.import("resource:///modules/TelURIParser.jsm"); |
michael@0 | 18 | |
michael@0 | 19 | XPCOMUtils.defineLazyServiceGetter(this, "cpmm", |
michael@0 | 20 | "@mozilla.org/childprocessmessagemanager;1", |
michael@0 | 21 | "nsIMessageSender"); |
michael@0 | 22 | |
michael@0 | 23 | function TelProtocolHandler() { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | TelProtocolHandler.prototype = { |
michael@0 | 27 | |
michael@0 | 28 | scheme: "tel", |
michael@0 | 29 | defaultPort: -1, |
michael@0 | 30 | protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | |
michael@0 | 31 | Ci.nsIProtocolHandler.URI_NOAUTH | |
michael@0 | 32 | Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE | |
michael@0 | 33 | Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA, |
michael@0 | 34 | allowPort: function() false, |
michael@0 | 35 | |
michael@0 | 36 | newURI: function Proto_newURI(aSpec, aOriginCharset) { |
michael@0 | 37 | let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); |
michael@0 | 38 | uri.spec = aSpec; |
michael@0 | 39 | return uri; |
michael@0 | 40 | }, |
michael@0 | 41 | |
michael@0 | 42 | newChannel: function Proto_newChannel(aURI) { |
michael@0 | 43 | let number = TelURIParser.parseURI('tel', aURI.spec); |
michael@0 | 44 | |
michael@0 | 45 | if (number) { |
michael@0 | 46 | cpmm.sendAsyncMessage("dial-handler", { |
michael@0 | 47 | number: number, |
michael@0 | 48 | type: "webtelephony/number" }); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | throw Components.results.NS_ERROR_ILLEGAL_VALUE; |
michael@0 | 52 | }, |
michael@0 | 53 | |
michael@0 | 54 | classID: Components.ID("{782775dd-7351-45ea-aff1-0ffa872cfdd2}"), |
michael@0 | 55 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]) |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelProtocolHandler]); |