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"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
class AbortController;
|
|
|
|
class AbortSignal;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
// This class must be implemented by objects who want to follow a AbortSignal.
|
|
|
|
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
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
void
|
|
|
|
Follow(AbortSignal* 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
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
RefPtr<AbortSignal> mFollowingSignal;
|
|
|
|
};
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
class AbortSignal final : public DOMEventTargetHelper
|
|
|
|
, public AbortFollower
|
|
|
|
{
|
|
|
|
public:
|
2017-03-22 13:04:57 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2017-08-29 12:31:06 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortSignal(AbortController* aController, bool aAborted);
|
|
|
|
explicit AbortSignal(bool aAborted);
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
bool
|
|
|
|
Aborted() const;
|
|
|
|
|
|
|
|
void
|
2017-08-29 12:31:07 +03:00
|
|
|
Abort() override;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort);
|
|
|
|
|
2017-03-22 13:05:10 +03:00
|
|
|
void
|
2017-08-29 12:31:07 +03:00
|
|
|
AddFollower(AbortFollower* aFollower);
|
2017-03-22 13:05:10 +03:00
|
|
|
|
|
|
|
void
|
2017-08-29 12:31:07 +03:00
|
|
|
RemoveFollower(AbortFollower* aFollower);
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-03-22 13:04:57 +03:00
|
|
|
private:
|
2017-08-29 12:31:06 +03:00
|
|
|
~AbortSignal() = default;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
RefPtr<AbortController> mController;
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:07 +03:00
|
|
|
// Raw pointers. AbortFollower unregisters itself in the DTOR.
|
|
|
|
nsTArray<AbortFollower*> mFollowers;
|
2017-03-22 13:05:10 +03:00
|
|
|
|
2017-03-22 13:04:57 +03:00
|
|
|
bool mAborted;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
#endif // mozilla_dom_AbortSignal_h
|