summaryrefslogtreecommitdiffstats
path: root/mobile/android/components/geckoview/GeckoViewStreamListener.h
blob: b42249f458f62d77712d8896e514660d902b3fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil; -*-
 * 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/. */

#ifndef GeckoViewStreamListener_h__
#define GeckoViewStreamListener_h__

#include "nsIStreamListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIChannelEventSink.h"

#include "mozilla/widget/EventDispatcher.h"
#include "mozilla/java/GeckoInputStreamNatives.h"
#include "mozilla/java/WebResponseWrappers.h"

#include "JavaBuiltins.h"

namespace mozilla {

class GeckoViewStreamListener : public nsIStreamListener,
                                public nsIInterfaceRequestor,
                                public nsIChannelEventSink {
 public:
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER
  NS_DECL_NSIINTERFACEREQUESTOR
  NS_DECL_NSICHANNELEVENTSINK

  explicit GeckoViewStreamListener() {}

  static std::tuple<jni::ByteArray::LocalRef, java::sdk::Boolean::LocalRef>
  CertificateFromChannel(nsIChannel* aChannel);

 protected:
  virtual ~GeckoViewStreamListener() {}

  java::GeckoInputStream::GlobalRef mStream;
  java::GeckoInputStream::Support::GlobalRef mSupport;

  void InitializeStreamSupport(nsIRequest* aRequest);

  static nsresult WriteSegment(nsIInputStream* aInputStream, void* aClosure,
                               const char* aFromSegment, uint32_t aToOffset,
                               uint32_t aCount, uint32_t* aWriteCount);

  virtual nsresult HandleWebResponse(nsIRequest* aRequest);

  virtual void SendWebResponse(java::WebResponse::Param aResponse) = 0;

  virtual void CompleteWithError(nsresult aStatus, nsIChannel* aChannel) = 0;
};

}  // namespace mozilla

#endif  // GeckoViewStreamListener_h__