~ubuntu-branches/ubuntu/trusty/fennec/trusty

« back to all changes in this revision

Viewing changes to mobile/components/protocols/nsTelProtocolHandler.js

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-01-26 20:31:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110126203140-zcg54f8ost2vmrxr
Tags: 4.0~b3-0ubuntu1
* New upstream release v4.0 B3 (FENNEC_4_0b3_RELEASE)

* Update build-depends for xulrunner-2.0
  - update debian/control
* Update mozclient to point to the mobile-browser repo
  - update debian/mozclient/fennec.conf
* Build with "--with-system-libxul"
  - update debian/rules
* Add launcher script, based on the one used in Firefox but with the
  unnecessary bits stripped out
  - add debian/fennec.sh
  - update debian/rules
* Refresh patches for new version
  - update debian/patches/bump_gecko_versions_in_application.ini.patch
  - update debian/patches/ubuntu_codes_google.patch
  - update debian/patches/installer.patch
* Drop unneeded patches
  - remove debian/patches/nspr_flags_by_pkg_config_hack.patch
  - remove debian/patches/xul191_l10n.patch
  - update debian/patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2
 
 
3
 
 
4
 
 
5
 
const kSCHEME = "tel";
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");
9
 
 
10
 
// Mozilla defined
11
 
const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
12
 
const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
13
 
 
14
 
const Ci = Components.interfaces;
15
 
 
16
 
 
17
 
 
18
 
function TelProtocol()
19
 
{
20
 
}
21
 
 
22
 
TelProtocol.prototype =
23
 
{
24
 
    
25
 
  classDescription: "Handler for tel URIs",
26
 
  classID:          Components.ID(kPROTOCOL_CID),
27
 
  contractID:       kPROTOCOL_CONTRACTID,
28
 
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
29
 
  
30
 
  
31
 
  scheme: kSCHEME,
32
 
  defaultPort: -1,
33
 
  protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE | 
34
 
                 Ci.nsIProtocolHandler.URI_NOAUTH,
35
 
  
36
 
  allowPort: function(port, scheme)
37
 
  {
38
 
    return false;
39
 
  },
40
 
  
41
 
  newURI: function(spec, charset, baseURI)
42
 
  {
43
 
    var uri = Components.classes[kSIMPLEURI_CONTRACTID].createInstance(Ci.nsIURI);
44
 
    uri.spec = spec;
45
 
    return uri;
46
 
  },
47
 
  
48
 
  
49
 
  newChannel: function(aURI)
50
 
  {
51
 
    // aURI is a nsIUri, so get a string from it using .spec
52
 
    let phoneNumber = aURI.spec;
53
 
    
54
 
    // strip away the kSCHEME: part
55
 
    phoneNumber = phoneNumber.substring(phoneNumber.indexOf(":") + 1, phoneNumber.length);    
56
 
    phoneNumber = encodeURI(phoneNumber);
57
 
 
58
 
#ifdef WINCE
59
 
    try {
60
 
      //try tel:
61
 
      let channel = new nsWinceTelChannel (aURI, phoneNumber);
62
 
      return channel;
63
 
    } catch(e){
64
 
      //tel not registered, try the next one
65
 
    }
66
 
#endif
67
 
    
68
 
    var ios = Components.classes[kIOSERVICE_CONTRACTID].getService(Ci.nsIIOService);
69
 
    
70
 
    try {
71
 
      //try voipto:
72
 
      let channel = ios.newChannel("voipto:"+phoneNumber, null, null);
73
 
      return channel;
74
 
    } catch(e){
75
 
      //voipto not registered, try the next one
76
 
    }
77
 
    try {
78
 
      //try callto:
79
 
      let channel = ios.newChannel("callto:"+phoneNumber, null, null);
80
 
      return channel;
81
 
    } catch(e){
82
 
      //callto not registered, try the next one
83
 
    }
84
 
    //try wtai:  
85
 
    //this is our last equivalent protocol, so if it fails pass the exception on
86
 
    let channel = ios.newChannel("wtai:"+phoneNumber, null, null);
87
 
    return channel;
88
 
  }
89
 
};
90
 
 
91
 
var components = [TelProtocol];
92
 
function NSGetModule(compMgr, fileSpec) {
93
 
  return XPCOMUtils.generateModule(components);
94
 
}
95
 
 
96
 
#ifdef WINCE
97
 
function nsWinceTelChannel(URI, phoneNumber)
98
 
{
99
 
    this.URI = URI;
100
 
    this.originalURI = URI;
101
 
    this.phoneNumber = phoneNumber
102
 
}
103
 
 
104
 
nsWinceTelChannel.prototype.QueryInterface =
105
 
function bc_QueryInterface(iid)
106
 
{
107
 
    if (!iid.equals(Ci.nsIChannel) && !iid.equals(Ci.nsIRequest) &&
108
 
        !iid.equals(Ci.nsISupports))
109
 
        throw Components.results.NS_ERROR_NO_INTERFACE;
110
 
    return this;
111
 
}
112
 
 
113
 
/* nsIChannel */
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;
120
 
 
121
 
nsWinceTelChannel.prototype.open =
122
 
nsWinceTelChannel.prototype.asyncOpen =
123
 
function bc_open(observer, ctxt)
124
 
{    
125
 
    var phoneInterface= Components.classes["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
126
 
    phoneInterface.makeCall(this.phoneNumber,"",false);
127
 
    
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;
131
 
}
132
 
 
133
 
nsWinceTelChannel.prototype.asyncRead =
134
 
function bc_asyncRead(listener, ctxt)
135
 
{
136
 
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
137
 
}
138
 
 
139
 
/* nsIRequest */
140
 
nsWinceTelChannel.prototype.isPending =
141
 
function bc_isPending()
142
 
{
143
 
    return true;
144
 
}
145
 
 
146
 
nsWinceTelChannel.prototype.status = Components.results.NS_OK;
147
 
 
148
 
nsWinceTelChannel.prototype.cancel =
149
 
function bc_cancel(status)
150
 
{
151
 
    this.status = status;
152
 
}
153
 
 
154
 
nsWinceTelChannel.prototype.suspend =
155
 
nsWinceTelChannel.prototype.resume =
156
 
function bc_suspres()
157
 
{
158
 
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
159
 
}
160
 
#endif