1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/components/TelProtocolHandler.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/** 1.9 + * TelProtocolHandle.js 1.10 + * 1.11 + * This file implements the URLs for Telephone Calls 1.12 + * https://www.ietf.org/rfc/rfc2806.txt 1.13 + */ 1.14 + 1.15 +"use strict"; 1.16 + 1.17 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.18 + 1.19 +Cu.import('resource://gre/modules/XPCOMUtils.jsm'); 1.20 +Cu.import("resource:///modules/TelURIParser.jsm"); 1.21 + 1.22 +XPCOMUtils.defineLazyServiceGetter(this, "cpmm", 1.23 + "@mozilla.org/childprocessmessagemanager;1", 1.24 + "nsIMessageSender"); 1.25 + 1.26 +function TelProtocolHandler() { 1.27 +} 1.28 + 1.29 +TelProtocolHandler.prototype = { 1.30 + 1.31 + scheme: "tel", 1.32 + defaultPort: -1, 1.33 + protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | 1.34 + Ci.nsIProtocolHandler.URI_NOAUTH | 1.35 + Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE | 1.36 + Ci.nsIProtocolHandler.URI_DOES_NOT_RETURN_DATA, 1.37 + allowPort: function() false, 1.38 + 1.39 + newURI: function Proto_newURI(aSpec, aOriginCharset) { 1.40 + let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); 1.41 + uri.spec = aSpec; 1.42 + return uri; 1.43 + }, 1.44 + 1.45 + newChannel: function Proto_newChannel(aURI) { 1.46 + let number = TelURIParser.parseURI('tel', aURI.spec); 1.47 + 1.48 + if (number) { 1.49 + cpmm.sendAsyncMessage("dial-handler", { 1.50 + number: number, 1.51 + type: "webtelephony/number" }); 1.52 + } 1.53 + 1.54 + throw Components.results.NS_ERROR_ILLEGAL_VALUE; 1.55 + }, 1.56 + 1.57 + classID: Components.ID("{782775dd-7351-45ea-aff1-0ffa872cfdd2}"), 1.58 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]) 1.59 +}; 1.60 + 1.61 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelProtocolHandler]);