Files
roytam1 ce0ac6811d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1255655 - Const-ify k{Unix,Win}Charsets and kLangGroups. r=smontagu. (75e9a5bf6c)
- Bug 1253010 - part 1 - refactor nsX509CertValidity time formatting; r=keeler (976afc4b16)
- Bug 1253010 - part 2 - provide a non-XPCOM way to create new nsIDateTimeFormat instances; r=smontagu (a2ccf520bb)
- Bug 1255239 - Reduce size of HuffmanIncomingTables. r=hurley. (8de07f2979)
- Bug 1224328 - Don't infinite loop when parsing headers with newlines. r=mcmanus (e7a9871294)
- Bug 1245106 - necko compilation warnings r=mcmanus (373b414d71)
- Bug 1253358 - no flags on priority frames r=hurley (0bfe9ccabe)
- Bug 1253358 - Assert no flags on several h2 frame types r=hurley (4315f882d7)
- Bug 1246735 - h2 reset recursive push. r=hurley (067e98a044)
- Bug 1253358 - minor h2 push fixes r=hurley (5a1c86723a)
- Bug 1246761 - Properly handle non-terminal 0-length DATA frames. r=mcmanus (4c1c907fc1)
- Bug 1120715 - Part 1: Add Necko APIs to preserve the Request cache mode on the channel; r=mayhemer (be7b704e09)
- Bug 1244122 P1 Always support SW intercept even when http cache is disabled. r=mayhemer (1929d6ff6b)
- Bug 1120715 - Part 2: Don't use OPEN_TRUNCATE when reopening a fake synthesized cache entry; r=mayhemer,jdm (84c5265a46)
- Bug 1148544 - Figure out UA override once per LoadGroup and cache it, rather than once per channel. r=nwgh (d610f7210f)
- Bug 1253582 - h2 coalescing impacts wss:// r=michal (bc7acebd2e)
- Bug 1064378 - Don't rewrite custom Authorization header set on a channel by cached credential. r=jduell (a427c97d24)
- Bug 1219482: Replace PRLogModuleInfo with LazyLogModule in uriloader subdirectory.r=erahm (2b54ad3276)
- Bug 1113196 - Pass a sane set of parameters to loadinfo for top-level loads in e10s. r=sicking (ea83174b6b)
- enable missing bit of 1487964 that is now valid (f6959fdcbc)
- Bug 1226928 - network and ipc bits for content-signing on remote about:newtab, r=mayhemer (0a183e0136)
- Bug 1257186 - Refactor the way compacting GC passes lists of arenas to background tasks to avoid possible race r=terrence (80e167e4b0)
2024-02-22 23:14:31 +08:00

170 lines
4.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 et: */
/* 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/. */
#include "nsViewSourceHandler.h"
#include "nsViewSourceChannel.h"
#include "nsNetUtil.h"
#include "nsSimpleNestedURI.h"
#define VIEW_SOURCE "view-source"
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS(nsViewSourceHandler, nsIProtocolHandler)
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP
nsViewSourceHandler::GetScheme(nsACString &result)
{
result.AssignLiteral(VIEW_SOURCE);
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceHandler::GetDefaultPort(int32_t *result)
{
*result = -1;
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceHandler::GetProtocolFlags(uint32_t *result)
{
*result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE |
URI_NON_PERSISTABLE;
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceHandler::NewURI(const nsACString &aSpec,
const char *aCharset,
nsIURI *aBaseURI,
nsIURI **aResult)
{
*aResult = nullptr;
// Extract inner URL and normalize to ASCII. This is done to properly
// support IDN in cases like "view-source:http://www.szalagavató.hu/"
int32_t colon = aSpec.FindChar(':');
if (colon == kNotFound)
return NS_ERROR_MALFORMED_URI;
nsCOMPtr<nsIURI> innerURI;
nsresult rv = NS_NewURI(getter_AddRefs(innerURI),
Substring(aSpec, colon + 1), aCharset, aBaseURI);
if (NS_FAILED(rv))
return rv;
nsAutoCString asciiSpec;
rv = innerURI->GetAsciiSpec(asciiSpec);
if (NS_FAILED(rv))
return rv;
// put back our scheme and construct a simple-uri wrapper
asciiSpec.Insert(VIEW_SOURCE ":", 0);
// We can't swap() from an RefPtr<nsSimpleNestedURI> to an nsIURI**,
// sadly.
nsSimpleNestedURI* ourURI = new nsSimpleNestedURI(innerURI);
nsCOMPtr<nsIURI> uri = ourURI;
if (!uri)
return NS_ERROR_OUT_OF_MEMORY;
rv = ourURI->SetSpec(asciiSpec);
if (NS_FAILED(rv))
return rv;
// Make the URI immutable so it's impossible to get it out of sync
// with its inner URI.
ourURI->SetMutable(false);
uri.swap(*aResult);
return rv;
}
NS_IMETHODIMP
nsViewSourceHandler::NewChannel2(nsIURI* uri,
nsILoadInfo* aLoadInfo,
nsIChannel** result)
{
NS_ENSURE_ARG_POINTER(uri);
nsViewSourceChannel *channel = new nsViewSourceChannel();
if (!channel)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(channel);
nsresult rv = channel->Init(uri);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
// set the loadInfo on the new channel
rv = channel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = static_cast<nsIViewSourceChannel*>(channel);
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
{
return NewChannel2(uri, nullptr, result);
}
nsresult
nsViewSourceHandler::NewSrcdocChannel(nsIURI *aURI,
nsIURI *aBaseURI,
const nsAString &aSrcdoc,
nsILoadInfo* aLoadInfo,
nsIChannel** outChannel)
{
NS_ENSURE_ARG_POINTER(aURI);
RefPtr<nsViewSourceChannel> channel = new nsViewSourceChannel();
nsresult rv = channel->InitSrcdoc(aURI, aBaseURI, aSrcdoc, aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
}
*outChannel = static_cast<nsIViewSourceChannel*>(channel.forget().take());
return NS_OK;
}
NS_IMETHODIMP
nsViewSourceHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
{
// don't override anything.
*_retval = false;
return NS_OK;
}
nsViewSourceHandler::nsViewSourceHandler()
{
gInstance = this;
}
nsViewSourceHandler::~nsViewSourceHandler()
{
gInstance = nullptr;
}
nsViewSourceHandler* nsViewSourceHandler::gInstance = nullptr;
nsViewSourceHandler*
nsViewSourceHandler::GetInstance()
{
return gInstance;
}