michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function debug(msg) { michael@0: //dump("B2GAboutRedirector: " + msg + "\n"); michael@0: } michael@0: michael@0: function netErrorURL() { michael@0: let uri = "app://system.gaiamobile.org/net_error.html"; michael@0: try { michael@0: uri = Services.prefs.getCharPref("b2g.neterror.url"); michael@0: } catch(e) {} michael@0: return uri; michael@0: } michael@0: michael@0: let modules = { michael@0: certerror: { michael@0: uri: "chrome://b2g/content/aboutCertError.xhtml", michael@0: privileged: false, michael@0: hide: true michael@0: }, michael@0: neterror: { michael@0: uri: netErrorURL(), michael@0: privileged: false, michael@0: hide: true michael@0: } michael@0: }; michael@0: michael@0: function B2GAboutRedirector() {} michael@0: B2GAboutRedirector.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), michael@0: classID: Components.ID("{920400b1-cf8f-4760-a9c4-441417b15134}"), michael@0: michael@0: _getModuleInfo: function (aURI) { michael@0: let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase(); michael@0: return modules[moduleName]; michael@0: }, michael@0: michael@0: // nsIAboutModule michael@0: getURIFlags: function(aURI) { michael@0: let flags; michael@0: let moduleInfo = this._getModuleInfo(aURI); michael@0: if (moduleInfo.hide) michael@0: flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT; michael@0: michael@0: return flags | Ci.nsIAboutModule.ALLOW_SCRIPT; michael@0: }, michael@0: michael@0: newChannel: function(aURI) { michael@0: let moduleInfo = this._getModuleInfo(aURI); michael@0: michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: michael@0: var channel = ios.newChannel(moduleInfo.uri, null, null); michael@0: michael@0: if (!moduleInfo.privileged) { michael@0: // Setting the owner to null means that we'll go through the normal michael@0: // path in GetChannelPrincipal and create a codebase principal based michael@0: // on the channel's originalURI michael@0: channel.owner = null; michael@0: } michael@0: michael@0: channel.originalURI = aURI; michael@0: michael@0: return channel; michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAboutRedirector]);