Title: [150971] trunk/Source/WebCore
Revision
150971
Author
[email protected]
Date
2013-05-30 11:19:00 -0700 (Thu, 30 May 2013)

Log Message

HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause.
https://bugs.webkit.org/show_bug.cgi?id=117016

Reviewed by Oliver Hunt.

Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple
knowledge of and control over the lifetime of PageThrottler. The new class will
have weak references to and from the PageThrottler so that holders of the token
will not need to care if the Page or PageThrottler has been destroyed.

HTMLMediaElement will create one of these PageActivityAssertionTokens when playback
begins and destroy it when playback stops for any reason, or when the element is
destroyed.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::~HTMLMediaElement):
(WebCore::HTMLMediaElement::playInternal):
(WebCore::HTMLMediaElement::pauseInternal):
(WebCore::HTMLMediaElement::playbackProgressTimerFired):
(WebCore::HTMLMediaElement::updatePlayState):
* html/HTMLMediaElement.h:
* page/Page.cpp:
(WebCore::createActivityToken): Added simple factory method.
* page/Page.h:
* page/PageActivityAssertionToken.cpp:
(WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken();
(WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken();
(WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler.
* page/PageActivityAssertionToken.h:
* page/PageThrottler.cpp:
(WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens.
(WebCore::PageThrottler::addActivityToken): Bump the activity count.
(WebCore::PageThrottler::removeActivityToken): Lower the activity count.
* page/PageThrottler.h:

Add the new files to the various build systems:
* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (150970 => 150971)


--- trunk/Source/WebCore/CMakeLists.txt	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/CMakeLists.txt	2013-05-30 18:19:00 UTC (rev 150971)
@@ -1753,6 +1753,7 @@
     page/NavigatorBase.cpp
     page/OriginAccessEntry.cpp
     page/Page.cpp
+    page/PageActivityAssertionToken.cpp
     page/PageConsole.cpp
     page/PageGroup.cpp
     page/PageGroupLoadDeferrer.cpp

Modified: trunk/Source/WebCore/ChangeLog (150970 => 150971)


--- trunk/Source/WebCore/ChangeLog	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/ChangeLog	2013-05-30 18:19:00 UTC (rev 150971)
@@ -1,3 +1,49 @@
+2013-05-30  Jer Noble  <[email protected]>
+
+        HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause.
+        https://bugs.webkit.org/show_bug.cgi?id=117016
+
+        Reviewed by Oliver Hunt.
+
+        Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple
+        knowledge of and control over the lifetime of PageThrottler. The new class will
+        have weak references to and from the PageThrottler so that holders of the token
+        will not need to care if the Page or PageThrottler has been destroyed. 
+
+        HTMLMediaElement will create one of these PageActivityAssertionTokens when playback
+        begins and destroy it when playback stops for any reason, or when the element is
+        destroyed.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::~HTMLMediaElement):
+        (WebCore::HTMLMediaElement::playInternal):
+        (WebCore::HTMLMediaElement::pauseInternal):
+        (WebCore::HTMLMediaElement::playbackProgressTimerFired):
+        (WebCore::HTMLMediaElement::updatePlayState):
+        * html/HTMLMediaElement.h:
+        * page/Page.cpp:
+        (WebCore::createActivityToken): Added simple factory method.
+        * page/Page.h:
+        * page/PageActivityAssertionToken.cpp: 
+        (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken();
+        (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken();
+        (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler.
+        * page/PageActivityAssertionToken.h:
+        * page/PageThrottler.cpp:
+        (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens.
+        (WebCore::PageThrottler::addActivityToken): Bump the activity count.
+        (WebCore::PageThrottler::removeActivityToken): Lower the activity count.
+        * page/PageThrottler.h:
+
+        Add the new files to the various build systems:
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2013-05-29  Jeffrey Pfau  <[email protected]>
 
         [Mac] Enable cache partitioning and the public suffix list on 10.8

Modified: trunk/Source/WebCore/GNUmakefile.list.am (150970 => 150971)


--- trunk/Source/WebCore/GNUmakefile.list.am	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2013-05-30 18:19:00 UTC (rev 150971)
@@ -4251,6 +4251,8 @@
 	Source/WebCore/page/OriginAccessEntry.h \
 	Source/WebCore/page/Page.cpp \
 	Source/WebCore/page/Page.h \
+	Source/WebCore/page/PageActivityAssertionToken.h \
+	Source/WebCore/page/PageActivityAssertionToken.cpp \
 	Source/WebCore/page/PageConsole.cpp \
 	Source/WebCore/page/PageConsole.h \
 	Source/WebCore/page/PageGroup.cpp \

Modified: trunk/Source/WebCore/Target.pri (150970 => 150971)


--- trunk/Source/WebCore/Target.pri	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/Target.pri	2013-05-30 18:19:00 UTC (rev 150971)
@@ -931,6 +931,7 @@
     page/NavigatorBase.cpp \
     page/OriginAccessEntry.cpp \
     page/Page.cpp \
+    page/PageActivityAssertionToken.cpp \
     page/PageConsole.cpp \
     page/PageGroup.cpp \
     page/PageGroupLoadDeferrer.cpp \
@@ -2100,6 +2101,7 @@
     page/PageGroup.h \
     page/PageGroupLoadDeferrer.h \
     page/Page.h \
+    page/PageActivityAssertionToken.h \
     page/PageConsole.h \
     page/PageThrottler.h \
     page/PageVisibilityState.h \

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (150970 => 150971)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2013-05-30 18:19:00 UTC (rev 150971)
@@ -27578,6 +27578,14 @@
 				RelativePath="..\page\Page.cpp"
 				>
 			</File>
+			<File
+				RelativePath="..\page\PageActivityAssertionToken.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\page\PageActivityAssertionToken.h"
+				>
+			</File>
              <File
 				RelativePath="..\page\PageConsole.cpp"
 				>

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (150970 => 150971)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2013-05-30 18:19:00 UTC (rev 150971)
@@ -3933,6 +3933,7 @@
     <ClCompile Include="..\page\NavigatorBase.cpp" />
     <ClCompile Include="..\page\OriginAccessEntry.cpp" />
     <ClCompile Include="..\page\Page.cpp" />
+    <ClCompile Include="..\page\PageActivityAssertionToken.cpp" />
     <ClCompile Include="..\page\PageConsole.cpp" />
     <ClCompile Include="..\page\PageGroup.cpp" />
     <ClCompile Include="..\page\PageGroupLoadDeferrer.cpp" />

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (150970 => 150971)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2013-05-30 18:19:00 UTC (rev 150971)
@@ -5223,6 +5223,9 @@
     <ClCompile Include="..\page\Page.cpp">
       <Filter>page</Filter>
     </ClCompile>
+    <ClCompile Include="..\page\PageActivityAssertionToken.cpp">
+      <Filter>page</Filter>
+    </ClCompile>
     <ClCompile Include="..\page\PageConsole.cpp">
       <Filter>page</Filter>
     </ClCompile>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (150970 => 150971)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-05-30 18:19:00 UTC (rev 150971)
@@ -5178,6 +5178,7 @@
 		CCC2B51415F613060048CDD6 /* DeviceClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51015F613060048CDD6 /* DeviceClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CCC2B51515F613060048CDD6 /* DeviceController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCC2B51115F613060048CDD6 /* DeviceController.cpp */; };
 		CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51215F613060048CDD6 /* DeviceController.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */; };
 		CD0EEE0E14743F39003EAFA2 /* AudioDestinationIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */; };
 		CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
 		CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11900,6 +11901,8 @@
 		CCC2B51015F613060048CDD6 /* DeviceClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceClient.h; sourceTree = "<group>"; };
 		CCC2B51115F613060048CDD6 /* DeviceController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceController.cpp; sourceTree = "<group>"; };
 		CCC2B51215F613060048CDD6 /* DeviceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceController.h; sourceTree = "<group>"; };
+		CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PageActivityAssertionToken.cpp; sourceTree = "<group>"; };
+		CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageActivityAssertionToken.h; sourceTree = "<group>"; };
 		CD0EEE0A14743E34003EAFA2 /* AudioDestinationIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioDestinationIOS.h; path = ios/AudioDestinationIOS.h; sourceTree = "<group>"; };
 		CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioDestinationIOS.cpp; path = ios/AudioDestinationIOS.cpp; sourceTree = "<group>"; };
 		CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenWindow.h; sourceTree = "<group>"; };
@@ -14748,6 +14751,8 @@
 				00146289103CD1DE000B20DB /* OriginAccessEntry.h */,
 				65FEA86809833ADE00BED4AB /* Page.cpp */,
 				65A21467097A329100B9050A /* Page.h */,
+				CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */,
+				CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */,
 				9302B0BC0D79F82900C7EE83 /* PageGroup.cpp */,
 				9302B0BE0D79F82C00C7EE83 /* PageGroup.h */,
 				7A674BD90F9EBF4E006CF099 /* PageGroupLoadDeferrer.cpp */,
@@ -26928,6 +26933,7 @@
 				E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
 				977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
 				977E2E0E12F0FC9C00C13380 /* XSSAuditorDelegate.cpp in Sources */,
+				CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */,
 				FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
 				DAED203016F2442B0070EC0F /* PageConsole.cpp in Sources */,
 				E1BA003116FB92AC00BA7A35 /* ResourceHandleClient.cpp in Sources */,

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (150970 => 150971)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2013-05-30 18:19:00 UTC (rev 150971)
@@ -69,8 +69,8 @@
 #include "MIMETypeRegistry.h"
 #include "NodeRenderingContext.h"
 #include "Page.h"
+#include "PageActivityAssertionToken.h"
 #include "PageGroup.h"
-#include "PageThrottler.h"
 #include "RenderVideo.h"
 #include "RenderView.h"
 #include "ScriptController.h"
@@ -346,10 +346,6 @@
 {
     LOG(Media, "HTMLMediaElement::~HTMLMediaElement");
 
-    if (!m_paused && m_pageThrottler) {
-        m_pageThrottler->allowThrottling();
-        m_pageThrottler.clear();
-    }
     if (m_isWaitingUntilMediaCanStart)
         document()->removeMediaCanStartListener(this);
     setShouldDelayLoadEvent(false);
@@ -2483,20 +2479,6 @@
     playInternal();
 }
 
-PageThrottler* HTMLMediaElement::pageThrottlerIfPossible()
-{
-    if (m_pageThrottler)
-        return m_pageThrottler.get();
-
-    if (!document())
-        return 0;
-
-    if (Page* page = document()->page())
-        m_pageThrottler = page->pageThrottler();
-    
-    return m_pageThrottler.get();
-}
-
 void HTMLMediaElement::playInternal()
 {
     LOG(Media, "HTMLMediaElement::playInternal");
@@ -2512,8 +2494,6 @@
         m_mediaController->bringElementUpToSpeed(this);
 
     if (m_paused) {
-        if (PageThrottler* throttler = pageThrottlerIfPossible())
-            throttler->preventThrottling();
         m_paused = false;
         invalidateCachedTime();
         scheduleEvent(eventNames().playEvent);
@@ -2550,8 +2530,6 @@
     m_autoplaying = false;
 
     if (!m_paused) {
-        if (PageThrottler* throttler = m_pageThrottler.get())
-            throttler->preventThrottling();
         m_paused = true;
         scheduleTimeupdateEvent(false);
         scheduleEvent(eventNames().pauseEvent);
@@ -2825,7 +2803,7 @@
 
     if (!m_paused && hasMediaControls())
         mediaControls()->playbackProgressed();
-    
+
 #if ENABLE(VIDEO_TRACK)
     if (RuntimeEnabledFeatures::webkitVideoTrackEnabled())
         updateActiveTextTrackCues(currentTime());
@@ -4002,6 +3980,7 @@
         m_playbackProgressTimer.stop();
         if (hasMediaControls())
             mediaControls()->playbackStopped();
+        m_activityToken = nullptr;
         return;
     }
     
@@ -4029,6 +4008,9 @@
 
         if (hasMediaControls())
             mediaControls()->playbackStarted();
+        if (document()->page())
+            m_activityToken = document()->page()->createActivityToken();
+
         startPlaybackProgressTimer();
         m_playing = true;
 
@@ -4048,6 +4030,7 @@
 
         if (hasMediaControls())
             mediaControls()->playbackStopped();
+        m_activityToken = nullptr;
     }
 
     updateMediaController();

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (150970 => 150971)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2013-05-30 18:19:00 UTC (rev 150971)
@@ -63,7 +63,7 @@
 class MediaController;
 class MediaControls;
 class MediaError;
-class PageThrottler;
+class PageActivityAssertionToken;
 class TimeRanges;
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
 class Widget;
@@ -756,9 +756,6 @@
     friend class MediaController;
     RefPtr<MediaController> m_mediaController;
 
-    PageThrottler* pageThrottlerIfPossible();
-    RefPtr<PageThrottler> m_pageThrottler;
-
 #if PLATFORM(MAC)
     OwnPtr<DisplaySleepDisabler> m_sleepDisabler;
 #endif
@@ -776,6 +773,8 @@
 #if USE(AUDIO_SESSION)
     OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
 #endif
+
+    OwnPtr<PageActivityAssertionToken> m_activityToken;
 };
 
 #if ENABLE(VIDEO_TRACK)

Modified: trunk/Source/WebCore/page/Page.cpp (150970 => 150971)


--- trunk/Source/WebCore/page/Page.cpp	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/page/Page.cpp	2013-05-30 18:19:00 UTC (rev 150971)
@@ -56,6 +56,7 @@
 #include "MediaCanStartListener.h"
 #include "Navigator.h"
 #include "NetworkStateNotifier.h"
+#include "PageActivityAssertionToken.h"
 #include "PageCache.h"
 #include "PageConsole.h"
 #include "PageGroup.h"
@@ -1514,6 +1515,11 @@
     m_seenMediaEngines.clear();
 }
 
+PassOwnPtr<PageActivityAssertionToken> Page::createActivityToken()
+{
+    return adoptPtr(new PageActivityAssertionToken(m_pageThrottler.get()));
+}
+
 #if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
 void Page::hiddenPageDOMTimerThrottlingStateChanged()
 {

Modified: trunk/Source/WebCore/page/Page.h (150970 => 150971)


--- trunk/Source/WebCore/page/Page.h	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/page/Page.h	2013-05-30 18:19:00 UTC (rev 150971)
@@ -75,6 +75,7 @@
 class InspectorController;
 class MediaCanStartListener;
 class Node;
+class PageActivityAssertionToken;
 class PageConsole;
 class PageGroup;
 class PageThrottler;
@@ -394,6 +395,7 @@
     void resetSeenMediaEngines();
 
     PageThrottler* pageThrottler() { return m_pageThrottler.get(); }
+    PassOwnPtr<PageActivityAssertionToken> createActivityToken();
 
     PageConsole* console() { return m_console.get(); }
 

Copied: trunk/Source/WebCore/page/PageActivityAssertionToken.cpp (from rev 150970, trunk/Source/WebCore/page/PageThrottler.h) (0 => 150971)


--- trunk/Source/WebCore/page/PageActivityAssertionToken.cpp	                        (rev 0)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.cpp	2013-05-30 18:19:00 UTC (rev 150971)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PageActivityAssertionToken.h"
+
+#include "PageThrottler.h"
+
+namespace WebCore {
+
+PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler* throttler)
+    :m_throttler(throttler)
+{
+    if (m_throttler)
+        m_throttler->addActivityToken(this);
+}
+
+PageActivityAssertionToken::~PageActivityAssertionToken()
+{
+    if (m_throttler)
+        m_throttler->removeActivityToken(this);
+}
+
+void PageActivityAssertionToken::invalidate()
+{
+    m_throttler = 0;
+}
+
+}
+
+

Copied: trunk/Source/WebCore/page/PageActivityAssertionToken.h (from rev 150970, trunk/Source/WebCore/page/PageThrottler.h) (0 => 150971)


--- trunk/Source/WebCore/page/PageActivityAssertionToken.h	                        (rev 0)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.h	2013-05-30 18:19:00 UTC (rev 150971)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PageActivityAssertionToken_h
+#define PageActivityAssertionToken_h
+
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class PageThrottler;
+
+class PageActivityAssertionToken {
+    WTF_MAKE_NONCOPYABLE(PageActivityAssertionToken);
+public:
+    ~PageActivityAssertionToken();
+
+    void invalidate();
+
+private:
+    friend class Page;
+    PageActivityAssertionToken(PageThrottler*);
+
+    PageThrottler* m_throttler;
+};
+
+}
+
+#endif // PageActivityAssertionToken_h

Modified: trunk/Source/WebCore/page/PageThrottler.cpp (150970 => 150971)


--- trunk/Source/WebCore/page/PageThrottler.cpp	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/page/PageThrottler.cpp	2013-05-30 18:19:00 UTC (rev 150971)
@@ -30,6 +30,7 @@
 #include "ChromeClient.h"
 #include "Frame.h"
 #include "Page.h"
+#include "PageActivityAssertionToken.h"
 
 namespace WebCore {
 
@@ -47,6 +48,9 @@
 
 PageThrottler::~PageThrottler()
 {
+    for (HashSet<PageActivityAssertionToken*>::iterator i = m_activityTokens.begin(); i != m_activityTokens.end(); ++i)
+        (*i)->invalidate();
+
     if (m_throttleState != PageThrottledState && m_page) {
         if (ChromeClient* chromeClient = m_page->chrome().client())
             chromeClient->decrementActivePageCount();
@@ -165,4 +169,22 @@
     throttlePage();
 }
 
+void PageThrottler::addActivityToken(PageActivityAssertionToken* token)
+{
+    if (!token || m_activityTokens.contains(token))
+        return;
+
+    m_activityTokens.add(token);
+    preventThrottling();
 }
+
+void PageThrottler::removeActivityToken(PageActivityAssertionToken* token)
+{
+    if (!token || !m_activityTokens.contains(token))
+        return;
+
+    m_activityTokens.remove(token);
+    allowThrottling();
+}
+
+}

Modified: trunk/Source/WebCore/page/PageThrottler.h (150970 => 150971)


--- trunk/Source/WebCore/page/PageThrottler.h	2013-05-30 17:52:33 UTC (rev 150970)
+++ trunk/Source/WebCore/page/PageThrottler.h	2013-05-30 18:19:00 UTC (rev 150971)
@@ -28,11 +28,13 @@
 
 #include "Timer.h"
 
+#include <wtf/HashSet.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
 
 class Page;
+class PageActivityAssertionToken;
 
 class PageThrottler : public RefCounted<PageThrottler> {
 public:
@@ -60,6 +62,10 @@
         PageThrottledState
     };
 
+    friend class PageActivityAssertionToken;
+    void addActivityToken(PageActivityAssertionToken*);
+    void removeActivityToken(PageActivityAssertionToken*);
+
     PageThrottler(Page*);
     void startThrottleHysteresisTimer();
     void stopThrottleHysteresisTimer();
@@ -73,6 +79,7 @@
     unsigned m_activeThrottleBlockers;
     PageThrottleState m_throttleState;
     Timer<PageThrottler> m_throttleHysteresisTimer;
+    HashSet<PageActivityAssertionToken*> m_activityTokens;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to