1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ExternalHelperAppChild.h"
8 #include "mozilla/dom/BrowserChild.h"
9 #include "nsIInputStream.h"
10 #include "nsIRequest.h"
11 #include "nsIResumableChannel.h"
12 #include "nsIPropertyBag2.h"
13 #include "nsNetUtil.h"
18 NS_IMPL_ISUPPORTS(ExternalHelperAppChild
, nsIStreamListener
, nsIRequestObserver
)
20 ExternalHelperAppChild::ExternalHelperAppChild() : mStatus(NS_OK
) {}
22 ExternalHelperAppChild::~ExternalHelperAppChild() {}
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 ExternalHelperAppChild::OnDataAvailable(nsIRequest
* request
,
29 nsIInputStream
* input
, uint64_t offset
,
31 if (NS_FAILED(mStatus
)) return mStatus
;
33 static uint32_t const kCopyChunkSize
= 128 * 1024;
34 uint32_t toRead
= std::min
<uint32_t>(count
, kCopyChunkSize
);
39 nsresult rv
= NS_ReadInputStreamToString(input
, data
, toRead
);
40 if (NS_WARN_IF(NS_FAILED(rv
))) {
44 if (NS_WARN_IF(!SendOnDataAvailable(data
, offset
, toRead
))) {
45 return NS_ERROR_UNEXPECTED
;
50 toRead
= std::min
<uint32_t>(count
, kCopyChunkSize
);
56 //////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
61 ExternalHelperAppChild::OnStartRequest(nsIRequest
* request
) {
62 nsresult rv
= mHandler
->OnStartRequest(request
);
63 NS_ENSURE_SUCCESS(rv
, NS_ERROR_UNEXPECTED
);
66 nsCOMPtr
<nsIResumableChannel
> resumable(do_QueryInterface(request
));
68 resumable
->GetEntityID(entityID
);
70 SendOnStartRequest(entityID
);
75 ExternalHelperAppChild::OnStopRequest(nsIRequest
* request
, nsresult status
) {
76 // mHandler can be null if we diverted the request to the parent
78 nsresult rv
= mHandler
->OnStopRequest(request
, status
);
79 SendOnStopRequest(status
);
80 NS_ENSURE_SUCCESS(rv
, NS_ERROR_UNEXPECTED
);
86 mozilla::ipc::IPCResult
ExternalHelperAppChild::RecvCancel(
87 const nsresult
& aStatus
) {
93 } // namespace mozilla