Bumping manifests a=b2g-bump
[gecko.git] / b2g / components / B2GAboutRedirector.js
blob8ad5e3c50c7487e58572e4759899f7dbe5a21931
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");
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;
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   }
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   }
76 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAboutRedirector]);