2017-03-22 13:06:23 +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/. */
|
|
|
|
|
|
|
|
#include "FetchObserver.h"
|
2017-03-22 13:07:27 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/EventBinding.h"
|
2017-03-22 13:06:23 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2017-03-22 13:06:23 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(FetchObserver)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FetchObserver,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FetchObserver,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchObserver)
|
2017-03-22 13:06:23 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(FetchObserver, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(FetchObserver, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
|
2018-08-26 15:16:21 +03:00
|
|
|
AbortSignalImpl* aSignalImpl)
|
2017-03-22 13:07:27 +03:00
|
|
|
: DOMEventTargetHelper(aGlobal), mState(FetchState::Requesting) {
|
2018-08-26 15:16:21 +03:00
|
|
|
if (aSignalImpl) {
|
|
|
|
Follow(aSignalImpl);
|
2017-03-22 13:07:27 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-22 13:06:23 +03:00
|
|
|
|
|
|
|
JSObject* FetchObserver::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return FetchObserver_Binding::Wrap(aCx, this, aGivenProto);
|
2017-03-22 13:06:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FetchState FetchObserver::State() const { return mState; }
|
|
|
|
|
2020-10-22 10:42:18 +03:00
|
|
|
void FetchObserver::RunAbortAlgorithm() { SetState(FetchState::Aborted); }
|
2017-03-22 13:07:27 +03:00
|
|
|
|
|
|
|
void FetchObserver::SetState(FetchState aState) {
|
|
|
|
MOZ_ASSERT(mState < aState);
|
|
|
|
|
|
|
|
if (mState == FetchState::Aborted || mState == FetchState::Errored ||
|
|
|
|
mState == FetchState::Complete) {
|
|
|
|
// We are already in a final state.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot pass from Requesting to Complete directly.
|
|
|
|
if (mState == FetchState::Requesting && aState == FetchState::Complete) {
|
|
|
|
SetState(FetchState::Responding);
|
|
|
|
}
|
|
|
|
|
|
|
|
mState = aState;
|
|
|
|
|
|
|
|
if (mState == FetchState::Aborted || mState == FetchState::Errored ||
|
|
|
|
mState == FetchState::Complete) {
|
|
|
|
Unfollow();
|
|
|
|
}
|
|
|
|
|
|
|
|
EventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
|
|
|
|
// TODO which kind of event should we dispatch here?
|
|
|
|
|
|
|
|
RefPtr<Event> event = Event::Constructor(this, u"statechange"_ns, init);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
DispatchEvent(*event);
|
2017-03-22 13:07:27 +03:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|