2017-03-22 13:04:57 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
#ifndef mozilla_dom_AbortSignal_h
|
|
|
|
#define mozilla_dom_AbortSignal_h
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-08-28 18:28:01 +03:00
|
|
|
#include "nsTObserverArray.h"
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
class AbortSignal;
|
2018-08-26 15:16:21 +03:00
|
|
|
class AbortSignalImpl;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2018-08-26 15:16:21 +03:00
|
|
|
// This class must be implemented by objects who want to follow a
|
|
|
|
// AbortSignalImpl.
|
2017-08-29 12:31:07 +03:00
|
|
|
class AbortFollower {
|
2017-03-22 13:04:57 +03:00
|
|
|
public:
|
2017-08-29 12:31:07 +03:00
|
|
|
virtual void Abort() = 0;
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2018-08-26 15:16:21 +03:00
|
|
|
void Follow(AbortSignalImpl* aSignal);
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
void Unfollow();
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
bool IsFollowing() const;
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
protected:
|
|
|
|
virtual ~AbortFollower();
|
2017-08-29 12:31:06 +03:00
|
|
|
|
2018-09-07 12:05:47 +03:00
|
|
|
// Subclasses of AbortFollower must Traverse this member and call
|
|
|
|
// Unfollow() when Unlinking.
|
2018-08-26 15:16:21 +03:00
|
|
|
RefPtr<AbortSignalImpl> mFollowingSignal;
|
2017-08-29 12:31:07 +03:00
|
|
|
};
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2018-09-07 12:05:47 +03:00
|
|
|
// Any subclass of this class must Traverse mFollowingSignal and call
|
|
|
|
// Unfollow() when Unlinking.
|
2018-08-26 15:16:21 +03:00
|
|
|
class AbortSignalImpl : public AbortFollower, public nsISupports {
|
2017-08-29 12:31:07 +03:00
|
|
|
public:
|
2018-08-26 15:16:21 +03:00
|
|
|
explicit AbortSignalImpl(bool aAborted);
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
bool Aborted() const;
|
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
void Abort() override;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
void AddFollower(AbortFollower* aFollower);
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
void RemoveFollower(AbortFollower* aFollower);
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2018-08-26 15:16:21 +03:00
|
|
|
protected:
|
|
|
|
virtual ~AbortSignalImpl() = default;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2018-08-26 15:16:21 +03:00
|
|
|
private:
|
2017-08-29 12:31:07 +03:00
|
|
|
// Raw pointers. AbortFollower unregisters itself in the DTOR.
|
2018-08-28 18:28:01 +03:00
|
|
|
nsTObserverArray<AbortFollower*> mFollowers;
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-03-22 13:04:57 +03:00
|
|
|
bool mAborted;
|
|
|
|
};
|
|
|
|
|
2018-08-26 15:16:21 +03:00
|
|
|
class AbortSignal final : public DOMEventTargetHelper, public AbortSignalImpl {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
AbortSignal(nsIGlobalObject* aGlobalObject, bool aAborted);
|
|
|
|
|
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort);
|
|
|
|
|
|
|
|
void Abort() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~AbortSignal() = default;
|
|
|
|
};
|
|
|
|
|
2017-03-22 13:04:57 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
#endif // mozilla_dom_AbortSignal_h
|