summaryrefslogtreecommitdiffstats
path: root/dom/fetch
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-11 12:43:17 +0000
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-06-13 11:52:17 +0200
commit29bca891d5ca243774a7355fc3a6a68903f0d596 (patch)
treeec5a36a57a179b811642c0ee5636ffd3005adc67 /dom/fetch
parentbb7060582934f087b71702d1e83f762d5fd6f0af (diff)
downloadUXP-29bca891d5ca243774a7355fc3a6a68903f0d596.tar
UXP-29bca891d5ca243774a7355fc3a6a68903f0d596.tar.gz
UXP-29bca891d5ca243774a7355fc3a6a68903f0d596.tar.lz
UXP-29bca891d5ca243774a7355fc3a6a68903f0d596.tar.xz
UXP-29bca891d5ca243774a7355fc3a6a68903f0d596.zip
Issue #1587 - Part 6: Move FetchController/Signal to its own dir
Since it is specced separately from fetch.
Diffstat (limited to 'dom/fetch')
-rw-r--r--dom/fetch/FetchController.cpp127
-rw-r--r--dom/fetch/FetchController.h73
-rw-r--r--dom/fetch/FetchSignal.cpp151
-rw-r--r--dom/fetch/FetchSignal.h79
-rw-r--r--dom/fetch/moz.build4
5 files changed, 0 insertions, 434 deletions
diff --git a/dom/fetch/FetchController.cpp b/dom/fetch/FetchController.cpp
deleted file mode 100644
index 2eb40b980..000000000
--- a/dom/fetch/FetchController.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* -*- 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 "FetchController.h"
-#include "FetchSignal.h"
-#include "mozilla/dom/FetchControllerBinding.h"
-#include "WorkerPrivate.h"
-
-namespace mozilla {
-namespace dom {
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FetchController, mGlobal, mSignal,
- mFollowingSignal)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(FetchController)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(FetchController)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchController)
- NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
- NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-/* static */ bool
-FetchController::IsEnabled(JSContext* aCx, JSObject* aGlobal)
-{
- if (NS_IsMainThread()) {
- return Preferences::GetBool("dom.fetchController.enabled", false);
- }
-
- using namespace workers;
-
- // Otherwise, check the pref via the WorkerPrivate
- WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
- if (!workerPrivate) {
- return false;
- }
-
- return workerPrivate->FetchControllerEnabled();
-}
-
-/* static */ already_AddRefed<FetchController>
-FetchController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
-{
- nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
- if (!global) {
- aRv.Throw(NS_ERROR_FAILURE);
- return nullptr;
- }
-
- RefPtr<FetchController> fetchController = new FetchController(global);
- return fetchController.forget();
-}
-
-FetchController::FetchController(nsIGlobalObject* aGlobal)
- : mGlobal(aGlobal)
- , mAborted(false)
-{}
-
-JSObject*
-FetchController::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return FetchControllerBinding::Wrap(aCx, this, aGivenProto);
-}
-
-nsIGlobalObject*
-FetchController::GetParentObject() const
-{
- return mGlobal;
-}
-
-FetchSignal*
-FetchController::Signal()
-{
- if (!mSignal) {
- mSignal = new FetchSignal(this, mAborted);
- }
-
- return mSignal;
-}
-
-void
-FetchController::Abort()
-{
- if (mAborted) {
- return;
- }
-
- mAborted = true;
-
- if (mSignal) {
- mSignal->Abort();
- }
-}
-
-void
-FetchController::Follow(FetchSignal& aSignal)
-{
- FetchSignal::Follower::Follow(&aSignal);
-}
-
-void
-FetchController::Unfollow(FetchSignal& aSignal)
-{
- if (mFollowingSignal != &aSignal) {
- return;
- }
-
- FetchSignal::Follower::Unfollow();
-}
-
-FetchSignal*
-FetchController::Following() const
-{
- return mFollowingSignal;
-}
-
-void
-FetchController::Aborted()
-{
- Abort();
-}
-
-} // dom namespace
-} // mozilla namespace
diff --git a/dom/fetch/FetchController.h b/dom/fetch/FetchController.h
deleted file mode 100644
index 7a0132dca..000000000
--- a/dom/fetch/FetchController.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- 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/. */
-
-#ifndef mozilla_dom_FetchController_h
-#define mozilla_dom_FetchController_h
-
-#include "mozilla/dom/BindingDeclarations.h"
-#include "mozilla/dom/FetchSignal.h"
-#include "nsCycleCollectionParticipant.h"
-#include "nsWrapperCache.h"
-#include "mozilla/ErrorResult.h"
-#include "nsIGlobalObject.h"
-
-namespace mozilla {
-namespace dom {
-
-class FetchController final : public nsISupports
- , public nsWrapperCache
- , public FetchSignal::Follower
-{
-public:
- NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FetchController)
-
- static bool
- IsEnabled(JSContext* aCx, JSObject* aGlobal);
-
- static already_AddRefed<FetchController>
- Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
-
- explicit FetchController(nsIGlobalObject* aGlobal);
-
- JSObject*
- WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
- nsIGlobalObject*
- GetParentObject() const;
-
- FetchSignal*
- Signal();
-
- void
- Abort();
-
- void
- Follow(FetchSignal& aSignal);
-
- void
- Unfollow(FetchSignal& aSignal);
-
- FetchSignal*
- Following() const;
-
- // FetchSignal::Follower
-
- void Aborted() override;
-
-private:
- ~FetchController() = default;
-
- nsCOMPtr<nsIGlobalObject> mGlobal;
- RefPtr<FetchSignal> mSignal;
-
- bool mAborted;
-};
-
-} // dom namespace
-} // mozilla namespace
-
-#endif // mozilla_dom_FetchController_h
diff --git a/dom/fetch/FetchSignal.cpp b/dom/fetch/FetchSignal.cpp
deleted file mode 100644
index 07ad6b53d..000000000
--- a/dom/fetch/FetchSignal.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/* -*- 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 "FetchSignal.h"
-#include "FetchController.h"
-#include "mozilla/dom/Event.h"
-#include "mozilla/dom/FetchSignalBinding.h"
-
-namespace mozilla {
-namespace dom {
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(FetchSignal)
-
-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(FetchSignal,
- DOMEventTargetHelper)
- NS_IMPL_CYCLE_COLLECTION_UNLINK(mController)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FetchSignal)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(FetchSignal, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(FetchSignal, DOMEventTargetHelper)
-
-FetchSignal::FetchSignal(FetchController* aController,
- bool aAborted)
- : DOMEventTargetHelper(aController->GetParentObject())
- , mController(aController)
- , mAborted(aAborted)
-{}
-
-FetchSignal::FetchSignal(bool aAborted)
- : mAborted(aAborted)
-{}
-
-JSObject*
-FetchSignal::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
- return FetchSignalBinding::Wrap(aCx, this, aGivenProto);
-}
-
-bool
-FetchSignal::Aborted() const
-{
- return mAborted;
-}
-
-void
-FetchSignal::Abort()
-{
- MOZ_ASSERT(!mAborted);
- mAborted = true;
-
- // Let's inform the followers.
- for (uint32_t i = 0; i < mFollowers.Length(); ++i) {
- mFollowers[i]->Aborted();
- }
-
- 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("abort"), init);
- event->SetTrusted(true);
-
- bool dummy;
- DispatchEvent(event, &dummy);
-}
-
-void
-FetchSignal::AddFollower(FetchSignal::Follower* aFollower)
-{
- MOZ_DIAGNOSTIC_ASSERT(aFollower);
- if (!mFollowers.Contains(aFollower)) {
- mFollowers.AppendElement(aFollower);
- }
-}
-
-void
-FetchSignal::RemoveFollower(FetchSignal::Follower* aFollower)
-{
- MOZ_DIAGNOSTIC_ASSERT(aFollower);
- mFollowers.RemoveElement(aFollower);
-}
-
-bool
-FetchSignal::CanAcceptFollower(FetchSignal::Follower* aFollower) const
-{
- MOZ_DIAGNOSTIC_ASSERT(aFollower);
-
- if (!mController) {
- return true;
- }
-
- if (aFollower == mController) {
- return false;
- }
-
- FetchSignal* following = mController->Following();
- if (!following) {
- return true;
- }
-
- return following->CanAcceptFollower(aFollower);
-}
-
-// FetchSignal::Follower
-// ----------------------------------------------------------------------------
-
-FetchSignal::Follower::~Follower()
-{
- Unfollow();
-}
-
-void
-FetchSignal::Follower::Follow(FetchSignal* aSignal)
-{
- MOZ_DIAGNOSTIC_ASSERT(aSignal);
-
- if (!aSignal->CanAcceptFollower(this)) {
- return;
- }
-
- Unfollow();
-
- mFollowingSignal = aSignal;
- aSignal->AddFollower(this);
-}
-
-void
-FetchSignal::Follower::Unfollow()
-{
- if (mFollowingSignal) {
- mFollowingSignal->RemoveFollower(this);
- mFollowingSignal = nullptr;
- }
-}
-
-} // dom namespace
-} // mozilla namespace
diff --git a/dom/fetch/FetchSignal.h b/dom/fetch/FetchSignal.h
deleted file mode 100644
index 4970f03de..000000000
--- a/dom/fetch/FetchSignal.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- 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/. */
-
-#ifndef mozilla_dom_FetchSignal_h
-#define mozilla_dom_FetchSignal_h
-
-#include "mozilla/DOMEventTargetHelper.h"
-
-namespace mozilla {
-namespace dom {
-
-class FetchController;
-class FetchSignal;
-
-class FetchSignal final : public DOMEventTargetHelper
-{
-public:
- // This class must be implemented by objects who want to follow a FetchSignal.
- class Follower
- {
- public:
- virtual void Aborted() = 0;
-
- protected:
- virtual ~Follower();
-
- void
- Follow(FetchSignal* aSignal);
-
- void
- Unfollow();
-
- RefPtr<FetchSignal> mFollowingSignal;
- };
-
- NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchSignal, DOMEventTargetHelper)
-
- FetchSignal(FetchController* aController, bool aAborted);
- explicit FetchSignal(bool aAborted);
-
- JSObject*
- WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
- bool
- Aborted() const;
-
- void
- Abort();
-
- IMPL_EVENT_HANDLER(abort);
-
- void
- AddFollower(Follower* aFollower);
-
- void
- RemoveFollower(Follower* aFollower);
-
- bool
- CanAcceptFollower(Follower* aFollower) const;
-
-private:
- ~FetchSignal() = default;
-
- RefPtr<FetchController> mController;
-
- // Raw pointers. Follower unregisters itself in the DTOR.
- nsTArray<Follower*> mFollowers;
-
- bool mAborted;
-};
-
-} // dom namespace
-} // mozilla namespace
-
-#endif // mozilla_dom_FetchSignal_h
diff --git a/dom/fetch/moz.build b/dom/fetch/moz.build
index 82fd99173..e2b466428 100644
--- a/dom/fetch/moz.build
+++ b/dom/fetch/moz.build
@@ -7,11 +7,9 @@
EXPORTS.mozilla.dom += [
'ChannelInfo.h',
'Fetch.h',
- 'FetchController.h',
'FetchDriver.h',
'FetchIPCTypes.h',
'FetchObserver.h',
- 'FetchSignal.h',
'FetchUtil.h',
'Headers.h',
'InternalHeaders.h',
@@ -30,10 +28,8 @@ UNIFIED_SOURCES += [
SOURCES += [
'ChannelInfo.cpp',
- 'FetchController.cpp',
'FetchDriver.cpp',
'FetchObserver.cpp',
- 'FetchSignal.cpp',
'FetchUtil.cpp',
'Headers.cpp',
'InternalHeaders.cpp',