Backed out changeset e5c6f95530f2 (bug 1378342)

--HG--
rename : dom/abort/AbortController.cpp => dom/abort/FetchController.cpp
rename : dom/abort/AbortController.h => dom/abort/FetchController.h
rename : dom/abort/AbortSignal.cpp => dom/abort/FetchSignal.cpp
rename : dom/abort/AbortSignal.h => dom/abort/FetchSignal.h
rename : dom/abort/tests/file_abort_controller.html => dom/abort/tests/file_fetch_controller.html
rename : dom/abort/tests/test_abort_controller.html => dom/abort/tests/test_fetch_controller.html
rename : dom/abort/tests/worker_abort_controller.js => dom/abort/tests/worker_fetch_controller.js
rename : dom/webidl/AbortController.webidl => dom/webidl/FetchController.webidl
rename : dom/webidl/AbortSignal.webidl => dom/webidl/FetchSignal.webidl
This commit is contained in:
Sebastian Hengst 2017-08-29 09:17:21 +02:00
Родитель d71637fab2
Коммит ffe4336403
22 изменённых файлов: 201 добавлений и 206 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -8,87 +8,87 @@ function is(a, b, msg) {
}
function testWebIDL() {
ok("AbortController" in self, "We have a AbortController prototype");
ok("AbortSignal" in self, "We have a AbortSignal prototype");
ok("FetchController" in self, "We have a FetchController prototype");
ok("FetchSignal" in self, "We have a FetchSignal prototype");
var ac = new AbortController();
ok(!!ac, "AbortController can be created");
ok(ac instanceof AbortController, "AbortController is a AbortController");
var fc = new FetchController();
ok(!!fc, "FetchController can be created");
ok(fc instanceof FetchController, "FetchController is a FetchController");
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");
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");
next();
}
function testUpdateData() {
var ac = new AbortController();
var fc = new FetchController();
is(ac.signal.aborted, false, "By default AbortSignal.aborted is false");
is(fc.signal.aborted, false, "By default FetchSignal.aborted is false");
ac.abort();
is(ac.signal.aborted, true, "Signal is aborted");
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOurself() {
// Let's follow ourself
var ac = new AbortController();
ac.follow(ac.signal);
var fc = new FetchController();
fc.follow(fc.signal);
ac.abort();
is(ac.signal.aborted, true, "Signal is aborted");
fc.abort();
is(fc.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingOther() {
// Let's follow another one
var ac1 = new AbortController();
var ac2 = new AbortController();
ac1.follow(ac2.signal);
var fc1 = new FetchController();
var fc2 = new FetchController();
fc1.follow(fc2.signal);
ac2.abort();
fc2.abort();
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
next();
}
function testFollowingLoop() {
// 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);
// 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);
ac3.abort();
fc3.abort();
is(ac1.signal.aborted, true, "Signal is aborted");
is(ac2.signal.aborted, true, "Signal is aborted");
is(ac3.signal.aborted, true, "Signal is aborted");
is(fc1.signal.aborted, true, "Signal is aborted");
is(fc2.signal.aborted, true, "Signal is aborted");
is(fc3.signal.aborted, true, "Signal is aborted");
next();
}
function testAbortEvent() {
var ac = new AbortController();
ac.signal.onabort = function(e) {
var fc = new FetchController();
fc.signal.onabort = function(e) {
is(e.type, "abort", "Abort received");
next();
}
ac.abort();
fc.abort();
}
function testAbortedFetch() {
var ac = new AbortController();
ac.abort();
var fc = new FetchController();
fc.abort();
fetch('slow.sjs', { signal: ac.signal }).then(() => {
fetch('slow.sjs', { signal: fc.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 ac = new AbortController();
var fc = new FetchController();
var p = fetch('slow.sjs', { signal: ac.signal });
ac.abort();
var p = fetch('slow.sjs', { signal: fc.signal });
fc.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_abort_controller.js');
var w = new Worker('worker_fetch_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_abort_controller.js');
var w = new Worker('worker_fetch_controller.js');
w.onmessage = function(e) {
ok(e.data, "Abort + Fetch works in workers");
next();

Просмотреть файл

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

Просмотреть файл

@ -5,16 +5,16 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AbortController</title>
<title>Test FetchController</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.abortController.enabled", true ]]}, () => {
SpecialPowers.pushPrefEnv({"set": [["dom.fetchController.enabled", true ]]}, () => {
let ifr = document.createElement('iframe');
ifr.src = "file_abort_controller.html";
ifr.src = "file_fetch_controller.html";
document.body.appendChild(ifr);
onmessage = function(e) {

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -12,7 +12,7 @@
#include "nsIStreamListener.h"
#include "nsIThreadRetargetableStreamListener.h"
#include "mozilla/ConsoleReportCollector.h"
#include "mozilla/dom/AbortSignal.h"
#include "mozilla/dom/FetchSignal.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 AbortSignal::Follower
public FetchSignal::Follower
{
public:
NS_DECL_ISUPPORTS
@ -101,7 +101,7 @@ public:
nsIEventTarget* aMainThreadEventTarget,
bool aIsTrackingFetch);
nsresult Fetch(AbortSignal* aSignal,
nsresult Fetch(FetchSignal* aSignal,
FetchDriverObserver* aObserver);
void
@ -114,7 +114,7 @@ public:
mWorkerScript = aWorkerScirpt;
}
// AbortSignal::Follower
// FetchSignal::Follower
void
Aborted() override;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -12,6 +12,7 @@
#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.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -2,17 +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/#abortcontroller
*/
[Constructor(), Exposed=(Window,Worker),
Func="AbortController::IsEnabled"]
interface AbortController {
readonly attribute AbortSignal signal;
Func="FetchController::IsEnabled"]
interface FetchController {
readonly attribute FetchSignal signal;
void abort();
void follow(AbortSignal signal);
void unfollow(AbortSignal signal);
void follow(FetchSignal signal);
void unfollow(FetchSignal signal);
};

Просмотреть файл

@ -2,14 +2,11 @@
/* 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="AbortController::IsEnabled"]
interface AbortSignal : EventTarget {
Func="FetchController::IsEnabled"]
interface FetchSignal : EventTarget {
readonly attribute boolean aborted;
attribute EventHandler onabort;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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.abortController.enabled", AbortControllerEnabled, ABORTCONTROLLER_ENABLED)
WORKER_SIMPLE_PREF("dom.fetchController.enabled", FetchControllerEnabled, FETCHCONTROLLER_ENABLED)
WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED)
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)