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
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_FetchSignal_h
8 : #define mozilla_dom_FetchSignal_h
9 :
10 : #include "mozilla/DOMEventTargetHelper.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 : class FetchController;
16 : class FetchSignal;
17 :
18 : class FetchSignal final : public DOMEventTargetHelper
19 : {
20 : public:
21 : // This class must be implemented by objects who want to follow a FetchSignal.
22 1 : class Follower
23 : {
24 : public:
25 : virtual void Aborted() = 0;
26 :
27 : protected:
28 : virtual ~Follower();
29 :
30 : void
31 : Follow(FetchSignal* aSignal);
32 :
33 : void
34 : Unfollow();
35 :
36 : RefPtr<FetchSignal> mFollowingSignal;
37 : };
38 :
39 : NS_DECL_ISUPPORTS_INHERITED
40 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchSignal, DOMEventTargetHelper)
41 :
42 : FetchSignal(FetchController* aController, bool aAborted);
43 : explicit FetchSignal(bool aAborted);
44 :
45 : JSObject*
46 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
47 :
48 : bool
49 : Aborted() const;
50 :
51 : void
52 : Abort();
53 :
54 0 : IMPL_EVENT_HANDLER(abort);
55 :
56 : void
57 : AddFollower(Follower* aFollower);
58 :
59 : void
60 : RemoveFollower(Follower* aFollower);
61 :
62 : bool
63 : CanAcceptFollower(Follower* aFollower) const;
64 :
65 : private:
66 0 : ~FetchSignal() = default;
67 :
68 : RefPtr<FetchController> mController;
69 :
70 : // Raw pointers. Follower unregisters itself in the DTOR.
71 : nsTArray<Follower*> mFollowers;
72 :
73 : bool mAborted;
74 : };
75 :
76 : } // dom namespace
77 : } // mozilla namespace
78 :
79 : #endif // mozilla_dom_FetchSignal_h
|