b2g/components/B2GAboutRedirector.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 const Cc = Components.classes;
     5 const Ci = Components.interfaces;
     7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     8 Components.utils.import("resource://gre/modules/Services.jsm");
    10 function debug(msg) {
    11   //dump("B2GAboutRedirector: " + msg + "\n");
    12 }
    14 function netErrorURL() {
    15   let uri = "app://system.gaiamobile.org/net_error.html";
    16   try {
    17     uri = Services.prefs.getCharPref("b2g.neterror.url");
    18   } catch(e) {}
    19   return uri;
    20 }
    22 let modules = {
    23   certerror: {
    24     uri: "chrome://b2g/content/aboutCertError.xhtml",
    25     privileged: false,
    26     hide: true
    27   },
    28   neterror: {
    29     uri: netErrorURL(),
    30     privileged: false,
    31     hide: true
    32   }
    33 };
    35 function B2GAboutRedirector() {}
    36 B2GAboutRedirector.prototype = {
    37   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
    38   classID: Components.ID("{920400b1-cf8f-4760-a9c4-441417b15134}"),
    40   _getModuleInfo: function (aURI) {
    41     let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase();
    42     return modules[moduleName];
    43   },
    45   // nsIAboutModule
    46   getURIFlags: function(aURI) {
    47     let flags;
    48     let moduleInfo = this._getModuleInfo(aURI);
    49     if (moduleInfo.hide)
    50       flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
    52     return flags | Ci.nsIAboutModule.ALLOW_SCRIPT;
    53   },
    55   newChannel: function(aURI) {
    56     let moduleInfo = this._getModuleInfo(aURI);
    58     var ios = Cc["@mozilla.org/network/io-service;1"].
    59               getService(Ci.nsIIOService);
    61     var channel = ios.newChannel(moduleInfo.uri, null, null);
    63     if (!moduleInfo.privileged) {
    64       // Setting the owner to null means that we'll go through the normal
    65       // path in GetChannelPrincipal and create a codebase principal based
    66       // on the channel's originalURI
    67       channel.owner = null;
    68     }
    70     channel.originalURI = aURI;
    72     return channel;
    73   }
    74 };
    76 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAboutRedirector]);

mercurial