~ubuntu-branches/debian/stretch/foxyproxy/stretch

« back to all changes in this revision

Viewing changes to src/components/relativeprotocolhandler.js

  • Committer: Bazaar Package Importer
  • Author(s): Yaroslav Halchenko
  • Date: 2011-04-25 09:41:06 UTC
  • mfrom: (1.2.1 upstream) (9.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110425094106-p6mrvjz0n6acwf9r
Tags: 2.22.6-1
* New upstream bugfix release
  - Should fix firefox/iceweasel 4.0 compatibility (Closes: #604029)
* debian/copyright -- updated copyright years

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
  FoxyProxy
3
 
  Copyright (C) 2006-2009 Eric H. Jung and LeahScape, Inc.
4
 
  http://foxyproxy.mozdev.org/
 
3
  Copyright (C) 2006-#%#% Eric H. Jung and LeahScape, Inc.
 
4
  http://getfoxyproxy.org/
5
5
  eric.jung@yahoo.com
6
6
 
7
7
  This source code is released under the GPL license,
8
8
  available in the LICENSE file at the root of this installation
9
9
  and also online at http://www.gnu.org/licenses/gpl.txt
10
10
**/
11
 
 
12
 
// Thanks for the template, doron (http://www.nexgenmedia.net/docs/protocol/)
13
11
const kSCHEME = "relative";
14
 
const kPROTOCOL_NAME = "FoxyProxy Relative Protocol";
15
 
const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
16
 
const kPROTOCOL_CID = Components.ID("22ed2962-a8ec-11dc-8314-0800200c9a66");
17
 
var CI = Components.interfaces, CC = Components.classes, CR = Components.results;
 
12
const CI = Components.interfaces;
 
13
const CC = Components.classes
 
14
const CR = Components.results;
18
15
 
19
 
// Mozilla defined
20
 
const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
21
16
const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
22
 
const nsISupports = Components.interfaces.nsISupports;
23
 
const nsIIOService = Components.interfaces.nsIIOService;
24
 
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
25
 
const nsIURI = Components.interfaces.nsIURI;
26
17
const IOS = CC[kIOSERVICE_CONTRACTID].
27
 
        getService(nsIIOService).getProtocolHandler("file").
28
 
        QueryInterface(CI.nsIFileProtocolHandler);
 
18
  getService(CI.nsIIOService).getProtocolHandler("file").
 
19
  QueryInterface(CI.nsIFileProtocolHandler);
 
20
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
29
21
 
30
22
function Protocol() {}
31
 
 
32
23
Protocol.prototype = {
33
 
  QueryInterface: function(iid) {
34
 
    if (!iid.equals(nsIProtocolHandler) &&
35
 
        !iid.equals(nsISupports))
36
 
      throw Components.results.NS_ERROR_NO_INTERFACE;
37
 
    return this;
38
 
  },
39
 
 
40
24
  scheme: kSCHEME,
41
25
  defaultPort: -1,
42
 
  protocolFlags: nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
 
26
  protocolFlags: CI.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
43
27
 
44
28
  allowPort: function(port, scheme) {
45
29
    return false;
46
30
  },
47
31
 
48
32
  newURI: function(spec, charset, baseURI) {
49
 
    var uri = Components.classes[kSIMPLEURI_CONTRACTID].createInstance(nsIURI);
 
33
    var uri = CC["@mozilla.org/network/simple-uri;1"].createInstance(CI.nsIURI);
50
34
    uri.spec = spec;
51
35
    return uri;
52
36
  },
68
52
    for (var i=1,sz=parts.length; i<sz; i++)
69
53
      file.appendRelativePath(parts[i]);
70
54
    var pHandler = CC[kIOSERVICE_CONTRACTID].
71
 
        getService(nsIIOService).getProtocolHandler("file").
 
55
        getService(CI.nsIIOService).getProtocolHandler("file").
72
56
        QueryInterface(CI.nsIFileProtocolHandler);
73
57
    return pHandler.newChannel(pHandler.newFileURI(file, null, null));
74
58
  },
75
 
}
76
 
 
77
 
var ProtocolFactory = new Object();
78
 
 
79
 
ProtocolFactory.createInstance = function (outer, iid) {
80
 
  if (outer != null)
81
 
    throw Components.results.NS_ERROR_NO_AGGREGATION;
82
 
 
83
 
  if (!iid.equals(nsIProtocolHandler) &&
84
 
      !iid.equals(nsISupports))
85
 
    throw Components.results.NS_ERROR_NO_INTERFACE;
86
 
 
87
 
  return new Protocol();
88
 
}
 
59
 
 
60
  QueryInterface: XPCOMUtils.generateQI([CI.nsISupports, CI.nsIProtocolHandler]),
 
61
  classDescription: "FoxyProxy Relative Component",
 
62
  classID: Components.ID("{22ed2962-a8ec-11dc-8314-0800200c9a66}"),
 
63
  contractID: "@mozilla.org/network/protocol;1?name=" + kSCHEME
 
64
};
89
65
 
90
66
/**
91
 
 * JS XPCOM boilerplate component registration code.
 
67
 * XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4)
 
68
 * XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 and earlier (Firefox 3.6)
92
69
 */
93
 
var prochandler = new Object();
94
 
 
95
 
prochandler.registerSelf = function (compMgr, fileSpec, location, type) {
96
 
  compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
97
 
  compMgr.registerFactoryLocation(kPROTOCOL_CID,
98
 
                                  kPROTOCOL_NAME,
99
 
                                  kPROTOCOL_CONTRACTID,
100
 
                                  fileSpec,
101
 
                                  location,
102
 
                                  type);
103
 
}
104
 
 
105
 
prochandler.getClassObject = function (compMgr, cid, iid) {
106
 
  if (!cid.equals(kPROTOCOL_CID))
107
 
    throw Components.results.NS_ERROR_NO_INTERFACE;
108
 
 
109
 
  if (!iid.equals(Components.interfaces.nsIFactory))
110
 
    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
111
 
 
112
 
  return ProtocolFactory;
113
 
}
114
 
 
115
 
prochandler.canUnload = function (compMgr) {
116
 
  return true;
117
 
}
118
 
 
119
 
function NSGetModule(compMgr, fileSpec){
120
 
  return prochandler;
121
 
}
 
70
if (XPCOMUtils.generateNSGetFactory)
 
71
  var NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]);
 
72
else
 
73
  var NSGetModule = XPCOMUtils.generateNSGetModule([Protocol]);