mobile/android/components/AboutRedirector.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6ed5a944bddc
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
9 let modules = {
10 // about:
11 "": {
12 uri: "chrome://browser/content/about.xhtml",
13 privileged: true
14 },
15
16 // about:fennec and about:firefox are aliases for about:,
17 // but hidden from about:about
18 fennec: {
19 uri: "chrome://browser/content/about.xhtml",
20 privileged: true,
21 hide: true
22 },
23 get firefox() this.fennec,
24
25 // about:blank has some bad loading behavior we can avoid, if we use an alias
26 empty: {
27 uri: "about:blank",
28 privileged: false,
29 hide: true
30 },
31
32 rights: {
33 #ifdef MOZ_OFFICIAL_BRANDING
34 uri: "chrome://browser/content/aboutRights.xhtml",
35 #else
36 uri: "chrome://global/content/aboutRights-unbranded.xhtml",
37 #endif
38 privileged: false
39 },
40 blocked: {
41 uri: "chrome://browser/content/blockedSite.xhtml",
42 privileged: false,
43 hide: true
44 },
45 certerror: {
46 uri: "chrome://browser/content/aboutCertError.xhtml",
47 privileged: false,
48 hide: true
49 },
50 home: {
51 uri: "chrome://browser/content/aboutHome.xhtml",
52 privileged: false
53 },
54 apps: {
55 uri: "chrome://browser/content/aboutApps.xhtml",
56 privileged: true
57 },
58 downloads: {
59 uri: "chrome://browser/content/aboutDownloads.xhtml",
60 privileged: true
61 },
62 reader: {
63 uri: "chrome://browser/content/aboutReader.html",
64 privileged: false,
65 hide: true
66 },
67 feedback: {
68 uri: "chrome://browser/content/aboutFeedback.xhtml",
69 privileged: true
70 },
71 privatebrowsing: {
72 uri: "chrome://browser/content/aboutPrivateBrowsing.xhtml",
73 privileged: true
74 },
75 #ifdef MOZ_SERVICES_HEALTHREPORT
76 healthreport: {
77 uri: "chrome://browser/content/aboutHealthReport.xhtml",
78 privileged: true
79 },
80 #endif
81 }
82
83 function AboutRedirector() {}
84 AboutRedirector.prototype = {
85 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
86 classID: Components.ID("{322ba47e-7047-4f71-aebf-cb7d69325cd9}"),
87
88 _getModuleInfo: function (aURI) {
89 let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase();
90 return modules[moduleName];
91 },
92
93 // nsIAboutModule
94 getURIFlags: function(aURI) {
95 let flags;
96 let moduleInfo = this._getModuleInfo(aURI);
97 if (moduleInfo.hide)
98 flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
99
100 return flags | Ci.nsIAboutModule.ALLOW_SCRIPT;
101 },
102
103 newChannel: function(aURI) {
104 let moduleInfo = this._getModuleInfo(aURI);
105
106 var ios = Cc["@mozilla.org/network/io-service;1"].
107 getService(Ci.nsIIOService);
108
109 var channel = ios.newChannel(moduleInfo.uri, null, null);
110
111 if (!moduleInfo.privileged) {
112 // Setting the owner to null means that we'll go through the normal
113 // path in GetChannelPrincipal and create a codebase principal based
114 // on the channel's originalURI
115 channel.owner = null;
116 }
117
118 channel.originalURI = aURI;
119
120 return channel;
121 }
122 };
123
124 const components = [AboutRedirector];
125 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);

mercurial