Bug 1845017 - Disable the TestPHCExhaustion test r=glandium
[gecko.git] / uriloader / exthandler / ExternalHelperAppChild.cpp
blob569d42e7a4ce344ec0582c9911b694914d89def4
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"
15 namespace mozilla {
16 namespace dom {
18 NS_IMPL_ISUPPORTS(ExternalHelperAppChild, nsIStreamListener, nsIRequestObserver)
20 ExternalHelperAppChild::ExternalHelperAppChild() : mStatus(NS_OK) {}
22 ExternalHelperAppChild::~ExternalHelperAppChild() {}
24 //-----------------------------------------------------------------------------
25 // nsIStreamListener
26 //-----------------------------------------------------------------------------
27 NS_IMETHODIMP
28 ExternalHelperAppChild::OnDataAvailable(nsIRequest* request,
29 nsIInputStream* input, uint64_t offset,
30 uint32_t count) {
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);
36 nsCString data;
38 while (count) {
39 nsresult rv = NS_ReadInputStreamToString(input, data, toRead);
40 if (NS_WARN_IF(NS_FAILED(rv))) {
41 return rv;
44 if (NS_WARN_IF(!SendOnDataAvailable(data, offset, toRead))) {
45 return NS_ERROR_UNEXPECTED;
48 count -= toRead;
49 offset += toRead;
50 toRead = std::min<uint32_t>(count, kCopyChunkSize);
53 return NS_OK;
56 //////////////////////////////////////////////////////////////////////////////
57 // nsIRequestObserver
58 //////////////////////////////////////////////////////////////////////////////
60 NS_IMETHODIMP
61 ExternalHelperAppChild::OnStartRequest(nsIRequest* request) {
62 nsresult rv = mHandler->OnStartRequest(request);
63 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
65 nsCString entityID;
66 nsCOMPtr<nsIResumableChannel> resumable(do_QueryInterface(request));
67 if (resumable) {
68 resumable->GetEntityID(entityID);
70 SendOnStartRequest(entityID);
71 return NS_OK;
74 NS_IMETHODIMP
75 ExternalHelperAppChild::OnStopRequest(nsIRequest* request, nsresult status) {
76 // mHandler can be null if we diverted the request to the parent
77 if (mHandler) {
78 nsresult rv = mHandler->OnStopRequest(request, status);
79 SendOnStopRequest(status);
80 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
83 return NS_OK;
86 mozilla::ipc::IPCResult ExternalHelperAppChild::RecvCancel(
87 const nsresult& aStatus) {
88 mStatus = aStatus;
89 return IPC_OK();
92 } // namespace dom
93 } // namespace mozilla