1
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
6
const kPROTOCOL_NAME = "Tel Protocol";
7
const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
8
const kPROTOCOL_CID = Components.ID("d4bc06cc-fa9f-48ce-98e4-5326ca96ba28");
11
const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
12
const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
14
const Ci = Components.interfaces;
18
function TelProtocol()
22
TelProtocol.prototype =
25
classDescription: "Handler for tel URIs",
26
classID: Components.ID(kPROTOCOL_CID),
27
contractID: kPROTOCOL_CONTRACTID,
28
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
33
protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
34
Ci.nsIProtocolHandler.URI_NOAUTH,
36
allowPort: function(port, scheme)
41
newURI: function(spec, charset, baseURI)
43
var uri = Components.classes[kSIMPLEURI_CONTRACTID].createInstance(Ci.nsIURI);
49
newChannel: function(aURI)
51
// aURI is a nsIUri, so get a string from it using .spec
52
let phoneNumber = aURI.spec;
54
// strip away the kSCHEME: part
55
phoneNumber = phoneNumber.substring(phoneNumber.indexOf(":") + 1, phoneNumber.length);
56
phoneNumber = encodeURI(phoneNumber);
61
let channel = new nsWinceTelChannel (aURI, phoneNumber);
64
//tel not registered, try the next one
68
var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(Ci.nsIIOService);
72
let channel = ios.newChannel("voipto:"+phoneNumber, null, null);
75
//voipto not registered, try the next one
79
let channel = ios.newChannel("callto:"+phoneNumber, null, null);
82
//callto not registered, try the next one
85
//this is our last equivalent protocol, so if it fails pass the exception on
86
let channel = ios.newChannel("wtai:"+phoneNumber, null, null);
91
var components = [TelProtocol];
92
function NSGetModule(compMgr, fileSpec) {
93
return XPCOMUtils.generateModule(components);
97
function nsWinceTelChannel(URI, phoneNumber)
100
this.originalURI = URI;
101
this.phoneNumber = phoneNumber
104
nsWinceTelChannel.prototype.QueryInterface =
105
function bc_QueryInterface(iid)
107
if (!iid.equals(Ci.nsIChannel) && !iid.equals(Ci.nsIRequest) &&
108
!iid.equals(Ci.nsISupports))
109
throw Components.results.NS_ERROR_NO_INTERFACE;
114
nsWinceTelChannel.prototype.loadAttributes = null;
115
nsWinceTelChannel.prototype.contentLength = 0;
116
nsWinceTelChannel.prototype.owner = null;
117
nsWinceTelChannel.prototype.loadGroup = null;
118
nsWinceTelChannel.prototype.notificationCallbacks = null;
119
nsWinceTelChannel.prototype.securityInfo = null;
121
nsWinceTelChannel.prototype.open =
122
nsWinceTelChannel.prototype.asyncOpen =
123
function bc_open(observer, ctxt)
125
var phoneInterface= Components.classes["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
126
phoneInterface.makeCall(this.phoneNumber,"",false);
128
// We don't throw this (a number, not a real 'resultcode') because it
129
// upsets xpconnect if we do (error in the js console).
130
Components.returnCode = NS_ERROR_NO_CONTENT;
133
nsWinceTelChannel.prototype.asyncRead =
134
function bc_asyncRead(listener, ctxt)
136
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
140
nsWinceTelChannel.prototype.isPending =
141
function bc_isPending()
146
nsWinceTelChannel.prototype.status = Components.results.NS_OK;
148
nsWinceTelChannel.prototype.cancel =
149
function bc_cancel(status)
151
this.status = status;
154
nsWinceTelChannel.prototype.suspend =
155
nsWinceTelChannel.prototype.resume =
156
function bc_suspres()
158
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;