Bug 1688832: part 5) Add `static` `AccessibleCaretManager::GetSelection`, `::GetFrame...
[gecko.git] / netwerk / dns / DNSRequestBase.h
bloba46eb1e4e2f5f85eee6715eafcf647541eaac42f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et 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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_net_DNSRequestBase_h
8 #define mozilla_net_DNSRequestBase_h
10 #include "mozilla/net/PDNSRequestParent.h"
11 #include "nsICancelable.h"
12 #include "nsIDNSRecord.h"
13 #include "nsIDNSListener.h"
14 #include "nsIDNSByTypeRecord.h"
15 #include "nsIEventTarget.h"
17 namespace mozilla {
18 namespace net {
20 class DNSRequestActor;
21 class DNSRequestChild;
22 class DNSRequestHandler;
23 class DNSRequestParent;
24 class DNSRequestSender;
26 // A base class for DNSRequestSender and DNSRequestHandler.
27 // Provide interfaces for processing DNS requests.
28 class DNSRequestBase : public nsISupports {
29 public:
30 explicit DNSRequestBase() = default;
32 void SetIPCActor(DNSRequestActor* aActor);
34 virtual void OnRecvCancelDNSRequest(const nsCString& hostName,
35 const nsCString& trrServer,
36 const uint16_t& type,
37 const OriginAttributes& originAttributes,
38 const uint32_t& flags,
39 const nsresult& reason) = 0;
40 virtual bool OnRecvLookupCompleted(const DNSRequestResponse& reply) = 0;
41 virtual void OnIPCActorDestroy() = 0;
43 virtual DNSRequestSender* AsDNSRequestSender() = 0;
44 virtual DNSRequestHandler* AsDNSRequestHandler() = 0;
46 protected:
47 virtual ~DNSRequestBase() = default;
49 RefPtr<DNSRequestActor> mIPCActor;
52 // DNSRequestSender is used to send an IPC request to DNSRequestHandler and
53 // deliver the result to nsIDNSListener.
54 // Note this class could be used both in content process and parent process.
55 class DNSRequestSender final : public DNSRequestBase, public nsICancelable {
56 public:
57 NS_DECL_THREADSAFE_ISUPPORTS
58 NS_DECL_NSICANCELABLE
60 DNSRequestSender(const nsACString& aHost, const nsACString& aTrrServer,
61 const uint16_t& aType,
62 const OriginAttributes& aOriginAttributes,
63 const uint32_t& aFlags, nsIDNSListener* aListener,
64 nsIEventTarget* target);
66 void OnRecvCancelDNSRequest(const nsCString& hostName,
67 const nsCString& trrServer, const uint16_t& type,
68 const OriginAttributes& originAttributes,
69 const uint32_t& flags,
70 const nsresult& reason) override;
71 bool OnRecvLookupCompleted(const DNSRequestResponse& reply) override;
72 void OnIPCActorDestroy() override;
74 // Sends IPDL request to DNSRequestHandler
75 void StartRequest();
76 void CallOnLookupComplete();
78 DNSRequestSender* AsDNSRequestSender() override { return this; }
79 DNSRequestHandler* AsDNSRequestHandler() override { return nullptr; }
81 private:
82 friend class ChildDNSService;
83 virtual ~DNSRequestSender() = default;
85 nsCOMPtr<nsIDNSListener> mListener;
86 nsCOMPtr<nsIEventTarget> mTarget;
87 nsCOMPtr<nsIDNSRecord> mResultRecord;
88 nsresult mResultStatus;
89 nsCString mHost;
90 nsCString mTrrServer;
91 uint16_t mType;
92 const OriginAttributes mOriginAttributes;
93 uint16_t mFlags;
96 // DNSRequestHandler handles the dns request and sends the result back via IPC.
97 // Note this class could be used both in parent process and socket process.
98 class DNSRequestHandler final : public DNSRequestBase, public nsIDNSListener {
99 public:
100 NS_DECL_THREADSAFE_ISUPPORTS
101 NS_DECL_NSIDNSLISTENER
103 DNSRequestHandler();
105 void DoAsyncResolve(const nsACString& hostname, const nsACString& trrServer,
106 uint16_t type, const OriginAttributes& originAttributes,
107 uint32_t flags);
109 void OnRecvCancelDNSRequest(const nsCString& hostName,
110 const nsCString& trrServer, const uint16_t& type,
111 const OriginAttributes& originAttributes,
112 const uint32_t& flags,
113 const nsresult& reason) override;
114 bool OnRecvLookupCompleted(const DNSRequestResponse& reply) override;
115 void OnIPCActorDestroy() override;
117 DNSRequestSender* AsDNSRequestSender() override { return nullptr; }
118 DNSRequestHandler* AsDNSRequestHandler() override { return this; }
120 private:
121 virtual ~DNSRequestHandler() = default;
123 uint32_t mFlags;
126 // Provides some common methods for DNSRequestChild and DNSRequestParent.
127 class DNSRequestActor {
128 public:
129 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
131 explicit DNSRequestActor(DNSRequestBase* aRequest) : mDNSRequest(aRequest) {}
133 virtual bool CanSend() const = 0;
134 virtual DNSRequestChild* AsDNSRequestChild() = 0;
135 virtual DNSRequestParent* AsDNSRequestParent() = 0;
137 DNSRequestBase* GetDNSRequest() { return mDNSRequest.get(); };
139 protected:
140 virtual ~DNSRequestActor() = default;
142 RefPtr<DNSRequestBase> mDNSRequest;
145 } // namespace net
146 } // namespace mozilla
148 #endif // mozilla_net_DNSRequestBase_h