1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/components/AboutRedirector.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 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 + 1.12 +let modules = { 1.13 + // about: 1.14 + "": { 1.15 + uri: "chrome://browser/content/about.xhtml", 1.16 + privileged: true 1.17 + }, 1.18 + 1.19 + // about:fennec and about:firefox are aliases for about:, 1.20 + // but hidden from about:about 1.21 + fennec: { 1.22 + uri: "chrome://browser/content/about.xhtml", 1.23 + privileged: true, 1.24 + hide: true 1.25 + }, 1.26 + get firefox() this.fennec, 1.27 + 1.28 + // about:blank has some bad loading behavior we can avoid, if we use an alias 1.29 + empty: { 1.30 + uri: "about:blank", 1.31 + privileged: false, 1.32 + hide: true 1.33 + }, 1.34 + 1.35 + rights: { 1.36 +#ifdef MOZ_OFFICIAL_BRANDING 1.37 + uri: "chrome://browser/content/aboutRights.xhtml", 1.38 +#else 1.39 + uri: "chrome://global/content/aboutRights-unbranded.xhtml", 1.40 +#endif 1.41 + privileged: false 1.42 + }, 1.43 + blocked: { 1.44 + uri: "chrome://browser/content/blockedSite.xhtml", 1.45 + privileged: false, 1.46 + hide: true 1.47 + }, 1.48 + certerror: { 1.49 + uri: "chrome://browser/content/aboutCertError.xhtml", 1.50 + privileged: false, 1.51 + hide: true 1.52 + }, 1.53 + home: { 1.54 + uri: "chrome://browser/content/aboutHome.xhtml", 1.55 + privileged: false 1.56 + }, 1.57 + apps: { 1.58 + uri: "chrome://browser/content/aboutApps.xhtml", 1.59 + privileged: true 1.60 + }, 1.61 + downloads: { 1.62 + uri: "chrome://browser/content/aboutDownloads.xhtml", 1.63 + privileged: true 1.64 + }, 1.65 + reader: { 1.66 + uri: "chrome://browser/content/aboutReader.html", 1.67 + privileged: false, 1.68 + hide: true 1.69 + }, 1.70 + feedback: { 1.71 + uri: "chrome://browser/content/aboutFeedback.xhtml", 1.72 + privileged: true 1.73 + }, 1.74 + privatebrowsing: { 1.75 + uri: "chrome://browser/content/aboutPrivateBrowsing.xhtml", 1.76 + privileged: true 1.77 + }, 1.78 +#ifdef MOZ_SERVICES_HEALTHREPORT 1.79 + healthreport: { 1.80 + uri: "chrome://browser/content/aboutHealthReport.xhtml", 1.81 + privileged: true 1.82 + }, 1.83 +#endif 1.84 +} 1.85 + 1.86 +function AboutRedirector() {} 1.87 +AboutRedirector.prototype = { 1.88 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), 1.89 + classID: Components.ID("{322ba47e-7047-4f71-aebf-cb7d69325cd9}"), 1.90 + 1.91 + _getModuleInfo: function (aURI) { 1.92 + let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase(); 1.93 + return modules[moduleName]; 1.94 + }, 1.95 + 1.96 + // nsIAboutModule 1.97 + getURIFlags: function(aURI) { 1.98 + let flags; 1.99 + let moduleInfo = this._getModuleInfo(aURI); 1.100 + if (moduleInfo.hide) 1.101 + flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT; 1.102 + 1.103 + return flags | Ci.nsIAboutModule.ALLOW_SCRIPT; 1.104 + }, 1.105 + 1.106 + newChannel: function(aURI) { 1.107 + let moduleInfo = this._getModuleInfo(aURI); 1.108 + 1.109 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.110 + getService(Ci.nsIIOService); 1.111 + 1.112 + var channel = ios.newChannel(moduleInfo.uri, null, null); 1.113 + 1.114 + if (!moduleInfo.privileged) { 1.115 + // Setting the owner to null means that we'll go through the normal 1.116 + // path in GetChannelPrincipal and create a codebase principal based 1.117 + // on the channel's originalURI 1.118 + channel.owner = null; 1.119 + } 1.120 + 1.121 + channel.originalURI = aURI; 1.122 + 1.123 + return channel; 1.124 + } 1.125 +}; 1.126 + 1.127 +const components = [AboutRedirector]; 1.128 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);