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.

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

mercurial