Bug 1378342 - AbortSignal/AbortController - part 2 - Renaming FetchController/FetchSignal, r=bkelly

--HG--
rename : dom/abort/FetchController.cpp => dom/abort/AbortController.cpp
rename : dom/abort/FetchController.h => dom/abort/AbortController.h
rename : dom/abort/FetchSignal.cpp => dom/abort/AbortSignal.cpp
rename : dom/abort/FetchSignal.h => dom/abort/AbortSignal.h
rename : dom/abort/tests/file_fetch_controller.html => dom/abort/tests/file_abort_controller.html
rename : dom/abort/tests/test_fetch_controller.html => dom/abort/tests/test_abort_controller.html
rename : dom/abort/tests/worker_fetch_controller.js => dom/abort/tests/worker_abort_controller.js
rename : dom/webidl/FetchController.webidl => dom/webidl/AbortController.webidl
rename : dom/webidl/FetchSignal.webidl => dom/webidl/AbortSignal.webidl
This commit is contained in:
Andrea Marchesini 2017-08-29 07:30:19 +02:00
parent ac5b9df285
commit 9b66f91da8
22 changed files with 206 additions and 201 deletions

View File

@ -4,30 +4,30 @@
* 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 "FetchController.h"
#include "FetchSignal.h"
#include "mozilla/dom/FetchControllerBinding.h"
#include "AbortController.h"
#include "AbortSignal.h"
#include "mozilla/dom/AbortControllerBinding.h"
#include "WorkerPrivate.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FetchController, mGlobal, mSignal,
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AbortController, mGlobal, mSignal,
mFollowingSignal)
NS_IMPL_CYCLE_COLLECTING_ADDREF(FetchController)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FetchController)
NS_IMPL_CYCLE_COLLECTING_ADDREF(AbortController)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AbortController)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchController)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AbortController)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
/* static */ bool
FetchController::IsEnabled(JSContext* aCx, JSObject* aGlobal)
AbortController::IsEnabled(JSContext* aCx, JSObject* aGlobal)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.fetchController.enabled", false);
return Preferences::GetBool("dom.abortController.enabled", false);
}
using namespace workers;
@ -38,11 +38,11 @@ FetchController::IsEnabled(JSContext* aCx, JSObject* aGlobal)
return false;
}
return workerPrivate->FetchControllerEnabled();
return workerPrivate->AbortControllerEnabled();
}
/* static */ already_AddRefed<FetchController>
FetchController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
/* static */ already_AddRefed<AbortController>
AbortController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
if (!global) {
@ -50,39 +50,39 @@ FetchController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
return nullptr;
}
RefPtr<FetchController> fetchController = new FetchController(global);
return fetchController.forget();
RefPtr<AbortController> abortController = new AbortController(global);
return abortController.forget();
}
FetchController::FetchController(nsIGlobalObject* aGlobal)
AbortController::AbortController(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal)
, mAborted(false)
{}
JSObject*
FetchController::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
AbortController::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return FetchControllerBinding::Wrap(aCx, this, aGivenProto);
return AbortControllerBinding::Wrap(aCx, this, aGivenProto);
}
nsIGlobalObject*
FetchController::GetParentObject() const
AbortController::GetParentObject() const
{
return mGlobal;
}
FetchSignal*
FetchController::Signal()
AbortSignal*
AbortController::Signal()
{
if (!mSignal) {
mSignal = new FetchSignal(this, mAborted);
mSignal = new AbortSignal(this, mAborted);
}
return mSignal;
}
void
FetchController::Abort()
AbortController::Abort()
{
if (mAborted) {
return;
@ -96,29 +96,29 @@ FetchController::Abort()
}
void
FetchController::Follow(FetchSignal& aSignal)
AbortController::Follow(AbortSignal& aSignal)
{
FetchSignal::Follower::Follow(&aSignal);
AbortSignal::Follower::Follow(&aSignal);
}
void
FetchController::Unfollow(FetchSignal& aSignal)
AbortController::Unfollow(AbortSignal& aSignal)
{
if (mFollowingSignal != &aSignal) {
return;
}
FetchSignal::Follower::Unfollow();
AbortSignal::Follower::Unfollow();
}
FetchSignal*
FetchController::Following() const
AbortSignal*
AbortController::Following() const
{
return mFollowingSignal;
}
void
FetchController::Aborted()
AbortController::Aborted()
{
Abort();
}

View File

@ -4,32 +4,32 @@
* 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/. */
#ifndef mozilla_dom_FetchController_h
#define mozilla_dom_FetchController_h
#ifndef mozilla_dom_AbortController_h
#define mozilla_dom_AbortController_h
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/FetchSignal.h"
#include "mozilla/dom/AbortSignal.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
class FetchController final : public nsISupports
class AbortController final : public nsISupports
, public nsWrapperCache
, public FetchSignal::Follower
, public AbortSignal::Follower
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FetchController)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AbortController)
static bool
IsEnabled(JSContext* aCx, JSObject* aGlobal);
static already_AddRefed<FetchController>
static already_AddRefed<AbortController>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
explicit FetchController(nsIGlobalObject* aGlobal);
explicit AbortController(nsIGlobalObject* aGlobal);
JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -37,30 +37,30 @@ public:
nsIGlobalObject*
GetParentObject() const;
FetchSignal*
AbortSignal*
Signal();
void
Abort();
void
Follow(FetchSignal& aSignal);
Follow(AbortSignal& aSignal);
void
Unfollow(FetchSignal& aSignal);
Unfollow(AbortSignal& aSignal);
FetchSignal*
AbortSignal*
Following() const;
// FetchSignal::Follower
// AbortSignal::Follower
void Aborted() override;
private:
~FetchController() = default;
~AbortController() = default;
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<FetchSignal> mSignal;
RefPtr<AbortSignal> mSignal;
bool mAborted;
};
@ -68,4 +68,4 @@ private:
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_FetchController_h
#endif // mozilla_dom_AbortController_h

