2006-09-15 13:51:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2006-09-15 13:51:57 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cindent: */
|
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"
|
2014-01-30 22:26:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2014-07-04 04:16:08 +04:00
|
|
|
#include "nsDOMString.h"
|
2006-09-15 13:51:36 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule)
|
2006-09-15 13:51:36 +04:00
|
|
|
|
2006-09-15 13:51:43 +04:00
|
|
|
struct RedirEntry {
|
|
|
|
const char* id;
|
|
|
|
const char* url;
|
2013-03-19 15:23:43 +04:00
|
|
|
uint32_t flags;
|
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
|
|
|
|
URI_SAFE_FOR_UNTRUSTED_CONTENT. Also note, however, that adding
|
|
|
|
URI_SAFE_FOR_UNTRUSTED_CONTENT will allow random web sites to link to that
|
|
|
|
URI. Perhaps we should separate the two concepts out...
|
2006-09-15 13:51:43 +04:00
|
|
|
*/
|
|
|
|
static RedirEntry kRedirMap[] = {
|
2010-10-15 14:28:54 +04:00
|
|
|
{ "", "chrome://global/content/about.xhtml",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2009-08-21 23:28:46 +04:00
|
|
|
{ "about", "chrome://global/content/aboutAbout.xhtml", 0 },
|
2006-09-15 13:52:08 +04:00
|
|
|
{ "credits", "http://www.mozilla.org/credits/",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
|
|
|
|
{ "mozilla", "chrome://global/content/mozilla.xhtml",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
|
|
|
|
{ "plugins", "chrome://global/content/plugins.html", 0 },
|
|
|
|
{ "config", "chrome://global/content/config.xul", 0 },
|
2008-01-24 19:11:09 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
{ "crashes", "chrome://global/content/crashes.xhtml", 0 },
|
|
|
|
#endif
|
2006-12-18 13:51:10 +03:00
|
|
|
{ "logo", "chrome://branding/content/about.png",
|
2006-09-15 13:52:08 +04:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT},
|
2006-09-15 13:52:06 +04:00
|
|
|
{ "buildconfig", "chrome://global/content/buildconfig.html",
|
2006-09-15 13:52:08 +04:00
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
|
|
|
|
{ "license", "chrome://global/content/license.html",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT },
|
|
|
|
{ "neterror", "chrome://global/content/netError.xhtml",
|
|
|
|
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
2010-01-23 13:07:48 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
|
2013-09-04 07:05:17 +04:00
|
|
|
{ "compartments", "chrome://global/content/aboutCompartments.xhtml",
|
2013-10-10 18:54:02 +04:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
|
2009-10-03 11:21:34 +04:00
|
|
|
{ "memory", "chrome://global/content/aboutMemory.xhtml",
|
2010-02-21 06:36:46 +03:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2010-04-29 21:54:32 +04:00
|
|
|
{ "addons", "chrome://mozapps/content/extensions/extensions.xul",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2011-08-13 00:50:47 +04:00
|
|
|
{ "newaddon", "chrome://mozapps/content/extensions/newaddon.xul",
|
2011-08-14 12:00:25 +04:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
|
2010-02-21 06:36:46 +03:00
|
|
|
{ "support", "chrome://global/content/aboutSupport.xhtml",
|
2012-11-09 00:36:06 +04:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
|
|
|
{ "telemetry", "chrome://global/content/aboutTelemetry.xhtml",
|
2013-06-29 07:13:20 +04:00
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2013-08-08 04:15:28 +04:00
|
|
|
{ "networking", "chrome://global/content/aboutNetworking.xhtml",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2013-11-25 23:01:48 +04:00
|
|
|
{ "webrtc", "chrome://global/content/aboutWebrtc.xhtml",
|
|
|
|
nsIAboutModule::ALLOW_SCRIPT },
|
2013-06-29 07:13:20 +04: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 |
|
|
|
|
nsIAboutModule::HIDE_FROM_ABOUTABOUT }
|
2006-09-15 13:51:36 +04:00
|
|
|
};
|
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
|
|
|
|
nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result)
|
|
|
|
{
|
2006-09-15 13:52:03 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2006-09-15 13:51:57 +04:00
|
|
|
NS_ASSERTION(result, "must not be null");
|
|
|
|
|
2006-09-15 13:51:36 +04:00
|
|
|
nsresult rv;
|
2006-09-15 13:51:57 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2006-09-15 13:52:02 +04:00
|
|
|
rv = NS_GetAboutModuleName(aURI, path);
|
2006-09-15 13:51:36 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2006-09-15 13:51:57 +04:00
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
for (int i=0; i<kRedirTotal; i++)
|
2006-09-15 13:51:36 +04:00
|
|
|
{
|
2006-09-15 13:52:01 +04:00
|
|
|
if (!strcmp(path.get(), kRedirMap[i].id))
|
2006-09-15 13:51:38 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChannel> tempChannel;
|
2006-09-15 13:51:57 +04:00
|
|
|
rv = ioService->NewChannel(nsDependentCString(kRedirMap[i].url),
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, nullptr, getter_AddRefs(tempChannel));
|
2006-09-15 13:51:57 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2006-09-15 13:51:59 +04:00
|
|
|
tempChannel->SetOriginalURI(aURI);
|
|
|
|
|
2006-09-15 13:51:57 +04:00
|
|
|
NS_ADDREF(*result = tempChannel);
|
|
|
|
return rv;
|
|
|
|
}
|
2006-09-15 13:51:36 +04:00
|
|
|
}
|
2006-09-15 13:51:57 +04:00
|
|
|
|
|
|
|
NS_ERROR("nsAboutRedirector called for unknown case");
|
2006-09-15 13:51:36 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2006-09-15 13:52:05 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
2006-09-15 13:52:05 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString name;
|
2006-09-15 13:52:05 +04:00
|
|
|
nsresult rv = NS_GetAboutModuleName(aURI, name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (int i=0; i < kRedirTotal; i++)
|
|
|
|
{
|
|
|
|
if (name.EqualsASCII(kRedirMap[i].id))
|
|
|
|
{
|
2006-09-15 13:52:08 +04:00
|
|
|
*result = kRedirMap[i].flags;
|
2006-09-15 13:52:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("nsAboutRedirector called for unknown case");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-07-04 04:16:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
|
|
|
{
|
|
|
|
SetDOMStringToNull(result);
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
nsresult
|
2006-09-15 13:51:36 +04:00
|
|
|
nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
nsAboutRedirector* about = new nsAboutRedirector();
|
2012-07-30 18:20:58 +04:00
|
|
|
if (about == nullptr)
|
2006-09-15 13:51:36 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(about);
|
|
|
|
nsresult rv = about->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(about);
|
|
|
|
return rv;
|
|
|
|
}
|