2015-02-13 22:36:47 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-09-15 13:51:36 +04:00
|
|
|
|
|
|
|
#include "nsAboutRedirector.h"
|
2006-09-15 13:51:57 +04:00
|
|
|
#include "nsNetUtil.h"
|
2006-09-15 13:52:02 +04:00
|
|
|
#include "nsAboutProtocolUtils.h"
|
2018-11-29 17:35:07 +03:00
|
|
|
#include "nsBaseChannel.h"
|
2014-01-30 22:26:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2015-10-10 08:03:27 +03:00
|
|
|
#include "nsIProtocolHandler.h"
|
2020-05-04 17:53:34 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2019-09-18 18:25:35 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2006-09-15 13:51:36 +04:00
|
|
|
|
2019-09-18 18:25:35 +03:00
|
|
|
#define ABOUT_CONFIG_ENABLED_PREF "general.aboutConfig.enable"
|
2018-11-01 17:33:37 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule)
|
2006-09-15 13:51:36 +04:00
|
|
|
|
2015-02-13 22:36:37 +03:00
|
|
|
struct RedirEntry {
|
|
|
|
const char* id;
|
|
|
|
const char* url;
|
|
|
|
uint32_t flags;
|
2006-09-15 13:51:43 +04:00
|
|
|
};
|
|
|
|
|
2018-11-29 17:35:07 +03:00
|
|
|
class CrashChannel final : public nsBaseChannel {
|
|
|
|
public:
|
|
|
|
explicit CrashChannel(nsIURI* aURI) { SetURI(aURI); }
|
|
|
|
|
|
|
|
nsresult OpenContentStream(bool async, nsIInputStream** stream,
|
|
|
|
nsIChannel** channel) override {
|
|
|
|
nsAutoCString spec;
|
|
|
|
mURI->GetSpec(spec);
|
|
|
|
|
|
|
|
if (spec.EqualsASCII("about:crashparent") && XRE_IsParentProcess()) {
|
|
|
|
MOZ_CRASH("Crash via about:crashparent");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spec.EqualsASCII("about:crashcontent") && XRE_IsContentProcess()) {
|
|
|
|
MOZ_CRASH("Crash via about:crashcontent");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Unhandled about:crash* URI or wrong process");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CrashChannel() = default;
|
|
|
|
};
|
|
|
|
|
2006-09-15 13:51:43 +04:00
|
|
|
/*
|
2006-09-15 13:52:08 +04:00
|
|
|
Entries which do not have URI_SAFE_FOR_UNTRUSTED_CONTENT will run with chrome
|
|
|
|
privileges. This is potentially dangerous. Please use
|
|
|
|
URI_SAFE_FOR_UNTRUSTED_CONTENT in the third argument to each map item below
|
|
|
|
unless your about: page really needs chrome privileges. Security review is
|
|
|
|
required before adding new map entries without
|
2018-03-15 21:20:02 +03:00
|
|
|
URI_SAFE_FOR_UNTRUSTED_CONTENT.
|
|
|
|
|
|
|
|
URI_SAFE_FOR_UNTRUSTED_CONTENT is not enough to let web pages load that page,
|
|
|
|
for that you need MAKE_LINKABLE.
|
2021-01-26 03:27:56 +03:00
|
|
|
|
|
|
|
NOTE: changes to this redir map need to be accompanied with changes to
|
|
|
|
docshell/build/components.conf
|
2006-09-15 13:51:43 +04:00
|
|
|
*/
|
2017-02-15 00:22:14 +03:00
|
|
|
static const RedirEntry kRedirMap[] = {
|
2020-02-28 20:40:09 +03:00
|
|
|
{"about", "chrome://global/content/aboutAbout.html", 0},
|
2021-02-03 20:08:14 +03:00
|
|
|
{"addons", "chrome://mozapps/content/extensions/aboutaddons.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2015-08-31 08:30:00 +03:00
|
|
|
{"buildconfig", "chrome://global/content/buildconfig.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2020-03-10 20:05:16 +03:00
|
|
|
{"checkerboard", "chrome://global/content/aboutCheckerboard.html",
|
2016-01-23 04:27:28 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2021-01-26 03:27:56 +03:00
|
|
|
#ifndef MOZ_WIDGET_ANDROID
|
2021-10-26 16:32:31 +03:00
|
|
|
{"config", "chrome://global/content/aboutconfig/aboutconfig.html",
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2021-01-26 03:27:56 +03:00
|
|
|
#else
|
2021-10-26 16:32:31 +03:00
|
|
|
{"config", "chrome://geckoview/content/config.xhtml",
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2019-10-14 18:58:42 +03:00
|
|
|
#endif
|
2008-01-24 19:11:09 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2021-10-26 16:32:31 +03:00
|
|
|
{"crashes", "chrome://global/content/crashes.html",
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2008-01-24 19:11:09 +03:00
|
|
|
#endif
|
2015-10-10 08:03:27 +03:00
|
|
|
{"credits", "https://www.mozilla.org/credits/",
|
2020-05-28 03:07:46 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::URI_MUST_LOAD_IN_CHILD},
|
2020-05-26 14:45:21 +03:00
|
|
|
{"httpsonlyerror", "chrome://global/content/httpsonlyerror/errorpage.html",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT},
|
2015-08-31 08:30:00 +03:00
|
|
|
{"license", "chrome://global/content/license.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2015-08-31 08:30:00 +03:00
|
|
|
{"logo", "chrome://branding/content/about.png",
|
2016-04-19 11:56:19 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
// Linkable for testing reasons.
|
|
|
|
nsIAboutModule::MAKE_LINKABLE},
|
2020-03-10 16:54:27 +03:00
|
|
|
{"memory", "chrome://global/content/aboutMemory.xhtml",
|
2015-08-31 08:30:00 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2019-05-24 01:12:30 +03:00
|
|
|
{"certificate", "chrome://global/content/certviewer/certviewer.html",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT |
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS |
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2020-07-07 05:22:07 +03:00
|
|
|
{"mozilla", "chrome://global/content/mozilla.html",
|
2015-02-13 22:36:37 +03:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT},
|
|
|
|
{"neterror", "chrome://global/content/netError.xhtml",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
2015-02-05 19:09:15 +03:00
|
|
|
nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
|
2015-02-13 22:36:37 +03:00
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT},
|
2020-01-23 19:42:02 +03:00
|
|
|
{"networking", "chrome://global/content/aboutNetworking.html",
|
2015-02-13 22:36:37 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2020-03-10 01:27:26 +03:00
|
|
|
{"performance", "chrome://global/content/aboutPerformance.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2021-12-01 20:45:45 +03:00
|
|
|
#ifndef ANDROID
|
2015-08-31 08:30:00 +03:00
|
|
|
{"plugins", "chrome://global/content/plugins.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
|
|
|
|
nsIAboutModule::IS_SECURE_CHROME_UI},
|
2021-12-01 20:45:45 +03:00
|
|
|
#endif
|
2020-05-06 23:11:55 +03:00
|
|
|
{"processes", "chrome://global/content/aboutProcesses.html",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2020-03-12 18:53:59 +03:00
|
|
|
// about:serviceworkers always wants to load in the parent process because
|
2021-06-15 11:52:39 +03:00
|
|
|
// the only place nsIServiceWorkerManager has any data is in the parent
|
|
|
|
// process.
|
2020-03-12 18:53:59 +03:00
|
|
|
//
|
|
|
|
// There is overlap without about:debugging, but about:debugging is not
|
|
|
|
// available on mobile at this time, and it's useful to be able to know if
|
|
|
|
// a ServiceWorker is registered directly from the mobile browser without
|
|
|
|
// having to connect the device to a desktop machine and all that entails.
|
2015-08-31 08:30:00 +03:00
|
|
|
{"serviceworkers", "chrome://global/content/aboutServiceWorkers.xhtml",
|
2020-03-12 18:53:59 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2015-12-29 21:42:47 +03:00
|
|
|
#ifndef ANDROID
|
2015-12-15 17:12:06 +03:00
|
|
|
{"profiles", "chrome://global/content/aboutProfiles.xhtml",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2015-12-29 21:42:47 +03:00
|
|
|
#endif
|
2015-08-31 08:30:00 +03:00
|
|
|
// about:srcdoc is unresolvable by specification. It is included here
|
|
|
|
// because the security manager would disallow srcdoc iframes otherwise.
|
|
|
|
{"srcdoc", "about:blank",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
2015-09-23 05:59:13 +03:00
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT |
|
2016-04-19 11:56:19 +03:00
|
|
|
// Needs to be linkable so content can touch its own srcdoc frames
|
2015-09-23 05:59:13 +03:00
|
|
|
nsIAboutModule::MAKE_LINKABLE | nsIAboutModule::URI_CAN_LOAD_IN_CHILD},
|
2015-02-13 22:36:37 +03:00
|
|
|
{"support", "chrome://global/content/aboutSupport.xhtml",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2021-05-29 01:35:57 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
{"third-party", "chrome://global/content/aboutThirdParty.html",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
|
|
|
#endif
|
2021-03-04 14:15:12 +03:00
|
|
|
#ifndef MOZ_GLEAN_ANDROID
|
2020-07-30 19:35:17 +03:00
|
|
|
{"glean", "chrome://global/content/aboutGlean.html",
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT | nsIAboutModule::ALLOW_SCRIPT},
|
|
|
|
#endif
|
2015-02-13 22:36:37 +03:00
|
|
|
{"telemetry", "chrome://global/content/aboutTelemetry.xhtml",
|
2021-10-26 16:32:31 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::IS_SECURE_CHROME_UI},
|
2017-04-18 19:33:08 +03:00
|
|
|
{"url-classifier", "chrome://global/content/aboutUrlClassifier.xhtml",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2016-01-28 03:05:10 +03:00
|
|
|
{"webrtc", "chrome://global/content/aboutwebrtc/aboutWebrtc.html",
|
2015-02-13 22:36:37 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT},
|
2017-01-13 21:04:16 +03:00
|
|
|
{"printpreview", "about:blank",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT |
|
|
|
|
nsIAboutModule::URI_CAN_LOAD_IN_CHILD},
|
2018-05-18 19:41:05 +03:00
|
|
|
{"crashparent", "about:blank", nsIAboutModule::HIDE_FROM_ABOUTABOUT},
|
|
|
|
{"crashcontent", "about:blank",
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT |
|
|
|
|
nsIAboutModule::URI_CAN_LOAD_IN_CHILD |
|
|
|
|
nsIAboutModule::URI_MUST_LOAD_IN_CHILD}};
|
2014-01-30 22:26:54 +04:00
|
|
|
static const int kRedirTotal = mozilla::ArrayLength(kRedirMap);
|
2006-09-15 13:51:36 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-23 04:18:26 +04:00
|
|
|
nsAboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
|
2015-02-13 22:36:37 +03:00
|
|
|
nsIChannel** aResult) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2017-05-30 19:07:59 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aLoadInfo);
|
2015-02-13 22:36:37 +03:00
|
|
|
NS_ASSERTION(aResult, "must not be null");
|
|
|
|
|
|
|
|
nsAutoCString path;
|
|
|
|
nsresult rv = NS_GetAboutModuleName(aURI, path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-11-29 17:35:07 +03:00
|
|
|
if (path.EqualsASCII("crashparent") || path.EqualsASCII("crashcontent")) {
|
2019-03-12 23:16:07 +03:00
|
|
|
bool isExternal;
|
|
|
|
aLoadInfo->GetLoadTriggeredFromExternal(&isExternal);
|
|
|
|
if (isExternal) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2018-11-29 17:35:07 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = new CrashChannel(aURI);
|
2019-02-19 12:26:54 +03:00
|
|
|
channel->SetLoadInfo(aLoadInfo);
|
2018-11-29 17:35:07 +03:00
|
|
|
channel.forget(aResult);
|
|
|
|
return NS_OK;
|
2018-05-18 19:41:05 +03:00
|
|
|
}
|
|
|
|
|
2019-09-18 18:25:35 +03:00
|
|
|
if (path.EqualsASCII("config") &&
|
|
|
|
!mozilla::Preferences::GetBool(ABOUT_CONFIG_ENABLED_PREF, true)) {
|
2018-11-01 17:33:37 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-02-13 22:36:37 +03:00
|
|
|
for (int i = 0; i < kRedirTotal; i++) {
|
|
|
|
if (!strcmp(path.get(), kRedirMap[i].id)) {
|
|
|
|
nsCOMPtr<nsIChannel> tempChannel;
|
|
|
|
nsCOMPtr<nsIURI> tempURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(tempURI), kRedirMap[i].url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-10-10 08:03:27 +03:00
|
|
|
|
2017-05-30 19:07:59 +03:00
|
|
|
rv = NS_NewChannelInternal(getter_AddRefs(tempChannel), tempURI,
|
|
|
|
aLoadInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-05-13 14:55:11 +03:00
|
|
|
// If tempURI links to an external URI (i.e. something other than
|
2017-05-30 19:07:59 +03:00
|
|
|
// chrome:// or resource://) then set result principal URI on the
|
|
|
|
// load info which forces the channel principal to reflect the displayed
|
2017-05-13 14:55:11 +03:00
|
|
|
// URL rather then being the systemPrincipal.
|
2015-10-10 08:03:27 +03:00
|
|
|
bool isUIResource = false;
|
|
|
|
rv = NS_URIChainHasFlags(tempURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,
|
|
|
|
&isUIResource);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-01-13 21:04:16 +03:00
|
|
|
bool isAboutBlank = NS_IsAboutBlank(tempURI);
|
|
|
|
|
2017-05-30 19:07:59 +03:00
|
|
|
if (!isUIResource && !isAboutBlank) {
|
|
|
|
aLoadInfo->SetResultPrincipalURI(tempURI);
|
|
|
|
}
|
2015-02-13 22:36:37 +03:00
|
|
|
|
|
|
|
tempChannel->SetOriginalURI(aURI);
|
|
|
|
|
2015-04-17 16:19:00 +03:00
|
|
|
tempChannel.forget(aResult);
|
2015-02-13 22:36:37 +03:00
|
|
|
return rv;
|
2006-09-15 13:51:36 +04:00
|
|
|
}
|
2015-02-13 22:36:37 +03:00
|
|
|
}
|
2006-09-15 13:51:57 +04:00
|
|
|
|
2015-02-13 22:36:37 +03:00
|
|
|
NS_ERROR("nsAboutRedirector called for unknown case");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2006-09-15 13:51:36 +04:00
|
|
|
}
|
|
|
|
|
2006-09-15 13:52:05 +04:00
|
|
|
NS_IMETHODIMP
|
2015-02-13 22:36:37 +03:00
|
|
|
nsAboutRedirector::GetURIFlags(nsIURI* aURI, uint32_t* aResult) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
nsresult rv = NS_GetAboutModuleName(aURI, name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (int i = 0; i < kRedirTotal; i++) {
|
|
|
|
if (name.EqualsASCII(kRedirMap[i].id)) {
|
|
|
|
*aResult = kRedirMap[i].flags;
|
|
|
|
return NS_OK;
|
2006-09-15 13:52:05 +04:00
|
|
|
}
|
2015-02-13 22:36:37 +03:00
|
|
|
}
|
2006-09-15 13:52:05 +04:00
|
|
|
|
2015-02-13 22:36:37 +03:00
|
|
|
NS_ERROR("nsAboutRedirector called for unknown case");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2006-09-15 13:52:05 +04:00
|
|
|
}
|
|
|
|
|
2020-10-22 22:36:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAboutRedirector::GetChromeURI(nsIURI* aURI, nsIURI** chromeURI) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
nsresult rv = NS_GetAboutModuleName(aURI, name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (const auto& redir : kRedirMap) {
|
|
|
|
if (name.EqualsASCII(redir.id)) {
|
|
|
|
return NS_NewURI(chromeURI, redir.url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("nsAboutRedirector called for unknown case");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2015-02-13 22:36:37 +03:00
|
|
|
nsresult nsAboutRedirector::Create(nsISupports* aOuter, REFNSIID aIID,
|
|
|
|
void** aResult) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAboutRedirector> about = new nsAboutRedirector();
|
2015-04-17 16:19:00 +03:00
|
|
|
return about->QueryInterface(aIID, aResult);
|
2006-09-15 13:51:36 +04:00
|
|
|
}
|