2010-08-18 07:19:24 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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/. */
|
2010-08-18 07:19:24 +04:00
|
|
|
|
|
|
|
#include "ExternalHelperAppChild.h"
|
2014-03-12 02:41:48 +04:00
|
|
|
#include "mozilla/net/ChannelDiverterChild.h"
|
|
|
|
#include "nsIDivertableChannel.h"
|
2010-08-18 07:19:24 +04:00
|
|
|
#include "nsIInputStream.h"
|
2014-03-12 02:41:48 +04:00
|
|
|
#include "nsIFTPChannel.h"
|
2010-08-18 07:19:24 +04:00
|
|
|
#include "nsIRequest.h"
|
2010-08-23 20:29:33 +04:00
|
|
|
#include "nsIResumableChannel.h"
|
2010-08-18 07:19:24 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(ExternalHelperAppChild,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2010-08-18 07:19:24 +04:00
|
|
|
|
|
|
|
ExternalHelperAppChild::ExternalHelperAppChild()
|
|
|
|
: mStatus(NS_OK)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalHelperAppChild::~ExternalHelperAppChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIStreamListener
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppChild::OnDataAvailable(nsIRequest *request,
|
|
|
|
nsISupports *ctx,
|
|
|
|
nsIInputStream *input,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t offset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count)
|
2010-08-18 07:19:24 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus))
|
|
|
|
return mStatus;
|
|
|
|
|
|
|
|
nsCString data;
|
|
|
|
nsresult rv = NS_ReadInputStreamToString(input, data, count);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!SendOnDataAvailable(data, offset, count))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIRequestObserver
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppChild::OnStartRequest(nsIRequest *request, nsISupports *ctx)
|
|
|
|
{
|
2014-03-12 02:41:48 +04:00
|
|
|
nsCOMPtr<nsIDivertableChannel> divertable = do_QueryInterface(request);
|
|
|
|
if (divertable) {
|
|
|
|
return DivertToParent(divertable, request);
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:37:00 +04:00
|
|
|
nsresult rv = mHandler->OnStartRequest(request, ctx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2010-08-23 20:29:33 +04:00
|
|
|
nsCString entityID;
|
|
|
|
nsCOMPtr<nsIResumableChannel> resumable(do_QueryInterface(request));
|
2014-03-12 02:41:48 +04:00
|
|
|
if (resumable) {
|
2010-08-23 20:29:33 +04:00
|
|
|
resumable->GetEntityID(entityID);
|
2014-03-12 02:41:48 +04:00
|
|
|
}
|
2010-08-23 20:29:33 +04:00
|
|
|
SendOnStartRequest(entityID);
|
2010-08-18 07:19:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ExternalHelperAppChild::OnStopRequest(nsIRequest *request,
|
|
|
|
nsISupports *ctx,
|
|
|
|
nsresult status)
|
|
|
|
{
|
2014-03-12 02:41:48 +04:00
|
|
|
// mHandler can be null if we diverted the request to the parent
|
|
|
|
if (mHandler) {
|
|
|
|
nsresult rv = mHandler->OnStopRequest(request, ctx, status);
|
|
|
|
SendOnStopRequest(status);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2010-09-13 22:37:00 +04:00
|
|
|
|
2010-08-18 07:19:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-12 02:41:48 +04:00
|
|
|
nsresult
|
|
|
|
ExternalHelperAppChild::DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request)
|
|
|
|
{
|
|
|
|
mozilla::net::ChannelDiverterChild *diverter = nullptr;
|
|
|
|
nsresult rv = divertable->DivertToParent(&diverter);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(diverter);
|
|
|
|
if (SendDivertToParentUsing(diverter)) {
|
|
|
|
mHandler->DidDivertRequest(request);
|
|
|
|
mHandler = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-08-18 07:19:24 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
ExternalHelperAppChild::RecvCancel(const nsresult& aStatus)
|
|
|
|
{
|
|
|
|
mStatus = aStatus;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|