Make sure media element loads hit content filter extensions.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 23:47:01 +0000 (23:47 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 23:47:01 +0000 (23:47 +0000)
<rdar://problem/20014012> and https://bugs.webkit.org/show_bug.cgi?id=143731

Reviewed by Jer Noble.

Source/WebCore:

Tests: http/tests/contentextensions/media-filtered.html
       http/tests/contentextensions/text-track-blocked.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute): Skip loads that are filtered.

LayoutTests:

* http/tests/contentextensions/media-filtered-expected.txt: Added.
* http/tests/contentextensions/media-filtered.html: Added.
* http/tests/contentextensions/media-filtered.html.json: Added.
* http/tests/contentextensions/text-track-blocked-expected.txt: Added.
* http/tests/contentextensions/text-track-blocked.html: Added.
* http/tests/contentextensions/text-track-blocked.html.json: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/contentextensions/media-filtered-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/media-filtered.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/media-filtered.html.json [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/text-track-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/text-track-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/text-track-blocked.html.json [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp

index c4e0599..7de05f6 100644 (file)
@@ -1,3 +1,17 @@
+2015-04-14  Brady Eidson  <beidson@apple.com>
+
+        Make sure media element loads hit content filter extensions.
+        <rdar://problem/20014012> and https://bugs.webkit.org/show_bug.cgi?id=143731
+
+        Reviewed by Jer Noble.
+
+        * http/tests/contentextensions/media-filtered-expected.txt: Added.
+        * http/tests/contentextensions/media-filtered.html: Added.
+        * http/tests/contentextensions/media-filtered.html.json: Added.
+        * http/tests/contentextensions/text-track-blocked-expected.txt: Added.
+        * http/tests/contentextensions/text-track-blocked.html: Added.
+        * http/tests/contentextensions/text-track-blocked.html.json: Added.
+
 2015-04-14  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Skip failling test due to list box scroll behavior.
diff --git a/LayoutTests/http/tests/contentextensions/media-filtered-expected.txt b/LayoutTests/http/tests/contentextensions/media-filtered-expected.txt
new file mode 100644 (file)
index 0000000..1bf2e05
--- /dev/null
@@ -0,0 +1,12 @@
+CONSOLE MESSAGE: line 14: Video error
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderText {#text} at (0,0) size 238x18
+        text run at (0,0) width 238: "The following video should not load."
+      RenderBR {BR} at (237,14) size 1x0
+      RenderText {#text} at (0,0) size 0x0
+layer at (8,26) size 300x150
+  RenderVideo {VIDEO} at (0,18) size 300x150
diff --git a/LayoutTests/http/tests/contentextensions/media-filtered.html b/LayoutTests/http/tests/contentextensions/media-filtered.html
new file mode 100644 (file)
index 0000000..1e2706a
--- /dev/null
@@ -0,0 +1,21 @@
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+function videoCanPlay()
+{
+    console.log("Video can play");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function videoError()
+{
+    console.log("Video error");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+</script>
+The following video should not load.<br>
+<video onerror="videoError();" oncanplay="videoCanPlay();" src="http://localhost:8000/media/resources/test.mp4" autoplay></video>
diff --git a/LayoutTests/http/tests/contentextensions/media-filtered.html.json b/LayoutTests/http/tests/contentextensions/media-filtered.html.json
new file mode 100644 (file)
index 0000000..a66719b
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*test.mp4"
+        }
+    }
+]
diff --git a/LayoutTests/http/tests/contentextensions/text-track-blocked-expected.txt b/LayoutTests/http/tests/contentextensions/text-track-blocked-expected.txt
new file mode 100644 (file)
index 0000000..ce0be2d
--- /dev/null
@@ -0,0 +1,15 @@
+CONSOLE MESSAGE: line 21: video loaded
+CONSOLE MESSAGE: line 14: vttError
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderText {#text} at (0,0) size 262x18
+        text run at (0,0) width 262: "The following text track should not load."
+      RenderBR {BR} at (261,14) size 1x0
+      RenderText {#text} at (0,0) size 0x0
+layer at (8,26) size 320x240
+  RenderVideo {VIDEO} at (0,18) size 320x240
+layer at (8,26) size 320x240
+  RenderFlexibleBox {DIV} at (0,0) size 320x240
diff --git a/LayoutTests/http/tests/contentextensions/text-track-blocked.html b/LayoutTests/http/tests/contentextensions/text-track-blocked.html
new file mode 100644 (file)
index 0000000..b178f41
--- /dev/null
@@ -0,0 +1,33 @@
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+function vttLoaded()
+{
+    console.log("vttLoaded");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function vttError()
+{
+    console.log("vttError");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function videoLoaded()
+{
+       console.log("video loaded");
+       var video = document.getElementById("video");
+       video.textTracks[0].mode = "showing";
+}
+
+</script>
+The following text track should not load.<br>
+<video id="video" src="/media-resources/content/test.mp4" autoplay oncanplay="videoLoaded();">
+<track id="track" src="/media-resources/track/captions-webvtt/captions-fast.vtt" kind="captions" srclang="en" onload="vttLoaded();" onerror="vttError();"></track>
+</video>
+       
+       
+</video>
diff --git a/LayoutTests/http/tests/contentextensions/text-track-blocked.html.json b/LayoutTests/http/tests/contentextensions/text-track-blocked.html.json
new file mode 100644 (file)
index 0000000..77b5cc9
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*captions-fast.vtt"
+        }
+    }
+]
index e2c7e98..0bc6fe3 100644 (file)
@@ -1,3 +1,16 @@
+2015-04-14  Brady Eidson  <beidson@apple.com>
+
+        Make sure media element loads hit content filter extensions.
+        <rdar://problem/20014012> and https://bugs.webkit.org/show_bug.cgi?id=143731
+
+        Reviewed by Jer Noble.
+
+        Tests: http/tests/contentextensions/media-filtered.html
+               http/tests/contentextensions/text-track-blocked.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::parseAttribute): Skip loads that are filtered.
+
 2015-04-14  Brian Weinstein  <bweinstein@apple.com>
 
         Add SPI to clear HSTS hosts added since a date.
index 25590ee..90ba686 100644 (file)
@@ -72,6 +72,7 @@
 #include "RenderLayerCompositor.h"
 #include "RenderVideo.h"
 #include "RenderView.h"
+#include "ResourceLoadInfo.h"
 #include "ScriptController.h"
 #include "ScriptSourceCode.h"
 #include "SecurityPolicy.h"
@@ -79,6 +80,7 @@
 #include "Settings.h"
 #include "ShadowRoot.h"
 #include "TimeRanges.h"
+#include "UserContentController.h"
 #include <limits>
 #include <runtime/Uint8Array.h>
 #include <wtf/CurrentTime.h>
@@ -1090,7 +1092,8 @@ void HTMLMediaElement::loadResource(const URL& initialURL, ContentType& contentT
         return;
     }
 
-    if (!frame->page()) {
+    Page* page = frame->page();
+    if (!page) {
         mediaLoadingFailed(MediaPlayer::FormatError);
         return;
     }
@@ -1101,6 +1104,19 @@ void HTMLMediaElement::loadResource(const URL& initialURL, ContentType& contentT
         return;
     }
 
+#if ENABLE(CONTENT_EXTENSIONS)
+    ResourceRequest request(url);
+    DocumentLoader* documentLoader = frame->loader().documentLoader();
+
+    if (page->userContentController() && documentLoader)
+        page->userContentController()->processContentExtensionRulesForLoad(request, ResourceType::Media, *documentLoader);
+
+    if (request.isNull()) {
+        mediaLoadingFailed(MediaPlayer::FormatError);
+        return;
+    }
+#endif
+
     // The resource fetch algorithm 
     m_networkState = NETWORK_LOADING;