View File

@ -4,56 +4,56 @@
* 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 "FetchSignal.h"
#include "AbortSignal.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/FetchSignalBinding.h"
#include "mozilla/dom/AbortSignalBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(FetchSignal)
NS_IMPL_CYCLE_COLLECTION_CLASS(AbortSignal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FetchSignal,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AbortSignal,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mController)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FetchSignal,
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AbortSignal,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mController)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FetchSignal)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AbortSignal)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(FetchSignal, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(FetchSignal, DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(AbortSignal, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(AbortSignal, DOMEventTargetHelper)
FetchSignal::FetchSignal(FetchController* aController,
AbortSignal::AbortSignal(AbortController* aController,
bool aAborted)
: DOMEventTargetHelper(aController->GetParentObject())
, mController(aController)
, mAborted(aAborted)
{}
FetchSignal::FetchSignal(bool aAborted)
AbortSignal::AbortSignal(bool aAborted)
: mAborted(aAborted)
{}
JSObject*
FetchSignal::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
AbortSignal::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return FetchSignalBinding::Wrap(aCx, this, aGivenProto);
return AbortSignalBinding::Wrap(aCx, this, aGivenProto);
}
bool
FetchSignal::Aborted() const
AbortSignal::Aborted() const
{
return mAborted;
}
void
FetchSignal::Abort()
AbortSignal::Abort()
{
MOZ_ASSERT(!mAborted);
mAborted = true;
@ -78,7 +78,7 @@ FetchSignal::Abort()
}
void
FetchSignal::AddFollower(FetchSignal::Follower* aFollower)
AbortSignal::AddFollower(AbortSignal::Follower* aFollower)
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
if (!mFollowers.Contains(aFollower)) {
@ -87,14 +87,14 @@ FetchSignal::AddFollower(FetchSignal::Follower* aFollower)
}
void
FetchSignal::RemoveFollower(FetchSignal::Follower* aFollower)
AbortSignal::RemoveFollower(AbortSignal::Follower* aFollower)
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
mFollowers.RemoveElement(aFollower);
}
bool
FetchSignal::CanAcceptFollower(FetchSignal::Follower* aFollower) const
AbortSignal::CanAcceptFollower(AbortSignal::Follower* aFollower) const
{
MOZ_DIAGNOSTIC_ASSERT(aFollower);
@ -106,7 +106,7 @@ FetchSignal::CanAcceptFollower(FetchSignal::Follower* aFollower) const
return false;
}
FetchSignal* following = mController->Following();
AbortSignal* following = mController->Following();
if (!following) {
return true;
}
@ -114,16 +114,16 @@ FetchSignal::CanAcceptFollower(FetchSignal::Follower* aFollower) const
return following->CanAcceptFollower(aFollower);
}
// FetchSignal::Follower
// AbortSignal::Follower
// ----------------------------------------------------------------------------
FetchSignal::Follower::~Follower()
AbortSignal::Follower::~Follower()
{
Unfollow();
}
void
FetchSignal::Follower::Follow(FetchSignal* aSignal)
AbortSignal::Follower::Follow(AbortSignal* aSignal)
{
MOZ_DIAGNOSTIC_ASSERT(aSignal);
@ -138,7 +138,7 @@ FetchSignal::Follower::Follow(FetchSignal* aSignal)
}
void
FetchSignal::Follower::Unfollow()
AbortSignal::Follower::Unfollow()
{
if (mFollowingSignal) {
mFollowingSignal->RemoveFollower(this);

View File

@ -4,21 +4,21 @@
* 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/. */
#ifndef mozilla_dom_FetchSignal_h
#define mozilla_dom_FetchSignal_h
#ifndef mozilla_dom_AbortSignal_h
#define mozilla_dom_AbortSignal_h
#include "mozilla/DOMEventTargetHelper.h"
namespace mozilla {
namespace dom {
class FetchController;
class FetchSignal;
class AbortController;
class AbortSignal;
class FetchSignal final : public DOMEventTargetHelper
class AbortSignal final : public DOMEventTargetHelper
{
public:
// This class must be implemented by objects who want to follow a FetchSignal.
// This class must be implemented by objects who want to follow a AbortSignal.
class Follower
{
public:
@ -28,19 +28,19 @@ public:
virtual ~Follower();
void
Follow(FetchSignal* aSignal);
Follow(AbortSignal* aSignal);
void
Unfollow();
RefPtr<FetchSignal> mFollowingSignal;
RefPtr<AbortSignal> mFollowingSignal;
};
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchSignal, DOMEventTargetHelper)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortSignal, DOMEventTargetHelper)
FetchSignal(FetchController* aController, bool aAborted);
explicit FetchSignal(bool aAborted);
AbortSignal(AbortController* aController, bool aAborted);
explicit AbortSignal(bool aAborted);
JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
@ -63,9 +63,9 @@ public:
CanAcceptFollower(Follower* aFollower) const;
private:
~FetchSignal() = default;
~AbortSignal() = default;
RefPtr<FetchController> mController;
RefPtr<AbortController> mController;
// Raw pointers. Follower unregisters itself in the DTOR.
nsTArray<Follower*> mFollowers;
@ -76,4 +76,4 @@ private:
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_FetchSignal_h
#endif // mozilla_dom_AbortSignal_h

View File

@ -10,13 +10,13 @@ with Files("**"):
TEST_DIRS += ['tests']
EXPORTS.mozilla.dom += [
'FetchController.h',
'FetchSignal.h',
'AbortController.h',
'AbortSignal.h',
]
UNIFIED_SOURCES += [
'FetchController.cpp',
'FetchSignal.cpp',
'AbortController.cpp',
'AbortSignal.cpp',
]
LOCAL_INCLUDES += [

View File

@ -8,87 +8,87 @@ function is(a, b, msg) {
}
function testWebIDL() {
ok("FetchController" in self, "We have a FetchController prototype");
ok("FetchSignal" in self, "We have a FetchSignal prototype");
ok("AbortController" in self, "We have a AbortController prototype");
ok("AbortSignal" in self, "We have a AbortSignal prototype");
var fc = new FetchController();
ok(!!fc, "FetchController can be created");
ok(fc instanceof FetchController, "FetchController is a FetchController");
var ac = new AbortController();
ok(!!ac, "AbortController can be created");
ok(ac instanceof AbortController, "AbortController is a AbortController");
ok(!!fc.signal, "FetchController has a signal");
ok(fc.signal instanceof FetchSignal, "fetchSignal is a FetchSignal");
is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
ok(!!ac.signal, "AbortController has a signal");
ok(ac.signal instanceof AbortSignal, "abortSignal is a AbortSignal");
is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
next();
}
function testUpdateData() {
var fc = new FetchController();
var ac = new AbortController();
is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
ac.abort();
is(ac.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOurself() {
// Let's follow ourself
var fc = new FetchController();
fc.follow(fc.signal);
var ac = new AbortController();
ac.follow(ac.signal);
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
ac.abort();
is(ac.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOther() {
// Let's follow another one
var fc1 = new FetchController();
var fc2 = new FetchController();
fc1.follow(fc2.signal);
var ac1 = new AbortController();
var ac2 = new AbortController();
ac1.follow(ac2.signal);
fc2.abort();
ac2.abort();
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingLoop() {
// fc1 -> fc2 -> fc3 -> fc1
var fc1 = new FetchController();
var fc2 = new FetchController();
var fc3 = new FetchController();
fc1.follow(fc2.signal);
fc2.follow(fc3.signal);
fc3.follow(fc1.signal);
// ac1 -> ac2 -> ac3 -> ac1
var ac1 = new AbortController();
var ac2 = new AbortController();
var ac3 = new AbortController();
ac1.follow(ac2.signal);
ac2.follow(ac3.signal);
ac3.follow(ac1.signal);
fc3.abort();
ac3.abort();
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
is(fc3.signal.aborted, true, "Signal is aborted");
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
is(ac3.signal.aborted, true, "Signal is aborted");
next();
}
function testAbortEvent() {
var fc = new FetchController();
fc.signal.onabort = function(e) {
var ac = new AbortController();
ac.signal.onabort = function(e) {
is(e.type, "abort", "Abort received");
next();
}
fc.abort();
ac.abort();
}
function testAbortedFetch() {
var fc = new FetchController();
fc.abort();
var ac = new AbortController();
ac.abort();
fetch('slow.sjs', { signal: fc.signal }).then(() => {
fetch('slow.sjs', { signal: ac.signal }).then(() => {
ok(false, "Fetch should not return a resolved promise");
}, e => {
is(e.name, "AbortError", "We have an abort error");
@ -96,10 +96,10 @@ function testAbortedFetch() {
}
function testFetchAndAbort() {
var fc = new FetchController();
var ac = new AbortController();
var p = fetch('slow.sjs', { signal: fc.signal });
fc.abort();
var p = fetch('slow.sjs', { signal: ac.signal });
ac.abort();
p.then(() => {
ok(false, "Fetch should not return a resolved promise");
@ -109,7 +109,7 @@ function testFetchAndAbort() {
}
function testWorkerAbortedFetch() {
var w = new Worker('worker_fetch_controller.js');
var w = new Worker('worker_abort_controller.js');
w.onmessage = function(e) {
ok(e.data, "Abort + Fetch works in workers");
next();
@ -118,7 +118,7 @@ function testWorkerAbortedFetch() {
}
function testWorkerFetchAndAbort() {
var w = new Worker('worker_fetch_controller.js');
var w = new Worker('worker_abort_controller.js');
w.onmessage = function(e) {
ok(e.data, "Abort + Fetch works in workers");
next();

View File

@ -1,6 +1,6 @@
[DEFAULT]
support-files =
file_fetch_controller.html
worker_fetch_controller.js
file_abort_controller.html
worker_abort_controller.js
[test_fetch_controller.html]
[test_abort_controller.html]

View File

@ -5,16 +5,16 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test FetchController</title>
<title>Test AbortController</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
SpecialPowers.pushPrefEnv({"set": [["dom.fetchController.enabled", true ]]}, () => {
SpecialPowers.pushPrefEnv({"set": [["dom.abortController.enabled", true ]]}, () => {
let ifr = document.createElement('iframe');
ifr.src = "file_fetch_controller.html";
ifr.src = "file_abort_controller.html";
document.body.appendChild(ifr);
onmessage = function(e) {

View File

@ -1,8 +1,8 @@
function testWorkerAbortedFetch() {
var fc = new FetchController();
fc.abort();
var ac = new AbortController();
ac.abort();
fetch('slow.sjs', { signal: fc.signal }).then(() => {
fetch('slow.sjs', { signal: ac.signal }).then(() => {
postMessage(false);
}, e => {
postMessage(e.name == "AbortError");
@ -10,10 +10,10 @@ function testWorkerAbortedFetch() {
}
function testWorkerFetchAndAbort() {
var fc = new FetchController();
var ac = new AbortController();
var p = fetch('slow.sjs', { signal: fc.signal });
fc.abort();
var p = fetch('slow.sjs', { signal: ac.signal });
ac.abort();
p.then(() => {
postMessage(false);

View File

@ -56,28 +56,28 @@ namespace dom {
using namespace workers;
// This class helps the proxying of FetchSignal changes cross threads.
class FetchSignalProxy final : public FetchSignal::Follower
// This class helps the proxying of AbortSignal changes cross threads.
class AbortSignalProxy final : public AbortSignal::Follower
{
// This is created and released on the main-thread.
RefPtr<FetchSignal> mSignalMainThread;
RefPtr<AbortSignal> mSignalMainThread;
// The main-thread event target for runnable dispatching.
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
// This value is used only for the creation of FetchSignal on the
// This value is used only for the creation of AbortSignal on the
// main-thread. They are not updated.
const bool mAborted;
// This runnable propagates changes from the FetchSignal on workers to the
// FetchSignal on main-thread.
class FetchSignalProxyRunnable final : public Runnable
// This runnable propagates changes from the AbortSignal on workers to the
// AbortSignal on main-thread.
class AbortSignalProxyRunnable final : public Runnable
{
RefPtr<FetchSignalProxy> mProxy;
RefPtr<AbortSignalProxy> mProxy;
public:
explicit FetchSignalProxyRunnable(FetchSignalProxy* aProxy)
: Runnable("dom::FetchSignalProxy::FetchSignalProxyRunnable")
explicit AbortSignalProxyRunnable(AbortSignalProxy* aProxy)
: Runnable("dom::AbortSignalProxy::AbortSignalProxyRunnable")
, mProxy(aProxy)
{}
@ -85,16 +85,16 @@ class FetchSignalProxy final : public FetchSignal::Follower
Run() override
{
MOZ_ASSERT(NS_IsMainThread());
FetchSignal* signal = mProxy->GetOrCreateSignalForMainThread();
AbortSignal* signal = mProxy->GetOrCreateSignalForMainThread();
signal->Abort();
return NS_OK;
}
};
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchSignalProxy)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbortSignalProxy)
FetchSignalProxy(FetchSignal* aSignal, nsIEventTarget* aMainThreadEventTarget)
AbortSignalProxy(AbortSignal* aSignal, nsIEventTarget* aMainThreadEventTarget)
: mMainThreadEventTarget(aMainThreadEventTarget)
, mAborted(aSignal->Aborted())
{
@ -105,17 +105,17 @@ public:
void
Aborted() override
{
RefPtr<FetchSignalProxyRunnable> runnable =
new FetchSignalProxyRunnable(this);
RefPtr<AbortSignalProxyRunnable> runnable =
new AbortSignalProxyRunnable(this);
mMainThreadEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
}
FetchSignal*
AbortSignal*
GetOrCreateSignalForMainThread()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mSignalMainThread) {
mSignalMainThread = new FetchSignal(mAborted);
mSignalMainThread = new AbortSignal(mAborted);
}
return mSignalMainThread;
}
@ -127,10 +127,10 @@ public:
}
private:
~FetchSignalProxy()
~AbortSignalProxy()
{
NS_ProxyRelease(
"FetchSignalProxy::mSignalMainThread",
"AbortSignalProxy::mSignalMainThread",
mMainThreadEventTarget, mSignalMainThread.forget());
}
};
@ -144,14 +144,14 @@ class WorkerFetchResolver final : public FetchDriverObserver
friend class WorkerFetchResponseRunnable;
RefPtr<PromiseWorkerProxy> mPromiseProxy;
RefPtr<FetchSignalProxy> mSignalProxy;
RefPtr<AbortSignalProxy> mSignalProxy;
RefPtr<FetchObserver> mFetchObserver;
public:
// Returns null if worker is shutting down.
static already_AddRefed<WorkerFetchResolver>
Create(workers::WorkerPrivate* aWorkerPrivate, Promise* aPromise,
FetchSignal* aSignal, FetchObserver* aObserver)
AbortSignal* aSignal, FetchObserver* aObserver)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
@ -161,10 +161,10 @@ public:
return nullptr;
}
RefPtr<FetchSignalProxy> signalProxy;
RefPtr<AbortSignalProxy> signalProxy;
if (aSignal) {
signalProxy =
new FetchSignalProxy(aSignal, aWorkerPrivate->MainThreadEventTarget());
new AbortSignalProxy(aSignal, aWorkerPrivate->MainThreadEventTarget());
}
RefPtr<WorkerFetchResolver> r =
@ -172,8 +172,8 @@ public:
return r.forget();
}
FetchSignal*
GetFetchSignal()
AbortSignal*
GetAbortSignal()
{
MOZ_ASSERT(NS_IsMainThread());
@ -195,7 +195,7 @@ public:
private:
WorkerFetchResolver(PromiseWorkerProxy* aProxy,
FetchSignalProxy* aSignalProxy,
AbortSignalProxy* aSignalProxy,
FetchObserver* aObserver)
: mPromiseProxy(aProxy)
, mSignalProxy(aSignalProxy)
@ -306,7 +306,7 @@ public:
fetch->SetWorkerScript(spec);
}
RefPtr<FetchSignal> signal = mResolver->GetFetchSignal();
RefPtr<AbortSignal> signal = mResolver->GetAbortSignal();
// ...but release it before calling Fetch, because mResolver's callback can
// be called synchronously and they want the mutex, too.
@ -348,7 +348,7 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
RefPtr<InternalRequest> r = request->GetInternalRequest();
RefPtr<FetchSignal> signal;
RefPtr<AbortSignal> signal;
if (aInit.mSignal.WasPassed()) {
signal = &aInit.mSignal.Value();
// Let's FetchDriver to deal with an already aborted signal.

View File

@ -73,7 +73,7 @@ FetchDriver::~FetchDriver()
}
nsresult
FetchDriver::Fetch(FetchSignal* aSignal, FetchDriverObserver* aObserver)
FetchDriver::Fetch(AbortSignal* aSignal, FetchDriverObserver* aObserver)
{
workers::AssertIsOnMainThread();
#ifdef DEBUG

View File

@ -12,7 +12,7 @@
#include "nsIStreamListener.h"
#include "nsIThreadRetargetableStreamListener.h"
#include "mozilla/ConsoleReportCollector.h"
#include "mozilla/dom/FetchSignal.h"
#include "mozilla/dom/AbortSignal.h"
#include "mozilla/dom/SRIMetadata.h"
#include "mozilla/RefPtr.h"
@ -85,7 +85,7 @@ class FetchDriver final : public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor,
public nsIThreadRetargetableStreamListener,
public FetchSignal::Follower
public AbortSignal::Follower
{
public:
NS_DECL_ISUPPORTS
@ -101,7 +101,7 @@ public:
nsIEventTarget* aMainThreadEventTarget,
bool aIsTrackingFetch);
nsresult Fetch(FetchSignal* aSignal,
nsresult Fetch(AbortSignal* aSignal,
FetchDriverObserver* aObserver);
void
@ -114,7 +114,7 @@ public:
mWorkerScript = aWorkerScirpt;
}
// FetchSignal::Follower
// AbortSignal::Follower
void
Aborted() override;

View File

@ -45,7 +45,7 @@ FetchObserver::IsEnabled(JSContext* aCx, JSObject* aGlobal)
}
FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
FetchSignal* aSignal)
AbortSignal* aSignal)
: DOMEventTargetHelper(aGlobal)
, mState(FetchState::Requesting)
{

View File

@ -9,13 +9,13 @@
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/FetchObserverBinding.h"
#include "mozilla/dom/FetchSignal.h"
#include "mozilla/dom/AbortSignal.h"
namespace mozilla {
namespace dom {
class FetchObserver final : public DOMEventTargetHelper
, public FetchSignal::Follower
, public AbortSignal::Follower
{
public:
NS_DECL_ISUPPORTS_INHERITED
@ -24,7 +24,7 @@ public:
static bool
IsEnabled(JSContext* aCx, JSObject* aGlobal);
FetchObserver(nsIGlobalObject* aGlobal, FetchSignal* aSignal);
FetchObserver(nsIGlobalObject* aGlobal, AbortSignal* aSignal);
JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

View File

@ -12,7 +12,6 @@
#include "nsWrapperCache.h"
#include "mozilla/dom/Fetch.h"
#include "mozilla/dom/FetchSignal.h"
#include "mozilla/dom/InternalRequest.h"
// Required here due to certain WebIDL enums/classes being declared in both
// files.

View File

@ -19,10 +19,10 @@ function testObserver() {
}
function testObserveAbort() {
var fc = new FetchController();
var ac = new AbortController();
fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
signal: fc.signal,
signal: ac.signal,
observe: o => {
o.onstatechange = () => {
ok(true, "StateChange event dispatched");
@ -31,16 +31,16 @@ function testObserveAbort() {
next();
}
}
fc.abort();
ac.abort();
}
});
}
function testObserveComplete() {
var fc = new FetchController();
var ac = new AbortController();
fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
signal: fc.signal,
signal: ac.signal,
observe: o => {
o.onstatechange = () => {
ok(true, "StateChange event dispatched");
@ -54,10 +54,10 @@ function testObserveComplete() {
}
function testObserveErrored() {
var fc = new FetchController();
var ac = new AbortController();
fetch('foo: bar', {
signal: fc.signal,
signal: ac.signal,
observe: o => {
o.onstatechange = () => {
ok(true, "StateChange event dispatched");
@ -71,10 +71,10 @@ function testObserveErrored() {
}
function testObserveResponding() {
var fc = new FetchController();
var ac = new AbortController();
fetch('http://mochi.test:8888/tests/dom/tests/mochitest/fetch/slow.sjs', {
signal: fc.signal,
signal: ac.signal,
observe: o => {
o.onstatechange = () => {
if (o.state == "responding") {

View File

@ -13,7 +13,7 @@
<script class="testbody" type="text/javascript">
SpecialPowers.pushPrefEnv({"set": [["dom.fetchObserver.enabled", true ],
["dom.fetchController.enabled", true ]]}, () => {
["dom.abortController.enabled", true ]]}, () => {
let ifr = document.createElement('iframe');
ifr.src = "file_fetch_observer.html";
document.body.appendChild(ifr);

View File

@ -2,14 +2,17 @@
/* 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/.
*
* The origin of this IDL file is
* https://dom.spec.whatwg.org/#abortcontroller
*/
[Constructor(), Exposed=(Window,Worker),
Func="FetchController::IsEnabled"]
interface FetchController {
readonly attribute FetchSignal signal;
Func="AbortController::IsEnabled"]
interface AbortController {
readonly attribute AbortSignal signal;
void abort();
void follow(FetchSignal signal);
void unfollow(FetchSignal signal);
void follow(AbortSignal signal);
void unfollow(AbortSignal signal);
};

View File

@ -2,11 +2,14 @@
/* 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/.
*
* The origin of this IDL file is
* https://dom.spec.whatwg.org/#abortsignal
*/
[Exposed=(Window,Worker),
Func="FetchController::IsEnabled"]
interface FetchSignal : EventTarget {
Func="AbortController::IsEnabled"]
interface AbortSignal : EventTarget {
readonly attribute boolean aborted;
attribute EventHandler onabort;

View File

@ -48,8 +48,8 @@ dictionary RequestInit {
RequestRedirect redirect;
DOMString integrity;
[Func="FetchController::IsEnabled"]
FetchSignal signal;
[Func="AbortController::IsEnabled"]
AbortSignal signal;
[Func="FetchObserver::IsEnabled"]
ObserverCallback observe;

View File

@ -378,6 +378,8 @@ PREPROCESSED_WEBIDL_FILES = [
]
WEBIDL_FILES = [
'AbortController.webidl',
'AbortSignal.webidl',
'AbstractWorker.webidl',
'AddonManager.webidl',
'AnalyserNode.webidl',
@ -515,10 +517,8 @@ WEBIDL_FILES = [
'ExtendableMessageEvent.webidl',
'FakePluginTagInit.webidl',
'Fetch.webidl',
'FetchController.webidl',
'FetchEvent.webidl',
'FetchObserver.webidl',
'FetchSignal.webidl',
'File.webidl',
'FileList.webidl',
'FileMode.webidl',

View File

@ -42,7 +42,7 @@ WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTC
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
WORKER_SIMPLE_PREF("dom.fetchController.enabled", FetchControllerEnabled, FETCHCONTROLLER_ENABLED)
WORKER_SIMPLE_PREF("dom.abortController.enabled", AbortControllerEnabled, ABORTCONTROLLER_ENABLED)
WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED)
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)