Media engine should not be told to prepare for playback if media loading is not allowed
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 19:58:10 +0000 (19:58 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 19:58:10 +0000 (19:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83620

Reviewed by Dan Bernstein.

Source/WebCore:

Test: media/video-load-require-user-gesture.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::load): Early return if user gesture requirement is not met.

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setMediaPlaybackRequiresUserGesture): Moved the method here from
    Internals to be with the rest of the Internals methods that expose preferences.
* testing/InternalSettings.h:
* testing/InternalSettings.idl:

* testing/Internals.cpp: Moved setMediaPlaybackRequiresUserGesture to InternalSettings.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/video-load-require-user-gesture-expected.txt: Added.
* media/video-load-require-user-gesture.html: Added.
* media/video-play-require-user-gesture.html: Update for move of setMediaPlaybackRequiresUserGesture
    from window.internals to window.internals.settings.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/media/video-load-require-user-gesture-expected.txt [new file with mode: 0644]
LayoutTests/media/video-load-require-user-gesture.html [new file with mode: 0644]
LayoutTests/media/video-play-require-user-gesture.html
LayoutTests/platform/efl/Skipped
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 2bfb56a..06e4c07 100644 (file)
@@ -1,3 +1,16 @@
+2012-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Media engine should not be told to prepare for playback if media loading is not allowed
+        https://bugs.webkit.org/show_bug.cgi?id=83620
+
+        Reviewed by Dan Bernstein.
+
+        * platform/efl/Skipped: Skipped new test because it requires preload=none support.
+        * media/video-load-require-user-gesture-expected.txt: Added.
+        * media/video-load-require-user-gesture.html: Added.
+        * media/video-play-require-user-gesture.html: Update for move of setMediaPlaybackRequiresUserGesture
+            from window.internals to window.internals.settings.
+
 2012-04-12  Bear Travis  <betravis@adobe.com>
 
         [CSS Exclusions] Add flag to enable / disable exclusions at runtime
diff --git a/LayoutTests/media/video-load-require-user-gesture-expected.txt b/LayoutTests/media/video-load-require-user-gesture-expected.txt
new file mode 100644 (file)
index 0000000..3aa1842
--- /dev/null
@@ -0,0 +1,9 @@
+Test that video.load() should not cause media loading when user gesture is required.
+
+* Setting video.src, no data should load.
+
+* Calling video.load(). It should throw an exception, and no data should load.
+TEST(video.load()) THROWS(DOMException.INVALID_STATE_ERR) OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/video-load-require-user-gesture.html b/LayoutTests/media/video-load-require-user-gesture.html
new file mode 100644 (file)
index 0000000..d1cb743
--- /dev/null
@@ -0,0 +1,56 @@
+<html>
+    <head>
+        <script src=media-file.js></script>
+        <script src=video-test.js></script>
+        <script>
+            var state = 0;
+            var userGestureInitiated = 0;
+
+            if (window.internals) 
+                window.internals.settings.setMediaPlaybackRequiresUserGesture(document, true);
+
+            function finishTest(success)
+            {
+                if (window.internals) 
+                    window.internals.settings.setMediaPlaybackRequiresUserGesture(document, false);
+
+                if (success)
+                    endTest();
+                else
+                    failTest("<b>Data loaded despite restriction.</b>");
+            }
+
+            function checkLoad()
+            {
+                consoleWrite("");
+
+                if (state == "load")
+                {
+                    finishTest(true);
+                    return;
+                }
+                
+                state = "load";
+                consoleWrite("* Calling video.load(). It should throw an exception, and no data should load.");
+                testException("video.load()", "DOMException.INVALID_STATE_ERR");
+                setTimeout(checkLoad, 250);
+            }
+
+            function start()
+            {
+                findMediaElement();
+                waitForEvent('loadedmetadata', function() { finishTest(false) } );
+
+                state = "src";
+                consoleWrite("* Setting video.src, no data should load.");
+                video.src = findMediaFile("video", "content/test");
+                setTimeout(checkLoad, 250);
+            }
+        </script>
+    </head>
+
+    <body onload="start()">
+        <video controls preload=none></video>
+        <p>Test that video.load() should not cause media loading when user gesture is required.</p>
+    </body>
+</html>
index 74edab1..dd3a868 100644 (file)
@@ -7,11 +7,11 @@
         <script>
             var userGestureInitiated = 0;
             if (window.internals) 
-                window.internals.setMediaPlaybackRequiresUserGesture(document, true);
+                window.internals.settings.setMediaPlaybackRequiresUserGesture(document, true);
 
             function cleanGestureRequirement() {
                 if (window.internals) 
-                    window.internals.setMediaPlaybackRequiresUserGesture(document, false);
+                    window.internals.settings.setMediaPlaybackRequiresUserGesture(document, false);
             }
 
             function click()
index 44cc4fc..24005c8 100644 (file)
@@ -1483,6 +1483,7 @@ media/video-layer-crash.html
 media/video-load-networkState.html
 media/video-load-preload-none.html
 media/video-load-readyState.html
+media/video-load-require-user-gesture.html
 media/video-muted.html
 media/video-no-autoplay.html
 media/video-pause-empty-events.html
