bug 816059 - properly reset blocklist in browser-chrome tests r=jaws
[gecko.git] / uriloader / exthandler / ExternalHelperAppChild.cpp
blob4cafa692193ad8d83d94ab89b39b484ba5870a99
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 "nsIInputStream.h"
9 #include "nsIRequest.h"
10 #include "nsIResumableChannel.h"
11 #include "nsNetUtil.h"
13 namespace mozilla {
14 namespace dom {
16 NS_IMPL_ISUPPORTS2(ExternalHelperAppChild,
17 nsIStreamListener,
18 nsIRequestObserver)
20 ExternalHelperAppChild::ExternalHelperAppChild()
21 : mStatus(NS_OK)
25 ExternalHelperAppChild::~ExternalHelperAppChild()
29 //-----------------------------------------------------------------------------
30 // nsIStreamListener
31 //-----------------------------------------------------------------------------
32 NS_IMETHODIMP
33 ExternalHelperAppChild::OnDataAvailable(nsIRequest *request,
34 nsISupports *ctx,
35 nsIInputStream *input,
36 uint64_t offset,
37 uint32_t count)
39 if (NS_FAILED(mStatus))
40 return mStatus;
42 nsCString data;
43 nsresult rv = NS_ReadInputStreamToString(input, data, count);
44 if (NS_FAILED(rv))
45 return rv;
47 if (!SendOnDataAvailable(data, offset, count))
48 return NS_ERROR_UNEXPECTED;
50 return NS_OK;
53 //////////////////////////////////////////////////////////////////////////////
54 // nsIRequestObserver
55 //////////////////////////////////////////////////////////////////////////////
57 NS_IMETHODIMP
58 ExternalHelperAppChild::OnStartRequest(nsIRequest *request, nsISupports *ctx)
60 nsresult rv = mHandler->OnStartRequest(request, ctx);
61 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
63 nsCString entityID;
64 nsCOMPtr<nsIResumableChannel> resumable(do_QueryInterface(request));
65 if (resumable)
66 resumable->GetEntityID(entityID);
67 SendOnStartRequest(entityID);
68 return NS_OK;
72 NS_IMETHODIMP
73 ExternalHelperAppChild::OnStopRequest(nsIRequest *request,
74 nsISupports *ctx,
75 nsresult status)
77 nsresult rv = mHandler->OnStopRequest(request, ctx, status);
78 SendOnStopRequest(status);
80 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
81 return NS_OK;
85 bool
86 ExternalHelperAppChild::RecvCancel(const nsresult& aStatus)
88 mStatus = aStatus;
89 return true;
92 } // namespace dom
93 } // namespace mozilla