Throttle DOM timers on hidden pages.
https://bugs.webkit.org/show_bug.cgi?id=98474
Patch by Kiran Muppala <cmuppala@apple.com> on 2012-10-08
Reviewed by Maciej Stachowiak.
Source/JavaScriptCore:
Add HIDDEN_PAGE_DOM_TIMER_THROTTLING feature define.
* Configurations/FeatureDefines.xcconfig:
Source/WebCore:
When the visibility of a page changes to "hidden", all it's DOM timers are
updated to align their fire times on one second intervals. This limits the
number of CPU wakes due to a hidden pages to one per second.
Test: fast/dom/timer-throttling-hidden-page.html
* Configurations/FeatureDefines.xcconfig:
* WebCore.exp.in:
* dom/Document.cpp:
(WebCore):
(WebCore::Document::timerAlignmentInterval):
Read Page::timerAlignmentInterval and pass it along to DOMTimer.
* dom/Document.h:
(Document):
* dom/ScriptExecutionContext.cpp:
(WebCore):
(WebCore::ScriptExecutionContext::didChangeTimerAlignmentInterval):
Scan through self DOM Timers and tell them to recompute their fire
time based on the updated alignment interval.
(WebCore::ScriptExecutionContext::timerAlignmentInterval):
* dom/ScriptExecutionContext.h:
(ScriptExecutionContext):
* page/DOMTimer.cpp:
(WebCore):
(WebCore::DOMTimer::alignedFireTime):
If the document's alignment interval is non zero, round up the fire
time to the next multiple of alignment interval.
* page/DOMTimer.h:
(DOMTimer):
(WebCore::DOMTimer::defaultTimerAlignmentInterval):
(WebCore::DOMTimer::setDefaultTimerAlignmentInterval):
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore):
(WebCore::Page::setTimerAlignmentInterval):
(WebCore::Page::timerAlignmentInterval):
(WebCore::Page::setVisibilityState):
Getter and Setter for alignment interval. Expose setVisibilityState
if either PAGE_VISIBILITY_API is enabled or if HIDDEN_PAGE_DOM_TIMER_REDUCTION
is enabled.
* page/Page.h:
(Page):
* page/Settings.cpp:
(WebCore):
(WebCore::Settings::setDefaultDOMTimerAlignmentInterval):
(WebCore::Settings::defaultDOMTimerAlignmentInterval):
(WebCore::Sett