docshell/base/nsAboutRedirector.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim:set ts=4 sw=4 sts=4 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsAboutRedirector.h"
michael@0 8 #include "nsNetUtil.h"
michael@0 9 #include "nsAboutProtocolUtils.h"
michael@0 10 #include "mozilla/ArrayUtils.h"
michael@0 11
michael@0 12 NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule)
michael@0 13
michael@0 14 struct RedirEntry {
michael@0 15 const char* id;
michael@0 16 const char* url;
michael@0 17 uint32_t flags;
michael@0 18 };
michael@0 19
michael@0 20 /*
michael@0 21 Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome
michael@0 22 privileges. This is potentially dangerous. Please use
michael@0 23 URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below
michael@0 24 unless your about: page really needs chrome privileges. Security review is
michael@0 25 required before adding new map entries without
michael@0 26 URI_SAFE_FOR_UNTRUSTED_CONTENT. Also note, however, that adding
michael@0 27 URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that
michael@0 28 URI. Perhaps we should separate the two concepts out...
michael@0 29 */
michael@0 30 static RedirEntry kRedirMap[] = {
michael@0 31 { "", "chrome://global/content/about.xhtml",
michael@0 32 nsIAboutModule::ALLOW_SCRIPT },
michael@0 33 { "about", "chrome://global/content/aboutAbout.xhtml", 0 },
michael@0 34 { "credits", "http://www.mozilla.org/credits/",
michael@0 35 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
michael@0 36 { "mozilla", "chrome://global/content/mozilla.xhtml",
michael@0 37 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
michael@0 38 { "plugins", "chrome://global/content/plugins.html", 0 },
michael@0 39 { "config", "chrome://global/content/config.xul", 0 },
michael@0 40 #ifdef MOZ_CRASHREPORTER
michael@0 41 { "crashes", "chrome://global/content/crashes.xhtml", 0 },
michael@0 42 #endif
michael@0 43 { "logo", "chrome://branding/content/about.png",
michael@0 44 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT},
michael@0 45 { "buildconfig", "chrome://global/content/buildconfig.html",
michael@0 46 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
michael@0 47 { "license", "chrome://global/content/license.html",
michael@0 48 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
michael@0 49 { "neterror", "chrome://global/content/netError.xhtml",
michael@0 50 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
michael@0 51 nsIAboutModule::ALLOW_SCRIPT |
michael@0 52 nsIAboutModule::HIDE_FROM_ABOUTABOUT },
michael@0 53 { "compartments", "chrome://global/content/aboutCompartments.xhtml",
michael@0 54 nsIAboutModule::ALLOW_SCRIPT |
michael@0 55 nsIAboutModule::HIDE_FROM_ABOUTABOUT },
michael@0 56 { "memory", "chrome://global/content/aboutMemory.xhtml",
michael@0 57 nsIAboutModule::ALLOW_SCRIPT },
michael@0 58 { "addons", "chrome://mozapps/content/extensions/extensions.xul",
michael@0 59 nsIAboutModule::ALLOW_SCRIPT },
michael@0 60 { "newaddon", "chrome://mozapps/content/extensions/newaddon.xul",
michael@0 61 nsIAboutModule::ALLOW_SCRIPT |
michael@0 62 nsIAboutModule::HIDE_FROM_ABOUTABOUT },
michael@0 63 { "support", "chrome://global/content/aboutSupport.xhtml",
michael@0 64 nsIAboutModule::ALLOW_SCRIPT },
michael@0 65 { "telemetry", "chrome://global/content/aboutTelemetry.xhtml",
michael@0 66 nsIAboutModule::ALLOW_SCRIPT },
michael@0 67 { "networking", "chrome://global/content/aboutNetworking.xhtml",
michael@0 68 nsIAboutModule::ALLOW_SCRIPT },
michael@0 69 { "webrtc", "chrome://global/content/aboutWebrtc.xhtml",
michael@0 70 nsIAboutModule::ALLOW_SCRIPT },
michael@0 71 // about:srcdoc is unresolvable by specification. It is included here
michael@0 72 // because the security manager would disallow srcdoc iframes otherwise.
michael@0 73 { "srcdoc", "about:blank",
michael@0 74 nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
michael@0 75 nsIAboutModule::HIDE_FROM_ABOUTABOUT }
michael@0 76 };
michael@0 77 static const int kRedirTotal = mozilla::ArrayLength(kRedirMap);
michael@0 78
michael@0 79 NS_IMETHODIMP
michael@0 80 nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result)
michael@0 81 {
michael@0 82 NS_ENSURE_ARG_POINTER(aURI);
michael@0 83 NS_ASSERTION(result, "must not be null");
michael@0 84
michael@0 85 nsresult rv;
michael@0 86
michael@0 87 nsAutoCString path;
michael@0 88 rv = NS_GetAboutModuleName(aURI, path);
michael@0 89 if (NS_FAILED(rv))
michael@0 90 return rv;
michael@0 91
michael@0 92 nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
michael@0 93 if (NS_FAILED(rv))
michael@0 94 return rv;
michael@0 95
michael@0 96 for (int i=0; i<kRedirTotal; i++)
michael@0 97 {
michael@0 98 if (!strcmp(path.get(), kRedirMap[i].id))
michael@0 99 {
michael@0 100 nsCOMPtr<nsIChannel> tempChannel;
michael@0 101 rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url),
michael@0 102 nullptr, nullptr, getter_AddRefs(tempChannel));
michael@0 103 if (NS_FAILED(rv))
michael@0 104 return rv;
michael@0 105
michael@0 106 tempChannel->SetOriginalURI(aURI);
michael@0 107
michael@0 108 NS_ADDREF(*result = tempChannel);
michael@0 109 return rv;
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 NS_ERROR("nsAboutRedirector called for unknown case");
michael@0 114 return NS_ERROR_ILLEGAL_VALUE;
michael@0 115 }
michael@0 116
michael@0 117 NS_IMETHODIMP
michael@0 118 nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result)
michael@0 119 {
michael@0 120 NS_ENSURE_ARG_POINTER(aURI);
michael@0 121
michael@0 122 nsAutoCString name;
michael@0 123 nsresult rv = NS_GetAboutModuleName(aURI, name);
michael@0 124 NS_ENSURE_SUCCESS(rv, rv);
michael@0 125
michael@0 126 for (int i=0; i < kRedirTotal; i++)
michael@0 127 {
michael@0 128 if (name.EqualsASCII(kRedirMap[i].id))
michael@0 129 {
michael@0 130 *result = kRedirMap[i].flags;
michael@0 131 return NS_OK;
michael@0 132 }
michael@0 133 }
michael@0 134
michael@0 135 NS_ERROR("nsAboutRedirector called for unknown case");
michael@0 136 return NS_ERROR_ILLEGAL_VALUE;
michael@0 137 }
michael@0 138
michael@0 139 nsresult
michael@0 140 nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
michael@0 141 {
michael@0 142 nsAboutRedirector* about = new nsAboutRedirector();
michael@0 143 if (about == nullptr)
michael@0 144 return NS_ERROR_OUT_OF_MEMORY;
michael@0 145 NS_ADDREF(about);
michael@0 146 nsresult rv = about->QueryInterface(aIID, aResult);
michael@0 147 NS_RELEASE(about);
michael@0 148 return rv;
michael@0 149 }

mercurial