Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=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 file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_TCPSocketParent_h
8 : #define mozilla_dom_TCPSocketParent_h
9 :
10 : #include "mozilla/dom/TCPSocketBinding.h"
11 : #include "mozilla/net/PTCPSocketParent.h"
12 : #include "nsCycleCollectionParticipant.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsISocketFilter.h"
15 : #include "js/TypeDecls.h"
16 :
17 : #define TCPSOCKETPARENT_CID \
18 : { 0x4e7246c6, 0xa8b3, 0x426d, { 0x9c, 0x17, 0x76, 0xda, 0xb1, 0xe1, 0xe1, 0x4a } }
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : class TCPSocket;
24 :
25 : class TCPSocketParentBase : public nsISupports
26 : {
27 : public:
28 0 : NS_DECL_CYCLE_COLLECTION_CLASS(TCPSocketParentBase)
29 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 :
31 : void AddIPDLReference();
32 : void ReleaseIPDLReference();
33 :
34 : protected:
35 : TCPSocketParentBase();
36 : virtual ~TCPSocketParentBase();
37 :
38 : RefPtr<TCPSocket> mSocket;
39 : bool mIPCOpen;
40 : };
41 :
42 0 : class TCPSocketParent : public mozilla::net::PTCPSocketParent
43 : , public TCPSocketParentBase
44 : {
45 : public:
46 : NS_IMETHOD_(MozExternalRefCountType) Release() override;
47 :
48 0 : TCPSocketParent() {}
49 :
50 : virtual mozilla::ipc::IPCResult RecvOpen(const nsString& aHost, const uint16_t& aPort,
51 : const bool& useSSL, const bool& aUseArrayBuffers) override;
52 :
53 : virtual mozilla::ipc::IPCResult RecvOpenBind(const nsCString& aRemoteHost,
54 : const uint16_t& aRemotePort,
55 : const nsCString& aLocalAddr,
56 : const uint16_t& aLocalPort,
57 : const bool& aUseSSL,
58 : const bool& aReuseAddrPort,
59 : const bool& aUseArrayBuffers,
60 : const nsCString& aFilter) override;
61 :
62 : virtual mozilla::ipc::IPCResult RecvStartTLS() override;
63 : virtual mozilla::ipc::IPCResult RecvSuspend() override;
64 : virtual mozilla::ipc::IPCResult RecvResume() override;
65 : virtual mozilla::ipc::IPCResult RecvClose() override;
66 : virtual mozilla::ipc::IPCResult RecvData(const SendableData& aData,
67 : const uint32_t& aTrackingNumber) override;
68 : virtual mozilla::ipc::IPCResult RecvRequestDelete() override;
69 : bool GetInIsolatedMozBrowser();
70 :
71 : void FireErrorEvent(const nsAString& aName, const nsAString& aType, TCPReadyState aReadyState);
72 : void FireEvent(const nsAString& aType, TCPReadyState aReadyState);
73 : void FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState);
74 : void FireStringDataEvent(const nsACString& aData, TCPReadyState aReadyState);
75 :
76 : void SetSocket(TCPSocket *socket);
77 : nsresult GetHost(nsAString& aHost);
78 : nsresult GetPort(uint16_t* aPort);
79 :
80 : private:
81 : virtual uint32_t GetAppId();
82 : virtual void ActorDestroy(ActorDestroyReason why) override;
83 : void SendEvent(const nsAString& aType, CallbackData aData, TCPReadyState aReadyState);
84 : nsresult SetFilter(const nsCString& aFilter);
85 :
86 : nsCOMPtr<nsISocketFilter> mFilter;
87 : };
88 :
89 : } // namespace dom
90 : } // namespace mozilla
91 :
92 : #endif
|