<video> playlist can not advance when playing in background tab
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2011 15:14:03 +0000 (15:14 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Aug 2011 15:14:03 +0000 (15:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66978

Reviewed by Darin Adler.

No new tests added because it isn't possible to simulate a background tab in DRT.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Set RequirePageConsentToLoadMedia restriction.
(WebCore::HTMLMediaElement::loadInternal): Don't consider page->canStartMedia if it has ever
    allowed a file to load.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::requirePageConsentToLoadMedia): New.
(WebCore::HTMLMediaElement::removeBehaviorRestriction): New.

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h

index c2273b7..a0c56f3 100644 (file)
@@ -1,3 +1,20 @@
+2011-08-26  Eric Carlson  <eric.carlson@apple.com>
+
+        <video> playlist can not advance when playing in background tab
+        https://bugs.webkit.org/show_bug.cgi?id=66978
+
+        Reviewed by Darin Adler.
+
+        No new tests added because it isn't possible to simulate a background tab in DRT.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement): Set RequirePageConsentToLoadMedia restriction.
+        (WebCore::HTMLMediaElement::loadInternal): Don't consider page->canStartMedia if it has ever
+            allowed a file to load.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::requirePageConsentToLoadMedia): New.
+        (WebCore::HTMLMediaElement::removeBehaviorRestriction): New.
+
 2011-08-26  Andreas Kling  <kling@webkit.org>
 
         [Qt] Path::boundingRect() is unnecessarily slow.
index 29388b6..496d260 100644 (file)
@@ -150,7 +150,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     , m_proxyWidget(0)
 #endif
-    , m_restrictions(RequireUserGestureForFullScreenRestriction)
+    , m_restrictions(RequireUserGestureForFullScreenRestriction | RequirePageConsentToLoadMedia)
     , m_preload(MediaPlayer::Auto)
     , m_displayMode(Unknown)
     , m_processingMediaPlayerCallback(0)
@@ -584,13 +584,18 @@ void HTMLMediaElement::loadInternal()
 {
     // If we can't start a load right away, start it later.
     Page* page = document()->page();
-    if (page && !page->canStartMedia()) {
+    if (requirePageConsentToLoadMedia() && page && !page->canStartMedia()) {
         if (m_isWaitingUntilMediaCanStart)
             return;
         document()->addMediaCanStartListener(this);
         m_isWaitingUntilMediaCanStart = true;
         return;
     }
+    
+    // Once the page has allowed an element to load media, it is free to load at will. This allows a 
+    // playlist that starts in a foreground tab to continue automatically if the tab is subsequently 
+    // put in the the background.
+    removeBehaviorRestriction(RequirePageConsentToLoadMedia);
 
     selectMediaResource();
 #if ENABLE(VIDEO_TRACK)
index ace5b06..d4df790 100644 (file)
@@ -184,13 +184,15 @@ public:
         NoRestrictions = 0,
         RequireUserGestureForLoadRestriction = 1 << 0,
         RequireUserGestureForRateChangeRestriction = 1 << 1,
-        RequireUserGestureForFullScreenRestriction = 1 << 2
+        RequireUserGestureForFullScreenRestriction = 1 << 2,
+        RequirePageConsentToLoadMedia = 1 << 3,
     };
     typedef unsigned BehaviorRestrictions;
     
     bool requireUserGestureForLoad() const { return m_restrictions & RequireUserGestureForLoadRestriction; }
     bool requireUserGestureForRateChange() const { return m_restrictions & RequireUserGestureForRateChangeRestriction; }
     bool requireUserGestureForFullScreen() const { return m_restrictions & RequireUserGestureForFullScreenRestriction; }
+    bool requirePageConsentToLoadMedia() const { return m_restrictions & RequirePageConsentToLoadMedia; }
 
     void setBehaviorRestrictions(BehaviorRestrictions restrictions) { m_restrictions = restrictions; }
 
@@ -332,6 +334,8 @@ private:
 
     virtual void mediaCanStart();
 
+    void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
+
     void setShouldDelayLoadEvent(bool);
 
     void invalidateCachedTime();