Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
6 :
7 : #ifndef mozilla_dom_FlyWebFetchEvent_h
8 : #define mozilla_dom_FlyWebFetchEvent_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/ErrorResult.h"
12 : #include "mozilla/dom/BindingUtils.h"
13 : #include "mozilla/dom/Event.h"
14 : #include "mozilla/dom/FlyWebFetchEventBinding.h"
15 : #include "mozilla/dom/PromiseNativeHandler.h"
16 : #include "mozilla/dom/WebSocket.h"
17 :
18 : struct JSContext;
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : class Request;
23 : class Response;
24 : class FlyWebPublishedServer;
25 : class InternalRequest;
26 : class InternalResponse;
27 :
28 : class FlyWebFetchEvent : public Event
29 : , public PromiseNativeHandler
30 : {
31 : public:
32 : NS_DECL_ISUPPORTS_INHERITED
33 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(FlyWebFetchEvent, Event)
34 :
35 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
36 :
37 : virtual void
38 : ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
39 : virtual void
40 : RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
41 :
42 0 : class Request* Request() const
43 : {
44 0 : return mRequest;
45 : }
46 :
47 : void RespondWith(Promise& aArg, ErrorResult& aRv);
48 :
49 : FlyWebFetchEvent(FlyWebPublishedServer* aServer,
50 : class Request* aRequest,
51 : InternalRequest* aInternalRequest);
52 :
53 : protected:
54 : virtual ~FlyWebFetchEvent();
55 :
56 : virtual void NotifyServer(InternalResponse* aResponse);
57 :
58 : RefPtr<class Request> mRequest;
59 : RefPtr<InternalRequest> mInternalRequest;
60 : RefPtr<FlyWebPublishedServer> mServer;
61 :
62 : bool mResponded;
63 : };
64 :
65 : class FlyWebWebSocketEvent final : public FlyWebFetchEvent
66 : {
67 : public:
68 0 : FlyWebWebSocketEvent(FlyWebPublishedServer* aServer,
69 : class Request* aRequest,
70 : InternalRequest* aInternalRequest)
71 0 : : FlyWebFetchEvent(aServer, aRequest, aInternalRequest)
72 0 : {}
73 :
74 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
75 :
76 : already_AddRefed<WebSocket> Accept(const Optional<nsAString>& aProtocol,
77 : ErrorResult& aRv);
78 :
79 : private:
80 0 : ~FlyWebWebSocketEvent() {};
81 :
82 : virtual void NotifyServer(InternalResponse* aResponse) override;
83 : };
84 :
85 : } // namespace dom
86 : } // namespace mozilla
87 :
88 : #endif // mozilla_dom_FlyWebFetchEvent_h
|