Changeset 251975 in webkit
- Timestamp:
- Nov 3, 2019 12:01:55 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251974 r251975 1 2019-11-03 Ryosuke Niwa <rniwa@webkit.org> 2 3 Add a helper function to schedule a task to dispatch an event to ActiveDOMObject 4 https://bugs.webkit.org/show_bug.cgi?id=203714 5 6 Reviewed by Chris Dumez. 7 8 Added two helper static member functions queueTaskKeepingObjectAlive and queueTaskToDispatchEvent 9 to ActiveDOMObject and deployed them in ServiceWorkerContainer. 10 11 No new tests since there should be no behavioral changes. 12 13 * Headers.cmake: 14 * WebCore.xcodeproj/project.pbxproj: 15 * dom/AbstractEventLoop.h: 16 * dom/ActiveDOMObject.cpp: 17 (WebCore::ActiveDOMObject::queueTaskInEventLoop): Added. 18 * dom/ActiveDOMObject.h: 19 (WebCore::ActiveDOMObject::queueTaskKeepingObjectAlive): Added. 20 (WebCore::ActiveDOMObject::queueTaskToDispatchEvent): Added. 21 * dom/TaskSource.h: Added. 22 * workers/service/ServiceWorkerContainer.cpp: 23 (WebCore::ServiceWorkerContainer::ready): 24 (WebCore::ServiceWorkerContainer::getRegistration): 25 (WebCore::ServiceWorkerContainer::getRegistrations): 26 (WebCore::ServiceWorkerContainer::jobFailedWithException): 27 (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration): 28 (WebCore::ServiceWorkerContainer::jobResolvedWithUnregistrationResult): 29 (WebCore::ServiceWorkerContainer::jobFailedLoadingScript): 30 (WebCore::ServiceWorkerContainer::fireControllerChangeEvent): 31 (WebCore::ServiceWorkerContainer::enqueueTask): Deleted. 32 * workers/service/ServiceWorkerContainer.h: 33 1 34 2019-11-03 Andres Gonzalez <andresg_22@apple.com> 2 35 -
trunk/Source/WebCore/Headers.cmake
r251720 r251975 452 452 dom/StyledElement.h 453 453 dom/SuccessOr.h 454 dom/TaskSource.h 454 455 dom/Text.h 455 456 dom/TextEvent.h -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r251959 r251975 2856 2856 9AB1F38018E2489A00534743 /* CSSToLengthConversionData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AB1F37E18E2489A00534743 /* CSSToLengthConversionData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2857 2857 9B02E0C8235EAD2A004044B2 /* TextManipulationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B02E0C3235E76AA004044B2 /* TextManipulationController.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2858 9B0ABCAE236BB43100B45085 /* TaskSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B0ABCAC236BB40A00B45085 /* TaskSource.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2858 2859 9B24DE8E15194B9500C59C27 /* HTMLBDIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B24DE8C15194B9500C59C27 /* HTMLBDIElement.h */; }; 2859 2860 9B27FC60234D9ADB00394A46 /* WindowEventLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B27FC5E234D9ADA00394A46 /* WindowEventLoop.h */; }; … … 11112 11113 9B0ABCA323679ACF00B45085 /* WorkerEventLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerEventLoop.cpp; sourceTree = "<group>"; }; 11113 11114 9B0ABCA423679ACF00B45085 /* WorkerEventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerEventLoop.h; sourceTree = "<group>"; }; 11115 9B0ABCAC236BB40A00B45085 /* TaskSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TaskSource.h; sourceTree = "<group>"; }; 11114 11116 9B0FE8731D9E02DF004A8ACB /* DocumentOrShadowRoot.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DocumentOrShadowRoot.idl; sourceTree = "<group>"; }; 11115 11117 9B13257B1F3D2ABA00DAAB69 /* DataTransferItemList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransferItemList.cpp; sourceTree = "<group>"; }; … … 28178 28180 463EB6201B8789CB0096ED51 /* TagCollection.cpp */, 28179 28181 463EB6211B8789CB0096ED51 /* TagCollection.h */, 28182 9B0ABCAC236BB40A00B45085 /* TaskSource.h */, 28180 28183 0F26A7A72054C2270090A141 /* TemplateContentDocumentFragment.cpp */, 28181 28184 C65046A8167BFB5500CC2A4D /* TemplateContentDocumentFragment.h */, … … 32419 32422 3BB6B81122A7D313003A2A69 /* TabSize.h in Headers */, 32420 32423 463EB6231B8789E00096ED51 /* TagCollection.h in Headers */, 32424 9B0ABCAE236BB43100B45085 /* TaskSource.h in Headers */, 32421 32425 F55B3DD61251F12D003EF269 /* TelephoneInputType.h in Headers */, 32422 32426 7CC564B818BABEA6001B9652 /* TelephoneNumberDetector.h in Headers */, -
trunk/Source/WebCore/dom/AbstractEventLoop.h
r251953 r251975 26 26 #pragma once 27 27 28 #include "TaskSource.h" 28 29 #include <wtf/Function.h> 29 30 #include <wtf/RefCounted.h> … … 32 33 33 34 class ScriptExecutionContext; 34 35 enum class TaskSource : uint8_t {36 DOMManipulation,37 FileReading,38 IdleTask,39 Networking,40 UserInteraction41 };42 35 43 36 // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop -
trunk/Source/WebCore/dom/ActiveDOMObject.cpp
r251327 r251975 28 28 #include "ActiveDOMObject.h" 29 29 30 #include "AbstractEventLoop.h" 30 31 #include "Document.h" 31 32 #include "ScriptExecutionContext.h" … … 131 132 } 132 133 134 void ActiveDOMObject::queueTaskInEventLoop(TaskSource source, Function<void ()>&& task) 135 { 136 auto* context = scriptExecutionContext(); 137 if (!context) 138 return; 139 context->eventLoop().queueTask(source, *context, WTFMove(task)); 140 } 141 133 142 } // namespace WebCore -
trunk/Source/WebCore/dom/ActiveDOMObject.h
r251327 r251975 28 28 29 29 #include "ContextDestructionObserver.h" 30 #include "TaskSource.h" 30 31 #include <wtf/Assertions.h> 31 32 #include <wtf/Forward.h> 33 #include <wtf/Function.h> 32 34 #include <wtf/RefCounted.h> 33 35 #include <wtf/Threading.h> … … 118 120 virtual ~ActiveDOMObject(); 119 121 122 template<typename T> 123 static void queueTaskKeepingObjectAlive(T& object, TaskSource source, Function<void ()>&& task) 124 { 125 object.queueTaskInEventLoop(source, [protectedObject = makeRef(object), activity = object.makePendingActivity(object), task = WTFMove(task)] () { 126 task(); 127 }); 128 } 129 130 template<typename EventTargetType, typename EventType> 131 static void queueTaskToDispatchEvent(EventTargetType& target, TaskSource source, Ref<EventType>&& event) 132 { 133 ASSERT(!event->target() || &target == event->target()); 134 queueTaskKeepingObjectAlive(target, source, [&target, event = WTFMove(event)] () mutable { 135 target.dispatchEvent(event.get()); 136 }); 137 } 138 120 139 private: 121 140 enum CheckedScriptExecutionContextType { CheckedScriptExecutionContext }; 122 141 ActiveDOMObject(ScriptExecutionContext*, CheckedScriptExecutionContextType); 142 143 void queueTaskInEventLoop(TaskSource, Function<void ()>&&); 123 144 124 145 unsigned m_pendingActivityCount { 0 }; -
trunk/Source/WebCore/dom/TaskSource.h
r251974 r251975 26 26 #pragma once 27 27 28 #include <wtf/Function.h>29 #include <wtf/RefCounted.h>30 31 28 namespace WebCore { 32 33 class ScriptExecutionContext;34 29 35 30 enum class TaskSource : uint8_t { … … 41 36 }; 42 37 43 // https://html.spec.whatwg.org/multipage/webappapis.html#event-loop44 class AbstractEventLoop : public RefCounted<AbstractEventLoop> {45 public:46 virtual ~AbstractEventLoop() = default;47 48 typedef WTF::Function<void ()> TaskFunction;49 virtual void queueTask(TaskSource, ScriptExecutionContext&, TaskFunction&&) = 0;50 51 protected:52 AbstractEventLoop() = default;53 };54 55 38 } // namespace WebCore -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp
r251934 r251975 110 110 auto& context = *scriptExecutionContext(); 111 111 ensureSWClientConnection().whenRegistrationReady(context.topOrigin().data(), context.url(), [this, protectedThis = makeRef(*this)](auto&& registrationData) mutable { 112 enqueueTask([this, registrationData = WTFMove(registrationData)]() mutable {112 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, registrationData = WTFMove(registrationData)]() mutable { 113 113 auto registration = ServiceWorkerRegistration::getOrCreate(*scriptExecutionContext(), *this, WTFMove(registrationData)); 114 114 m_readyPromise->resolve(WTFMove(registration)); … … 272 272 273 273 ensureSWClientConnection().matchRegistration(SecurityOriginData { context.topOrigin().data() }, parsedURL, [this, protectedThis = makeRef(*this), promise = WTFMove(promise)](auto&& result) mutable { 274 enqueueTask([this, promise = WTFMove(promise), result = WTFMove(result)]() mutable {274 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), result = WTFMove(result)]() mutable { 275 275 if (!result) { 276 276 promise->resolve(); … … 304 304 auto& context = *scriptExecutionContext(); 305 305 ensureSWClientConnection().getRegistrations(SecurityOriginData { context.topOrigin().data() }, context.url(), [this, protectedThis = makeRef(*this), promise = WTFMove(promise)] (auto&& registrationDatas) mutable { 306 enqueueTask([this, promise = WTFMove(promise), registrationDatas = WTFMove(registrationDatas)]() mutable {306 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), registrationDatas = WTFMove(registrationDatas)]() mutable { 307 307 auto registrations = WTF::map(WTFMove(registrationDatas), [&](auto&& registrationData) { 308 308 return ServiceWorkerRegistration::getOrCreate(*scriptExecutionContext(), *this, WTFMove(registrationData)); … … 336 336 return; 337 337 338 enqueueTask([promise = WTFMove(promise), exception]() mutable {338 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [promise = WTFMove(promise), exception]() mutable { 339 339 promise->reject(exception); 340 340 }); … … 381 381 return; 382 382 383 enqueueTask([this, promise = WTFMove(promise), jobIdentifier = job.identifier(), data = WTFMove(data), shouldNotifyWhenResolved, notifyIfExitEarly = WTFMove(notifyIfExitEarly)]() mutable {383 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [this, promise = WTFMove(promise), jobIdentifier = job.identifier(), data = WTFMove(data), shouldNotifyWhenResolved, notifyIfExitEarly = WTFMove(notifyIfExitEarly)]() mutable { 384 384 notifyIfExitEarly.release(); 385 385 … … 436 436 } 437 437 438 enqueueTask([promise = job.takePromise(), unregistrationResult]() mutable {438 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [promise = job.takePromise(), unregistrationResult]() mutable { 439 439 promise->resolve<IDLBoolean>(unregistrationResult); 440 440 }); … … 483 483 484 484 if (auto promise = job.takePromise()) { 485 enqueueTask([promise = WTFMove(promise), exception = WTFMove(exception)]() mutable {485 queueTaskKeepingObjectAlive(*this, TaskSource::DOMManipulation, [promise = WTFMove(promise), exception = WTFMove(exception)]() mutable { 486 486 promise->reject(WTFMove(exception)); 487 487 }); … … 553 553 #endif 554 554 555 enqueueTask([this] { 556 dispatchEvent(Event::create(eventNames().controllerchangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 557 }); 555 queueTaskToDispatchEvent(*this, TaskSource::DOMManipulation, Event::create(eventNames().controllerchangeEvent, Event::CanBubble::No, Event::IsCancelable::No)); 558 556 } 559 557 … … 619 617 } 620 618 621 void ServiceWorkerContainer::enqueueTask(Function<void()>&& task)622 {623 auto* context = scriptExecutionContext();624 if (!context)625 return;626 context->eventLoop().queueTask(TaskSource::DOMManipulation, *context, [protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this), task = WTFMove(task)] {627 task();628 });629 }630 631 619 } // namespace WebCore 632 620 -
trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h
r251934 r251975 95 95 private: 96 96 bool addEventListener(const AtomString& eventType, Ref<EventListener>&&, const AddEventListenerOptions& = { }) final; 97 void enqueueTask(Function<void()>&&);98 97 99 98 void scheduleJob(std::unique_ptr<ServiceWorkerJob>&&);
Note: See TracChangeset
for help on using the changeset viewer.