uriloader/exthandler/ExternalHelperAppChild.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "ExternalHelperAppChild.h"
michael@0 8 #include "mozilla/net/ChannelDiverterChild.h"
michael@0 9 #include "nsIDivertableChannel.h"
michael@0 10 #include "nsIInputStream.h"
michael@0 11 #include "nsIFTPChannel.h"
michael@0 12 #include "nsIRequest.h"
michael@0 13 #include "nsIResumableChannel.h"
michael@0 14 #include "nsNetUtil.h"
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace dom {
michael@0 18
michael@0 19 NS_IMPL_ISUPPORTS(ExternalHelperAppChild,
michael@0 20 nsIStreamListener,
michael@0 21 nsIRequestObserver)
michael@0 22
michael@0 23 ExternalHelperAppChild::ExternalHelperAppChild()
michael@0 24 : mStatus(NS_OK)
michael@0 25 {
michael@0 26 }
michael@0 27
michael@0 28 ExternalHelperAppChild::~ExternalHelperAppChild()
michael@0 29 {
michael@0 30 }
michael@0 31
michael@0 32 //-----------------------------------------------------------------------------
michael@0 33 // nsIStreamListener
michael@0 34 //-----------------------------------------------------------------------------
michael@0 35 NS_IMETHODIMP
michael@0 36 ExternalHelperAppChild::OnDataAvailable(nsIRequest *request,
michael@0 37 nsISupports *ctx,
michael@0 38 nsIInputStream *input,
michael@0 39 uint64_t offset,
michael@0 40 uint32_t count)
michael@0 41 {
michael@0 42 if (NS_FAILED(mStatus))
michael@0 43 return mStatus;
michael@0 44
michael@0 45 nsCString data;
michael@0 46 nsresult rv = NS_ReadInputStreamToString(input, data, count);
michael@0 47 if (NS_FAILED(rv))
michael@0 48 return rv;
michael@0 49
michael@0 50 if (!SendOnDataAvailable(data, offset, count))
michael@0 51 return NS_ERROR_UNEXPECTED;
michael@0 52
michael@0 53 return NS_OK;
michael@0 54 }
michael@0 55
michael@0 56 //////////////////////////////////////////////////////////////////////////////
michael@0 57 // nsIRequestObserver
michael@0 58 //////////////////////////////////////////////////////////////////////////////
michael@0 59
michael@0 60 NS_IMETHODIMP
michael@0 61 ExternalHelperAppChild::OnStartRequest(nsIRequest *request, nsISupports *ctx)
michael@0 62 {
michael@0 63 nsCOMPtr<nsIDivertableChannel> divertable = do_QueryInterface(request);
michael@0 64 if (divertable) {
michael@0 65 return DivertToParent(divertable, request);
michael@0 66 }
michael@0 67
michael@0 68 nsresult rv = mHandler->OnStartRequest(request, ctx);
michael@0 69 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
michael@0 70
michael@0 71 nsCString entityID;
michael@0 72 nsCOMPtr<nsIResumableChannel> resumable(do_QueryInterface(request));
michael@0 73 if (resumable) {
michael@0 74 resumable->GetEntityID(entityID);
michael@0 75 }
michael@0 76 SendOnStartRequest(entityID);
michael@0 77 return NS_OK;
michael@0 78 }
michael@0 79
michael@0 80 NS_IMETHODIMP
michael@0 81 ExternalHelperAppChild::OnStopRequest(nsIRequest *request,
michael@0 82 nsISupports *ctx,
michael@0 83 nsresult status)
michael@0 84 {
michael@0 85 // mHandler can be null if we diverted the request to the parent
michael@0 86 if (mHandler) {
michael@0 87 nsresult rv = mHandler->OnStopRequest(request, ctx, status);
michael@0 88 SendOnStopRequest(status);
michael@0 89 NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
michael@0 90 }
michael@0 91
michael@0 92 return NS_OK;
michael@0 93 }
michael@0 94
michael@0 95 nsresult
michael@0 96 ExternalHelperAppChild::DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request)
michael@0 97 {
michael@0 98 mozilla::net::ChannelDiverterChild *diverter = nullptr;
michael@0 99 nsresult rv = divertable->DivertToParent(&diverter);
michael@0 100 if (NS_WARN_IF(NS_FAILED(rv))) {
michael@0 101 return rv;
michael@0 102 }
michael@0 103
michael@0 104 MOZ_ASSERT(diverter);
michael@0 105 if (SendDivertToParentUsing(diverter)) {
michael@0 106 mHandler->DidDivertRequest(request);
michael@0 107 mHandler = nullptr;
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 return NS_ERROR_FAILURE;
michael@0 112 }
michael@0 113
michael@0 114 bool
michael@0 115 ExternalHelperAppChild::RecvCancel(const nsresult& aStatus)
michael@0 116 {
michael@0 117 mStatus = aStatus;
michael@0 118 return true;
michael@0 119 }
michael@0 120
michael@0 121 } // namespace dom
michael@0 122 } // namespace mozilla

mercurial