Changeset 242058 in webkit
- Timestamp:
- Feb 25, 2019 3:11:19 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r242056 r242058 1 2019-02-25 Zalan Bujtas <zalan@apple.com> 2 3 [ContentChangeObserver] Move observing logic from DOMTimer to ContentChangeObserver 4 https://bugs.webkit.org/show_bug.cgi?id=194987 5 <rdar://problem/48342910> 6 7 Reviewed by Tim Horton. 8 9 Content obvservation logic should all move to the ContentChangeObserver class. 10 11 * page/DOMTimer.cpp: 12 (WebCore::DOMTimer::install): 13 (WebCore::DOMTimer::fired): 14 * page/Page.cpp: 15 (WebCore::Page::Page): 16 * page/Page.h: 17 (WebCore::Page::contentChangeObserver): 18 * page/ios/ContentChangeObserver.h: 19 * page/ios/ContentChangeObserver.mm: 20 (WebCore::ContentChangeObserver::ContentChangeObserver): 21 (WebCore::ContentChangeObserver::registerDOMTimerForContentObservationIfNeeded): 22 (WebCore::ContentChangeObserver::startObservingDOMTimer): 23 (WebCore::ContentChangeObserver::stopObservingDOMTimer): 24 (WebCore::ContentChangeObserver::containsObservedDOMTimer): 25 (WebCore::ContentChangeObserver::addObservedDOMTimer): 26 (WebCore::ContentChangeObserver::removeObservedDOMTimer): 27 1 28 2019-02-25 John Wilander <wilander@apple.com> 2 29 -
trunk/Source/WebCore/page/DOMTimer.cpp
r242041 r242058 43 43 44 44 #if PLATFORM(IOS_FAMILY) 45 #include "Chrome.h"46 #include "ChromeClient.h"47 45 #include "ContentChangeObserver.h" 48 #include "Frame.h"49 46 #endif 50 47 … … 225 222 if (NestedTimersMap* nestedTimers = NestedTimersMap::instanceForContext(context)) 226 223 nestedTimers->add(timer->m_timeoutId, *timer); 227 228 224 #if PLATFORM(IOS_FAMILY) 229 auto startObservingThisTimerIfNeeded = [&] { 230 if (!is<Document>(context)) 231 return; 232 if (context.activeDOMObjectsAreSuspended()) 233 return; 234 if (timeout > 250_ms || !singleShot) 235 return; 236 auto& contentChangeObserver = downcast<Document>(context).page()->contentChangeObserver(); 237 if (!contentChangeObserver.isObservingDOMTimerScheduling()) 238 return; 239 240 contentChangeObserver.setObservedContentChange(WKContentIndeterminateChange); 241 contentChangeObserver.addObservedDOMTimer(*timer); 242 LOG_WITH_STREAM(ContentObservation, stream << "DOMTimer::install: register this timer: (" << timer->m_timeoutId << ") and observe when it fires."); 243 }; 244 245 startObservingThisTimerIfNeeded(); 225 if (is<Document>(context)) 226 downcast<Document>(context).page()->contentChangeObserver().registerDOMTimerForContentObservationIfNeeded(*timer, timeout, singleShot); 246 227 #endif 247 228 return timer->m_timeoutId; … … 349 330 context.removeTimeout(m_timeoutId); 350 331 351 #if PLATFORM(IOS_FAMILY)352 auto isObservingLastTimer = false;353 auto shouldBeginObservingChanges = false;354 Page* page = nullptr;355 if (is<Document>(context) && downcast<Document>(context).page()) {356 page = downcast<Document>(context).page();357 auto& contentChangeObserver = page->contentChangeObserver();358 isObservingLastTimer = contentChangeObserver.countOfObservedDOMTimers() == 1;359 shouldBeginObservingChanges = contentChangeObserver.containsObservedDOMTimer(*this);360 }361 362 if (shouldBeginObservingChanges) {363 ASSERT(page);364 LOG_WITH_STREAM(ContentObservation, stream << "DOMTimer::fired: start observing (" << m_timeoutId << ") timer callback.");365 auto& contentChangeObserver = page->contentChangeObserver();366 contentChangeObserver.startObservingContentChanges();367 contentChangeObserver.startObservingStyleRecalcScheduling();368 contentChangeObserver.removeObservedDOMTimer(*this);369 }370 #endif371 372 332 // Keep track nested timer installs. 373 333 NestedTimersMap* nestedTimers = NestedTimersMap::instanceForContext(context); … … 375 335 nestedTimers->startTracking(); 376 336 337 #if PLATFORM(IOS_FAMILY) 338 Page* page = is<Document>(context) ? downcast<Document>(context).page() : nullptr; 339 if (page) 340 page->contentChangeObserver().startObservingDOMTimerExecute(*this); 341 #endif 377 342 m_action->execute(context); 378 379 343 #if PLATFORM(IOS_FAMILY) 380 if (shouldBeginObservingChanges) { 381 ASSERT(page); 382 LOG_WITH_STREAM(ContentObservation, stream << "DOMTimer::fired: stop observing (" << m_timeoutId << ") timer callback."); 383 auto& contentChangeObserver = page->contentChangeObserver(); 384 contentChangeObserver.stopObservingStyleRecalcScheduling(); 385 contentChangeObserver.stopObservingContentChanges(); 386 387 auto observedContentChange = contentChangeObserver.observedContentChange(); 388 // Check if the timer callback triggered either a sync or async style update. 389 auto inDeterminedState = observedContentChange == WKContentVisibilityChange || (isObservingLastTimer && observedContentChange == WKContentNoChange); 390 if (inDeterminedState) { 391 LOG_WITH_STREAM(ContentObservation, stream << "DOMTimer::fired(" << m_timeoutId << "): in determined state."); 392 page->chrome().client().observedContentChange(*downcast<Document>(context).frame()); 393 } else if (observedContentChange == WKContentIndeterminateChange) { 394 // An async style recalc has been scheduled. Let's observe it. 395 LOG_WITH_STREAM(ContentObservation, stream << "DOMTimer::fired(" << m_timeoutId << "): wait until next style recalc fires."); 396 contentChangeObserver.setShouldObserveNextStyleRecalc(true); 397 } 398 } 344 if (page) 345 page->contentChangeObserver().stopObservingDOMTimerExecute(*this); 399 346 #endif 400 347 -
trunk/Source/WebCore/page/Page.cpp
r242056 r242058 150 150 #endif 151 151 152 #if PLATFORM(IOS_FAMILY) 153 #include "ContentChangeObserver.h" 154 #endif 155 152 156 namespace WebCore { 153 157 … … 232 236 , m_webGLStateTracker(WTFMove(pageConfiguration.webGLStateTracker)) 233 237 , m_libWebRTCProvider(WTFMove(pageConfiguration.libWebRTCProvider)) 238 #if PLATFORM(IOS_FAMILY) 239 , m_contentChangeObserver(std::make_unique<ContentChangeObserver>(*this)) 240 #endif 234 241 , m_verticalScrollElasticity(ScrollElasticityAllowed) 235 242 , m_horizontalScrollElasticity(ScrollElasticityAllowed) -
trunk/Source/WebCore/page/Page.h
r242056 r242058 68 68 #endif 69 69 70 #if PLATFORM(IOS_FAMILY)71 #include "ContentChangeObserver.h"72 #endif73 74 70 namespace JSC { 75 71 class Debugger; … … 91 87 class ChromeClient; 92 88 class Color; 89 #if PLATFORM(IOS_FAMILY) 90 class ContentChangeObserver; 91 #endif 93 92 class ContextMenuClient; 94 93 class ContextMenuController; … … 258 257 #endif 259 258 #if PLATFORM(IOS_FAMILY) 260 ContentChangeObserver& contentChangeObserver() { return m_contentChangeObserver; }259 ContentChangeObserver& contentChangeObserver() { return *m_contentChangeObserver; } 261 260 #endif 262 261 LibWebRTCProvider& libWebRTCProvider() { return m_libWebRTCProvider.get(); } … … 817 816 #if PLATFORM(IOS_FAMILY) 818 817 bool m_enclosedInScrollableAncestorView { false }; 819 ContentChangeObserverm_contentChangeObserver;818 std::unique_ptr<ContentChangeObserver> m_contentChangeObserver; 820 819 #endif 821 820 -
trunk/Source/WebCore/page/ios/ContentChangeObserver.h
r242032 r242058 33 33 34 34 class DOMTimer; 35 class Page; 35 36 36 37 class ContentChangeObserver { 37 38 public: 38 ContentChangeObserver() = default; 39 ContentChangeObserver(Page&); 40 41 void registerDOMTimerForContentObservationIfNeeded(const DOMTimer&, Seconds timeout, bool singleShot); 42 void startObservingDOMTimerExecute(const DOMTimer&); 43 void stopObservingDOMTimerExecute(const DOMTimer&); 39 44 40 45 WEBCORE_EXPORT void startObservingContentChanges(); … … 44 49 WEBCORE_EXPORT void startObservingDOMTimerScheduling(); 45 50 WEBCORE_EXPORT void stopObservingDOMTimerScheduling(); 46 bool isObservingDOMTimerScheduling();47 51 48 WEBCORE_EXPORT void startObservingStyleRecalcScheduling();49 WEBCORE_EXPORT void stopObservingStyleRecalcScheduling();50 52 bool isObservingStyleRecalcScheduling(); 51 53 … … 56 58 WEBCORE_EXPORT WKContentChange observedContentChange(); 57 59 58 void addObservedDOMTimer(DOMTimer&); 59 void removeObservedDOMTimer(DOMTimer&); 60 bool containsObservedDOMTimer(DOMTimer&); 60 void removeObservedDOMTimer(const DOMTimer&); 61 bool containsObservedDOMTimer(const DOMTimer&); 61 62 WEBCORE_EXPORT unsigned countOfObservedDOMTimers(); 62 63 WEBCORE_EXPORT void clearObservedDOMTimers(); 64 65 private: 66 void addObservedDOMTimer(const DOMTimer&); 67 bool isObservingDOMTimerScheduling(); 68 69 void startObservingStyleRecalcScheduling(); 70 void stopObservingStyleRecalcScheduling(); 71 72 Page& m_page; 63 73 }; 64 74 -
trunk/Source/WebCore/page/ios/ContentChangeObserver.mm
r242032 r242058 27 27 28 28 #if PLATFORM(IOS_FAMILY) 29 #import "Chrome.h" 30 #import "ChromeClient.h" 29 31 #import "DOMTimer.h" 32 #import "Logging.h" 33 #import "Page.h" 30 34 #import "WKContentObservationInternal.h" 31 35 32 36 namespace WebCore { 37 38 ContentChangeObserver::ContentChangeObserver(Page& page) 39 : m_page(page) 40 { 41 } 42 43 void ContentChangeObserver::registerDOMTimerForContentObservationIfNeeded(const DOMTimer& timer, Seconds timeout, bool singleShot) 44 { 45 if (!m_page.mainFrame().document()) 46 return; 47 if (m_page.mainFrame().document()->activeDOMObjectsAreSuspended()) 48 return; 49 if (timeout > 250_ms || !singleShot) 50 return; 51 if (!isObservingDOMTimerScheduling()) 52 return; 53 setObservedContentChange(WKContentIndeterminateChange); 54 addObservedDOMTimer(timer); 55 LOG_WITH_STREAM(ContentObservation, stream << "registerDOMTimerForContentObservationIfNeeded: registed this timer: (" << &timer << ") and observe when it fires."); 56 } 57 58 void ContentChangeObserver::startObservingDOMTimerExecute(const DOMTimer& timer) 59 { 60 if (!containsObservedDOMTimer(timer)) 61 return; 62 LOG_WITH_STREAM(ContentObservation, stream << "startObservingDOMTimerExecute: start observing (" << &timer << ") timer callback."); 63 startObservingContentChanges(); 64 startObservingStyleRecalcScheduling(); 65 } 66 67 void ContentChangeObserver::stopObservingDOMTimerExecute(const DOMTimer& timer) 68 { 69 if (!containsObservedDOMTimer(timer)) 70 return; 71 removeObservedDOMTimer(timer); 72 stopObservingStyleRecalcScheduling(); 73 stopObservingContentChanges(); 74 auto observedContentChange = this->observedContentChange(); 75 // Check if the timer callback triggered either a sync or async style update. 76 auto inDeterminedState = observedContentChange == WKContentVisibilityChange || (!countOfObservedDOMTimers() && observedContentChange == WKContentNoChange); 77 78 LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: stop observing (" << &timer << ") timer callback."); 79 if (inDeterminedState) { 80 LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") in determined state."); 81 m_page.chrome().client().observedContentChange(m_page.mainFrame()); 82 } else if (observedContentChange == WKContentIndeterminateChange) { 83 // An async style recalc has been scheduled. Let's observe it. 84 LOG_WITH_STREAM(ContentObservation, stream << "stopObservingDOMTimerExecute: (" << &timer << ") wait until next style recalc fires."); 85 setShouldObserveNextStyleRecalc(true); 86 } 87 } 33 88 34 89 void ContentChangeObserver::startObservingContentChanges() … … 39 94 void ContentChangeObserver::stopObservingContentChanges() 40 95 { 41 WKStopObservingContentChanges(); 96 WKStopObservingContentChanges(); 42 97 } 43 98 44 99 bool ContentChangeObserver::isObservingContentChanges() 45 100 { 46 return WKObservingContentChanges(); 101 return WKObservingContentChanges(); 47 102 } 48 103 … … 107 162 } 108 163 109 bool ContentChangeObserver::containsObservedDOMTimer( DOMTimer& timer)164 bool ContentChangeObserver::containsObservedDOMTimer(const DOMTimer& timer) 110 165 { 111 return WebThreadContainsObservedDOMTimer( &timer);166 return WebThreadContainsObservedDOMTimer(const_cast<DOMTimer*>(&timer)); 112 167 } 113 168 114 void ContentChangeObserver::addObservedDOMTimer( DOMTimer& timer)169 void ContentChangeObserver::addObservedDOMTimer(const DOMTimer& timer) 115 170 { 116 WebThreadAddObservedDOMTimer( &timer);171 WebThreadAddObservedDOMTimer(const_cast<DOMTimer*>(&timer)); 117 172 } 118 173 119 void ContentChangeObserver::removeObservedDOMTimer( DOMTimer& timer)174 void ContentChangeObserver::removeObservedDOMTimer(const DOMTimer& timer) 120 175 { 121 WebThreadRemoveObservedDOMTimer( &timer);176 WebThreadRemoveObservedDOMTimer(const_cast<DOMTimer*>(&timer)); 122 177 } 123 178
Note: See TracChangeset
for help on using the changeset viewer.