index 2b74b24..1b9c3a5 100644 (file)
@@ -1,3 +1,25 @@
+2012-04-12  Eric Carlson  <eric.carlson@apple.com>
+
+        Media engine should not be told to prepare for playback if media loading is not allowed
+        https://bugs.webkit.org/show_bug.cgi?id=83620
+
+        Reviewed by Dan Bernstein.
+
+        Test: media/video-load-require-user-gesture.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::load): Early return if user gesture requirement is not met.
+
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::setMediaPlaybackRequiresUserGesture): Moved the method here from
+            Internals to be with the rest of the Internals methods that expose preferences.
+        * testing/InternalSettings.h:
+        * testing/InternalSettings.idl:
+
+        * testing/Internals.cpp: Moved setMediaPlaybackRequiresUserGesture to InternalSettings.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2012-04-12  Bear Travis  <betravis@adobe.com>
 
         [CSS Exclusions] Add flag to enable / disable exclusions at runtime
index 39fef31..f9998a6 100644 (file)
@@ -267,8 +267,10 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     document->registerForMediaVolumeCallbacks(this);
     document->registerForPrivateBrowsingStateChangedCallbacks(this);
     
-    if (document->settings() && document->settings()->mediaPlaybackRequiresUserGesture())
+    if (document->settings() && document->settings()->mediaPlaybackRequiresUserGesture()) {
         addBehaviorRestriction(RequireUserGestureForRateChangeRestriction);
+        addBehaviorRestriction(RequireUserGestureForLoadRestriction);
+    }
 
 #if ENABLE(MEDIA_SOURCE)
     m_mediaSourceURL.setProtocol(mediaSourceURLProtocol);
@@ -634,16 +636,17 @@ void HTMLMediaElement::load(ExceptionCode& ec)
     RefPtr<HTMLMediaElement> protect(this); // loadInternal may result in a 'beforeload' event, which can make arbitrary DOM mutations.
     
     LOG(Media, "HTMLMediaElement::load()");
-
-    if (userGestureRequiredForLoad() && !ScriptController::processingUserGesture())
+    
+    if (userGestureRequiredForLoad() && !ScriptController::processingUserGesture()) {
         ec = INVALID_STATE_ERR;
-    else {
-        m_loadInitiatedByUserGesture = ScriptController::processingUserGesture();
-        if (m_loadInitiatedByUserGesture)
-            removeBehaviorsRestrictionsAfterFirstUserGesture();
-        prepareForLoad();
-        loadInternal();
+        return;
     }
+    
+    m_loadInitiatedByUserGesture = ScriptController::processingUserGesture();
+    if (m_loadInitiatedByUserGesture)
+        removeBehaviorsRestrictionsAfterFirstUserGesture();
+    prepareForLoad();
+    loadInternal();
     prepareToPlay();
 }
 
index f2df23e..493a39d 100644 (file)
@@ -322,4 +322,11 @@ void InternalSettings::setCSSExclusionsEnabled(bool enabled, ExceptionCode& ec)
     UNUSED_PARAM(ec);
     RuntimeEnabledFeatures::setCSSExclusionsEnabled(enabled);
 }
+
+void InternalSettings::setMediaPlaybackRequiresUserGesture(bool enabled, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setMediaPlaybackRequiresUserGesture(enabled);
+}
+
 }
index 3a58d3b..6619767 100644 (file)
@@ -73,6 +73,7 @@ public:
     void setEnableScrollAnimator(bool enabled, ExceptionCode&);
     bool scrollAnimatorEnabled(ExceptionCode&);
     void setCSSExclusionsEnabled(bool enabled, ExceptionCode&);
+    void setMediaPlaybackRequiresUserGesture(bool, ExceptionCode&);
 
     void restoreTo(Settings*);
 
index 2c7d4fa..bbabe3a 100644 (file)
@@ -52,6 +52,7 @@ module window {
         void setEnableScrollAnimator(in boolean enabled) raises(DOMException);
         boolean scrollAnimatorEnabled() raises(DOMException);
         void setCSSExclusionsEnabled(in boolean enabled) raises(DOMException);
+        void setMediaPlaybackRequiresUserGesture(in boolean enabled) raises(DOMException);
     };
 }
 
index ab75f43..01056d7 100644 (file)
@@ -739,16 +739,6 @@ int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode
     return checker->lastProcessedSequence();
 }
 
-void Internals::setMediaPlaybackRequiresUserGesture(Document* document, bool enabled, ExceptionCode& ec)
-{
-    if (!document || !document->settings()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
-    document->settings()->setMediaPlaybackRequiresUserGesture(enabled);
-}
-
 Vector<String> Internals::userPreferredLanguages() const
 {
     return WebCore::userPreferredLanguages();
index ea77552..51a5a85 100644 (file)
@@ -130,8 +130,6 @@ public:
     int lastSpellCheckRequestSequence(Document*, ExceptionCode&);
     int lastSpellCheckProcessedSequence(Document*, ExceptionCode&);
     
-    void setMediaPlaybackRequiresUserGesture(Document*, bool enabled, ExceptionCode&);
-
     Vector<String> userPreferredLanguages() const;
     void setUserPreferredLanguages(const Vector<String>&);
 
index a2a5235..50632a6 100644 (file)
@@ -103,8 +103,6 @@ module window {
         long lastSpellCheckRequestSequence(in Document document) raises (DOMException);
         long lastSpellCheckProcessedSequence(in Document document) raises (DOMException);
 
-        void setMediaPlaybackRequiresUserGesture(in Document document, in boolean enabled) raises(DOMException);
-
 #if defined(ENABLE_VIDEO_TRACK) && ENABLE_VIDEO_TRACK
         void setShouldDisplayTrackKind(in Document document, in DOMString kind, in boolean enabled) raises (DOMException);
         boolean shouldDisplayTrackKind(in Document document, in DOMString trackKind) raises (DOMException);