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