Don't throttle timers if a page is doing something that might be interesting
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Jun 2013 22:24:29 +0000 (22:24 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Jun 2013 22:24:29 +0000 (22:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=117273

Reviewed by Gavin Barraclough.

Make the decision about whether or not to throttle timers be
determined by the PageThrottler

* page/Page.cpp:
(WebCore::Page::throttleTimers):
(WebCore::Page::unthrottleTimers):
(WebCore::Page::setVisibilityState):
(WebCore::Page::hiddenPageDOMTimerThrottlingStateChanged):
* page/Page.h:
* page/PageThrottler.cpp:
(WebCore::PageThrottler::throttlePage):
(WebCore::PageThrottler::unthrottlePage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@151244 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageThrottler.cpp

index 5e8ba80..1893150 100644 (file)
@@ -1,3 +1,23 @@
+2013-06-05  Oliver Hunt  <oliver@apple.com>
+
+        Don't throttle timers if a page is doing something that might be interesting
+        https://bugs.webkit.org/show_bug.cgi?id=117273
+
+        Reviewed by Gavin Barraclough.
+
+        Make the decision about whether or not to throttle timers be
+        determined by the PageThrottler
+
+        * page/Page.cpp:
+        (WebCore::Page::throttleTimers):
+        (WebCore::Page::unthrottleTimers):
+        (WebCore::Page::setVisibilityState):
+        (WebCore::Page::hiddenPageDOMTimerThrottlingStateChanged):
+        * page/Page.h:
+        * page/PageThrottler.cpp:
+        (WebCore::PageThrottler::throttlePage):
+        (WebCore::PageThrottler::unthrottlePage):
+
 2013-06-05  Mark Salisbury  <mark.salisbury@hp.com>
 
         [WinCE,WinCairo] RenderThemeWin.cpp needs to include FrameSelection.h.
index 20dd862..4e83832 100644 (file)
@@ -1250,6 +1250,22 @@ void Page::checkSubframeCountConsistency() const
 }
 #endif
 
+void Page::throttleTimers()
+{
+#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
+    if (m_settings->hiddenPageDOMTimerThrottlingEnabled())
+        setTimerAlignmentInterval(Settings::hiddenPageDOMTimerAlignmentInterval());
+#endif
+}
+
+void Page::unthrottleTimers()
+{
+#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
+    if (m_settings->hiddenPageDOMTimerThrottlingEnabled())
+        setTimerAlignmentInterval(Settings::defaultDOMTimerAlignmentInterval());
+#endif
+}
+
 #if ENABLE(PAGE_VISIBILITY_API) || ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
 void Page::setVisibilityState(PageVisibilityState visibilityState, bool isInitialState)
 {
@@ -1265,17 +1281,12 @@ void Page::setVisibilityState(PageVisibilityState visibilityState, bool isInitia
 #endif
 
     if (visibilityState == WebCore::PageVisibilityStateHidden) {
-#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
-        if (m_settings->hiddenPageDOMTimerThrottlingEnabled())
-            setTimerAlignmentInterval(Settings::hiddenPageDOMTimerAlignmentInterval());
-#endif
+        if (m_pageThrottler->shouldThrottleTimers())
+            throttleTimers();
         if (m_settings->hiddenPageCSSAnimationSuspensionEnabled())
             mainFrame()->animation()->suspendAnimations();
     } else {
-#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
-        if (m_settings->hiddenPageDOMTimerThrottlingEnabled())
-            setTimerAlignmentInterval(Settings::defaultDOMTimerAlignmentInterval());
-#endif
+        unthrottleTimers();
         if (m_settings->hiddenPageCSSAnimationSuspensionEnabled())
             mainFrame()->animation()->resumeAnimations();
     }
@@ -1525,7 +1536,7 @@ void Page::hiddenPageDOMTimerThrottlingStateChanged()
 {
     if (m_settings->hiddenPageDOMTimerThrottlingEnabled()) {
 #if ENABLE(PAGE_VISIBILITY_API)
-        if (m_visibilityState == WebCore::PageVisibilityStateHidden)
+        if (m_pageThrottler->shouldThrottleTimers())
             setTimerAlignmentInterval(Settings::hiddenPageDOMTimerAlignmentInterval());
 #endif
     } else
index d2b4383..721e60b 100644 (file)
@@ -431,6 +431,9 @@ private:
 
     void collectPluginViews(Vector<RefPtr<PluginViewBase>, 32>& pluginViewBases);
 
+    void throttleTimers();
+    void unthrottleTimers();
+
     const OwnPtr<Chrome> m_chrome;
     OwnPtr<DragCaretController> m_dragCaretController;
 
index 5dd3894..19b0fc2 100644 (file)
@@ -77,6 +77,8 @@ void PageThrottler::throttlePage()
         if (frame->document())
             frame->document()->scriptedAnimationControllerSetThrottled(true);
     }
+
+    m_page->throttleTimers();
 }
 
 void PageThrottler::unthrottlePage()
@@ -96,6 +98,8 @@ void PageThrottler::unthrottlePage()
         if (frame->document())
             frame->document()->scriptedAnimationControllerSetThrottled(false);
     }
+
+    m_page->unthrottleTimers();
 }
 
 void PageThrottler::setThrottled(bool isThrottled)