b2g/components/TelProtocolHandler.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     5 /**
     6  * TelProtocolHandle.js
     7  *
     8  * This file implements the URLs for Telephone Calls
     9  * https://www.ietf.org/rfc/rfc2806.txt
    10  */
    12 "use strict";
    14 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
    16 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
    17 Cu.import("resource:///modules/TelURIParser.jsm");
    19 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
    20                                    "@mozilla.org/childprocessmessagemanager;1",
    21                                    "nsIMessageSender");
    23 function TelProtocolHandler() {
    24 }
    26 TelProtocolHandler.prototype = {
    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,
    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   },
    42   newChannel: function Proto_newChannel(aURI) {
    43     let number = TelURIParser.parseURI('tel', aURI.spec);
    45     if (number) {
    46       cpmm.sendAsyncMessage("dial-handler", {
    47         number: number,
    48         type: "webtelephony/number" });
    49     }
    51     throw Components.results.NS_ERROR_ILLEGAL_VALUE;
    52   },
    54   classID: Components.ID("{782775dd-7351-45ea-aff1-0ffa872cfdd2}"),
    55   QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler])
    56 };
    58 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelProtocolHandler]);

mercurial