summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/nsGopherProtocolStubHandler.js
blob: 5f4451d9e91b4b3da7fc4a6c56c4dcc6d136673d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");

/* This is a simple module which can be used as a template for any newly
   unsupported protocol. In this case, it redirects gopher:// protocol
   requests to the Mozilla Add-Ons page for OverbiteFF, which is a
   cross-platform extension for Gopherspace. This gives a soft-landing for
   support, which was withdrawn in Mozilla 2.0. See bugs 388195 and 572000. */

function GopherProtocol()
{
}

GopherProtocol.prototype = {
  classDescription: "Gopher protocol handler stub",
  classID: Components.ID("{22042bdb-56e4-47c6-8b12-fdfa859c05a9}"),

  // nsISupports
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),

  // nsIProtocolHandler
  scheme: "gopher",
  defaultPort: 70,
  protocolFlags: Ci.nsIProtocolHandler.URI_NORELATIVE |
                 Ci.nsIProtocolHandler.URI_NOAUTH |
                 Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,

  allowPort: function GP_allowPort(port, scheme) {
    return false; // meaningless.
  },

  newURI: function GP_newURI(spec, charset, baseURI) {
    var uri = Cc["@mozilla.org/network/standard-url;1"]
                .createInstance(Ci.nsIStandardURL);
    uri.init(Ci.nsIStandardURL.URLTYPE_STANDARD,
      this.defaultPort, spec, charset, baseURI)
    return uri;
  },

  newChannel: function GP_newChannel(inputURI) {
    return this.newChannel2(inputURI, null);
  },

  newChannel2: function GP_newChannel2(inputURI, loadinfo) {
    var newURI = Services.io.newURI("chrome://communicator/content/gopherAddon.xhtml");
    // Create a chrome channel, and de-chrome it, to our information page.
    var chan =
      loadinfo ? Services.io.newChannelFromURIWithLoadInfo(newURI, loadinfo) :
                 Services.io.newChannelFromURI(newURI, null,
                                               Services.scriptSecurityManager.getSystemPrincipal(),
                                               null,
                                               Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
                                               Ci.nsIContentPolicy.TYPE_OTHER);
    chan.originalURI = inputURI;
    chan.owner = Services.scriptSecurityManager.createCodebasePrincipal(inputURI, {});
    return chan;
  }
};

/* Make our factory. */
var components = [ GopherProtocol ];
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);