Title: [206659] trunk
Revision
206659
Author
[email protected]
Date
2016-09-30 13:08:27 -0700 (Fri, 30 Sep 2016)

Log Message

FileSaver.js does not work in WebKit
https://bugs.webkit.org/show_bug.cgi?id=162788

Reviewed by Sam Weinig.

Source/WebCore:

FileSaver.js does not work in WebKit:
- https://eligrey.com/demos/FileSaver.js/

It works in Firefox and Chrome, but in WebKit, we were getting a
"Synthetic clicks on anchors that have a download attribute are
ignored." warning. We were too strict in restricting synthetic clicks.
We now allow synthetic clicks as long as they are triggered by a user
gesture.

Test: fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html

* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::handleClick):

LayoutTests:

Add layout test coverage.

* fast/dom/HTMLAnchorElement/anchor-download-synthetic-click-expected.txt:
* fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt: Added.
* fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (206658 => 206659)


--- trunk/LayoutTests/ChangeLog	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/ChangeLog	2016-09-30 20:08:27 UTC (rev 206659)
@@ -1,3 +1,16 @@
+2016-09-30  Chris Dumez  <[email protected]>
+
+        FileSaver.js does not work in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=162788
+
+        Reviewed by Sam Weinig.
+
+        Add layout test coverage.
+
+        * fast/dom/HTMLAnchorElement/anchor-download-synthetic-click-expected.txt:
+        * fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt: Added.
+        * fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html: Added.
+
 2016-09-30  Ryan Haddad  <[email protected]>
 
         Marking fast/images/gif-loop-count.html as flaky on ios-simulator.

Modified: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-synthetic-click-expected.txt (206658 => 206659)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-synthetic-click-expected.txt	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-synthetic-click-expected.txt	2016-09-30 20:08:27 UTC (rev 206659)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 22: Synthetic clicks on anchors that have a download attribute are ignored.
+CONSOLE MESSAGE: line 22: Non user-triggered activations of anchors that have a download attribute are ignored.
 Test that synthetic clicks on an anchor with a download attribute are ignored.
 
 This test passes if you do not see any 'Download started' message above.

Added: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt (0 => 206659)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt	2016-09-30 20:08:27 UTC (rev 206659)
@@ -0,0 +1,8 @@
+Download started.
+Downloading URL with suggested filename "unknown"
+Download completed.
+Test that user triggered synthetic clicks on an anchor with a download attribute are not ignored.
+
+This test passes if you see a 'Download started' message above.
+
+

