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_TCPSocketChild_h
8 : #define mozilla_dom_TCPSocketChild_h
9 :
10 : #include "mozilla/dom/TypedArray.h"
11 : #include "mozilla/net/PTCPSocketChild.h"
12 : #include "nsCycleCollectionParticipant.h"
13 : #include "nsCOMPtr.h"
14 : #include "js/TypeDecls.h"
15 :
16 : class nsITCPSocketCallback;
17 :
18 : namespace IPC {
19 : bool
20 : DeserializeArrayBuffer(JSContext* cx,
21 : const InfallibleTArray<uint8_t>& aBuffer,
22 : JS::MutableHandle<JS::Value> aVal);
23 : }
24 :
25 : namespace mozilla {
26 : namespace dom {
27 :
28 : class TCPSocket;
29 :
30 : class TCPSocketChildBase : public nsISupports {
31 : public:
32 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TCPSocketChildBase)
33 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 :
35 : void AddIPDLReference();
36 : void ReleaseIPDLReference();
37 :
38 : protected:
39 : TCPSocketChildBase();
40 : virtual ~TCPSocketChildBase();
41 :
42 : nsCOMPtr<nsITCPSocketCallback> mSocket;
43 : bool mIPCOpen;
44 : };
45 :
46 : class TCPSocketChild : public mozilla::net::PTCPSocketChild
47 : , public TCPSocketChildBase
48 : {
49 : public:
50 : NS_IMETHOD_(MozExternalRefCountType) Release() override;
51 :
52 : TCPSocketChild(const nsAString& aHost,
53 : const uint16_t& aPort,
54 : nsIEventTarget* aTarget);
55 : ~TCPSocketChild();
56 :
57 : void SendOpen(nsITCPSocketCallback* aSocket, bool aUseSSL, bool aUseArrayBuffers);
58 : void SendWindowlessOpenBind(nsITCPSocketCallback* aSocket,
59 : const nsACString& aRemoteHost, uint16_t aRemotePort,
60 : const nsACString& aLocalHost, uint16_t aLocalPort,
61 : bool aUseSSL, bool aUseRealtimeOptions);
62 : NS_IMETHOD SendSendArray(nsTArray<uint8_t>& aArray,
63 : uint32_t aTrackingNumber);
64 : void SendSend(const nsACString& aData, uint32_t aTrackingNumber);
65 : nsresult SendSend(const ArrayBuffer& aData,
66 : uint32_t aByteOffset,
67 : uint32_t aByteLength,
68 : uint32_t aTrackingNumber);
69 : void SendSendArray(nsTArray<uint8_t>* arr,
70 : uint32_t trackingNumber);
71 : void SetSocket(TCPSocket* aSocket);
72 :
73 : void GetHost(nsAString& aHost);
74 : void GetPort(uint16_t* aPort);
75 :
76 : virtual mozilla::ipc::IPCResult RecvCallback(const nsString& aType,
77 : const CallbackData& aData,
78 : const uint32_t& aReadyState) override;
79 : virtual mozilla::ipc::IPCResult RecvRequestDelete() override;
80 : virtual mozilla::ipc::IPCResult RecvUpdateBufferedAmount(const uint32_t& aBufferred,
81 : const uint32_t& aTrackingNumber) override;
82 : nsresult SetFilterName(const nsACString& aFilterName);
83 : private:
84 : nsString mHost;
85 : uint16_t mPort;
86 : nsCString mFilterName;
87 : nsCOMPtr<nsIEventTarget> mIPCEventTarget;
88 : };
89 :
90 : } // namespace dom
91 : } // namespace mozilla
92 :
93 : #endif
|