WebCore: Allow forms submitting to target="_blank" to open popups if the submission
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 May 2010 08:51:41 +0000 (08:51 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 May 2010 08:51:41 +0000 (08:51 +0000)
originated from a user gesture.

Reviewed by Maciej Stachowiak.

https://bugs.webkit.org/show_bug.cgi?id=37335
<rdar://problem/7884980>

Test: fast/events/popup-allowed-from-gesture-initiated-form-submit.html

* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::processingUserGesture): If no DOM event is
being processed, consult UserGestureIndicator to determine return value.
* bindings/js/ScriptController.h: Moved the logic of processingUserGestureEvent()
into processingUserGesture().

LayoutTests: Add a test to ensure popups are allowed when the user submits a form with target="_blank".

Reviewed by Maciej Stachowiak.

https://bugs.webkit.org/show_bug.cgi?id=37335
<rdar://problem/7884980>

* fast/events/popup-allowed-from-gesture-initiated-form-submit-expected.txt: Added.
* fast/events/popup-allowed-from-gesture-initiated-form-submit.html: Added.
* fast/events/resources/popup-allowed-from-gesture-initiated-form-submit-target.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit.html [new file with mode: 0644]
LayoutTests/fast/events/resources/popup-allowed-from-gesture-initiated-form-submit-target.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/bindings/js/ScriptController.cpp
WebCore/bindings/js/ScriptController.h

index b77df7b..33b5354 100644 (file)
@@ -1,3 +1,16 @@
+2010-05-06  Andy Estes  <aestes@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Add a test to ensure popups are allowed when the user submits a form with target="_blank".
+
+        https://bugs.webkit.org/show_bug.cgi?id=37335
+        <rdar://problem/7884980>
+
+        * fast/events/popup-allowed-from-gesture-initiated-form-submit-expected.txt: Added.
+        * fast/events/popup-allowed-from-gesture-initiated-form-submit.html: Added.
+        * fast/events/resources/popup-allowed-from-gesture-initiated-form-submit-target.html: Added.
+
 2010-05-05  Charles Wei  <charles.wei@torchmobile.com.cn>
 
         Reviewed by George Staikos
diff --git a/LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit-expected.txt b/LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit-expected.txt
new file mode 100644 (file)
index 0000000..aa44e7c
--- /dev/null
@@ -0,0 +1,2 @@
+
+PASS
diff --git a/LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit.html b/LayoutTests/fast/events/popup-allowed-from-gesture-initiated-form-submit.html
new file mode 100644 (file)
index 0000000..ce2b7ab
--- /dev/null
@@ -0,0 +1,25 @@
+<html> 
+    <body>
+        <form action="resources/popup-allowed-from-gesture-initiated-form-submit-target.html" method="post" target="_blank">
+            <input id="button" type="submit" value="Click Here" />
+        </form>
+        <div id="console">FAIL</div>
+        <script> 
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+                layoutTestController.setCanOpenWindows();
+                layoutTestController.setPopupBlockingEnabled(true);
+                layoutTestController.setCloseRemainingWindowsWhenComplete(true);
+                layoutTestController.waitUntilDone();
+
+                var button = document.getElementById("button");
+
+                if (window.eventSender) {
+                    eventSender.mouseMoveTo(button.offsetLeft + button.offsetWidth / 2, button.offsetTop + button.offsetHeight / 2);
+                    eventSender.mouseDown();
+                    eventSender.mouseUp();
+                }
+            }
+        </script> 
+    </body> 
+</html>
diff --git a/LayoutTests/fast/events/resources/popup-allowed-from-gesture-initiated-form-submit-target.html b/LayoutTests/fast/events/resources/popup-allowed-from-gesture-initiated-form-submit-target.html
new file mode 100644 (file)
index 0000000..1a6eaf3
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+    <head>
+        <script>
+            var parentWindow = window.opener;
+            var console = parentWindow.document.getElementById("console");
+            console.innerHTML = "PASS";
+            if (parentWindow.layoutTestController)
+                parentWindow.layoutTestController.notifyDone();
+        </script>
+    </head>
+</html>
index f043665..b2d0cb5 100644 (file)
@@ -1,3 +1,21 @@
+2010-05-06  Andy Estes  <aestes@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Allow forms submitting to target="_blank" to open popups if the submission
+        originated from a user gesture.
+
+        https://bugs.webkit.org/show_bug.cgi?id=37335
+        <rdar://problem/7884980>
+
+        Test: fast/events/popup-allowed-from-gesture-initiated-form-submit.html
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::processingUserGesture): If no DOM event is
+        being processed, consult UserGestureIndicator to determine return value.
+        * bindings/js/ScriptController.h: Moved the logic of processingUserGestureEvent()
+        into processingUserGesture().
+
 2010-05-06  Xan Lopez  <xlopez@igalia.com>
 
         Rubber-stamped by Eric Seidel.
index 42bce01..e4c9876 100644 (file)
@@ -36,6 +36,7 @@
 #include "ScriptValue.h"
 #include "Settings.h"
 #include "StorageNamespace.h"
+#include "UserGestureIndicator.h"
 #include "WebCoreJSClientData.h"
 #include "XSSAuditor.h"
 #include "npruntime_impl.h"
@@ -228,19 +229,16 @@ JSDOMWindowShell* ScriptController::initScript(DOMWrapperWorld* world)
 
 bool ScriptController::processingUserGesture(DOMWrapperWorld* world) const
 {
-    return m_allowPopupsFromPlugin || processingUserGestureEvent(world) || isJavaScriptAnchorNavigation();
-}
+    if (m_allowPopupsFromPlugin || isJavaScriptAnchorNavigation())
+        return true;
 
-bool ScriptController::processingUserGestureEvent(DOMWrapperWorld* world) const
-{
-    JSDOMWindowShell* shell = existingWindowShell(world);
-    if (!shell)
-        return false;
+    // If a DOM event is being processed, check that it was initiated by the user
+    // and that it is in the whitelist of event types allowed to generate pop-ups.
+    if (JSDOMWindowShell* shell = existingWindowShell(world))
+        if (Event* event = shell->window()->currentEvent())
+            return event->fromUserGesture();
 
-    if (Event* event = shell->window()->currentEvent())
-        return event->fromUserGesture();
-    
-    return false;
+    return UserGestureIndicator::processingUserGesture();
 }
 
 // FIXME: This seems like an insufficient check to verify a click on a javascript: anchor.
index d096c2e..ad03869 100644 (file)
@@ -172,7 +172,6 @@ private:
 
     void disconnectPlatformScriptObjects();
 
-    bool processingUserGestureEvent(DOMWrapperWorld*) const;
     bool isJavaScriptAnchorNavigation() const;
 
     ShellMap m_windowShells;