2015-05-22 00:32:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "InterceptedJARChannel.h"
|
|
|
|
#include "nsIPipe.h"
|
2015-05-25 11:21:05 -07:00
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
2015-05-22 00:32:25 -07:00
|
|
|
|
|
|
|
using namespace mozilla::net;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(InterceptedJARChannel, nsIInterceptedChannel)
|
|
|
|
|
|
|
|
InterceptedJARChannel::InterceptedJARChannel(nsJARChannel* aChannel,
|
|
|
|
nsINetworkInterceptController* aController,
|
|
|
|
bool aIsNavigation)
|
|
|
|
: mController(aController)
|
|
|
|
, mChannel(aChannel)
|
|
|
|
, mIsNavigation(aIsNavigation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::GetResponseBody(nsIOutputStream** aStream)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aStream = mResponseBody);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::GetIsNavigation(bool* aIsNavigation)
|
|
|
|
{
|
|
|
|
*aIsNavigation = mIsNavigation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::GetChannel(nsIChannel** aChannel)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aChannel = mChannel);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::ResetInterception()
|
|
|
|
{
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mResponseBody = nullptr;
|
|
|
|
mSynthesizedInput = nullptr;
|
|
|
|
|
|
|
|
mChannel->ResetInterception();
|
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::SynthesizeStatus(uint16_t aStatus,
|
|
|
|
const nsACString& aReason)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::SynthesizeHeader(const nsACString& aName,
|
|
|
|
const nsACString& aValue)
|
|
|
|
{
|
2015-06-05 03:53:58 -07:00
|
|
|
if (aName.LowerCaseEqualsLiteral("content-type")) {
|
|
|
|
mContentType = aValue;
|
|
|
|
}
|
2015-05-22 00:32:25 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
InterceptedJARChannel::FinishSynthesizedResponse()
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mChannel)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:53:58 -07:00
|
|
|
mChannel->OverrideWithSynthesizedResponse(mSynthesizedInput, mContentType);
|
2015-05-22 00:32:25 -07:00
|
|
|
|
|
|
|
mResponseBody = nullptr;
|
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-14 13:11:26 -07:00
|
|
|
InterceptedJARChannel::Cancel(nsresult aStatus)
|
2015-05-22 00:32:25 -07:00
|
|
|
{
|
2015-07-14 13:11:26 -07:00
|
|
|
MOZ_ASSERT(NS_FAILED(aStatus));
|
|
|
|
|
2015-05-22 00:32:25 -07:00
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:11:26 -07:00
|
|
|
nsresult rv = mChannel->Cancel(aStatus);
|
2015-05-22 00:32:25 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mResponseBody = nullptr;
|
|
|
|
mChannel = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-25 11:21:05 -07:00
|
|
|
InterceptedJARChannel::SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo)
|
2015-05-22 00:32:25 -07:00
|
|
|
{
|
|
|
|
if (!mChannel) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-05-25 11:21:05 -07:00
|
|
|
return aChannelInfo->ResurrectInfoOnChannel(mChannel);
|
2015-05-22 00:32:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InterceptedJARChannel::NotifyController()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_NewPipe(getter_AddRefs(mSynthesizedInput),
|
|
|
|
getter_AddRefs(mResponseBody),
|
|
|
|
0, UINT32_MAX, true, true);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
2015-09-21 14:10:37 -07:00
|
|
|
nsCOMPtr<nsIFetchEventDispatcher> dispatcher;
|
|
|
|
rv = mController->ChannelIntercepted(this, getter_AddRefs(dispatcher));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
rv = ResetInterception();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to resume intercepted network request");
|
|
|
|
}
|
|
|
|
rv = dispatcher->Dispatch();
|
2015-05-22 00:32:25 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
rv = ResetInterception();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed to resume intercepted network request");
|
|
|
|
}
|
|
|
|
mController = nullptr;
|
|
|
|
}
|