michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:set ts=4 sw=4 sts=4 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsAboutRedirector.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsAboutProtocolUtils.h" michael@0: #include "mozilla/ArrayUtils.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule) michael@0: michael@0: struct RedirEntry { michael@0: const char* id; michael@0: const char* url; michael@0: uint32_t flags; michael@0: }; michael@0: michael@0: /* michael@0: Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome michael@0: privileges. This is potentially dangerous. Please use michael@0: URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below michael@0: unless your about: page really needs chrome privileges. Security review is michael@0: required before adding new map entries without michael@0: URI_SAFE_FOR_UNTRUSTED_CONTENT. Also note, however, that adding michael@0: URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that michael@0: URI. Perhaps we should separate the two concepts out... michael@0: */ michael@0: static RedirEntry kRedirMap[] = { michael@0: { "", "chrome://global/content/about.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "about", "chrome://global/content/aboutAbout.xhtml", 0 }, michael@0: { "credits", "http://www.mozilla.org/credits/", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, michael@0: { "mozilla", "chrome://global/content/mozilla.xhtml", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, michael@0: { "plugins", "chrome://global/content/plugins.html", 0 }, michael@0: { "config", "chrome://global/content/config.xul", 0 }, michael@0: #ifdef MOZ_CRASHREPORTER michael@0: { "crashes", "chrome://global/content/crashes.xhtml", 0 }, michael@0: #endif michael@0: { "logo", "chrome://branding/content/about.png", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT}, michael@0: { "buildconfig", "chrome://global/content/buildconfig.html", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, michael@0: { "license", "chrome://global/content/license.html", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT }, michael@0: { "neterror", "chrome://global/content/netError.xhtml", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | michael@0: nsIAboutModule::ALLOW_SCRIPT | michael@0: nsIAboutModule::HIDE_FROM_ABOUTABOUT }, michael@0: { "compartments", "chrome://global/content/aboutCompartments.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT | michael@0: nsIAboutModule::HIDE_FROM_ABOUTABOUT }, michael@0: { "memory", "chrome://global/content/aboutMemory.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "addons", "chrome://mozapps/content/extensions/extensions.xul", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "newaddon", "chrome://mozapps/content/extensions/newaddon.xul", michael@0: nsIAboutModule::ALLOW_SCRIPT | michael@0: nsIAboutModule::HIDE_FROM_ABOUTABOUT }, michael@0: { "support", "chrome://global/content/aboutSupport.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "telemetry", "chrome://global/content/aboutTelemetry.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "networking", "chrome://global/content/aboutNetworking.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: { "webrtc", "chrome://global/content/aboutWebrtc.xhtml", michael@0: nsIAboutModule::ALLOW_SCRIPT }, michael@0: // about:srcdoc is unresolvable by specification. It is included here michael@0: // because the security manager would disallow srcdoc iframes otherwise. michael@0: { "srcdoc", "about:blank", michael@0: nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | michael@0: nsIAboutModule::HIDE_FROM_ABOUTABOUT } michael@0: }; michael@0: static const int kRedirTotal = mozilla::ArrayLength(kRedirMap); michael@0: michael@0: NS_IMETHODIMP michael@0: nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aURI); michael@0: NS_ASSERTION(result, "must not be null"); michael@0: michael@0: nsresult rv; michael@0: michael@0: nsAutoCString path; michael@0: rv = NS_GetAboutModuleName(aURI, path); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr ioService = do_GetIOService(&rv); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: for (int i=0; i tempChannel; michael@0: rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url), michael@0: nullptr, nullptr, getter_AddRefs(tempChannel)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: tempChannel->SetOriginalURI(aURI); michael@0: michael@0: NS_ADDREF(*result = tempChannel); michael@0: return rv; michael@0: } michael@0: } michael@0: michael@0: NS_ERROR("nsAboutRedirector called for unknown case"); michael@0: return NS_ERROR_ILLEGAL_VALUE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aURI); michael@0: michael@0: nsAutoCString name; michael@0: nsresult rv = NS_GetAboutModuleName(aURI, name); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: for (int i=0; i < kRedirTotal; i++) michael@0: { michael@0: if (name.EqualsASCII(kRedirMap[i].id)) michael@0: { michael@0: *result = kRedirMap[i].flags; michael@0: return NS_OK; michael@0: } michael@0: } michael@0: michael@0: NS_ERROR("nsAboutRedirector called for unknown case"); michael@0: return NS_ERROR_ILLEGAL_VALUE; michael@0: } michael@0: michael@0: nsresult michael@0: nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) michael@0: { michael@0: nsAboutRedirector* about = new nsAboutRedirector(); michael@0: if (about == nullptr) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: NS_ADDREF(about); michael@0: nsresult rv = about->QueryInterface(aIID, aResult); michael@0: NS_RELEASE(about); michael@0: return rv; michael@0: }