summaryrefslogtreecommitdiffstats
path: root/security/manager/ssl/PSMContentListener.h
blob: d948383a453511c556076a86b864f665f5860998 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * 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 mozilla_psm_PSMCOntentListener_h_
#define mozilla_psm_PSMCOntentListener_h_

#include "nsCOMPtr.h"
#include "nsIURIContentListener.h"
#include "nsWeakReference.h"
#include "mozilla/psm/PPSMContentDownloaderChild.h"
#include "mozilla/psm/PPSMContentDownloaderParent.h"

#define NS_PSMCONTENTLISTEN_CID {0xc94f4a30, 0x64d7, 0x11d4, {0x99, 0x60, 0x00, 0xb0, 0xd0, 0x23, 0x54, 0xa0}}
#define NS_PSMCONTENTLISTEN_CONTRACTID "@mozilla.org/security/psmdownload;1"

namespace mozilla {
namespace net {

class PChannelDiverterParent;

} // namespace net
} // namespace mozilla

namespace mozilla { namespace psm {

// PSMContentStreamListener for parent-process downloading.
class PSMContentStreamListener : public nsIStreamListener
{
public:
  explicit PSMContentStreamListener(uint32_t type);
  NS_DECL_ISUPPORTS
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER

  void ImportCertificate();

protected:
  virtual ~PSMContentStreamListener();

  nsCString mByteData;
  uint32_t mType;
};

// Parent actor for importing a remote cert when the load was started by the
// child.
class PSMContentDownloaderParent : public PPSMContentDownloaderParent
                                 , public PSMContentStreamListener
{
public:
  explicit PSMContentDownloaderParent(uint32_t type);

  virtual bool RecvOnStartRequest(const uint32_t &contentLength) override;
  virtual bool RecvOnDataAvailable(const nsCString &data,
                                   const uint64_t &offset,
                                   const uint32_t &count) override;
  virtual bool RecvOnStopRequest(const nsresult &code) override;

  // We inherit most of nsIStreamListener from PSMContentStreamListener, but
  // we have to override OnStopRequest to know when we're done with our IPC
  // ref.
  NS_IMETHOD OnStopRequest(nsIRequest *request, nsISupports *aContext, nsresult code) override;

  virtual bool RecvDivertToParentUsing(mozilla::net::PChannelDiverterParent *diverter) override;

protected:
  virtual ~PSMContentDownloaderParent();

  virtual void ActorDestroy(ActorDestroyReason why) override;
  bool mIPCOpen;
};

// Child actor for importing a cert.
class PSMContentDownloaderChild : public nsIStreamListener
                                , public PPSMContentDownloaderChild
{
public:
  PSMContentDownloaderChild();

  NS_DECL_ISUPPORTS
  NS_DECL_NSIREQUESTOBSERVER
  NS_DECL_NSISTREAMLISTENER

private:
  ~PSMContentDownloaderChild();
};


class PSMContentListener : public nsIURIContentListener,
                           public nsSupportsWeakReference
{
public:
  PSMContentListener();
  nsresult init();

  NS_DECL_ISUPPORTS
  NS_DECL_NSIURICONTENTLISTENER

protected:
  virtual ~PSMContentListener();

private:
  nsCOMPtr<nsISupports> mLoadCookie;
  nsCOMPtr<nsIURIContentListener> mParentContentListener;
};

} } // namespace mozilla::psm

#endif // mozilla_psm_PSMCOntentListener_h