summaryrefslogtreecommitdiffstats
path: root/dom/fetch/FetchObserver.cpp
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-11 08:51:07 +0000
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-06-13 11:52:04 +0200
commitbb7060582934f087b71702d1e83f762d5fd6f0af (patch)
treef61da2175542328c6a5e7a69280874dd1298f9b6 /dom/fetch/FetchObserver.cpp
parent3f3d626434b2533182ca0ee90adc92a1e7db373c (diff)
downloadUXP-bb7060582934f087b71702d1e83f762d5fd6f0af.tar
UXP-bb7060582934f087b71702d1e83f762d5fd6f0af.tar.gz
UXP-bb7060582934f087b71702d1e83f762d5fd6f0af.tar.lz
UXP-bb7060582934f087b71702d1e83f762d5fd6f0af.tar.xz
UXP-bb7060582934f087b71702d1e83f762d5fd6f0af.zip
Issue #1587 - Part 5: Hook FetchObserver up to the Fetch API
Diffstat (limited to 'dom/fetch/FetchObserver.cpp')
-rw-r--r--dom/fetch/FetchObserver.cpp57
1 files changed, 54 insertions, 3 deletions
diff --git a/dom/fetch/FetchObserver.cpp b/dom/fetch/FetchObserver.cpp
index bc8c6fc2b..982f0ad49 100644
--- a/dom/fetch/FetchObserver.cpp
+++ b/dom/fetch/FetchObserver.cpp
@@ -6,6 +6,7 @@
#include "FetchObserver.h"
#include "WorkerPrivate.h"
+#include "mozilla/dom/Event.h"
namespace mozilla {
namespace dom {
@@ -45,10 +46,14 @@ FetchObserver::IsEnabled(JSContext* aCx, JSObject* aGlobal)
}
FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
- FetchState aState)
+ FetchSignal* aSignal)
: DOMEventTargetHelper(aGlobal)
- , mState(aState)
-{}
+ , mState(FetchState::Requesting)
+{
+ if (aSignal) {
+ Follow(aSignal);
+ }
+}
JSObject*
FetchObserver::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
@@ -62,5 +67,51 @@ FetchObserver::State() const
return mState;
}
+void
+FetchObserver::Aborted()
+{
+ SetState(FetchState::Aborted);
+}
+
+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, NS_LITERAL_STRING("statechange"), init);
+ event->SetTrusted(true);
+
+ bool dummy;
+ DispatchEvent(event, &dummy);
+}
+
} // dom namespace
} // mozilla namespace