Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | |
michael@0 | 8 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | let modules = { |
michael@0 | 11 | newtab: { |
michael@0 | 12 | uri: "chrome://browser/content/Start.xul", |
michael@0 | 13 | privileged: true |
michael@0 | 14 | }, |
michael@0 | 15 | // about:blank has some bad loading behavior we can avoid, if we use an alias |
michael@0 | 16 | empty: { |
michael@0 | 17 | uri: "about:blank", |
michael@0 | 18 | privileged: false |
michael@0 | 19 | }, |
michael@0 | 20 | firstrun: { |
michael@0 | 21 | uri: "chrome://browser/content/firstrun/firstrun.xhtml", |
michael@0 | 22 | privileged: true |
michael@0 | 23 | }, |
michael@0 | 24 | rights: { |
michael@0 | 25 | #ifdef MOZ_OFFICIAL_BRANDING |
michael@0 | 26 | uri: "chrome://browser/content/aboutRights.xhtml", |
michael@0 | 27 | #else |
michael@0 | 28 | uri: "chrome://global/content/aboutRights-unbranded.xhtml", |
michael@0 | 29 | #endif |
michael@0 | 30 | privileged: false |
michael@0 | 31 | }, |
michael@0 | 32 | blocked: { |
michael@0 | 33 | uri: "chrome://browser/content/blockedSite.xhtml", |
michael@0 | 34 | privileged: true |
michael@0 | 35 | }, |
michael@0 | 36 | certerror: { |
michael@0 | 37 | uri: "chrome://browser/content/aboutCertError.xhtml", |
michael@0 | 38 | privileged: true |
michael@0 | 39 | }, |
michael@0 | 40 | start: { |
michael@0 | 41 | uri: "about:newtab", |
michael@0 | 42 | privileged: true |
michael@0 | 43 | }, |
michael@0 | 44 | home: { |
michael@0 | 45 | uri: "about:newtab", |
michael@0 | 46 | privileged: true |
michael@0 | 47 | }, |
michael@0 | 48 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 49 | crashprompt: { |
michael@0 | 50 | uri: "chrome://browser/content/crashprompt.xhtml", |
michael@0 | 51 | privileged: true |
michael@0 | 52 | }, |
michael@0 | 53 | #endif |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function AboutGeneric() {} |
michael@0 | 57 | |
michael@0 | 58 | AboutGeneric.prototype = { |
michael@0 | 59 | classID: Components.ID("{433d2d75-5923-49b0-854d-f37267b03dc7}"), |
michael@0 | 60 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]), |
michael@0 | 61 | |
michael@0 | 62 | _getModuleInfo: function (aURI) { |
michael@0 | 63 | let moduleName = aURI.path.replace(/[?#].*/, "").toLowerCase(); |
michael@0 | 64 | return modules[moduleName]; |
michael@0 | 65 | }, |
michael@0 | 66 | |
michael@0 | 67 | getURIFlags: function(aURI) { |
michael@0 | 68 | return Ci.nsIAboutModule.ALLOW_SCRIPT; |
michael@0 | 69 | }, |
michael@0 | 70 | |
michael@0 | 71 | newChannel: function(aURI) { |
michael@0 | 72 | let moduleInfo = this._getModuleInfo(aURI); |
michael@0 | 73 | |
michael@0 | 74 | var ios = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 75 | getService(Ci.nsIIOService); |
michael@0 | 76 | |
michael@0 | 77 | var channel = ios.newChannel(moduleInfo.uri, null, null); |
michael@0 | 78 | |
michael@0 | 79 | if (!moduleInfo.privileged) { |
michael@0 | 80 | // Setting the owner to null means that we'll go through the normal |
michael@0 | 81 | // path in GetChannelPrincipal and create a codebase principal based |
michael@0 | 82 | // on the channel's originalURI |
michael@0 | 83 | channel.owner = null; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | channel.originalURI = aURI; |
michael@0 | 87 | return channel; |
michael@0 | 88 | } |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | const components = [AboutGeneric]; |
michael@0 | 92 | const NSGetFactory = XPCOMUtils.generateNSGetFactory(components); |