mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-02 13:58:40 +09:00
Issue #1587 - Part 5: Hook FetchObserver up to the Fetch API
This commit is contained in:
parent
6722d7f4b4
commit
3d2ca85edd
11 changed files with 399 additions and 75 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue