|
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; |
|
6 |
|
7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
8 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
9 |
|
10 function debug(msg) { |
|
11 //dump("B2GAboutRedirector: " + msg + "\n"); |
|
12 } |
|
13 |
|
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 } |
|
21 |
|
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 }; |
|
34 |
|
35 function B2GAboutRedirector() {} |
|
36 B2GAboutRedirector.prototype = { |
|
37 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), |
|
38 classID: Components.ID("{920400b1-cf8f-4760-a9c4-441417b15134}"), |
|
39 |
|
40 _getModuleInfo: function (aURI) { |
|
41 let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase(); |
|
42 return modules[moduleName]; |
|
43 }, |
|
44 |
|
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; |
|
51 |
|
52 return flags | Ci.nsIAboutModule.ALLOW_SCRIPT; |
|
53 }, |
|
54 |
|
55 newChannel: function(aURI) { |
|
56 let moduleInfo = this._getModuleInfo(aURI); |
|
57 |
|
58 var ios = Cc["@mozilla.org/network/io-service;1"]. |
|
59 getService(Ci.nsIIOService); |
|
60 |
|
61 var channel = ios.newChannel(moduleInfo.uri, null, null); |
|
62 |
|
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 } |
|
69 |
|
70 channel.originalURI = aURI; |
|
71 |
|
72 return channel; |
|
73 } |
|
74 }; |
|
75 |
|
76 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([B2GAboutRedirector]); |