2014-10-17 13:55:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: -*- */
|
|
|
|
/* vim:set expandtab ts=2 sw=2 sts=2 cin: */
|
|
|
|
/* 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 "HttpLog.h"
|
|
|
|
|
|
|
|
#include "InterceptedChannel.h"
|
|
|
|
#include "nsInputStreamPump.h"
|
|
|
|
#include "nsIPipe.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsHttpChannel.h"
|
|
|
|
#include "HttpChannelChild.h"
|
|
|
|
#include "nsHttpResponseHead.h"
|
2016-03-10 23:23:45 +00:00
|
|
|
#include "nsNetUtil.h"
|
2015-11-03 19:20:56 +00:00
|
|
|
#include "mozilla/ConsoleReportCollector.h"
|
2015-05-25 18:21:05 +00:00
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
2016-01-09 01:20:50 +00:00
|
|
|
#include "nsIChannelEventSink.h"
|
2014-10-17 13:55:09 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2015-06-12 14:20:21 +00:00
|
|
|
extern bool
|
|
|
|
WillRedirect(const nsHttpResponseHead * response);
|
|
|
|
|
2015-10-22 17:34:13 +00:00
|
|
|
extern nsresult
|
|
|
|
DoUpdateExpirationTime(nsHttpChannel* aSelf,
|
|
|
|
nsICacheEntry* aCacheEntry,
|
|
|
|
nsHttpResponseHead* aResponseHead,
|
|
|
|
uint32_t& aExpirationTime);
|
2014-10-17 13:55:09 +00:00
|
|
|
extern nsresult
|
|
|
|
DoAddCacheEntryHeaders(nsHttpChannel *self,
|
|
|
|
nsICacheEntry *entry,
|
|
|
|
nsHttpRequestHead *requestHead,
|
|
|
|
nsHttpResponseHead *responseHead,
|
|
|
|
nsISupports *securityInfo);
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(InterceptedChannelBase, nsIInterceptedChannel)
|
|
|
|
|
2015-10-07 02:52:43 +00:00
|
|
|
InterceptedChannelBase::InterceptedChannelBase(nsINetworkInterceptController* aController)
|
2014-10-17 13:55:09 +00:00
|
|
|
: mController(aController)
|
2015-11-03 19:20:56 +00:00
|
|
|
, mReportCollector(new ConsoleReportCollector())
|
2014-10-17 13:55:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InterceptedChannelBase::~InterceptedChannelBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelBase::GetResponseBody(nsIOutputStream** aStream)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aStream = mResponseBody);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
void
|
|
|
|
InterceptedChannelBase::EnsureSynthesizedResponse()
|
|
|
|
{
|
|
|
|
if (mSynthesizedResponseHead.isNothing()) {
|
2015-02-19 01:34:29 +00:00
|
|
|
mSynthesizedResponseHead.emplace(new nsHttpResponseHead());
|
2014-10-17 13:55:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-19 01:34:29 +00:00
|
|
|
InterceptedChannelBase::DoNotifyController()
|
2014-10-17 13:55:09 +00:00
|
|
|
{
|
2015-12-22 19:57:10 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mController)) {
|
2015-09-21 21:10:37 +00:00
|
|
|
rv = ResetInterception();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to resume intercepted network request");
|
2015-12-22 19:57:10 +00:00
|
|
|
return;
|
2015-09-21 21:10:37 +00:00
|
|
|
}
|
2015-12-22 19:57:10 +00:00
|
|
|
|
2016-01-04 22:40:04 +00:00
|
|
|
rv = mController->ChannelIntercepted(this);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2015-12-22 19:57:10 +00:00
|
|
|
rv = ResetInterception();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to resume intercepted network request");
|
2015-03-31 01:36:26 +00:00
|
|
|
}
|
2015-02-19 01:34:29 +00:00
|
|
|
mController = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 15:48:30 +00:00
|
|
|
nsresult
|
|
|
|
InterceptedChannelBase::DoSynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
|
|
|
|
{
|
|
|
|
EnsureSynthesizedResponse();
|
|
|
|
|
|
|
|
// Always assume HTTP 1.1 for synthesized responses.
|
|
|
|
nsAutoCString statusLine;
|
|
|
|
statusLine.AppendLiteral("HTTP/1.1 ");
|
|
|
|
statusLine.AppendInt(aStatus);
|
|
|
|
statusLine.AppendLiteral(" ");
|
|
|
|
statusLine.Append(aReason);
|
|
|
|
|
|
|
|
(*mSynthesizedResponseHead)->ParseStatusLine(statusLine.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
nsresult
|
|
|
|
InterceptedChannelBase::DoSynthesizeHeader(const nsACString& aName, const nsACString& aValue)
|
|
|
|
{
|
|
|
|
EnsureSynthesizedResponse();
|
|
|
|
|
|
|
|
nsAutoCString header = aName + NS_LITERAL_CSTRING(": ") + aValue;
|
|
|
|
// Overwrite any existing header.
|
2015-02-19 01:34:29 +00:00
|
|
|
nsresult rv = (*mSynthesizedResponseHead)->ParseHeaderLine(header.get());
|
2014-10-17 13:55:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelBase::GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCollectorOut);
|
|
|
|
nsCOMPtr<nsIConsoleReportCollector> ref = mReportCollector;
|
|
|
|
ref.forget(aCollectorOut);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:04:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelBase::SetReleaseHandle(nsISupports* aHandle)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mReleaseHandle);
|
|
|
|
MOZ_ASSERT(aHandle);
|
|
|
|
mReleaseHandle = aHandle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-02 16:27:00 +00:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> upgradedURI;
|
2016-03-10 23:23:45 +00:00
|
|
|
rv = NS_GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
|
2015-11-02 16:27:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
return upgradedURI.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
InterceptedChannelChrome::InterceptedChannelChrome(nsHttpChannel* aChannel,
|
|
|
|
nsINetworkInterceptController* aController,
|
|
|
|
nsICacheEntry* aEntry)
|
2015-10-07 02:52:43 +00:00
|
|
|
: InterceptedChannelBase(aController)
|
2014-10-17 13:55:09 +00:00
|
|
|
, mChannel(aChannel)
|
|
|
|
, mSynthesizedCacheEntry(aEntry)
|
|
|
|
{
|
2015-03-17 15:48:32 +00:00
|
|
|
nsresult rv = mChannel->GetApplyConversion(&mOldApplyConversion);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mOldApplyConversion = false;
|
|
|
|
}
|
2014-10-17 13:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InterceptedChannelChrome::NotifyController()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIOutputStream> out;
|
|
|
|
|
2015-03-17 15:48:32 +00:00
|
|
|
// Intercepted responses should already be decoded.
|
|
|
|
mChannel->SetApplyConversion(false);
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
nsresult rv = mSynthesizedCacheEntry->OpenOutputStream(0, getter_AddRefs(mResponseBody));
|
2014-10-17 13:55:09 +00:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
DoNotifyController();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::GetChannel(nsIChannel** aChannel)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aChannel = mChannel);
|
|
|
|
return NS_OK;
|
2014-10-17 13:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::ResetInterception()
|
|
|
|
{
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
mSynthesizedCacheEntry->AsyncDoom(nullptr);
|
|
|
|
mSynthesizedCacheEntry = nullptr;
|
|
|
|
|
2015-03-17 15:48:32 +00:00
|
|
|
mChannel->SetApplyConversion(mOldApplyConversion);
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
|
|
|
|
nsresult rv = mChannel->StartRedirectChannelToURI(uri, nsIChannelEventSink::REDIRECT_INTERNAL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2016-04-04 20:24:05 +00:00
|
|
|
mResponseBody->Close();
|
|
|
|
mResponseBody = nullptr;
|
|
|
|
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-17 15:48:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::SynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
|
|
|
|
{
|
|
|
|
if (!mSynthesizedCacheEntry) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoSynthesizeStatus(aStatus, aReason);
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::SynthesizeHeader(const nsACString& aName, const nsACString& aValue)
|
|
|
|
{
|
|
|
|
if (!mSynthesizedCacheEntry) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoSynthesizeHeader(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-10-22 13:23:39 +00:00
|
|
|
InterceptedChannelChrome::FinishSynthesizedResponse(const nsACString& aFinalURLSpec)
|
2014-10-17 13:55:09 +00:00
|
|
|
{
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2016-04-04 20:24:05 +00:00
|
|
|
// Make sure the cache entry's output stream is always closed. If the
|
|
|
|
// channel was intercepted with a null-body response then its possible
|
|
|
|
// the synthesis completed without a stream copy operation.
|
|
|
|
mResponseBody->Close();
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
EnsureSynthesizedResponse();
|
|
|
|
|
2015-06-12 14:20:21 +00:00
|
|
|
// If the synthesized response is a redirect, then we want to respect
|
|
|
|
// the encoding of whatever is loaded as a result.
|
|
|
|
if (WillRedirect(mSynthesizedResponseHead.ref())) {
|
|
|
|
nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
mChannel->MarkIntercepted();
|
|
|
|
|
|
|
|
// First we ensure the appropriate metadata is set on the synthesized cache entry
|
|
|
|
// (i.e. the flattened response head)
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> securityInfo;
|
|
|
|
nsresult rv = mChannel->GetSecurityInfo(getter_AddRefs(securityInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-10-22 17:34:13 +00:00
|
|
|
uint32_t expirationTime = 0;
|
|
|
|
rv = DoUpdateExpirationTime(mChannel, mSynthesizedCacheEntry,
|
|
|
|
mSynthesizedResponseHead.ref(),
|
|
|
|
expirationTime);
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
rv = DoAddCacheEntryHeaders(mChannel, mSynthesizedCacheEntry,
|
|
|
|
mChannel->GetRequestHead(),
|
2015-02-19 01:34:29 +00:00
|
|
|
mSynthesizedResponseHead.ref(), securityInfo);
|
2014-10-17 13:55:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-10-22 13:23:39 +00:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
mChannel->GetURI(getter_AddRefs(originalURI));
|
2014-10-17 13:55:09 +00:00
|
|
|
|
2015-10-22 13:23:39 +00:00
|
|
|
nsCOMPtr<nsIURI> responseURI;
|
|
|
|
if (!aFinalURLSpec.IsEmpty()) {
|
2016-05-11 06:57:24 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
|
2015-10-22 13:23:39 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
responseURI = originalURI;
|
|
|
|
}
|
2014-10-17 13:55:09 +00:00
|
|
|
|
2015-10-22 13:23:39 +00:00
|
|
|
bool equal = false;
|
|
|
|
originalURI->Equals(responseURI, &equal);
|
|
|
|
if (!equal) {
|
2016-05-11 06:57:24 +00:00
|
|
|
rv =
|
2015-10-22 13:23:39 +00:00
|
|
|
mChannel->StartRedirectChannelToURI(responseURI, nsIChannelEventSink::REDIRECT_INTERNAL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
bool usingSSL = false;
|
|
|
|
responseURI->SchemeIs("https", &usingSSL);
|
2015-10-21 04:05:40 +00:00
|
|
|
|
2015-10-22 13:23:39 +00:00
|
|
|
// Then we open a real cache entry to read the synthesized response from.
|
|
|
|
rv = mChannel->OpenCacheEntry(usingSSL);
|
2015-10-22 03:21:05 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-10-22 13:23:39 +00:00
|
|
|
mSynthesizedCacheEntry = nullptr;
|
|
|
|
|
|
|
|
if (!mChannel->AwaitingCacheCallbacks()) {
|
|
|
|
rv = mChannel->ContinueConnect();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
NS_IMETHODIMP
|
2015-07-14 20:11:26 +00:00
|
|
|
InterceptedChannelChrome::Cancel(nsresult aStatus)
|
2015-02-19 01:34:29 +00:00
|
|
|
{
|
2015-07-14 20:11:26 +00:00
|
|
|
MOZ_ASSERT(NS_FAILED(aStatus));
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
// we need to use AsyncAbort instead of Cancel since there's no active pump
|
|
|
|
// to cancel which will provide OnStart/OnStopRequest to the channel.
|
2015-07-14 20:11:26 +00:00
|
|
|
nsresult rv = mChannel->AsyncAbort(aStatus);
|
2015-02-19 01:34:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2015-02-19 01:34:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-04 23:27:33 +00:00
|
|
|
NS_IMETHODIMP
|
2015-05-25 18:21:05 +00:00
|
|
|
InterceptedChannelChrome::SetChannelInfo(dom::ChannelInfo* aChannelInfo)
|
2015-03-04 23:27:33 +00:00
|
|
|
{
|
2015-03-22 19:42:12 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-05-25 18:21:05 +00:00
|
|
|
return aChannelInfo->ResurrectInfoOnChannel(mChannel);
|
2015-03-04 23:27:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 18:56:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPolicyType);
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aPolicyType = loadInfo->InternalContentPolicyType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-02 16:27:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelChrome::GetSecureUpgradedChannelURI(nsIURI** aURI)
|
|
|
|
{
|
|
|
|
return mChannel->GetURI(aURI);
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
InterceptedChannelContent::InterceptedChannelContent(HttpChannelChild* aChannel,
|
|
|
|
nsINetworkInterceptController* aController,
|
2015-11-02 16:27:00 +00:00
|
|
|
InterceptStreamListener* aListener,
|
|
|
|
bool aSecureUpgrade)
|
2015-10-07 02:52:43 +00:00
|
|
|
: InterceptedChannelBase(aController)
|
2014-10-17 13:55:09 +00:00
|
|
|
, mChannel(aChannel)
|
|
|
|
, mStreamListener(aListener)
|
2015-11-02 16:27:00 +00:00
|
|
|
, mSecureUpgrade(aSecureUpgrade)
|
2014-10-17 13:55:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InterceptedChannelContent::NotifyController()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_NewPipe(getter_AddRefs(mSynthesizedInput),
|
2015-02-19 01:34:29 +00:00
|
|
|
getter_AddRefs(mResponseBody),
|
2014-10-17 13:55:09 +00:00
|
|
|
0, UINT32_MAX, true, true);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
DoNotifyController();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::GetChannel(nsIChannel** aChannel)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aChannel = mChannel);
|
|
|
|
return NS_OK;
|
2014-10-17 13:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::ResetInterception()
|
|
|
|
{
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2016-04-04 20:24:05 +00:00
|
|
|
mResponseBody->Close();
|
2015-02-19 01:34:29 +00:00
|
|
|
mResponseBody = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
mSynthesizedInput = nullptr;
|
|
|
|
|
|
|
|
mChannel->ResetInterception();
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-17 15:48:30 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::SynthesizeStatus(uint16_t aStatus, const nsACString& aReason)
|
|
|
|
{
|
|
|
|
if (!mResponseBody) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoSynthesizeStatus(aStatus, aReason);
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::SynthesizeHeader(const nsACString& aName, const nsACString& aValue)
|
|
|
|
{
|
2015-02-19 01:34:29 +00:00
|
|
|
if (!mResponseBody) {
|
2014-10-17 13:55:09 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoSynthesizeHeader(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-10-22 13:23:39 +00:00
|
|
|
InterceptedChannelContent::FinishSynthesizedResponse(const nsACString& aFinalURLSpec)
|
2014-10-17 13:55:09 +00:00
|
|
|
{
|
2015-02-19 01:34:29 +00:00
|
|
|
if (NS_WARN_IF(!mChannel)) {
|
2014-10-17 13:55:09 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2016-04-04 20:24:05 +00:00
|
|
|
// Make sure the body output stream is always closed. If the channel was
|
|
|
|
// intercepted with a null-body response then its possible the synthesis
|
|
|
|
// completed without a stream copy operation.
|
|
|
|
mResponseBody->Close();
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
EnsureSynthesizedResponse();
|
|
|
|
|
2015-10-22 13:23:48 +00:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
mChannel->GetURI(getter_AddRefs(originalURI));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> responseURI;
|
|
|
|
if (!aFinalURLSpec.IsEmpty()) {
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-11-02 16:27:00 +00:00
|
|
|
} else if (mSecureUpgrade) {
|
2016-03-10 23:23:45 +00:00
|
|
|
nsresult rv = NS_GetSecureUpgradedURI(originalURI,
|
|
|
|
getter_AddRefs(responseURI));
|
2015-11-02 16:27:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-10-22 13:23:48 +00:00
|
|
|
} else {
|
|
|
|
responseURI = originalURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool equal = false;
|
|
|
|
originalURI->Equals(responseURI, &equal);
|
|
|
|
if (!equal) {
|
|
|
|
mChannel->ForceIntercepted(mSynthesizedInput);
|
|
|
|
mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr());
|
|
|
|
} else {
|
|
|
|
mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(),
|
|
|
|
mSynthesizedInput,
|
|
|
|
mStreamListener);
|
|
|
|
}
|
2014-10-17 13:55:09 +00:00
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
mResponseBody = nullptr;
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
mChannel = nullptr;
|
2015-02-19 01:34:29 +00:00
|
|
|
mStreamListener = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-14 20:11:26 +00:00
|
|
|
InterceptedChannelContent::Cancel(nsresult aStatus)
|
2015-02-19 01:34:29 +00:00
|
|
|
{
|
2015-07-14 20:11:26 +00:00
|
|
|
MOZ_ASSERT(NS_FAILED(aStatus));
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:20:56 +00:00
|
|
|
mReportCollector->FlushConsoleReports(mChannel);
|
|
|
|
|
2015-02-19 01:34:29 +00:00
|
|
|
// we need to use AsyncAbort instead of Cancel since there's no active pump
|
|
|
|
// to cancel which will provide OnStart/OnStopRequest to the channel.
|
2015-07-14 20:11:26 +00:00
|
|
|
nsresult rv = mChannel->AsyncAbort(aStatus);
|
2015-02-19 01:34:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-11-16 16:04:11 +00:00
|
|
|
mReleaseHandle = nullptr;
|
2015-02-19 01:34:29 +00:00
|
|
|
mChannel = nullptr;
|
|
|
|
mStreamListener = nullptr;
|
2014-10-17 13:55:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-04 23:27:33 +00:00
|
|
|
NS_IMETHODIMP
|
2015-05-25 18:21:05 +00:00
|
|
|
InterceptedChannelContent::SetChannelInfo(dom::ChannelInfo* aChannelInfo)
|
2015-03-04 23:27:33 +00:00
|
|
|
{
|
2015-03-22 19:42:12 +00:00
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-05-25 18:21:05 +00:00
|
|
|
return aChannelInfo->ResurrectInfoOnChannel(mChannel);
|
2015-03-04 23:27:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 18:56:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPolicyType);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aPolicyType = loadInfo->InternalContentPolicyType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-02 16:27:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedChannelContent::GetSecureUpgradedChannelURI(nsIURI** aURI)
|
|
|
|
{
|
2015-11-02 16:27:00 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (mSecureUpgrade) {
|
|
|
|
uri = SecureUpgradeChannelURI(mChannel);
|
|
|
|
} else {
|
|
|
|
nsresult rv = mChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2015-11-02 16:27:00 +00:00
|
|
|
if (uri) {
|
|
|
|
uri.forget(aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-10-17 13:55:09 +00:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|