1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/components/B2GAboutRedirector.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +const Cc = Components.classes; 1.8 +const Ci = Components.interfaces; 1.9 + 1.10 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.11 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.12 + 1.13 +function debug(msg) { 1.14 + //dump("B2GAboutRedirector: " + msg + "\n"); 1.15 +} 1.16 + 1.17 +function netErrorURL() { 1.18 + let uri = "app://system.gaiamobile.org/net_error.html"; 1.19 + try { 1.20 + uri = Services.prefs.getCharPref("b2g.neterror.url"); 1.21 + } catch(e) {} 1.22 + return uri; 1.23 +} 1.24 + 1.25 +let modules = { 1.26 + certerror: { 1.27 + uri: "chrome://b2g/content/aboutCertError.xhtml", 1.28 + privileged: false, 1.29 + hide: true 1.30 + }, 1.31 + neterror: { 1.32 + uri: netErrorURL(), 1.33 + privileged: false, 1.34 + hide: true 1.35 + } 1.36 +}; 1.37 + 1.38 +function B2GAboutRedirector() {} 1.39 +B2GAboutRedirector.prototype = { 1.40 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), 1.41 + classID: Components.ID("{920400b1-cf8f-4760-a9c4-441417b15134}"), 1.42 + 1.43 + _getModuleInfo: function (aURI) { 1.44 + let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase(); 1.45 + return modules[moduleName]; 1.46 + }, 1.47 + 1.48 + // nsIAboutModule 1.49 + getURIFlags: function(aURI) { 1.50 + let flags; 1.51 + let moduleInfo = this._getModuleInfo(aURI); 1.52 + if (moduleInfo.hide) 1.53 + flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT; 1.54 + 1.55 + return flags | Ci.nsIAboutModule.ALLOW_SCRIPT; 1.56 + }, 1.57 + 1.58 + newChannel: function(aURI) { 1.59 + let moduleInfo = this._getModuleInfo(aURI); 1.60 + 1.61 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.62 + getService(Ci.nsIIOService); 1.63 + 1.64 + var channel = ios.newChannel(moduleInfo.uri, null, null); 1.65 + 1.66 + if (!moduleInfo.privileged) { 1.67 + // Setting the owner to null means that we'll go through the normal 1.68 + // path in GetChannelPrincipal and create a codebase principal based 1.69 + // on the channel's originalURI 1.70 + channel.owner = null; 1.71 + } 1.72 + 1.73 + channel.originalURI = aURI; 1.74 + 1.75 + return channel; 1.76 + } 1.77 +}; 1.78 + 1.79 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAboutRedirector]);