Added: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html (0 => 206659)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html	2016-09-30 20:08:27 UTC (rev 206659)
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type='text/_javascript_'>
+if (window.testRunner) {
+  testRunner.dumpAsText();
+  testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<p>Test that user triggered synthetic clicks on an anchor with a download attribute are not ignored.</p>
+<p> This test passes if you see a 'Download started' message above.</p>
+<a style="display:none" id="blob-url" download>Blob URL</a>
+<input type="button" id="testButton" value="Download">
+<script>
+function userClick(element)
+{
+    if (!window.eventSender) {
+        alert('Click the button to run the test.');
+        return;
+    }
+    eventSender.mouseMoveTo(element.offsetLeft + 5, element.offsetTop + 5);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+function runTest()
+{
+    var string = "test";
+    var blob = new Blob([string], {type: "text/html"});
+    var link = document.getElementById("blob-url");
+    link.href = ""
+    var button = document.getElementById("testButton");
+    button._onclick_ = function() {
+        link.click();
+    }
+    userClick(button);
+    setTimeout(function() {
+        testRunner.notifyDone();
+    }, 100);
+}
+runTest();
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations (206658 => 206659)


--- trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/platform/ios-simulator-wk1/TestExpectations	2016-09-30 20:08:27 UTC (rev 206659)
@@ -1314,6 +1314,7 @@
 
 # <a download> is not supported in WK1 yet.
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
+webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 webkit.org/b/156069 http/tests/download/area-download.html [ Skip ]
 webkit.org/b/156069 http/tests/security/anchor-download-allow-blob.html [ Skip ]
 webkit.org/b/156069 http/tests/security/anchor-download-allow-data.html [ Skip ]

Modified: trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations (206658 => 206659)


--- trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations	2016-09-30 20:08:27 UTC (rev 206659)
@@ -1807,6 +1807,8 @@
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-nodownload.html [ Skip ]
+webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
+webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 webkit.org/b/156067 http/tests/download/area-download.html [ Skip ]
 webkit.org/b/156067 http/tests/security/anchor-download-allow-blob.html [ Skip ]
 webkit.org/b/156067 http/tests/security/anchor-download-allow-data.html [ Skip ]

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (206658 => 206659)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-09-30 20:08:27 UTC (rev 206659)
@@ -191,6 +191,7 @@
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Failure ]
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download.html [ Failure ]
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
+webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 webkit.org/b/156069 http/tests/download/area-download.html [ Skip ]
 webkit.org/b/156069 http/tests/security/anchor-download-allow-blob.html [ Skip ]
 webkit.org/b/156069 http/tests/security/anchor-download-allow-data.html [ Skip ]

Modified: trunk/LayoutTests/platform/win/TestExpectations (206658 => 206659)


--- trunk/LayoutTests/platform/win/TestExpectations	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/LayoutTests/platform/win/TestExpectations	2016-09-30 20:08:27 UTC (rev 206659)
@@ -442,6 +442,8 @@
 fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
 fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Skip ]
 fast/dom/HTMLAnchorElement/anchor-download-unset.html [ Skip ]
+fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
+fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 http/tests/download/area-download.html [ Skip ]
 http/tests/security/anchor-download-allow-data.html [ Skip ]
 http/tests/security/anchor-download-allow-sameorigin.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (206658 => 206659)


--- trunk/Source/WebCore/ChangeLog	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/Source/WebCore/ChangeLog	2016-09-30 20:08:27 UTC (rev 206659)
@@ -1,3 +1,24 @@
+2016-09-30  Chris Dumez  <[email protected]>
+
+        FileSaver.js does not work in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=162788
+
+        Reviewed by Sam Weinig.
+
+        FileSaver.js does not work in WebKit:
+        - https://eligrey.com/demos/FileSaver.js/
+
+        It works in Firefox and Chrome, but in WebKit, we were getting a
+        "Synthetic clicks on anchors that have a download attribute are
+        ignored." warning. We were too strict in restricting synthetic clicks.
+        We now allow synthetic clicks as long as they are triggered by a user
+        gesture.
+
+        Test: fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html
+
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::handleClick):
+
 2016-09-30  Joseph Pecoraro  <[email protected]>
 
         Breakpoints on blank lines or comments don't break

Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (206658 => 206659)


--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp	2016-09-30 19:47:54 UTC (rev 206658)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp	2016-09-30 20:08:27 UTC (rev 206659)
@@ -44,6 +44,7 @@
 #include "ResourceRequest.h"
 #include "RuntimeEnabledFeatures.h"
 #include "SVGImage.h"
+#include "ScriptController.h"
 #include "SecurityOrigin.h"
 #include "SecurityPolicy.h"
 #include "Settings.h"
@@ -380,9 +381,9 @@
         // If the a element has a download attribute and the algorithm is not triggered by user activation
         // then abort these steps.
         // https://html.spec.whatwg.org/#the-a-element:triggered-by-user-activation
-        if (!downloadAttribute.isNull() && !event.isTrusted()) {
+        if (!downloadAttribute.isNull() && !event.isTrusted() && !ScriptController::processingUserGesture()) {
             // The specification says to throw an InvalidAccessError but other browsers do not.
-            document().addConsoleMessage(MessageSource::Security, MessageLevel::Warning, "Synthetic clicks on anchors that have a download attribute are ignored.");
+            document().addConsoleMessage(MessageSource::Security, MessageLevel::Warning, "Non user-triggered activations of anchors that have a download attribute are ignored.");
             return;
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to