Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu

Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.

I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).

Differential Revision: https://phabricator.services.mozilla.com/D190450
This commit is contained in:
Emilio Cobos Álvarez 2023-10-10 08:51:12 +00:00
Родитель a9bfae6bf6
Коммит 25c0d10932
214 изменённых файлов: 595 добавлений и 1481 удалений

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

@ -1373,28 +1373,20 @@ void nsDocShell::FirePageHideShowNonRecursive(bool aShow) {
}
}
nsresult nsDocShell::Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) {
nsresult nsDocShell::Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) {
nsCOMPtr<nsIRunnable> runnable(aRunnable);
nsCOMPtr<nsPIDOMWindowOuter> win = GetWindow();
if (NS_WARN_IF(!win)) {
if (NS_WARN_IF(!GetWindow())) {
// Window should only be unavailable after destroyed.
MOZ_ASSERT(mIsBeingDestroyed);
return NS_ERROR_FAILURE;
}
if (win->GetDocGroup()) {
return win->GetDocGroup()->Dispatch(aCategory, runnable.forget());
}
return SchedulerGroup::Dispatch(aCategory, runnable.forget());
return SchedulerGroup::Dispatch(runnable.forget());
}
NS_IMETHODIMP
nsDocShell::DispatchLocationChangeEvent() {
return Dispatch(
TaskCategory::Other,
NewRunnableMethod("nsDocShell::FireDummyOnLocationChange", this,
return Dispatch(NewRunnableMethod("nsDocShell::FireDummyOnLocationChange",
this,
&nsDocShell::FireDummyOnLocationChange));
}
@ -2579,7 +2571,7 @@ void nsDocShell::MaybeCreateInitialClientSource(nsIPrincipal* aPrincipal) {
}
mInitialClientSource = ClientManager::CreateSource(
ClientType::Window, win->EventTargetFor(TaskCategory::Other), principal);
ClientType::Window, GetMainThreadSerialEventTarget(), principal);
MOZ_DIAGNOSTIC_ASSERT(mInitialClientSource);
// Mark the initial client as execution ready, but owned by the docshell.
@ -7262,7 +7254,7 @@ nsresult nsDocShell::RestorePresentation(nsISHEntry* aSHEntry,
mRestorePresentationEvent.Revoke();
RefPtr<RestorePresentationEvent> evt = new RestorePresentationEvent(this);
nsresult rv = Dispatch(TaskCategory::Other, do_AddRef(evt));
nsresult rv = Dispatch(do_AddRef(evt));
if (NS_SUCCEEDED(rv)) {
mRestorePresentationEvent = evt.get();
// The rest of the restore processing will happen on our event
@ -9350,7 +9342,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// Do this asynchronously
nsCOMPtr<nsIRunnable> ev = new InternalLoadEvent(this, aLoadState);
return Dispatch(TaskCategory::Other, ev.forget());
return Dispatch(ev.forget());
}
// Just ignore this load attempt
@ -10756,13 +10748,13 @@ nsresult nsDocShell::OpenInitializedChannel(nsIChannel* aChannel,
// When using DocumentChannel, all redirect handling is done in the parent,
// so we just need the child variant to watch for the internal redirect
// to the final channel.
rv = AddClientChannelHelperInChild(
aChannel, win->EventTargetFor(TaskCategory::Other));
rv = AddClientChannelHelperInChild(aChannel,
GetMainThreadSerialEventTarget());
docChannel->SetInitialClientInfo(GetInitialClientInfo());
} else {
rv = AddClientChannelHelper(aChannel, std::move(noReservedClient),
GetInitialClientInfo(),
win->EventTargetFor(TaskCategory::Other));
GetMainThreadSerialEventTarget());
}
NS_ENSURE_SUCCESS(rv, rv);
@ -10807,8 +10799,7 @@ nsresult nsDocShell::OpenRedirectedChannel(nsDocShellLoadState* aLoadState) {
// If we did a process switch, then we should have an existing allocated
// ClientInfo, so we just need to allocate a corresponding ClientSource.
CreateReservedSourceIfNeeded(channel,
win->EventTargetFor(TaskCategory::Other));
CreateReservedSourceIfNeeded(channel, GetMainThreadSerialEventTarget());
RefPtr<nsDocumentOpenInfo> loader =
new nsDocumentOpenInfo(this, nsIURILoader::DONT_RETARGET, nullptr);
@ -12913,7 +12904,7 @@ nsresult nsDocShell::OnLinkClick(
nsCOMPtr<nsIRunnable> ev =
new OnLinkClickEvent(this, aContent, loadState, noOpenerImplied,
aIsTrusted, aTriggeringPrincipal);
return Dispatch(TaskCategory::UI, ev.forget());
return Dispatch(ev.forget());
}
bool nsDocShell::ShouldOpenInBlankTarget(const nsAString& aOriginalTarget,

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

@ -980,8 +980,7 @@ class nsDocShell final : public nsDocLoader,
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
MOZ_CAN_RUN_SCRIPT_BOUNDARY void FirePageHideShowNonRecursive(bool aShow);
nsresult Dispatch(mozilla::TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable);
nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable);
void ReattachEditorToWindow(nsISHEntry* aSHEntry);
void ClearFrameHistory(nsISHEntry* aEntry);

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

@ -1177,20 +1177,16 @@ nsresult ChromeTooltipListener::MouseMove(Event* aMouseEvent) {
}
if (!mShowingTooltip) {
nsIEventTarget* target = nullptr;
if (nsCOMPtr<EventTarget> eventTarget = aMouseEvent->GetComposedTarget()) {
mPossibleTooltipNode = nsINode::FromEventTarget(eventTarget);
nsCOMPtr<nsIGlobalObject> global(eventTarget->GetOwnerGlobal());
if (global) {
target = global->EventTargetFor(TaskCategory::UI);
}
}
if (mPossibleTooltipNode) {
nsresult rv = NS_NewTimerWithFuncCallback(
getter_AddRefs(mTooltipTimer), sTooltipCallback, this,
LookAndFeel::GetInt(LookAndFeel::IntID::TooltipDelay, 500),
nsITimer::TYPE_ONE_SHOT, "ChromeTooltipListener::MouseMove", target);
nsITimer::TYPE_ONE_SHOT, "ChromeTooltipListener::MouseMove",
GetMainThreadSerialEventTarget());
if (NS_FAILED(rv)) {
mPossibleTooltipNode = nullptr;
NS_WARNING("Could not create a timer for tooltip tracking");

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

@ -319,7 +319,7 @@ nsresult nsPingListener::StartTimeout(DocGroup* aDocGroup) {
return NS_NewTimerWithFuncCallback(
getter_AddRefs(mTimer), OnPingTimeout, mLoadGroup, PING_TIMEOUT,
nsITimer::TYPE_ONE_SHOT, "nsPingListener::StartTimeout",
aDocGroup->EventTargetFor(TaskCategory::Network));
GetMainThreadSerialEventTarget());
}
NS_IMETHODIMP

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

@ -290,11 +290,8 @@ nsresult nsSHEntryShared::RemoveFromBFCacheAsync() {
nsCOMPtr<nsIContentViewer> viewer = mContentViewer;
RefPtr<dom::Document> document = mDocument;
RefPtr<nsSHEntryShared> self = this;
nsresult rv = mDocument->Dispatch(
mozilla::TaskCategory::Other,
NS_NewRunnableFunction(
"nsSHEntryShared::RemoveFromBFCacheAsync",
[self, viewer, document]() {
nsresult rv = mDocument->Dispatch(NS_NewRunnableFunction(
"nsSHEntryShared::RemoveFromBFCacheAsync", [self, viewer, document]() {
if (viewer) {
viewer->Destroy();
}

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

@ -1418,8 +1418,7 @@ already_AddRefed<Promise> ChromeUtils::RequestProcInfo(GlobalObject& aGlobal,
}
// Now place background request.
RefPtr<nsISerialEventTarget> target =
global->EventTargetFor(TaskCategory::Performance);
RefPtr<nsISerialEventTarget> target = global->SerialEventTarget();
mozilla::GetProcInfo(std::move(requests))
->Then(
target, __func__,

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

@ -1,28 +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 "mozilla/dom/DispatcherTrait.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/SchedulerGroup.h"
using namespace mozilla;
using namespace mozilla::dom;
nsresult DispatcherTrait::Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) {
return SchedulerGroup::Dispatch(aCategory, std::move(aRunnable));
}
nsISerialEventTarget* DispatcherTrait::EventTargetFor(
TaskCategory aCategory) const {
return GetMainThreadSerialEventTarget();
}
AbstractThread* DispatcherTrait::AbstractMainThreadFor(TaskCategory aCategory) {
// Return non DocGroup version by default.
return AbstractThread::MainThread();
}

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

@ -1,44 +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_DispatcherTrait_h
#define mozilla_dom_DispatcherTrait_h
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/TaskCategory.h"
#include "ErrorList.h"
class nsIRunnable;
class nsISerialEventTarget;
namespace mozilla {
class AbstractThread;
namespace dom {
// This trait should be attached to classes like nsIGlobalObject and
// Document that have a DocGroup attached to them. The methods here
// should delegate to the DocGroup. We can't use the
// Dispatcher class directly because it inherits from nsISupports.
class DispatcherTrait {
public:
// This method may or may not be safe off of the main thread. For Document it
// is safe. For nsIGlobalWindow it is not safe.
virtual nsresult Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable);
// This method may or may not be safe off of the main thread. For Document it
// is safe. For nsIGlobalWindow it is not safe. The nsISerialEventTarget can
// always be used off the main thread.
virtual nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const;
// Must be called on the main thread. The AbstractThread can always be used
// off the main thread.
virtual AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_DispatcherTrait_h

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

@ -50,9 +50,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
/* static */
already_AddRefed<DocGroup> DocGroup::Create(
BrowsingContextGroup* aBrowsingContextGroup, const nsACString& aKey) {
RefPtr<DocGroup> docGroup = new DocGroup(aBrowsingContextGroup, aKey);
docGroup->mEventTarget = mozilla::GetMainThreadSerialEventTarget();
return docGroup.forget();
return do_AddRef(new DocGroup(aBrowsingContextGroup, aKey));
}
/* static */
@ -129,34 +127,6 @@ DocGroup::~DocGroup() {
FlushIframePostMessageQueue();
}
}
nsresult DocGroup::Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
return SchedulerGroup::Dispatch(aCategory, std::move(aRunnable));
}
nsISerialEventTarget* DocGroup::EventTargetFor(TaskCategory aCategory) const {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mDocuments.IsEmpty());
// Here we have the same event target for every TaskCategory. The
// reason for that is that currently TaskCategory isn't used, and
// it's unsure if it ever will be (See Bug 1624819).
return mEventTarget;
}
AbstractThread* DocGroup::AbstractMainThreadFor(TaskCategory aCategory) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mDocuments.IsEmpty());
// Here we have the same thread for every TaskCategory. The reason
// for that is that currently TaskCategory isn't used, and it's
// unsure if it ever will be (See Bug 1624819).
return AbstractThread::MainThread();
}
void DocGroup::SignalSlotChange(HTMLSlotElement& aSlot) {
MOZ_ASSERT(!mSignalSlotList.Contains(&aSlot));
mSignalSlotList.AppendElement(&aSlot);
@ -218,7 +188,7 @@ void DocGroup::TryFlushIframePostMessages(uint64_t aWindowId) {
void DocGroup::FlushIframePostMessageQueue() {
nsCOMPtr<nsIRunnable> event;
while ((event = mIframePostMessageQueue->GetEvent())) {
Dispatch(TaskCategory::Other, event.forget());
SchedulerGroup::Dispatch(event.forget());
}
}

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

@ -87,13 +87,6 @@ class DocGroup final {
return mDocuments.end();
}
nsresult Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable);
nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const;
AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
// Return a pointer that can be continually checked to see if access to this
// DocGroup is valid. This pointer should live at least as long as the
// DocGroup.
@ -135,7 +128,6 @@ class DocGroup final {
RefPtr<BrowsingContextGroup> mBrowsingContextGroup;
RefPtr<mozilla::ThrottledEventQueue> mIframePostMessageQueue;
nsTHashSet<uint64_t> mIframesUsedPostMessageQueue;
nsCOMPtr<nsISerialEventTarget> mEventTarget;
// non-null if the JS execution for this docgroup is regulated with regards
// to worker threads. This should only be used when we are forcing serialized

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

@ -100,6 +100,7 @@
#include "mozilla/RelativeTo.h"
#include "mozilla/RestyleManager.h"
#include "mozilla/ReverseIterator.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/ScrollTimelineAnimationTracker.h"
#include "mozilla/SMILAnimationController.h"
#include "mozilla/SMILTimeContainer.h"
@ -4292,29 +4293,8 @@ void Document::AssertDocGroupMatchesKey() const {
}
#endif
nsresult Document::Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) {
// Note that this method may be called off the main thread.
if (mDocGroup) {
return mDocGroup->Dispatch(aCategory, std::move(aRunnable));
}
return DispatcherTrait::Dispatch(aCategory, std::move(aRunnable));
}
nsISerialEventTarget* Document::EventTargetFor(TaskCategory aCategory) const {
if (mDocGroup) {
return mDocGroup->EventTargetFor(aCategory);
}
return DispatcherTrait::EventTargetFor(aCategory);
}
AbstractThread* Document::AbstractMainThreadFor(
mozilla::TaskCategory aCategory) {
MOZ_ASSERT(NS_IsMainThread());
if (mDocGroup) {
return mDocGroup->AbstractMainThreadFor(aCategory);
}
return DispatcherTrait::AbstractMainThreadFor(aCategory);
nsresult Document::Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const {
return SchedulerGroup::Dispatch(std::move(aRunnable));
}
void Document::NoteScriptTrackingStatus(const nsACString& aURL,
@ -8243,7 +8223,7 @@ void Document::UnblockDOMContentLoaded() {
nsCOMPtr<nsIRunnable> ev =
NewRunnableMethod("Document::DispatchContentLoadedEvents", this,
&Document::DispatchContentLoadedEvents);
Dispatch(TaskCategory::Other, ev.forget());
Dispatch(ev.forget());
} else {
DispatchContentLoadedEvents();
}
@ -9271,7 +9251,7 @@ void Document::NotifyPossibleTitleChange(bool aBoundTitleElement) {
RefPtr<nsRunnableMethod<Document, void, false>> event =
NewNonOwningRunnableMethod("Document::DoNotifyPossibleTitleChange", this,
&Document::DoNotifyPossibleTitleChange);
if (NS_WARN_IF(NS_FAILED(Dispatch(TaskCategory::Other, do_AddRef(event))))) {
if (NS_WARN_IF(NS_FAILED(Dispatch(do_AddRef(event))))) {
return;
}
mPendingTitleChangeEvent = std::move(event);
@ -11671,7 +11651,7 @@ class nsUnblockOnloadEvent : public Runnable {
void Document::PostUnblockOnloadEvent() {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> evt = new nsUnblockOnloadEvent(this);
nsresult rv = Dispatch(TaskCategory::Other, evt.forget());
nsresult rv = Dispatch(evt.forget());
if (NS_SUCCEEDED(rv)) {
// Stabilize block count so we don't post more events while this one is up
++mOnloadBlockCount;
@ -12716,7 +12696,7 @@ void Document::UnsuppressEventHandlingAndFireEvents(bool aFireEvents) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> ded =
new nsDelayedEventDispatcher(std::move(documents));
Dispatch(TaskCategory::Other, ded.forget());
Dispatch(ded.forget());
} else {
FireOrClearDelayedEvents(std::move(documents), false);
}
@ -14472,12 +14452,8 @@ class nsCallExitFullscreen : public Runnable {
void Document::AsyncExitFullscreen(Document* aDoc) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> exit = new nsCallExitFullscreen(aDoc);
if (aDoc) {
aDoc->Dispatch(TaskCategory::Other, exit.forget());
} else {
NS_DispatchToCurrentThread(exit.forget());
}
}
static uint32_t CountFullscreenSubDocuments(Document& aDoc) {
uint32_t count = 0;
@ -15476,9 +15452,7 @@ void Document::RequestFullscreenInContentProcess(
PendingFullscreenChangeList::Add(std::move(aRequest));
// If we are not the top level process, dispatch an event to make
// our parent process go fullscreen first.
Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
Dispatch(NS_NewRunnableFunction(
"Document::RequestFullscreenInContentProcess", [self = RefPtr{this}] {
if (!self->HasPendingFullscreenRequests()) {
return;
@ -15742,7 +15716,7 @@ void Document::PostVisibilityUpdateEvent() {
nsCOMPtr<nsIRunnable> event = NewRunnableMethod<DispatchVisibilityChange>(
"Document::UpdateVisibilityState", this, &Document::UpdateVisibilityState,
DispatchVisibilityChange::Yes);
Dispatch(TaskCategory::Other, event.forget());
Dispatch(event.forget());
}
void Document::MaybeActiveMediaComponents() {
@ -16372,7 +16346,7 @@ void Document::ScheduleIntersectionObserverNotification() {
nsCOMPtr<nsIRunnable> notification =
NewRunnableMethod("Document::NotifyIntersectionObservers", this,
&Document::NotifyIntersectionObservers);
Dispatch(TaskCategory::Other, notification.forget());
Dispatch(notification.forget());
}
void Document::NotifyIntersectionObservers() {
@ -17528,7 +17502,7 @@ Document::CreatePermissionGrantPromise(
// If we get here, the auto-decision failed and we need to
// wait for the user prompt to complete.
sapr->RequestDelayedTask(
inner->EventTargetFor(TaskCategory::Other),
GetMainThreadSerialEventTarget(),
ContentPermissionRequestBase::DelayedTaskType::Request);
});
},

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

@ -40,14 +40,12 @@
#include "mozilla/Result.h"
#include "mozilla/SegmentedVector.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/UseCounter.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/css/StylePreloadKind.h"
#include "mozilla/dom/AnimationFrameProvider.h"
#include "mozilla/dom/DispatcherTrait.h"
#include "mozilla/dom/DocumentOrShadowRoot.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/EventTarget.h"
@ -533,7 +531,6 @@ class Document : public nsINode,
public DocumentOrShadowRoot,
public nsSupportsWeakReference,
public nsIScriptObjectPrincipal,
public DispatcherTrait,
public SupportsWeakPtr {
friend class DocumentOrShadowRoot;
@ -3745,12 +3742,7 @@ class Document : public nsINode,
void UnobserveForLastRememberedSize(Element&);
// Dispatch a runnable related to the document.
nsresult Dispatch(TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) final;
nsISerialEventTarget* EventTargetFor(TaskCategory) const override;
AbstractThread* AbstractMainThreadFor(TaskCategory) override;
nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const;
// The URLs passed to this function should match what
// JS::DescribeScriptedCaller() returns, since this API is used to

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

@ -162,7 +162,7 @@ void PointerLockManager::RequestLock(Element* aElement,
aCallerType == CallerType::System;
nsCOMPtr<nsIRunnable> request =
new PointerLockRequest(aElement, userInputOrSystemCaller);
doc->Dispatch(TaskCategory::Other, request.forget());
doc->Dispatch(request.forget());
}
/* static */

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

@ -302,7 +302,7 @@ void PostMessageEvent::DispatchToTargetThread(ErrorResult& aError) {
}
}
aError = mTargetWindow->Dispatch(TaskCategory::Other, event.forget());
aError = mTargetWindow->Dispatch(event.forget());
}
} // namespace mozilla::dom

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

@ -382,9 +382,7 @@ class AutoScroller final : public nsITimerCallback, public nsINamed {
mContent = PresShell::GetCapturingContent();
if (!mTimer) {
mTimer = NS_NewTimer(
mPresContext->Document()->EventTargetFor(TaskCategory::Other));
mTimer = NS_NewTimer(GetMainThreadSerialEventTarget());
if (!mTimer) {
return NS_ERROR_OUT_OF_MEMORY;
}

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

@ -171,7 +171,6 @@ EXPORTS.mozilla.dom += [
"CustomElementRegistry.h",
"DecompressionStream.h",
"DirectionalityUtils.h",
"DispatcherTrait.h",
"DocGroup.h",
"Document.h",
"DocumentFragment.h",
@ -333,7 +332,6 @@ UNIFIED_SOURCES += [
"Crypto.cpp",
"CustomElementRegistry.cpp",
"DirectionalityUtils.cpp",
"DispatcherTrait.cpp",
"DocGroup.cpp",
"Document.cpp",
"DocumentFragment.cpp",

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

@ -23,7 +23,6 @@
#include "nsContentUtils.h"
#include "mozilla/dom/nsMixedContentBlocker.h"
#include "nsIContentSecurityPolicy.h"
#include "mozilla/TaskCategory.h"
class nsIDOMWindow;
@ -97,19 +96,9 @@ inline nsresult nsContentPolicy::CheckPolicy(CPMethod policyMethod,
*/
nsresult rv;
const nsCOMArray<nsIContentPolicy>& entries = mPolicies.GetCachedEntries();
nsCOMPtr<nsPIDOMWindowOuter> window;
if (nsCOMPtr<nsINode> node = do_QueryInterface(requestingContext)) {
window = node->OwnerDoc()->GetWindow();
} else {
window = do_QueryInterface(requestingContext);
}
if (doc) {
nsCOMPtr<nsIContentSecurityPolicy> csp = doc->GetCsp();
if (csp && window) {
csp->EnsureEventTarget(
window->EventTargetFor(mozilla::TaskCategory::Other));
if (nsCOMPtr<nsIContentSecurityPolicy> csp = doc->GetCsp()) {
csp->EnsureEventTarget(mozilla::GetMainThreadSerialEventTarget());
}
}

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

@ -122,7 +122,6 @@
#include "mozilla/StaticPrefs_test.h"
#include "mozilla/StaticPrefs_ui.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TextControlState.h"
#include "mozilla/TextEditor.h"
#include "mozilla/TextEvents.h"
@ -10458,27 +10457,6 @@ uint32_t nsContentUtils::HtmlObjectContentTypeForMIMEType(
return nsIObjectLoadingContent::TYPE_NULL;
}
/* static */
already_AddRefed<nsISerialEventTarget> nsContentUtils::GetEventTargetByLoadInfo(
nsILoadInfo* aLoadInfo, TaskCategory aCategory) {
if (NS_WARN_IF(!aLoadInfo)) {
return nullptr;
}
RefPtr<Document> doc;
aLoadInfo->GetLoadingDocument(getter_AddRefs(doc));
nsCOMPtr<nsISerialEventTarget> target;
if (doc) {
if (DocGroup* group = doc->GetDocGroup()) {
target = group->EventTargetFor(aCategory);
}
} else {
target = GetMainThreadSerialEventTarget();
}
return target.forget();
}
/* static */
bool nsContentUtils::IsLocalRefURL(const nsAString& aString) {
return !aString.IsEmpty() && aString[0] == '#';

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

@ -35,7 +35,6 @@
#include "mozilla/CallState.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/BindingDeclarations.h"
@ -3179,9 +3178,6 @@ class nsContentUtils {
static uint32_t HtmlObjectContentTypeForMIMEType(const nsCString& aMIMEType,
bool aNoFakePlugin);
static already_AddRefed<nsISerialEventTarget> GetEventTargetByLoadInfo(
nsILoadInfo* aLoadInfo, mozilla::TaskCategory aCategory);
/**
* Detect whether a string is a local-url.
* https://drafts.csswg.org/css-values/#local-urls

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

@ -84,7 +84,6 @@
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryHistogramEnums.h"
#include "mozilla/TimeStamp.h"
@ -112,7 +111,6 @@
#include "mozilla/dom/DebuggerNotification.h"
#include "mozilla/dom/DebuggerNotificationBinding.h"
#include "mozilla/dom/DebuggerNotificationManager.h"
#include "mozilla/dom/DispatcherTrait.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentInlines.h"
@ -461,7 +459,7 @@ class nsGlobalWindowObserver final : public nsIObserver,
}
nsIEventTarget* GetEventTarget() const override {
return mWindow ? mWindow->EventTargetFor(TaskCategory::Other) : nullptr;
return mWindow ? mWindow->SerialEventTarget() : nullptr;
}
private:
@ -1952,8 +1950,7 @@ nsresult nsGlobalWindowInner::EnsureClientSource() {
// the opener, but we probably don't handle that yet.
if (!mClientSource) {
mClientSource = ClientManager::CreateSource(
ClientType::Window, EventTargetFor(TaskCategory::Other),
foreignPartitionedPrincipal);
ClientType::Window, SerialEventTarget(), foreignPartitionedPrincipal);
MOZ_DIAGNOSTIC_ASSERT(mClientSource);
newClientSource = true;
@ -1991,8 +1988,7 @@ nsresult nsGlobalWindowInner::EnsureClientSource() {
else if (mClientSource->GetController().isSome()) {
mClientSource.reset();
mClientSource = ClientManager::CreateSource(
ClientType::Window, EventTargetFor(TaskCategory::Other),
foreignPartitionedPrincipal);
ClientType::Window, SerialEventTarget(), foreignPartitionedPrincipal);
MOZ_DIAGNOSTIC_ASSERT(mClientSource);
newClientSource = true;
}
@ -4089,7 +4085,7 @@ void nsGlobalWindowInner::NotifyDOMWindowDestroyed(
void nsGlobalWindowInner::NotifyWindowIDDestroyed(const char* aTopic) {
nsCOMPtr<nsIRunnable> runnable =
new WindowDestroyedEvent(this, mWindowID, aTopic);
Dispatch(TaskCategory::Other, runnable.forget());
Dispatch(runnable.forget());
}
// static
@ -4529,7 +4525,7 @@ nsresult nsGlobalWindowInner::DispatchAsyncHashchange(nsIURI* aOldURI,
nsCOMPtr<nsIRunnable> callback =
new HashchangeCallback(oldWideSpec, newWideSpec, this);
return Dispatch(TaskCategory::Other, callback.forget());
return Dispatch(callback.forget());
}
nsresult nsGlobalWindowInner::FireHashchange(const nsAString& aOldURL,
@ -7376,30 +7372,14 @@ void nsGlobalWindowInner::StructuredClone(
}
nsresult nsGlobalWindowInner::Dispatch(
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable) {
already_AddRefed<nsIRunnable>&& aRunnable) const {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->Dispatch(aCategory, std::move(aRunnable));
}
return DispatcherTrait::Dispatch(aCategory, std::move(aRunnable));
return NS_DispatchToCurrentThread(std::move(aRunnable));
}
nsISerialEventTarget* nsGlobalWindowInner::EventTargetFor(
TaskCategory aCategory) const {
nsISerialEventTarget* nsGlobalWindowInner::SerialEventTarget() const {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->EventTargetFor(aCategory);
}
return DispatcherTrait::EventTargetFor(aCategory);
}
AbstractThread* nsGlobalWindowInner::AbstractMainThreadFor(
TaskCategory aCategory) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->AbstractMainThreadFor(aCategory);
}
return DispatcherTrait::AbstractMainThreadFor(aCategory);
return GetMainThreadSerialEventTarget();
}
Worklet* nsGlobalWindowInner::GetPaintWorklet(ErrorResult& aRv) {

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

@ -1186,14 +1186,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
static uint32_t GetShortcutsPermission(nsIPrincipal* aPrincipal);
// Dispatch a runnable related to the global.
virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) override;
virtual nsISerialEventTarget* EventTargetFor(
mozilla::TaskCategory aCategory) const override;
virtual mozilla::AbstractThread* AbstractMainThreadFor(
mozilla::TaskCategory aCategory) override;
nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final;
nsISerialEventTarget* SerialEventTarget() const final;
void DisableIdleCallbackRequests();
uint32_t LastIdleRequestHandle() const {

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

@ -15,7 +15,6 @@
// Local Includes
#include "Navigator.h"
#include "mozilla/Encoding.h"
#include "nsContentSecurityManager.h"
#include "nsGlobalWindowOuter.h"
#include "nsScreen.h"
@ -92,6 +91,7 @@
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Preferences.h"
#include "mozilla/Likely.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/SpinEventLoopUntil.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Unused.h"
@ -5874,8 +5874,7 @@ class nsCloseEvent : public Runnable {
public:
static nsresult PostCloseEvent(nsGlobalWindowOuter* aWindow, bool aIndirect) {
nsCOMPtr<nsIRunnable> ev = new nsCloseEvent(aWindow, aIndirect);
nsresult rv = aWindow->Dispatch(TaskCategory::Other, ev.forget());
return rv;
return aWindow->Dispatch(ev.forget());
}
NS_IMETHOD Run() override {
@ -6239,7 +6238,7 @@ bool nsGlobalWindowOuter::IsInModalState() {
void nsGlobalWindowOuter::NotifyWindowIDDestroyed(const char* aTopic) {
nsCOMPtr<nsIRunnable> runnable =
new WindowDestroyedEvent(this, mWindowID, aTopic);
Dispatch(TaskCategory::Other, runnable.forget());
Dispatch(runnable.forget());
}
Element* nsGlobalWindowOuter::GetFrameElement(nsIPrincipal& aSubjectPrincipal) {
@ -6679,7 +6678,7 @@ class AutoUnblockScriptClosing {
&nsGlobalWindowOuter::UnblockScriptedClosing;
nsCOMPtr<nsIRunnable> caller = NewRunnableMethod(
"AutoUnblockScriptClosing::~AutoUnblockScriptClosing", mWin, run);
mWin->Dispatch(TaskCategory::Other, caller.forget());
mWin->Dispatch(caller.forget());
}
};
@ -7253,30 +7252,14 @@ void nsGlobalWindowOuter::CheckForDPIChange() {
}
nsresult nsGlobalWindowOuter::Dispatch(
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable) {
already_AddRefed<nsIRunnable>&& aRunnable) const {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->Dispatch(aCategory, std::move(aRunnable));
}
return DispatcherTrait::Dispatch(aCategory, std::move(aRunnable));
return NS_DispatchToCurrentThread(std::move(aRunnable));
}
nsISerialEventTarget* nsGlobalWindowOuter::EventTargetFor(
TaskCategory aCategory) const {
nsISerialEventTarget* nsGlobalWindowOuter::SerialEventTarget() const {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->EventTargetFor(aCategory);
}
return DispatcherTrait::EventTargetFor(aCategory);
}
AbstractThread* nsGlobalWindowOuter::AbstractMainThreadFor(
TaskCategory aCategory) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (GetDocGroup()) {
return GetDocGroup()->AbstractMainThreadFor(aCategory);
}
return DispatcherTrait::AbstractMainThreadFor(aCategory);
return GetMainThreadSerialEventTarget();
}
void nsGlobalWindowOuter::MaybeResetWindowName(Document* aNewDocument) {

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

@ -983,14 +983,8 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
}
// Dispatch a runnable related to the global.
virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) override;
virtual nsISerialEventTarget* EventTargetFor(
mozilla::TaskCategory aCategory) const override;
virtual mozilla::AbstractThread* AbstractMainThreadFor(
mozilla::TaskCategory aCategory) override;
nsresult Dispatch(already_AddRefed<nsIRunnable>&&) const final;
nsISerialEventTarget* SerialEventTarget() const final;
protected:
nsresult ProcessWidgetFullscreenRequest(FullscreenReason aReason,

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

@ -10,7 +10,6 @@
#include "mozilla/LinkedList.h"
#include "mozilla/Maybe.h"
#include "mozilla/dom/ClientInfo.h"
#include "mozilla/dom/DispatcherTrait.h"
#include "mozilla/dom/ServiceWorkerDescriptor.h"
#include "mozilla/OriginTrials.h"
#include "nsContentUtils.h"
@ -65,8 +64,7 @@ class ModuleLoaderBase;
/**
* See <https://developer.mozilla.org/en-US/docs/Glossary/Global_object>.
*/
class nsIGlobalObject : public nsISupports,
public mozilla::dom::DispatcherTrait {
class nsIGlobalObject : public nsISupports {
private:
nsTArray<nsCString> mHostObjectURIs;
@ -140,6 +138,9 @@ class nsIGlobalObject : public nsISupports,
*/
bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); }
virtual nsISerialEventTarget* SerialEventTarget() const = 0;
virtual nsresult Dispatch(already_AddRefed<nsIRunnable>&&) const = 0;
// This method is not meant to be overridden.
nsIPrincipal* PrincipalOrNull() const;

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

@ -16,7 +16,6 @@
#include "mozilla/dom/EventTarget.h"
#include "mozilla/EventForwards.h"
#include "mozilla/Maybe.h"
#include "mozilla/TaskCategory.h"
#include "js/TypeDecls.h"
#include "nsRefPtrHashtable.h"
#include "nsILoadInfo.h"
@ -635,8 +634,6 @@ class nsPIDOMWindowInner : public mozIDOMWindow {
virtual nsresult Close() = 0;
mozilla::dom::DocGroup* GetDocGroup() const;
virtual nsISerialEventTarget* EventTargetFor(
mozilla::TaskCategory aCategory) const = 0;
void SaveStorageAccessPermissionGranted();
void SaveStorageAccessPermissionRevoked();
@ -1136,8 +1133,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {
virtual void UpdateCommands(const nsAString& anAction) = 0;
mozilla::dom::DocGroup* GetDocGroup() const;
virtual nsISerialEventTarget* EventTargetFor(
mozilla::TaskCategory aCategory) const = 0;
already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
already_AddRefed<nsIBaseWindow> GetTreeOwnerWindow();

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

@ -13,17 +13,18 @@
#ifndef mozilla_dom_SimpleGlobalObject_h__
#define mozilla_dom_SimpleGlobalObject_h__
#include "nsThreadUtils.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIGlobalObject.h"
#include "nsISupportsImpl.h"
#include "nsWrapperCache.h"
#include "js/TypeDecls.h"
#include "js/Value.h"
#include "nsISupportsImpl.h"
#include "nsCycleCollectionParticipant.h"
namespace mozilla::dom {
class SimpleGlobalObject : public nsIGlobalObject, public nsWrapperCache {
class SimpleGlobalObject final : public nsIGlobalObject, public nsWrapperCache {
public:
enum class GlobalType {
BindingDetail, // Should only be used by DOM bindings code.
@ -68,6 +69,13 @@ class SimpleGlobalObject : public nsIGlobalObject, public nsWrapperCache {
OriginTrials Trials() const override { return {}; }
nsISerialEventTarget* SerialEventTarget() const final {
return NS_GetCurrentThread();
}
nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final {
return NS_DispatchToCurrentThread(std::move(aRunnable));
}
JSObject* WrapObject(JSContext* cx,
JS::Handle<JSObject*> aGivenProto) override {
MOZ_CRASH("SimpleGlobalObject doesn't use DOM bindings!");

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

@ -1729,7 +1729,7 @@ static void AsyncCreateImageBitmapFromBlob(Promise* aPromise,
// Let's identify the main-thread event target.
nsCOMPtr<nsIEventTarget> mainThreadEventTarget;
if (NS_IsMainThread()) {
mainThreadEventTarget = aGlobal->EventTargetFor(TaskCategory::Other);
mainThreadEventTarget = aGlobal->SerialEventTarget();
} else {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);

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

@ -34,9 +34,8 @@ NS_INTERFACE_MAP_END
void Client::EnsureHandle() {
NS_ASSERT_OWNINGTHREAD(mozilla::dom::Client);
if (!mHandle) {
mHandle = ClientManager::CreateHandle(
ClientInfo(mData->info()),
mGlobal->EventTargetFor(TaskCategory::Other));
mHandle = ClientManager::CreateHandle(ClientInfo(mData->info()),
mGlobal->SerialEventTarget());
}
}
@ -147,7 +146,7 @@ already_AddRefed<Promise> Client::Focus(CallerType aCallerType,
mHandle->Focus(aCallerType)
->Then(
mGlobal->EventTargetFor(TaskCategory::Other), __func__,
mGlobal->SerialEventTarget(), __func__,
[ipcClientInfo, holder, outerPromise](const ClientState& aResult) {
holder->Complete();
NS_ENSURE_TRUE_VOID(holder->GetParentObject());

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

@ -23,9 +23,7 @@ void StartClientManagerOp(Func aFunc, const Arg& aArg, nsIGlobalObject* aGlobal,
Resolve aResolve, Reject aReject) {
MOZ_DIAGNOSTIC_ASSERT(aGlobal);
nsCOMPtr<nsISerialEventTarget> target =
aGlobal->EventTargetFor(TaskCategory::Other);
nsCOMPtr<nsISerialEventTarget> target = aGlobal->SerialEventTarget();
auto holder =
MakeRefPtr<DOMMozPromiseRequestHolder<ClientOpPromise>>(aGlobal);

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

@ -73,9 +73,7 @@ already_AddRefed<Promise> Clients::Get(const nsAString& aClientID,
}
const PrincipalInfo& principalInfo = workerPrivate->GetPrincipalInfo();
nsCOMPtr<nsISerialEventTarget> target =
mGlobal->EventTargetFor(TaskCategory::Other);
nsCOMPtr<nsISerialEventTarget> target = mGlobal->SerialEventTarget();
RefPtr<ClientOpPromise> innerPromise = ClientManager::GetInfoAndState(
ClientGetInfoAndStateArgs(id, principalInfo), target);
@ -103,7 +101,7 @@ already_AddRefed<Promise> Clients::Get(const nsAString& aClientID,
scope, "ServiceWorkerGetClientStorageError",
nsTArray<nsString>());
});
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget());
SchedulerGroup::Dispatch(r.forget());
outerPromise->MaybeResolveWithUndefined();
},
[outerPromise, holder](const CopyableErrorResult& aResult) {
@ -188,7 +186,7 @@ already_AddRefed<Promise> Clients::MatchAll(const ClientQueryOptions& aOptions,
scope, "ServiceWorkerGetClientStorageError",
nsTArray<nsString>());
});
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget());
SchedulerGroup::Dispatch(r.forget());
}
clientList.Sort(MatchAllComparator());
outerPromise->MaybeResolve(clientList);

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

@ -102,8 +102,7 @@ RefPtr<GenericPromise> OnShutdown() {
}
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
return ref;
}
@ -611,8 +610,7 @@ RefPtr<ClientOpPromise> ClaimOnMainThread(
scopeExit.release();
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
return promise;
}

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

@ -182,7 +182,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
MOZ_ASSERT(NS_IsMainThread());
mSerialEventTarget = window->EventTargetFor(TaskCategory::Other);
mSerialEventTarget = GetMainThreadSerialEventTarget();
// In theory we could do the URL work before paying the IPC overhead
// cost, but in practice its easier to do it here. The ClientHandle

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

@ -77,8 +77,7 @@ void ClientSourceParent::KillInvalidChild() {
// there is a small window of time before we kill the process. This is why
// we start the actor destruction immediately above.
nsCOMPtr<nsIRunnable> r = new KillContentParentRunnable(std::move(process));
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
}
mozilla::ipc::IPCResult ClientSourceParent::RecvWorkerSyncPing() {
@ -154,8 +153,7 @@ IPCResult ClientSourceParent::RecvInheritController(
swm->NoteInheritedController(clientInfo, controller);
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
return IPC_OK();
}
@ -172,8 +170,7 @@ IPCResult ClientSourceParent::RecvNoteDOMContentLoaded() {
swm->MaybeCheckNavigationUpdate(clientInfo);
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
}
return IPC_OK();
}

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

@ -96,26 +96,12 @@ nsresult AsyncEventDispatcher::Cancel() {
nsresult AsyncEventDispatcher::PostDOMEvent() {
RefPtr<AsyncEventDispatcher> ensureDeletionWhenFailing = this;
if (NS_IsMainThread()) {
if (nsCOMPtr<nsIGlobalObject> global = mTarget->GetOwnerGlobal()) {
return global->Dispatch(TaskCategory::Other,
ensureDeletionWhenFailing.forget());
}
// Sometimes GetOwnerGlobal returns null because it uses
// GetScriptHandlingObject rather than GetScopeObject.
if (nsINode* node = nsINode::FromEventTargetOrNull(mTarget)) {
RefPtr<Document> doc = node->OwnerDoc();
return doc->Dispatch(TaskCategory::Other,
ensureDeletionWhenFailing.forget());
}
}
return NS_DispatchToCurrentThread(this);
return NS_DispatchToCurrentThread(ensureDeletionWhenFailing.forget());
}
void AsyncEventDispatcher::RunDOMEventWhenSafe() {
RefPtr<AsyncEventDispatcher> ensureDeletionWhenFailing = this;
nsContentUtils::AddScriptRunner(this);
nsContentUtils::AddScriptRunner(ensureDeletionWhenFailing.forget());
}
// static

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

@ -503,7 +503,7 @@ void DataTransferItem::GetAsString(FunctionStringCallback* aCallback,
}
}
if (global) {
rv = global->Dispatch(TaskCategory::Other, runnable.forget());
rv = global->Dispatch(runnable.forget());
} else {
rv = NS_DispatchToMainThread(runnable);
}

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

@ -371,13 +371,7 @@ void EventListenerService::NotifyAboutMainThreadListenerChangeInternal(
nsCOMPtr<nsIRunnable> runnable =
NewRunnableMethod("EventListenerService::NotifyPendingChanges", this,
&EventListenerService::NotifyPendingChanges);
if (nsCOMPtr<nsIGlobalObject> global = aTarget->GetOwnerGlobal()) {
global->Dispatch(TaskCategory::Other, runnable.forget());
} else if (nsINode* node = nsINode::FromEventTarget(aTarget)) {
node->OwnerDoc()->Dispatch(TaskCategory::Other, runnable.forget());
} else {
NS_DispatchToCurrentThread(runnable);
}
NS_DispatchToCurrentThread(runnable.forget());
}
RefPtr<EventListenerChange> changes =

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

@ -1665,25 +1665,15 @@ bool IMEContentObserver::AChangeEvent::IsSafeToNotifyIME(
void IMEContentObserver::IMENotificationSender::Dispatch(
nsIDocShell* aDocShell) {
if (XRE_IsContentProcess() && aDocShell) {
RefPtr<nsPresContext> presContext = aDocShell->GetPresContext();
if (presContext) {
nsRefreshDriver* refreshDriver = presContext->RefreshDriver();
if (refreshDriver) {
if (RefPtr<nsPresContext> presContext = aDocShell->GetPresContext()) {
if (nsRefreshDriver* refreshDriver = presContext->RefreshDriver()) {
refreshDriver->AddEarlyRunner(this);
return;
}
}
}
nsIScriptGlobalObject* globalObject =
aDocShell ? aDocShell->GetScriptGlobalObject() : nullptr;
if (globalObject) {
RefPtr<IMENotificationSender> queuedSender = this;
globalObject->Dispatch(TaskCategory::Other, queuedSender.forget());
} else {
NS_DispatchToCurrentThread(this);
}
}
NS_IMETHODIMP
IMEContentObserver::IMENotificationSender::Run() {

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

@ -588,9 +588,8 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
RefPtr<MainThreadFetchResolver> resolver = new MainThreadFetchResolver(
p, observer, signalImpl, request->MozErrors());
RefPtr<FetchDriver> fetch =
new FetchDriver(std::move(r), principal, loadGroup,
aGlobal->EventTargetFor(TaskCategory::Other),
RefPtr<FetchDriver> fetch = new FetchDriver(
std::move(r), principal, loadGroup, aGlobal->SerialEventTarget(),
cookieJarSettings, nullptr, // PerformanceStorage
isTrackingFetch);
fetch->SetDocument(doc);
@ -1197,7 +1196,7 @@ FetchBody<Derived>::FetchBody(nsIGlobalObject* aOwner)
MOZ_ASSERT(wp);
mMainThreadEventTarget = wp->MainThreadEventTarget();
} else {
mMainThreadEventTarget = aOwner->EventTargetFor(TaskCategory::Other);
mMainThreadEventTarget = GetMainThreadSerialEventTarget();
}
MOZ_ASSERT(mMainThreadEventTarget);
@ -1237,7 +1236,7 @@ template bool FetchBody<Response>::BodyUsed() const;
template <class Derived>
void FetchBody<Derived>::SetBodyUsed(JSContext* aCx, ErrorResult& aRv) {
MOZ_ASSERT(aCx);
MOZ_ASSERT(mOwner->EventTargetFor(TaskCategory::Other)->IsOnCurrentThread());
MOZ_ASSERT(mOwner->SerialEventTarget()->IsOnCurrentThread());
MOZ_DIAGNOSTIC_ASSERT(!BodyUsed(), "Consuming already used body?");
if (BodyUsed()) {

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

@ -181,8 +181,7 @@ mozilla::ipc::IPCResult FetchChild::RecvOnFlushConsoleReport(
reporter->FlushConsoleReports(workerRef->Private()->GetLoadGroup());
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
return IPC_OK();
}
@ -245,8 +244,7 @@ mozilla::ipc::IPCResult FetchChild::RecvOnCSPViolationEvent(
return;
}
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
if (mCSPEventListener) {
Unused << NS_WARN_IF(
@ -305,8 +303,7 @@ mozilla::ipc::IPCResult FetchChild::RecvOnNotifyNetworkMonitorAlternateStack(
NotifyNetworkMonitorAlternateStack(channel, std::move(stack));
});
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(r.forget()));
return IPC_OK();
}

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

@ -18,7 +18,6 @@
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/TaskCategory.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsIAsyncInputStream.h"
@ -105,8 +104,7 @@ nsresult FetchStreamReader::Create(JSContext* aCx, nsIGlobalObject* aGlobal,
}
FetchStreamReader::FetchStreamReader(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal),
mOwningEventTarget(mGlobal->EventTargetFor(TaskCategory::Other)) {
: mGlobal(aGlobal), mOwningEventTarget(mGlobal->SerialEventTarget()) {
MOZ_ASSERT(aGlobal);
mozilla::HoldJSObjects(this);

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

@ -497,8 +497,7 @@ class JSStreamConsumer final : public nsIInputStreamCallback,
RefPtr<JSStreamConsumer> consumer;
if (aMaybeWorker) {
RefPtr<WorkerStreamOwner> owner = WorkerStreamOwner::Create(
asyncStream, aMaybeWorker,
aGlobal->EventTargetFor(TaskCategory::Other));
asyncStream, aMaybeWorker, aGlobal->SerialEventTarget());
if (!owner) {
return false;
}

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

@ -280,7 +280,7 @@ already_AddRefed<Promise> Blob::ConsumeBody(
MOZ_ASSERT(workerPrivate);
mainThreadEventTarget = workerPrivate->MainThreadEventTarget();
} else {
mainThreadEventTarget = mGlobal->EventTargetFor(TaskCategory::Other);
mainThreadEventTarget = GetMainThreadSerialEventTarget();
}
MOZ_ASSERT(mainThreadEventTarget);

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

@ -131,7 +131,7 @@ FileReader::FileReader(nsIGlobalObject* aGlobal, WeakWorkerRef* aWorkerRef)
MOZ_ASSERT_IF(NS_IsMainThread(), !mWeakWorkerRef);
if (NS_IsMainThread()) {
mTarget = aGlobal->EventTargetFor(TaskCategory::Other);
mTarget = aGlobal->SerialEventTarget();
} else {
mTarget = GetCurrentSerialEventTarget();
}

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

@ -11,7 +11,6 @@
#include "mozilla/SchedulerGroup.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "nsXPCOMPrivate.h"
@ -96,8 +95,7 @@ bool RemoteLazyInputStreamThread::Initialize() {
if (!NS_IsMainThread()) {
RefPtr<Runnable> runnable = new ThreadInitializeRunnable();
nsresult rv =
SchedulerGroup::Dispatch(TaskCategory::Other, runnable.forget());
nsresult rv = SchedulerGroup::Dispatch(runnable.forget());
return !NS_WARN_IF(NS_FAILED(rv));
}

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

@ -404,8 +404,7 @@ class ReleasingTimerHolder final : public Runnable,
// but we need at least to be able to dispatch to the main thread here.
auto raii = MakeScopeExit([holder] { holder->CancelTimerAndRevokeURI(); });
nsresult rv =
SchedulerGroup::Dispatch(TaskCategory::Other, holder.forget());
nsresult rv = SchedulerGroup::Dispatch(holder.forget());
NS_ENSURE_SUCCESS_VOID(rv);
raii.release();

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

@ -68,7 +68,7 @@ nsresult FileSystemUtils::DispatchRunnable(
if (!aGlobal) {
target = GetMainThreadSerialEventTarget();
} else {
target = aGlobal->EventTargetFor(TaskCategory::Other);
target = aGlobal->SerialEventTarget();
}
MOZ_ASSERT(target);

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

@ -82,7 +82,7 @@ class nsGeolocationRequest final : public ContentPermissionRequestBase,
nsGeolocationRequest(Geolocation* aLocator, GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
UniquePtr<PositionOptions>&& aOptions,
nsIEventTarget* aMainThreadTarget,
nsIEventTarget* aMainThreadSerialEventTarget,
bool aWatchPositionRequest = false,
int32_t aWatchId = 0);
@ -145,7 +145,7 @@ class nsGeolocationRequest final : public ContentPermissionRequestBase,
int32_t mWatchId;
bool mShutdown;
nsCOMPtr<nsIEventTarget> mMainThreadTarget;
nsCOMPtr<nsIEventTarget> mMainThreadSerialEventTarget;
};
static UniquePtr<PositionOptions> CreatePositionOptionsCopy(
@ -195,8 +195,9 @@ static nsPIDOMWindowInner* ConvertWeakReferenceToWindow(
nsGeolocationRequest::nsGeolocationRequest(
Geolocation* aLocator, GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
UniquePtr<PositionOptions>&& aOptions, nsIEventTarget* aMainThreadTarget,
bool aWatchPositionRequest, int32_t aWatchId)
UniquePtr<PositionOptions>&& aOptions,
nsIEventTarget* aMainThreadSerialEventTarget, bool aWatchPositionRequest,
int32_t aWatchId)
: ContentPermissionRequestBase(
aLocator->GetPrincipal(),
ConvertWeakReferenceToWindow(aLocator->GetOwner()), "geo"_ns,
@ -208,11 +209,7 @@ nsGeolocationRequest::nsGeolocationRequest(
mLocator(aLocator),
mWatchId(aWatchId),
mShutdown(false),
mMainThreadTarget(aMainThreadTarget) {
if (nsCOMPtr<nsPIDOMWindowInner> win =
do_QueryReferent(mLocator->GetOwner())) {
}
}
mMainThreadSerialEventTarget(aMainThreadSerialEventTarget) {}
nsGeolocationRequest::~nsGeolocationRequest() { StopTimeoutTimer(); }
@ -418,7 +415,7 @@ nsIPrincipal* nsGeolocationRequest::GetPrincipal() {
NS_IMETHODIMP
nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition) {
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(aPosition, this);
mMainThreadTarget->Dispatch(ev.forget());
mMainThreadSerialEventTarget->Dispatch(ev.forget());
return NS_OK;
}
@ -1012,15 +1009,6 @@ void Geolocation::GetCurrentPosition(PositionCallback& aCallback,
}
}
static nsIEventTarget* MainThreadTarget(Geolocation* geo) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(geo->GetOwner());
if (!window) {
return GetMainThreadSerialEventTarget();
}
return nsGlobalWindowInner::Cast(window)->EventTargetFor(
mozilla::TaskCategory::Other);
}
nsresult Geolocation::GetCurrentPosition(GeoPositionCallback callback,
GeoPositionErrorCallback errorCallback,
UniquePtr<PositionOptions>&& options,
@ -1039,7 +1027,7 @@ nsresult Geolocation::GetCurrentPosition(GeoPositionCallback callback,
// After this we hand over ownership of options to our nsGeolocationRequest.
nsIEventTarget* target = MainThreadTarget(this);
nsIEventTarget* target = GetMainThreadSerialEventTarget();
RefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(
this, std::move(callback), std::move(errorCallback), std::move(options),
target);
@ -1115,7 +1103,7 @@ int32_t Geolocation::WatchPosition(GeoPositionCallback aCallback,
// The watch ID:
int32_t watchId = mLastWatchId++;
nsIEventTarget* target = MainThreadTarget(this);
nsIEventTarget* target = GetMainThreadSerialEventTarget();
RefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(
this, std::move(aCallback), std::move(aErrorCallback),
std::move(aOptions), target, true, watchId);
@ -1209,7 +1197,7 @@ void Geolocation::NotifyAllowedRequest(nsGeolocationRequest* aRequest) {
}
bool Geolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) {
nsIEventTarget* target = MainThreadTarget(this);
nsIEventTarget* target = GetMainThreadSerialEventTarget();
ContentPermissionRequestBase::PromptResult pr = request->CheckPromptPrefs();
if (pr == ContentPermissionRequestBase::PromptResult::Granted) {
request->RequestDelayedTask(target,

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

@ -645,7 +645,7 @@ nsresult HTMLCanvasElement::DispatchPrintCallback(nsITimerCallback* aCallback) {
RefPtr<nsRunnableMethod<HTMLCanvasElement>> renderEvent =
NewRunnableMethod("dom::HTMLCanvasElement::CallPrintCallback", this,
&HTMLCanvasElement::CallPrintCallback);
return OwnerDoc()->Dispatch(TaskCategory::Other, renderEvent.forget());
return OwnerDoc()->Dispatch(renderEvent.forget());
}
void HTMLCanvasElement::CallPrintCallback() {
@ -972,9 +972,7 @@ void HTMLCanvasElement::ToBlob(JSContext* aCx, BlobCallback& aCallback,
// According to spec, blob should return null if either its horizontal
// dimension or its vertical dimension is zero. See link below.
// https://html.spec.whatwg.org/multipage/scripting.html#dom-canvas-toblob
OwnerDoc()->Dispatch(
TaskCategory::Other,
NewRunnableMethod<Blob*, const char*>(
OwnerDoc()->Dispatch(NewRunnableMethod<Blob*, const char*>(
"dom::HTMLCanvasElement::ToBlob", &aCallback,
static_cast<void (BlobCallback::*)(Blob*, const char*)>(
&BlobCallback::Call),

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

@ -156,10 +156,8 @@ int32_t HTMLDialogElement::TabIndexDefault() { return 0; }
void HTMLDialogElement::QueueCancelDialog() {
// queues an element task on the user interaction task source
OwnerDoc()
->EventTargetFor(TaskCategory::UI)
->Dispatch(NewRunnableMethod("HTMLDialogElement::RunCancelDialogSteps",
this,
OwnerDoc()->Dispatch(
NewRunnableMethod("HTMLDialogElement::RunCancelDialogSteps", this,
&HTMLDialogElement::RunCancelDialogSteps));
}

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

@ -61,6 +61,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/PresShell.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/Sprintf.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/SVGObserverUtils.h"
@ -991,15 +992,13 @@ class HTMLMediaElement::MediaElementTrackSource
MediaStreamTrackSource)
/* MediaDecoder track source */
MediaElementTrackSource(nsISerialEventTarget* aMainThreadEventTarget,
ProcessedMediaTrack* aTrack, nsIPrincipal* aPrincipal,
MediaElementTrackSource(ProcessedMediaTrack* aTrack, nsIPrincipal* aPrincipal,
OutputMuteState aMuteState, bool aHasAlpha)
: MediaStreamTrackSource(
aPrincipal, nsString(),
TrackingId(TrackingId::Source::MediaElementDecoder,
sDecoderCaptureSourceId++,
TrackingId::TrackAcrossProcesses::Yes)),
mMainThreadEventTarget(aMainThreadEventTarget),
mTrack(aTrack),
mIntendedElementMuteState(aMuteState),
mElementMuteState(aMuteState),
@ -1008,8 +1007,7 @@ class HTMLMediaElement::MediaElementTrackSource
}
/* MediaStream track source */
MediaElementTrackSource(nsISerialEventTarget* aMainThreadEventTarget,
MediaStreamTrack* aCapturedTrack,
MediaElementTrackSource(MediaStreamTrack* aCapturedTrack,
MediaStreamTrackSource* aCapturedTrackSource,
ProcessedMediaTrack* aTrack, MediaInputPort* aPort,
OutputMuteState aMuteState)
@ -1018,7 +1016,6 @@ class HTMLMediaElement::MediaElementTrackSource
TrackingId(TrackingId::Source::MediaElementStream,
sStreamCaptureSourceId++,
TrackingId::TrackAcrossProcesses::Yes)),
mMainThreadEventTarget(aMainThreadEventTarget),
mCapturedTrack(aCapturedTrack),
mCapturedTrackSource(aCapturedTrackSource),
mTrack(aTrack),
@ -1052,7 +1049,7 @@ class HTMLMediaElement::MediaElementTrackSource
return;
}
mIntendedElementMuteState = aMuteState;
mMainThreadEventTarget->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"MediaElementTrackSource::SetMutedByElement",
[self = RefPtr<MediaElementTrackSource>(this), this, aMuteState] {
mElementMuteState = aMuteState;
@ -1145,7 +1142,6 @@ class HTMLMediaElement::MediaElementTrackSource
private:
virtual ~MediaElementTrackSource() { Destroy(); };
const RefPtr<nsISerialEventTarget> mMainThreadEventTarget;
RefPtr<MediaStreamTrack> mCapturedTrack;
RefPtr<MediaStreamTrackSource> mCapturedTrackSource;
const RefPtr<ProcessedMediaTrack> mTrack;
@ -1789,9 +1785,8 @@ class HTMLMediaElement::ChannelLoader final {
MOZ_ASSERT(aElement);
// Per bug 1235183 comment 8, we can't spin the event loop from stable
// state. Defer NS_NewChannel() to a new regular runnable.
return aElement->MainThreadEventTarget()->Dispatch(
NewRunnableMethod<HTMLMediaElement*>("ChannelLoader::LoadInternal",
this, &ChannelLoader::LoadInternal,
return aElement->OwnerDoc()->Dispatch(NewRunnableMethod<HTMLMediaElement*>(
"ChannelLoader::LoadInternal", this, &ChannelLoader::LoadInternal,
aElement));
}
@ -2034,7 +2029,7 @@ already_AddRefed<Promise> HTMLMediaElement::MozRequestDebugInfo(
if (mDecoder) {
mDecoder->RequestDebugInfo(result->mDecoder)
->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[promise, ptr = std::move(result)]() {
promise->MaybeResolve(ptr.get());
},
@ -2060,7 +2055,7 @@ already_AddRefed<Promise> HTMLMediaElement::MozRequestDebugLog(
}
DecoderDoctorLogger::RetrieveMessages(this)->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[promise](const nsACString& aString) {
promise->MaybeResolve(NS_ConvertUTF8toUTF16(aString));
},
@ -2619,7 +2614,7 @@ void HTMLMediaElement::SelectResource() {
// The media element has neither a src attribute nor a source element child:
// set the networkState to NETWORK_EMPTY, and abort these steps; the
// synchronous section ends.
mMainThreadEventTarget->Dispatch(NewRunnableMethod<nsCString>(
GetMainThreadSerialEventTarget()->Dispatch(NewRunnableMethod<nsCString>(
"HTMLMediaElement::NoSupportedMediaSourceError", this,
&HTMLMediaElement::NoSupportedMediaSourceError, rv.Description()));
} else {
@ -2770,7 +2765,7 @@ void HTMLMediaElement::DealWithFailedElement(nsIContent* aSourceElement) {
}
DispatchAsyncSourceError(aSourceElement);
mMainThreadEventTarget->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod("HTMLMediaElement::QueueLoadFromSourceTask", this,
&HTMLMediaElement::QueueLoadFromSourceTask));
}
@ -3563,7 +3558,7 @@ void HTMLMediaElement::AddOutputTrackSourceToOutputStream(
switch (aMode) {
case AddTrackMode::ASYNC:
mMainThreadEventTarget->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod<StoreRefPtrPassByPtr<MediaStreamTrack>>(
"DOMMediaStream::AddTrackInternal", aOutputStream.mStream,
&DOMMediaStream::AddTrackInternal, domTrack));
@ -3654,7 +3649,7 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
// If we bounce it to the MediaTrackGraph it might not be picked up,
// for instance if the MediaInputPort was destroyed in the same
// iteration as it was added.
mMainThreadEventTarget->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod("MediaElementTrackSource::OverrideEnded", source,
&MediaElementTrackSource::OverrideEnded));
@ -3670,7 +3665,7 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
if (&aTrack->GetSource() != source) {
return false;
}
mMainThreadEventTarget->Dispatch(
GetMainThreadSerialEventTarget()->Dispatch(
NewRunnableMethod<RefPtr<MediaStreamTrack>>(
"DOMMediaStream::RemoveTrackInternal", ms.mStream,
&DOMMediaStream::RemoveTrackInternal, aTrack));
@ -3755,7 +3750,7 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
principal = NodePrincipal();
}
source = MakeAndAddRef<MediaElementTrackSource>(
mMainThreadEventTarget, track, principal, OutputTracksMuted(),
track, principal, OutputTracksMuted(),
type == MediaSegment::VIDEO
? HTMLVideoElement::FromNode(this)->HasAlpha()
: false);
@ -3779,8 +3774,8 @@ void HTMLMediaElement::UpdateOutputTrackSources() {
track = inputTrack->Graph()->CreateForwardedInputTrack(type);
RefPtr<MediaInputPort> port = inputTrack->ForwardTrackContentsTo(track);
source = MakeAndAddRef<MediaElementTrackSource>(
mMainThreadEventTarget, inputTrack, &inputTrack->GetSource(), track,
port, OutputTracksMuted());
inputTrack, &inputTrack->GetSource(), track, port,
OutputTracksMuted());
// Track is muted initially, so we don't leak data if it's added while
// paused and an MTG iteration passes before the mute comes into effect.
@ -4225,11 +4220,7 @@ NS_IMPL_ISUPPORTS(HTMLMediaElement::TitleChangeObserver, nsIObserver)
HTMLMediaElement::HTMLMediaElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: nsGenericHTMLElement(std::move(aNodeInfo)),
mWatchManager(this,
OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other)),
mMainThreadEventTarget(OwnerDoc()->EventTargetFor(TaskCategory::Other)),
mAbstractMainThread(
OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other)),
mWatchManager(this, AbstractThread::MainThread()),
mShutdownObserver(new ShutdownObserver),
mTitleChangeObserver(new TitleChangeObserver(this)),
mEventBlocker(new EventBlocker(this)),
@ -4240,8 +4231,7 @@ HTMLMediaElement::HTMLMediaElement(
mSink(std::pair(nsString(), RefPtr<AudioDeviceInfo>())),
mShowPoster(IsVideo()),
mMediaControlKeyListener(new MediaControlKeyListener(this)) {
MOZ_ASSERT(mMainThreadEventTarget);
MOZ_ASSERT(mAbstractMainThread);
MOZ_ASSERT(GetMainThreadSerialEventTarget());
// Please don't add anything to this constructor or the initialization
// list that can cause AddRef to be called. This prevents subclasses
// from overriding AddRef in a way that works with our refcount
@ -5188,11 +5178,11 @@ void HTMLMediaElement::SetupSrcMediaStreamPlayback(DOMMediaStream* aStream) {
VideoFrameContainer* container = GetVideoFrameContainer();
RefPtr<FirstFrameVideoOutput> firstFrameOutput =
container
? MakeAndAddRef<FirstFrameVideoOutput>(container, mAbstractMainThread)
container ? MakeAndAddRef<FirstFrameVideoOutput>(container,
AbstractMainThread())
: nullptr;
mMediaStreamRenderer = MakeAndAddRef<MediaStreamRenderer>(
mAbstractMainThread, container, firstFrameOutput, this);
AbstractMainThread(), container, firstFrameOutput, this);
mWatchManager.Watch(mPaused,
&HTMLMediaElement::UpdateSrcStreamPotentiallyPlaying);
mWatchManager.Watch(mReadyState,
@ -5587,7 +5577,7 @@ void HTMLMediaElement::SeekCompleted() {
}
if (mSeekDOMPromise) {
mAbstractMainThread->Dispatch(NS_NewRunnableFunction(
AbstractMainThread()->Dispatch(NS_NewRunnableFunction(
__func__, [promise = std::move(mSeekDOMPromise)] {
promise->MaybeResolveWithUndefined();
}));
@ -5597,7 +5587,7 @@ void HTMLMediaElement::SeekCompleted() {
void HTMLMediaElement::SeekAborted() {
if (mSeekDOMPromise) {
mAbstractMainThread->Dispatch(NS_NewRunnableFunction(
AbstractMainThread()->Dispatch(NS_NewRunnableFunction(
__func__, [promise = std::move(mSeekDOMPromise)] {
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}));
@ -5696,7 +5686,7 @@ void HTMLMediaElement::StartProgressTimer() {
NS_NewTimerWithFuncCallback(
getter_AddRefs(mProgressTimer), ProgressTimerCallback, this, PROGRESS_MS,
nsITimer::TYPE_REPEATING_SLACK, "HTMLMediaElement::ProgressTimerCallback",
mMainThreadEventTarget);
GetMainThreadSerialEventTarget());
}
void HTMLMediaElement::StartProgress() {
@ -6279,7 +6269,7 @@ void HTMLMediaElement::DispatchAsyncEvent(RefPtr<nsMediaEventRunner> aRunner) {
mEventBlocker->PostponeEvent(aRunner);
return;
}
mMainThreadEventTarget->Dispatch(aRunner.forget());
GetMainThreadSerialEventTarget()->Dispatch(aRunner.forget());
}
bool HTMLMediaElement::IsPotentiallyPlaying() const {
@ -6521,13 +6511,13 @@ void HTMLMediaElement::AddRemoveSelfReference() {
// The shutdown observer will hold a strong reference to us. This
// will do to keep us alive. We need to know about shutdown so that
// we can release our self-reference.
mMainThreadEventTarget->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"dom::HTMLMediaElement::AddSelfReference",
[self]() { self->mShutdownObserver->AddRefMediaElement(); }));
} else {
// Dispatch Release asynchronously so that we don't destroy this object
// inside a call stack of method calls on this object
mMainThreadEventTarget->Dispatch(NS_NewRunnableFunction(
GetMainThreadSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
"dom::HTMLMediaElement::AddSelfReference",
[self]() { self->mShutdownObserver->ReleaseMediaElement(); }));
}
@ -6545,7 +6535,7 @@ void HTMLMediaElement::DispatchAsyncSourceError(nsIContent* aSourceElement) {
nsCOMPtr<nsIRunnable> event =
new nsSourceErrorEventRunner(this, aSourceElement);
mMainThreadEventTarget->Dispatch(event.forget());
GetMainThreadSerialEventTarget()->Dispatch(event.forget());
}
void HTMLMediaElement::NotifyAddedSource() {
@ -6893,7 +6883,7 @@ bool HTMLMediaElement::TryRemoveMediaKeysAssociation() {
RefPtr<HTMLMediaElement> self = this;
mDecoder->SetCDMProxy(nullptr)
->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[self]() {
self->mSetCDMRequest.Complete();
@ -6967,7 +6957,7 @@ bool HTMLMediaElement::TryMakeAssociationWithCDM(CDMProxy* aProxy) {
RefPtr<HTMLMediaElement> self = this;
mDecoder->SetCDMProxy(aProxy)
->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[self]() {
self->mSetCDMRequest.Complete();
self->MakeAssociationWithCDMResolved();
@ -7341,9 +7331,7 @@ void HTMLMediaElement::UpdateCustomPolicyAfterPlayed() {
}
AbstractThread* HTMLMediaElement::AbstractMainThread() const {
MOZ_ASSERT(mAbstractMainThread);
return mAbstractMainThread;
return AbstractThread::MainThread();
}
nsTArray<RefPtr<PlayPromise>> HTMLMediaElement::TakePendingPlayPromises() {
@ -7391,7 +7379,7 @@ void HTMLMediaElement::AsyncResolvePendingPlayPromises() {
nsCOMPtr<nsIRunnable> event = new nsResolveOrRejectPendingPlayPromisesRunner(
this, TakePendingPlayPromises());
mMainThreadEventTarget->Dispatch(event.forget());
GetMainThreadSerialEventTarget()->Dispatch(event.forget());
}
void HTMLMediaElement::AsyncRejectPendingPlayPromises(nsresult aError) {
@ -7411,7 +7399,7 @@ void HTMLMediaElement::AsyncRejectPendingPlayPromises(nsresult aError) {
nsCOMPtr<nsIRunnable> event = new nsResolveOrRejectPendingPlayPromisesRunner(
this, TakePendingPlayPromises(), aError);
mMainThreadEventTarget->Dispatch(event.forget());
GetMainThreadSerialEventTarget()->Dispatch(event.forget());
}
void HTMLMediaElement::GetEMEInfo(dom::EMEDebugInfo& aInfo) {
@ -7559,14 +7547,14 @@ already_AddRefed<Promise> HTMLMediaElement::SetSinkId(const nsAString& aSinkId,
nsString sinkId(aSinkId);
mediaDevices->GetSinkDevice(sinkId)
->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[self = RefPtr<HTMLMediaElement>(this),
this](RefPtr<AudioDeviceInfo>&& aInfo) {
// Sink found switch output device.
MOZ_ASSERT(aInfo);
if (mDecoder) {
RefPtr<SinkInfoPromise> p = mDecoder->SetSink(aInfo)->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[aInfo](const GenericPromise::ResolveOrRejectValue& aValue) {
if (aValue.IsResolve()) {
return SinkInfoPromise::CreateAndResolve(aInfo, __func__);
@ -7580,7 +7568,7 @@ already_AddRefed<Promise> HTMLMediaElement::SetSinkId(const nsAString& aSinkId,
MOZ_ASSERT(mMediaStreamRenderer);
RefPtr<SinkInfoPromise> p =
mMediaStreamRenderer->SetAudioOutputDevice(aInfo)->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[aInfo](const GenericPromise::AllPromiseType::
ResolveOrRejectValue& aValue) {
if (aValue.IsResolve()) {
@ -7599,7 +7587,7 @@ already_AddRefed<Promise> HTMLMediaElement::SetSinkId(const nsAString& aSinkId,
// Promise is rejected, sink not found.
return SinkInfoPromise::CreateAndReject(res, __func__);
})
->Then(mAbstractMainThread, __func__,
->Then(AbstractMainThread(), __func__,
[promise, self = RefPtr<HTMLMediaElement>(this), this,
sinkId](const SinkInfoPromise::ResolveOrRejectValue& aValue) {
if (aValue.IsResolve()) {
@ -7630,7 +7618,7 @@ void HTMLMediaElement::NotifyTextTrackModeChanged() {
return;
}
mPendingTextTrackChanged = true;
mAbstractMainThread->Dispatch(
AbstractMainThread()->Dispatch(
NS_NewRunnableFunction("HTMLMediaElement::NotifyTextTrackModeChanged",
[this, self = RefPtr<HTMLMediaElement>(this)]() {
mPendingTextTrackChanged = false;
@ -7659,7 +7647,7 @@ void HTMLMediaElement::CreateResumeDelayedMediaPlaybackAgentIfNeeded() {
}
mResumeDelayedPlaybackAgent->GetResumePromise()
->Then(
mAbstractMainThread, __func__,
AbstractMainThread(), __func__,
[self = RefPtr<HTMLMediaElement>(this)]() {
LOG(LogLevel::Debug, ("%p Resume delayed Play() call", self.get()));
self->mResumePlaybackRequest.Complete();
@ -7775,7 +7763,7 @@ void HTMLMediaElement::SetSecondaryMediaStreamRenderer(
}
if (aContainer) {
mSecondaryMediaStreamRenderer = MakeAndAddRef<MediaStreamRenderer>(
mAbstractMainThread, aContainer, aFirstFrameOutput, this);
AbstractMainThread(), aContainer, aFirstFrameOutput, this);
if (mSrcStreamIsPlaying) {
mSecondaryMediaStreamRenderer->Start();
}

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

@ -809,10 +809,6 @@ class HTMLMediaElement : public nsGenericHTMLElement,
already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() override;
nsISerialEventTarget* MainThreadEventTarget() {
return mMainThreadEventTarget;
}
// Set the sink id (of the output device) that the audio will play. If aSinkId
// is empty the default device will be set.
already_AddRefed<Promise> SetSinkId(const nsAString& aSinkId,
@ -1416,13 +1412,6 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;
// The DocGroup-specific nsISerialEventTarget of this HTML element on the main
// thread.
nsCOMPtr<nsISerialEventTarget> mMainThreadEventTarget;
// The DocGroup-specific AbstractThread::MainThread() of this HTML element.
RefPtr<AbstractThread> mAbstractMainThread;
// A reference to the VideoFrameContainer which contains the current frame
// of video to display.
RefPtr<VideoFrameContainer> mVideoFrameContainer;

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

@ -370,7 +370,7 @@ void HTMLTrackElement::LoadResource(RefPtr<WebVTTListener>&& aWebVTTListener) {
}
mChannel = channel;
});
doc->Dispatch(TaskCategory::Other, runnable.forget());
doc->Dispatch(runnable.forget());
}
nsresult HTMLTrackElement::BindToTree(BindContext& aContext, nsINode& aParent) {
@ -460,7 +460,7 @@ void HTMLTrackElement::DispatchTrackRunnable(const nsString& aEventName) {
nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod<const nsString>(
"dom::HTMLTrackElement::DispatchTrustedEvent", this,
&HTMLTrackElement::DispatchTrustedEvent, aEventName);
doc->Dispatch(TaskCategory::Other, runnable.forget());
doc->Dispatch(runnable.forget());
}
void HTMLTrackElement::DispatchTrustedEvent(const nsAString& aName) {

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

@ -94,7 +94,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
HTMLVideoElement::HTMLVideoElement(already_AddRefed<NodeInfo>&& aNodeInfo)
: HTMLMediaElement(std::move(aNodeInfo)),
mIsOrientationLocked(false),
mVideoWatchManager(this, mAbstractMainThread) {
mVideoWatchManager(this, AbstractThread::MainThread()) {
DecoderDoctorLogger::LogConstruction(this);
}
@ -583,8 +583,8 @@ void HTMLVideoElement::MaybeBeginCloningVisually() {
VideoFrameContainer* container =
mVisualCloneTarget->GetVideoFrameContainer();
if (container) {
mSecondaryVideoOutput =
MakeRefPtr<FirstFrameVideoOutput>(container, mAbstractMainThread);
mSecondaryVideoOutput = MakeRefPtr<FirstFrameVideoOutput>(
container, AbstractThread::MainThread());
mVideoWatchManager.Watch(
mSecondaryVideoOutput->mFirstFrameRendered,
&HTMLVideoElement::OnSecondaryVideoOutputFirstFrameRendered);
@ -635,7 +635,7 @@ void HTMLVideoElement::OnSecondaryVideoContainerInstalled(
return;
}
mMainThreadEventTarget->Dispatch(NewRunnableMethod(
NS_DispatchToCurrentThread(NewRunnableMethod(
"Promise::MaybeResolveWithUndefined", mVisualCloneTargetPromise,
&Promise::MaybeResolveWithUndefined));
mVisualCloneTargetPromise = nullptr;

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

@ -463,7 +463,7 @@ class SimpleTextTrackEvent : public Runnable {
void Dispatch() {
if (nsCOMPtr<nsIGlobalObject> global = mCue->GetOwnerGlobal()) {
global->Dispatch(TaskCategory::Other, do_AddRef(this));
global->Dispatch(do_AddRef(this));
} else {
NS_DispatchToMainThread(do_AddRef(this));
}
@ -587,10 +587,8 @@ class TextTrackListInternal {
void TextTrackManager::DispatchUpdateCueDisplay() {
if (!mUpdateCueDisplayDispatched && !IsShutdown()) {
WEBVTT_LOG("DispatchUpdateCueDisplay");
nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow();
if (win) {
if (nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow()) {
nsGlobalWindowInner::Cast(win)->Dispatch(
TaskCategory::Other,
NewRunnableMethod("dom::TextTrackManager::UpdateCueDisplay", this,
&TextTrackManager::UpdateCueDisplay));
mUpdateCueDisplayDispatched = true;
@ -605,10 +603,8 @@ void TextTrackManager::DispatchTimeMarchesOn() {
// executing call upon completion will check queue for further 'work'.
if (!mTimeMarchesOnDispatched && !IsShutdown()) {
WEBVTT_LOG("DispatchTimeMarchesOn");
nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow();
if (win) {
if (nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow()) {
nsGlobalWindowInner::Cast(win)->Dispatch(
TaskCategory::Other,
NewRunnableMethod("dom::TextTrackManager::TimeMarchesOn", this,
&TextTrackManager::TimeMarchesOn));
mTimeMarchesOnDispatched = true;

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

@ -3253,8 +3253,7 @@ void nsGenericHTMLElement::QueuePopoverEventTask(
auto task =
MakeRefPtr<PopoverToggleEventTask>(do_GetWeakReference(this), aOldState);
data->SetToggleEventTask(task);
OwnerDoc()->Dispatch(TaskCategory::UI, task.forget());
OwnerDoc()->Dispatch(task.forget());
}
void nsGenericHTMLElement::RunPopoverToggleEventTask(

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

@ -933,7 +933,5 @@ void HTMLContentSink::ContinueInterruptedParsingAsync() {
nsCOMPtr<nsIRunnable> ev = NewRunnableMethod(
"HTMLContentSink::ContinueInterruptedParsingIfEnabled", this,
&HTMLContentSink::ContinueInterruptedParsingIfEnabled);
RefPtr<Document> doc = mHTMLDocument;
doc->Dispatch(mozilla::TaskCategory::Other, ev.forget());
mHTMLDocument->Dispatch(ev.forget());
}

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

@ -737,8 +737,7 @@ void nsHTMLDocument::GetFormsAndFormControls(nsContentList** aFormList,
holder = new ContentListHolder(this, htmlForms, htmlFormControls);
RefPtr<ContentListHolder> runnable = holder;
if (NS_SUCCEEDED(
Dispatch(TaskCategory::GarbageCollection, runnable.forget()))) {
if (NS_SUCCEEDED(Dispatch(runnable.forget()))) {
mContentListHolder = holder;
}
}

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

@ -86,7 +86,6 @@
#include "mozilla/SnappyCompressOutputStream.h"
#include "mozilla/SpinEventLoopUntil.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
@ -6413,8 +6412,7 @@ class DeserializeIndexValueHelper final : public Runnable {
MonitorAutoLock lock(mMonitor);
RefPtr<Runnable> self = this;
QM_TRY(MOZ_TO_RESULT(
SchedulerGroup::Dispatch(TaskCategory::Other, self.forget())));
QM_TRY(MOZ_TO_RESULT(SchedulerGroup::Dispatch(self.forget())));
lock.Wait();
return mStatus;

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

@ -179,7 +179,7 @@ Result<RefPtr<IDBFactory>, nsresult> IDBFactory::CreateForWindow(
factory->mBrowserChild = BrowserChild::GetFrom(aWindow);
factory->mEventTarget =
nsGlobalWindowInner::Cast(aWindow)->EventTargetFor(TaskCategory::Other);
nsGlobalWindowInner::Cast(aWindow)->SerialEventTarget();
factory->mInnerWindowID = aWindow->WindowID();
factory->mPrivateBrowsingMode =
loadContext && loadContext->UsePrivateBrowsing();

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

@ -42,7 +42,6 @@
#include "mozilla/RefPtr.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/Span.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/indexedDB/IDBResult.h"
@ -2755,8 +2754,7 @@ class DeserializeUpgradeValueHelper final : public Runnable {
MonitorAutoLock lock(mMonitor);
RefPtr<Runnable> self = this;
const nsresult rv =
SchedulerGroup::Dispatch(TaskCategory::Other, self.forget());
const nsresult rv = SchedulerGroup::Dispatch(self.forget());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -165,8 +165,7 @@ void ScriptErrorHelper::Dump(const nsAString& aMessage,
RefPtr<ScriptErrorRunnable> runnable =
new ScriptErrorRunnable(aMessage, aFilename, aLineNumber, aColumnNumber,
aSeverityFlag, aIsChrome, aInnerWindowID);
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, runnable.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
}
}
@ -183,8 +182,7 @@ void ScriptErrorHelper::DumpLocalizedMessage(
RefPtr<ScriptErrorRunnable> runnable = new ScriptErrorRunnable(
aMessageName, aFilename, aLineNumber, aColumnNumber, aSeverityFlag,
aIsChrome, aInnerWindowID);
MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, runnable.forget()));
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
}
}

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

@ -4,33 +4,24 @@
* 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 "base/basictypes.h"
#include "BrowserChild.h"
#ifdef ACCESSIBILITY
# include "mozilla/a11y/DocAccessibleChild.h"
#endif
#include <algorithm>
#include <utility>
#include "BrowserParent.h"
#include "ContentChild.h"
#include "DocumentInlines.h"
#include "EventStateManager.h"
#include "MMPrinter.h"
#include "PermissionMessageUtils.h"
#include "PuppetWidget.h"
#include "StructuredCloneData.h"
#include "UnitTransforms.h"
#include "Units.h"
#include "VRManagerChild.h"
#include "ipc/nsGUIEventIPC.h"
#include "js/JSON.h"
#include "mozilla/Assertions.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/EventForwards.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/HoldDropJSObjects.h"
@ -39,36 +30,29 @@
#include "mozilla/MouseEvents.h"
#include "mozilla/NativeKeyBindingsType.h"
#include "mozilla/NullPrincipal.h"
#include "mozilla/Preferences.h"
#include "mozilla/PresShell.h"
#include "mozilla/ProcessHangMonitor.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
#include "mozilla/ToString.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/AutoPrintEventDispatcher.h"
#include "mozilla/dom/BrowserBridgeChild.h"
#include "mozilla/dom/DataTransfer.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/ImageDocument.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/MediaDocument.h"
#include "mozilla/dom/MessageManagerBinding.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PBrowser.h"
#include "mozilla/dom/PaymentRequestChild.h"
#include "mozilla/dom/PBrowser.h"
#include "mozilla/dom/PointerEventHandler.h"
#include "mozilla/dom/SessionStoreUtils.h"
#include "mozilla/dom/SessionStoreChild.h"
@ -76,11 +60,9 @@
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/gfx/CrossProcessPaint.h"
#include "mozilla/gfx/Matrix.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/ipc/URIUtils.h"
#include "mozilla/layers/APZCCallbackHelper.h"
#include "mozilla/layers/TouchActionHelper.h"
#include "mozilla/layers/APZCTreeManagerChild.h"
@ -94,14 +76,12 @@
#include "mozilla/layers/InputAPZContext.h"
#include "mozilla/layers/WebRenderLayerManager.h"
#include "nsBrowserStatusFilter.h"
#include "nsColorPickerProxy.h"
#include "nsCommandParams.h"
#include "nsContentPermissionHelper.h"
#include "nsContentUtils.h"
#include "nsDeviceContext.h"
#include "nsDocShell.h"
#include "nsDocShellLoadState.h"
#include "nsEmbedCID.h"
#include "nsExceptionHandler.h"
#include "nsFilePickerProxy.h"
#include "nsFocusManager.h"
@ -116,7 +96,6 @@
#include "nsISHistory.h"
#include "nsIScreenManager.h"
#include "nsIScriptError.h"
#include "nsISecureBrowserUI.h"
#include "nsIURI.h"
#include "nsIURIMutator.h"
#include "nsIWeakReferenceUtils.h"
@ -127,18 +106,11 @@
#include "nsIOpenWindowInfo.h"
#include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h"
#include "nsPointerHashKeys.h"
#include "nsPrintfCString.h"
#include "nsQueryActor.h"
#include "nsQueryObject.h"
#include "nsRefreshDriver.h"
#include "nsSandboxFlags.h"
#include "nsString.h"
#include "nsTHashtable.h"
#include "nsThreadManager.h"
#include "nsThreadUtils.h"
#include "nsViewManager.h"
#include "nsViewportInfo.h"
#include "nsWebBrowser.h"
#include "nsWindowWatcher.h"
#include "nsIXULRuntime.h"
@ -3808,21 +3780,10 @@ already_AddRefed<nsIDocShell> BrowserChildMessageManager::GetDocShell(
already_AddRefed<nsIEventTarget>
BrowserChildMessageManager::GetTabEventTarget() {
nsCOMPtr<nsIEventTarget> target = EventTargetFor(TaskCategory::Other);
return target.forget();
return do_AddRef(GetMainThreadSerialEventTarget());
}
nsresult BrowserChildMessageManager::Dispatch(
TaskCategory aCategory, already_AddRefed<nsIRunnable>&& aRunnable) {
return DispatcherTrait::Dispatch(aCategory, std::move(aRunnable));
}
nsISerialEventTarget* BrowserChildMessageManager::EventTargetFor(
TaskCategory aCategory) const {
return DispatcherTrait::EventTargetFor(aCategory);
}
AbstractThread* BrowserChildMessageManager::AbstractMainThreadFor(
TaskCategory aCategory) {
return DispatcherTrait::AbstractMainThreadFor(aCategory);
already_AddRefed<nsIRunnable>&& aRunnable) const {
return SchedulerGroup::Dispatch(std::move(aRunnable));
}

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

@ -13,7 +13,6 @@
#include "nsCOMPtr.h"
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIDOMEventListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWindowProvider.h"
#include "nsIDocShell.h"
@ -33,16 +32,14 @@
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventForwards.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/APZCCallbackHelper.h"
#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/GeckoContentControllerTypes.h"
#include "mozilla/dom/ipc/IdType.h"
#include "AudioChannelService.h"
#include "PuppetWidget.h"
#include "nsDeque.h"
#include "nsIRemoteTab.h"
#include "nsTHashSet.h"
class nsBrowserStatusFilter;
class nsIDOMWindow;
@ -91,7 +88,6 @@ class WebProgressData;
class BrowserChildMessageManager : public ContentFrameMessageManager,
public nsIMessageSender,
public DispatcherTrait,
public nsSupportsWeakReference {
public:
explicit BrowserChildMessageManager(BrowserChild* aBrowserChild);
@ -105,10 +101,9 @@ class BrowserChildMessageManager : public ContentFrameMessageManager,
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
virtual Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) override;
virtual already_AddRefed<nsIDocShell> GetDocShell(
ErrorResult& aError) override;
virtual already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) override;
already_AddRefed<nsIDocShell> GetDocShell(ErrorResult& aError) override;
already_AddRefed<nsIEventTarget> GetTabEventTarget() override;
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
@ -117,14 +112,7 @@ class BrowserChildMessageManager : public ContentFrameMessageManager,
}
// Dispatch a runnable related to the global.
virtual nsresult Dispatch(mozilla::TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable) override;
virtual nsISerialEventTarget* EventTargetFor(
mozilla::TaskCategory aCategory) const override;
virtual AbstractThread* AbstractMainThreadFor(
mozilla::TaskCategory aCategory) override;
nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const;
RefPtr<BrowserChild> mBrowserChild;

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

@ -802,7 +802,6 @@ void ContentChild::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
// NOTE: We have to register the annotator on the main thread, as annotators
// only affect a single thread.
SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction("RegisterPendingInputEventHangAnnotator", [] {
BackgroundHangMonitor::RegisterAnnotator(
PendingInputEventHangAnnotator::sSingleton);

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

@ -708,7 +708,7 @@ nsJSChannel::AsyncOpen(nsIStreamListener* aListener) {
nsCOMPtr<nsIRunnable> runnable =
mozilla::NewRunnableMethod(name, this, method);
nsGlobalWindowInner* window = nsGlobalWindowInner::Cast(mOriginalInnerWindow);
rv = window->Dispatch(mozilla::TaskCategory::Other, runnable.forget());
rv = window->Dispatch(runnable.forget());
if (NS_FAILED(rv)) {
loadGroup->RemoveRequest(this, nullptr, rv);

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

@ -51,12 +51,9 @@ void BackgroundVideoDecodingPermissionObserver::RegisterEvent() {
// Events shall not be fired synchronously to prevent anything visible
// from the scripts while we are in stable state.
if (nsCOMPtr<dom::Document> doc = GetOwnerDoc()) {
doc->Dispatch(
TaskCategory::Other,
NewRunnableMethod(
"BackgroundVideoDecodingPermissionObserver::"
"EnableEvent",
this, &BackgroundVideoDecodingPermissionObserver::EnableEvent));
doc->Dispatch(NewRunnableMethod(
"BackgroundVideoDecodingPermissionObserver::EnableEvent", this,
&BackgroundVideoDecodingPermissionObserver::EnableEvent));
}
} else {
EnableEvent();
@ -75,12 +72,8 @@ void BackgroundVideoDecodingPermissionObserver::UnregisterEvent() {
// Events shall not be fired synchronously to prevent anything visible
// from the scripts while we are in stable state.
if (nsCOMPtr<dom::Document> doc = GetOwnerDoc()) {
doc->Dispatch(
TaskCategory::Other,
NewRunnableMethod(
"BackgroundVideoDecodingPermissionObserver::"
"DisableEvent",
this,
doc->Dispatch(NewRunnableMethod(
"BackgroundVideoDecodingPermissionObserver::DisableEvent", this,
&BackgroundVideoDecodingPermissionObserver::DisableEvent));
}
} else {

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

@ -98,7 +98,7 @@ ThreadedDriver::~ThreadedDriver() {
if (mThread) {
nsCOMPtr<nsIRunnable> event =
new MediaTrackGraphShutdownThreadRunnable(mThread.forget());
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
SchedulerGroup::Dispatch(event.forget());
}
}

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

@ -766,14 +766,8 @@ void MediaDevices::SetupDeviceChangeListener() {
return;
}
nsISerialEventTarget* mainThread =
window->EventTargetFor(TaskCategory::Other);
if (!mainThread) {
return;
}
mDeviceChangeListener = MediaManager::Get()->DeviceListChangeEvent().Connect(
mainThread, this, &MediaDevices::OnDeviceChange);
GetMainThreadSerialEventTarget(), this, &MediaDevices::OnDeviceChange);
mIsDeviceChangeListenerSetUp = true;
MediaManager::Get()->GetPhysicalDevices()->Then(

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

@ -588,7 +588,6 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
uint32_t aVideoBitsPerSecond, uint32_t aAudioBitsPerSecond)
: mRecorder(aRecorder),
mMediaStreamTracks(std::move(aMediaStreamTracks)),
mMainThread(mRecorder->GetOwner()->EventTargetFor(TaskCategory::Other)),
mMimeType(SelectMimeType(
mMediaStreamTracks.Contains(TrackTypeComparator::VIDEO,
TrackTypeComparator()),
@ -762,7 +761,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
InvokeAsync(mEncoderThread, mEncoder.get(), __func__,
&MediaEncoder::RequestData)
->Then(
mMainThread, __func__,
GetMainThreadSerialEventTarget(), __func__,
[this, self = RefPtr<Session>(this)](
const MediaEncoder::BlobPromise::ResolveOrRejectValue& aRrv) {
if (aRrv.IsReject()) {
@ -868,13 +867,14 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
return;
}
mStartedListener = mEncoder->StartedEvent().Connect(mMainThread, this,
&Session::OnStarted);
nsISerialEventTarget* mainThread = GetMainThreadSerialEventTarget();
mStartedListener =
mEncoder->StartedEvent().Connect(mainThread, this, &Session::OnStarted);
mDataAvailableListener = mEncoder->DataAvailableEvent().Connect(
mMainThread, this, &Session::OnDataAvailable);
mainThread, this, &Session::OnDataAvailable);
mErrorListener =
mEncoder->ErrorEvent().Connect(mMainThread, this, &Session::OnError);
mShutdownListener = mEncoder->ShutdownEvent().Connect(mMainThread, this,
mEncoder->ErrorEvent().Connect(mainThread, this, &Session::OnError);
mShutdownListener = mEncoder->ShutdownEvent().Connect(mainThread, this,
&Session::OnShutdown);
if (mRecorder->mAudioNode) {
@ -946,7 +946,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
blobPromise
->Then(
mMainThread, __func__,
GetMainThreadSerialEventTarget(), __func__,
[this, self = RefPtr<Session>(this), rv, needsStartEvent](
const MediaEncoder::BlobPromise::ResolveOrRejectValue& aRv) {
if (mRecorder->mSessions.LastElement() == this) {
@ -991,10 +991,11 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
// And finally, Shutdown and destroy the Session
return Shutdown();
})
->Then(mMainThread, __func__, [this, self = RefPtr<Session>(this)] {
// Guard against the case where we fail to add a blocker due to being
// in XPCOM shutdown. If we're in this state we shouldn't try and get
// a shutdown barrier as we'll fail.
->Then(GetMainThreadSerialEventTarget(), __func__,
[this, self = RefPtr<Session>(this)] {
// Guard against the case where we fail to add a blocker due to
// being in XPCOM shutdown. If we're in this state we shouldn't
// try and get a shutdown barrier as we'll fail.
if (!mShutdownBlocker) {
return;
}
@ -1065,7 +1066,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
if (mEncoder) {
mShutdownPromise =
mShutdownPromise
->Then(mMainThread, __func__,
->Then(GetMainThreadSerialEventTarget(), __func__,
[this, self = RefPtr<Session>(this)] {
mStartedListener.DisconnectIfExists();
mDataAvailableListener.DisconnectIfExists();
@ -1095,7 +1096,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
// Break the cycle reference between Session and MediaRecorder.
mShutdownPromise = mShutdownPromise->Then(
mMainThread, __func__,
GetMainThreadSerialEventTarget(), __func__,
[self = RefPtr<Session>(this)]() {
self->mRecorder->RemoveSession(self);
return ShutdownPromise::CreateAndResolve(true, __func__);
@ -1107,7 +1108,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
if (mEncoderThread) {
mShutdownPromise = mShutdownPromise->Then(
mMainThread, __func__,
GetMainThreadSerialEventTarget(), __func__,
[encoderThread = mEncoderThread]() {
return encoderThread->BeginShutdown();
},
@ -1139,8 +1140,6 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
// set.
nsTArray<RefPtr<MediaStreamTrack>> mMediaStreamTracks;
// Main thread used for MozPromise operations.
const RefPtr<nsISerialEventTarget> mMainThread;
// Runnable thread for reading data from MediaEncoder.
RefPtr<TaskQueue> mEncoderThread;
// MediaEncoder pipeline.

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

@ -122,11 +122,8 @@ class MediaStreamTrack::MTGListener : public MediaTrackListener {
return;
}
AbstractThread* mainThread =
nsGlobalWindowInner::Cast(mTrack->GetParentObject())
->AbstractMainThreadFor(TaskCategory::Other);
mainThread->Dispatch(NewRunnableMethod("MediaStreamTrack::OverrideEnded",
mTrack.get(),
AbstractThread::MainThread()->Dispatch(
NewRunnableMethod("MediaStreamTrack::OverrideEnded", mTrack.get(),
&MediaStreamTrack::OverrideEnded));
}

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

@ -3418,22 +3418,14 @@ MediaTrackGraph* MediaTrackGraph::GetInstance(
aGraphDriverRequested, aWindow->WindowID(),
aWindow->AsGlobal()->ShouldResistFingerprinting(
RFPTarget::AudioSampleRate),
aSampleRate, aOutputDeviceID,
aWindow->EventTargetFor(TaskCategory::Other));
aSampleRate, aOutputDeviceID, GetMainThreadSerialEventTarget());
}
MediaTrackGraph* MediaTrackGraph::CreateNonRealtimeInstance(
TrackRate aSampleRate, nsPIDOMWindowInner* aWindow) {
TrackRate aSampleRate) {
MOZ_ASSERT(NS_IsMainThread(), "Main thread only");
nsISerialEventTarget* mainThread = GetMainThreadSerialEventTarget();
// aWindow can be null when the document is being unlinked, so this works when
// with a generic main thread if that's the case.
if (aWindow) {
mainThread =
aWindow->AsGlobal()->AbstractMainThreadFor(TaskCategory::Other);
}
// Offline graphs have 0 output channel count: they write the output to a
// buffer, not an audio output track.
MediaTrackGraphImpl* graph =

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

@ -1025,8 +1025,7 @@ class MediaTrackGraph {
static MediaTrackGraph* GetInstance(
GraphDriverType aGraphDriverRequested, nsPIDOMWindowInner* aWindow,
TrackRate aSampleRate, CubebUtils::AudioDeviceID aOutputDeviceID);
static MediaTrackGraph* CreateNonRealtimeInstance(
TrackRate aSampleRate, nsPIDOMWindowInner* aWindowId);
static MediaTrackGraph* CreateNonRealtimeInstance(TrackRate aSampleRate);
// Idempotent
void ForceShutDown();

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

@ -31,9 +31,7 @@ void VideoStreamTrack::AddVideoOutput(VideoFrameContainer* aSink) {
if (Ended()) {
return;
}
auto output = MakeRefPtr<VideoOutput>(
aSink, nsGlobalWindowInner::Cast(GetParentObject())
->AbstractMainThreadFor(TaskCategory::Other));
auto output = MakeRefPtr<VideoOutput>(aSink, AbstractThread::MainThread());
AddVideoOutput(output);
}

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

@ -18,7 +18,6 @@
#include "mozilla/SharedThreadPool.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/TaskCategory.h"
#include "mozilla/TaskQueue.h"
#include "mozilla/Telemetry.h"
#include "nsCharSeparatedTokenizer.h"
@ -1028,7 +1027,7 @@ void LogToBrowserConsole(const nsAString& aMsg) {
nsString msg(aMsg);
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
"LogToBrowserConsole", [msg]() { LogToBrowserConsole(msg); });
SchedulerGroup::Dispatch(TaskCategory::Other, task.forget());
SchedulerGroup::Dispatch(task.forget());
return;
}
nsCOMPtr<nsIConsoleService> console(

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

@ -111,7 +111,7 @@ void GVAutoplayPermissionRequest::CreateRequest(nsGlobalWindowInner* aWindow,
} else {
LOG("Dispatch async request");
request->RequestDelayedTask(
aWindow->EventTargetFor(TaskCategory::Other),
aWindow->SerialEventTarget(),
GVAutoplayPermissionRequest::DelayedTaskType::Request);
}
}

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

@ -113,7 +113,6 @@ bool DecoderDoctorLogger::EnsureLogIsEnabled() {
sMediaLogs = mediaLogsConstruction.mMediaLogs;
// Setup shutdown-time clean-up.
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction("DDLogger shutdown setup", [] {
sDDLogShutdowner = MakeUnique<DDLogShutdowner>();
ClearOnShutdown(&sDDLogShutdowner,

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

@ -425,7 +425,7 @@ GeckoMediaPluginServiceChild::GetServiceChild() {
if (mGetServiceChildPromises.Length() == 1) {
nsCOMPtr<nsIRunnable> r =
WrapRunnable(contentChild, &dom::ContentChild::SendCreateGMPService);
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget());
SchedulerGroup::Dispatch(r.forget());
}
return promise;
}

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

@ -29,10 +29,8 @@ class GMPTestMonitor {
public:
void SetFinished() {
mozilla::SchedulerGroup::Dispatch(mozilla::TaskCategory::Other,
mozilla::NewNonOwningRunnableMethod(
"GMPTestMonitor::MarkFinished", this,
&GMPTestMonitor::MarkFinished));
mozilla::SchedulerGroup::Dispatch(mozilla::NewNonOwningRunnableMethod(
"GMPTestMonitor::MarkFinished", this, &GMPTestMonitor::MarkFinished));
}
private:

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

@ -194,7 +194,7 @@ static void ClearCDMStorage(already_AddRefed<nsIRunnable> aContinuation,
nsIThread* aTarget, PRTime aSince = -1) {
RefPtr<ClearCDMStorageTask> task(
new ClearCDMStorageTask(std::move(aContinuation), aTarget, aSince));
SchedulerGroup::Dispatch(TaskCategory::Other, task.forget());
SchedulerGroup::Dispatch(task.forget());
}
static void SimulatePBModeExit() {
@ -504,9 +504,7 @@ class CDMStorageTest {
// Collect nodeIds that are expected to remain for later comparison.
EnumerateCDMStorageDir("id"_ns, NodeIdCollector(siteInfo.get()));
// Invoke "Forget this site" on the main thread.
SchedulerGroup::Dispatch(
TaskCategory::Other,
NewRunnableMethod<UniquePtr<NodeInfo>&&>(
SchedulerGroup::Dispatch(NewRunnableMethod<UniquePtr<NodeInfo>&&>(
"CDMStorageTest::TestForgetThisSite_Forget", this,
&CDMStorageTest::TestForgetThisSite_Forget, std::move(siteInfo)));
}
@ -669,12 +667,9 @@ class CDMStorageTest {
// Collect nodeIds that are expected to remain for later comparison.
EnumerateCDMStorageDir("id"_ns, BaseDomainNodeIdCollector(siteInfo.get()));
// Invoke "ForgetThisBaseDomain" on the main thread.
SchedulerGroup::Dispatch(
TaskCategory::Other,
NewRunnableMethod<UniquePtr<BaseDomainNodeInfo>&&>(
SchedulerGroup::Dispatch(NewRunnableMethod<UniquePtr<BaseDomainNodeInfo>&&>(
"CDMStorageTest::TestForgetThisBaseDomain_Forget", this,
&CDMStorageTest::TestForgetThisBaseDomain_Forget,
std::move(siteInfo)));
&CDMStorageTest::TestForgetThisBaseDomain_Forget, std::move(siteInfo)));
}
void TestForgetThisBaseDomain_Forget(
@ -1093,7 +1088,7 @@ class CDMStorageTest {
NewRunnableMethod("CDMStorageTest::Shutdown", this,
&CDMStorageTest::Shutdown),
std::move(aContinuation), mNodeId));
SchedulerGroup::Dispatch(TaskCategory::Other, task.forget());
SchedulerGroup::Dispatch(task.forget());
}
void Shutdown() {
@ -1111,7 +1106,7 @@ class CDMStorageTest {
Shutdown();
nsCOMPtr<nsIRunnable> task = NewRunnableMethod(
"CDMStorageTest::Dummy", this, &CDMStorageTest::Dummy);
SchedulerGroup::Dispatch(TaskCategory::Other, task.forget());
SchedulerGroup::Dispatch(task.forget());
}
void SessionMessage(const nsACString& aSessionId, uint32_t aMessageType,

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

@ -191,7 +191,7 @@ void CaptureTask::PostTrackEndEvent() {
IC_LOG("Got MediaTrack track removed or finished event.");
nsCOMPtr<nsIRunnable> event = new TrackEndRunnable(this);
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
SchedulerGroup::Dispatch(event.forget());
}
} // namespace mozilla

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

@ -296,7 +296,6 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo(
// otherwise.
static RefPtr<AllocPolicy> sVideoAllocPolicy = [&taskQueue]() {
SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
"MediaCapabilities::AllocPolicy:Video", []() {
ClearOnShutdown(&sVideoAllocPolicy,
@ -436,7 +435,7 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo(
RefPtr<StrongWorkerRef> workerRef;
if (NS_IsMainThread()) {
targetThread = mParent->AbstractMainThreadFor(TaskCategory::Other);
targetThread = GetMainThreadSerialEventTarget();
} else {
WorkerPrivate* wp = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(wp, "Must be called from a worker thread");

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

@ -530,8 +530,7 @@ MediaSource::MediaSource(nsPIDOMWindowInner* aWindow)
: DOMEventTargetHelper(aWindow),
mDecoder(nullptr),
mPrincipal(nullptr),
mAbstractMainThread(
GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)),
mAbstractMainThread(AbstractThread::MainThread()),
mReadyState(MediaSourceReadyState::Closed) {
MOZ_ASSERT(NS_IsMainThread());
mSourceBuffers = new SourceBufferList(this);

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

@ -93,24 +93,18 @@ NotNull<AllocPolicy*> GlobalAllocPolicy::Instance(TrackType aTrack) {
StaticMutexAutoLock lock(sMutex);
if (aTrack == TrackType::kAudioTrack) {
static RefPtr<AllocPolicyImpl> sAudioPolicy = []() {
SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
SchedulerGroup::Dispatch(NS_NewRunnableFunction(
"GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
ClearOnShutdown(&sAudioPolicy,
ShutdownPhase::XPCOMShutdownThreads);
ClearOnShutdown(&sAudioPolicy, ShutdownPhase::XPCOMShutdownThreads);
}));
return new AllocPolicyImpl(MediaDecoderLimitDefault());
}();
return WrapNotNull(sAudioPolicy.get());
}
static RefPtr<AllocPolicyImpl> sVideoPolicy = []() {
SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
SchedulerGroup::Dispatch(NS_NewRunnableFunction(
"GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
ClearOnShutdown(&sVideoPolicy,
ShutdownPhase::XPCOMShutdownThreads);
ClearOnShutdown(&sVideoPolicy, ShutdownPhase::XPCOMShutdownThreads);
}));
return new AllocPolicyImpl(MediaDecoderLimitDefault());
}();

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

@ -76,7 +76,7 @@ class AnalyserNodeEngine final : public AudioNodeEngine {
RefPtr<TransferBuffer> transfer =
new TransferBuffer(aTrack, aInput.AsAudioChunk());
mAbstractMainThread->Dispatch(transfer.forget());
AbstractThread::MainThread()->Dispatch(transfer.forget());
}
virtual bool IsActive() const override { return mChunksToProcess != 0; }

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

@ -766,9 +766,8 @@ double AudioContext::CurrentTime() {
nsISerialEventTarget* AudioContext::GetMainThread() const {
if (nsPIDOMWindowInner* window = GetParentObject()) {
return window->AsGlobal()->EventTargetFor(TaskCategory::Other);
return window->AsGlobal()->SerialEventTarget();
}
return GetCurrentSerialEventTarget();
}
@ -851,12 +850,10 @@ class OnStateChangeTask final : public Runnable {
void AudioContext::Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> parentObject = do_QueryInterface(GetParentObject());
// It can happen that this runnable took a long time to reach the main thread,
// and the global is not valid anymore.
if (parentObject) {
parentObject->AbstractMainThreadFor(TaskCategory::Other)
->Dispatch(std::move(aRunnable));
if (GetParentObject()) {
AbstractThread::MainThread()->Dispatch(std::move(aRunnable));
} else {
RefPtr<nsIRunnable> runnable(aRunnable);
runnable = nullptr;

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

@ -390,8 +390,8 @@ AudioNodeTrack* AudioDestinationNode::Track() {
// GetParentObject can return nullptr here when the document has been
// unlinked.
MediaTrackGraph* graph = MediaTrackGraph::CreateNonRealtimeInstance(
context->SampleRate(), context->GetParentObject());
MediaTrackGraph* graph =
MediaTrackGraph::CreateNonRealtimeInstance(context->SampleRate());
AudioNodeEngine* engine = new OfflineDestinationNodeEngine(this);
mTrack = AudioNodeTrack::Create(context, engine, kTrackFlags, graph);
@ -426,8 +426,8 @@ void AudioDestinationNode::NotifyMainThreadTrackEnded() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mTrack->IsEnded());
if (mIsOffline && GetAbstractMainThread()) {
GetAbstractMainThread()->Dispatch(NewRunnableMethod(
if (mIsOffline) {
AbstractThread::MainThread()->Dispatch(NewRunnableMethod(
"dom::AudioDestinationNode::FireOfflineCompletionEvent", this,
&AudioDestinationNode::FireOfflineCompletionEvent));
}

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

@ -54,12 +54,7 @@ AudioNode::AudioNode(AudioContext* aContext, uint32_t aChannelCount,
mChannelCountMode(aChannelCountMode),
mChannelInterpretation(aChannelInterpretation),
mId(gId++),
mPassThrough(false),
mAbstractMainThread(
aContext->GetOwnerGlobal()
? aContext->GetOwnerGlobal()->AbstractMainThreadFor(
TaskCategory::Other)
: nullptr) {
mPassThrough(false) {
MOZ_ASSERT(aContext);
aContext->RegisterNode(this);
}

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

@ -207,10 +207,6 @@ class AudioNode : public DOMEventTargetHelper, public nsSupportsWeakReference {
// type.
virtual const char* NodeType() const = 0;
// This can return nullptr, but only when the AudioNode has been created
// during document shutdown.
AbstractThread* GetAbstractMainThread() const { return mAbstractMainThread; }
const nsTArray<RefPtr<AudioParam>>& GetAudioParams() const { return mParams; }
private:
@ -286,9 +282,6 @@ class AudioNode : public DOMEventTargetHelper, public nsSupportsWeakReference {
// Whether the node just passes through its input. This is a devtools API
// that only works for some node types.
bool mPassThrough;
// DocGroup-specifc AbstractThread::MainThread() for MediaTrackGraph
// operations.
const RefPtr<AbstractThread> mAbstractMainThread;
};
} // namespace dom

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

@ -410,10 +410,7 @@ AudioNodeEngine::AudioNodeEngine(dom::AudioNode* aNode)
: mNode(aNode),
mNodeType(aNode ? aNode->NodeType() : nullptr),
mInputCount(aNode ? aNode->NumberOfInputs() : 1),
mOutputCount(aNode ? aNode->NumberOfOutputs() : 0),
mAbstractMainThread(aNode && aNode->GetAbstractMainThread()
? aNode->GetAbstractMainThread()
: AbstractThread::MainThread()) {
mOutputCount(aNode ? aNode->NumberOfOutputs() : 0) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(AudioNodeEngine);
}

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

@ -382,9 +382,6 @@ class AudioNodeEngine {
const char* const mNodeType;
const uint16_t mInputCount;
const uint16_t mOutputCount;
protected:
const RefPtr<AbstractThread> mAbstractMainThread;
};
} // namespace mozilla

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

@ -147,7 +147,8 @@ class DynamicsCompressorNodeEngine final : public AudioNodeEngine {
float mReduction;
};
mAbstractMainThread->Dispatch(do_AddRef(new Command(aTrack, aReduction)));
AbstractThread::MainThread()->Dispatch(
do_AddRef(new Command(aTrack, aReduction)));
}
private:

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

@ -204,8 +204,7 @@ bool MediaDecodeTask::Init() {
RefPtr<BufferMediaResource> resource =
new BufferMediaResource(static_cast<uint8_t*>(mBuffer), mLength);
mMainThread = mDecodeJob.mContext->GetOwnerGlobal()->AbstractMainThreadFor(
TaskCategory::Other);
mMainThread = AbstractThread::MainThread();
mPSupervisorTaskQueue =
TaskQueue::Create(GetMediaThreadPool(MediaThreadType::SUPERVISOR),

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

@ -74,14 +74,9 @@ JSObject* MediaElementAudioSourceNode::WrapObject(
void MediaElementAudioSourceNode::ListenForAllowedToPlay(
const MediaElementAudioSourceOptions& aOptions) {
if (!GetAbstractMainThread()) {
// The AudioContext must have been closed. It won't be able to start anyway.
return;
}
aOptions.mMediaElement->GetAllowedToPlayPromise()
->Then(
GetAbstractMainThread(), __func__,
AbstractThread::MainThread(), __func__,
// Capture by reference to bypass the mozilla-refcounted-inside-lambda
// static analysis. We capture a non-owning reference so as to allow
// cycle collection of the node. The reference is cleared via

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

@ -455,7 +455,7 @@ class ScriptProcessorNodeEngine final : public AudioNodeEngine {
RefPtr<Command> command =
new Command(aTrack, mInputBuffer.forget(), playbackTime);
mAbstractMainThread->Dispatch(command.forget());
AbstractThread::MainThread()->Dispatch(command.forget());
}
friend class ScriptProcessorNode;

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

@ -69,7 +69,7 @@ void WebAudioUtils::LogToDeveloperConsole(uint64_t aWindowID,
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
"dom::WebAudioUtils::LogToDeveloperConsole",
[aWindowID, aKey] { LogToDeveloperConsole(aWindowID, aKey); });
SchedulerGroup::Dispatch(TaskCategory::Other, task.forget());
SchedulerGroup::Dispatch(task.forget());
return;
}

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

@ -38,7 +38,6 @@ CubebDeviceEnumerator* CubebDeviceEnumerator::GetInstance() {
setClearOnShutdown();
} else {
SchedulerGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction("CubebDeviceEnumerator::::GetInstance()",
std::move(setClearOnShutdown)));
}

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

@ -818,8 +818,7 @@ PeerConnectionImpl::EnsureDataConnection(uint16_t aLocalPort,
return NS_OK;
}
nsCOMPtr<nsISerialEventTarget> target =
mWindow ? mWindow->EventTargetFor(TaskCategory::Other) : nullptr;
nsCOMPtr<nsISerialEventTarget> target = GetMainThreadSerialEventTarget();
Maybe<uint64_t> mms = aMMSSet ? Some(aMaxMessageSize) : Nothing();
if (auto res = DataChannelConnection::Create(this, target, mTransportHandler,
aLocalPort, aNumstreams, mms)) {

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

@ -283,9 +283,7 @@ void TextTrack::DispatchAsyncTrustedEvent(const nsString& aEventName) {
return;
}
RefPtr<TextTrack> self = this;
nsGlobalWindowInner::Cast(win)->Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
nsGlobalWindowInner::Cast(win)->Dispatch(NS_NewRunnableFunction(
"dom::TextTrack::DispatchAsyncTrustedEvent",
[self, aEventName]() { self->DispatchTrustedEvent(aEventName); }));
}

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

@ -58,8 +58,7 @@ TextTrackCue::TextTrackCue(nsPIDOMWindowInner* aOwnerWindow, double aStartTime,
mLine(0.0),
mReset(false, "TextTrackCue::mReset"),
mHaveStartedWatcher(false),
mWatchManager(
this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)) {
mWatchManager(this, AbstractThread::MainThread()) {
LOG("create TextTrackCue");
SetDefaultCueSettings();
MOZ_ASSERT(aOwnerWindow);
@ -80,8 +79,7 @@ TextTrackCue::TextTrackCue(nsPIDOMWindowInner* aOwnerWindow, double aStartTime,
mLine(0.0),
mReset(false, "TextTrackCue::mReset"),
mHaveStartedWatcher(false),
mWatchManager(
this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)) {
mWatchManager(this, AbstractThread::MainThread()) {
LOG("create TextTrackCue");
SetDefaultCueSettings();
MOZ_ASSERT(aOwnerWindow);

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

@ -132,13 +132,11 @@ void TextTrackList::CreateAndDispatchChangeEvent() {
event->SetTrusted(true);
nsCOMPtr<nsIRunnable> eventRunner = new TrackEventRunner(this, event);
nsGlobalWindowInner::Cast(win)->Dispatch(TaskCategory::Other,
eventRunner.forget());
nsGlobalWindowInner::Cast(win)->Dispatch(eventRunner.forget());
}
void TextTrackList::CreateAndDispatchTrackEventRunner(
TextTrack* aTrack, const nsAString& aEventName) {
DebugOnly<nsresult> rv;
nsCOMPtr<nsIEventTarget> target = GetMainThreadSerialEventTarget();
if (!target) {
// If we are not able to get the main-thread object we are shutting down.
@ -151,8 +149,8 @@ void TextTrackList::CreateAndDispatchTrackEventRunner(
TrackEvent::Constructor(this, aEventName, eventInit);
// Dispatch the TrackEvent asynchronously.
rv = target->Dispatch(do_AddRef(new TrackEventRunner(this, event)),
NS_DISPATCH_NORMAL);
DebugOnly<nsresult> rv = target->Dispatch(
do_AddRef(new TrackEventRunner(this, event)), NS_DISPATCH_NORMAL);
// If we are shutting down this can file but it's still ok.
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Dispatch failed");

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше