WebCore:
authorkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Jan 2008 19:33:44 +0000 (19:33 +0000)
committerkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Jan 2008 19:33:44 +0000 (19:33 +0000)
        Reviewed by Darin, Sam, and Adam.

        - <rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
        - link in gmail message displays JavaScript alert falsely complaining
        about pop-up blocking
        - When trying to open a new window, we now see if the user gesture
        occurred in the global dynamic object instead of the frame since that is
        the only place an event can occur.

        * bindings/js/kjs_window.cpp: - Check the dynamic global object instead
        of the frame.
        (KJS::allowPopUp):
        (KJS::showModalDialog):
        (KJS::WindowProtoFuncOpen::callAsFunction):

WebKitTools:

        Reviewed by Darin, Sam and Adam.

        -<rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
        link in gmail message displays JavaScript alert falsely complaining
        about pop-up blocking.
        - Added the ability to enable the pop-up blocker via the
        LayoutTestController.

        * DumpRenderTree/LayoutTestController.cpp:
        (setPopupBlockingEnabledCallback):
        (LayoutTestController::staticFunctions):
        * DumpRenderTree/LayoutTestController.h:
        * DumpRenderTree/mac/DumpRenderTree.mm:
        (setDefaultsToConsistentValuesForTesting):
        (resetWebViewToConsistentStateBeforeTesting):
        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
        (LayoutTestController::setPopupBlockingEnabled):

LayoutTests:

        Reviewed by Darin, Sam, and Adam.

        -<rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
        link in gmail message displays JavaScript alert falsely complaining
        about pop-up blocking
        - When trying to open a new window, we now see if the user gesture
        occurred in the global dynamic object instead of the frame since that is
        the only place an event can occur.

        * fast/events/open-window-from-another-frame-expected.txt: Added.
        * fast/events/open-window-from-another-frame.html: Added.
        * fast/events/resources/open-window-from-another-frame-otherFrame.html: Added.
        * fast/events/resources/window-opened.html: Added.
        * platform/win/Skipped:

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/open-window-from-another-frame-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/open-window-from-another-frame.html [new file with mode: 0644]
LayoutTests/fast/events/resources/open-window-from-another-frame-otherFrame.html [new file with mode: 0644]
LayoutTests/fast/events/resources/window-opened.html [new file with mode: 0644]
LayoutTests/platform/win/Skipped
WebCore/ChangeLog
WebCore/bindings/js/kjs_window.cpp
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/gtk/LayoutTestControllerGtk.cpp
WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp

index 4118d8a..ba199ea 100644 (file)
@@ -1,3 +1,20 @@
+2008-01-10  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Darin, Sam, and Adam.
+
+        -<rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
+        link in gmail message displays JavaScript alert falsely complaining
+        about pop-up blocking
+        - When trying to open a new window, we now see if the user gesture
+        occurred in the global dynamic object instead of the frame since that is
+        the only place an event can occur.
+
+        * fast/events/open-window-from-another-frame-expected.txt: Added.
+        * fast/events/open-window-from-another-frame.html: Added.
+        * fast/events/resources/open-window-from-another-frame-otherFrame.html: Added.
+        * fast/events/resources/window-opened.html: Added.
+        * platform/win/Skipped:
+
 2008-01-10  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/fast/events/open-window-from-another-frame-expected.txt b/LayoutTests/fast/events/open-window-from-another-frame-expected.txt
new file mode 100644 (file)
index 0000000..bd2118e
--- /dev/null
@@ -0,0 +1,11 @@
+This tests that window.open works across frames.
+To run manually click the link below.
+GreenBox or Success page.
+
+Window was opened! Test succeeded!
+
+
+--------
+Frame: 'otherFrame'
+--------
+This frame should handle the click event on the anchor element in the other window.
diff --git a/LayoutTests/fast/events/open-window-from-another-frame.html b/LayoutTests/fast/events/open-window-from-another-frame.html
new file mode 100644 (file)
index 0000000..5e5469d
--- /dev/null
@@ -0,0 +1,41 @@
+<html>
+    <head>
+        <script>
+        if (window.layoutTestController) {
+            layoutTestController.dumpAsText();
+            layoutTestController.setCanOpenWindows();
+            layoutTestController.dumpChildFramesAsText();
+            layoutTestController.waitUntilDone();
+            layoutTestController.setCloseRemainingWindowsWhenComplete()
+            layoutTestController.setPopupBlockingEnabled(true);
+        }
+
+        function test()
+        {
+            var myLink = document.getElementById('link');
+            var myFrame = document.getElementById('otherFrame').contentWindow;
+            myLink.onclick = myFrame.handleClick;
+            if (window.layoutTestController) {
+                var x = myLink.offsetLeft + 2;
+                var y = myLink.offsetTop + 2;
+                eventSender.mouseMoveTo(x, y);
+                eventSender.mouseDown();
+                eventSender.mouseUp();
+            }
+        }
+
+        function log(msg)
+        {
+            var res = document.getElementById('res');
+            res.innerHTML = res.innerHTML + msg + "<br>";
+        }
+        </script>
+    </head>
+    <body onload="test()">
+        This tests that window.open works across frames.<br>
+        To run manually click the link below.<br>
+        <a href="resources/greenbox.png" id="link">GreenBox or Success page.</a><br>
+        <iframe src="resources/open-window-from-another-frame-otherFrame.html" id="otherFrame"></iframe>
+        <div id="res"></div>
+    </body>
+</html>
diff --git a/LayoutTests/fast/events/resources/open-window-from-another-frame-otherFrame.html b/LayoutTests/fast/events/resources/open-window-from-another-frame-otherFrame.html
new file mode 100644 (file)
index 0000000..6630734
--- /dev/null
@@ -0,0 +1,27 @@
+<body>
+    This frame should handle the click event on the anchor element in the other window.
+    <script>
+        function closeWin(winToClose) {
+            winToClose.close();
+            setTimeout(doneHandler, 1);
+
+            function doneHandler() {
+                if (!winToClose.closed)
+                    setTimeout(doneHandler, 1);
+                else if (window.layoutTestController)
+                    layoutTestController.notifyDone();
+            }
+        }
+
+        function handleClick(event) {
+            var newWin = window.open('resources/window-opened.html', 'badName', 'width=100, height=100');
+            if (newWin) {
+                parent.log("Window was opened! Test succeeded!");
+                closeWin(newWin);
+            }
+
+            event.preventDefault();
+            return false;
+        }
+    </script>
+</body>
diff --git a/LayoutTests/fast/events/resources/window-opened.html b/LayoutTests/fast/events/resources/window-opened.html
new file mode 100644 (file)
index 0000000..dc1a48a
--- /dev/null
@@ -0,0 +1,3 @@
+<body>
+    This window was opened! Test succeeded!
+</body>
\ No newline at end of file
index 666224f..f13bfa7 100644 (file)
@@ -186,6 +186,7 @@ fast/lists/drag-into-marker.html
 fast/dom/open-and-close-by-DOM.html
 fast/dom/Document/early-document-access.html
 fast/events/attempt-scroll-with-no-scrollbars.html
+fast/events/open-window-from-another-frame.html
 fast/history/history_reload.html
 http/tests/navigation/new-window-redirect-history.html
 http/tests/navigation/target-frame-from-window.html
index 0994be7..ad3ff9d 100644 (file)
@@ -1,3 +1,20 @@
+2008-01-10  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Darin, Sam, and Adam.
+
+        - <rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
+        - link in gmail message displays JavaScript alert falsely complaining
+        about pop-up blocking
+        - When trying to open a new window, we now see if the user gesture 
+        occurred in the global dynamic object instead of the frame since that is
+        the only place an event can occur. 
+
+        * bindings/js/kjs_window.cpp: - Check the dynamic global object instead
+        of the frame.
+        (KJS::allowPopUp):
+        (KJS::showModalDialog):
+        (KJS::WindowProtoFuncOpen::callAsFunction):
+
 2008-01-10  David Hyatt  <hyatt@apple.com>
 
         Fix for bug 16247, visibility:hidden not honored when hit testing inline replaced elements.
index 7dc988e..93bb5cb 100644 (file)
@@ -278,10 +278,11 @@ void Window::mark()
         d->loc->mark();
 }
 
-static bool allowPopUp(Frame* frame)
+static bool allowPopUp(ExecState* exec)
 {
-    if (!frame)
-        return false;
+    Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+
+    ASSERT(frame);
     if (frame->scriptProxy()->processingUserGesture())
         return true;
     Settings* settings = frame->settings();
@@ -379,7 +380,7 @@ static bool canShowModalDialogNow(const Frame* frame)
 
 static JSValue* showModalDialog(ExecState* exec, Frame* frame, const String& url, JSValue* dialogArgs, const String& featureArgs)
 {
-    if (!canShowModalDialogNow(frame) || !allowPopUp(frame))
+    if (!canShowModalDialogNow(frame) || !allowPopUp(exec))
         return jsUndefined();
 
     const HashMap<String, String> features = parseModalDialogFeatures(featureArgs);
@@ -1050,7 +1051,7 @@ JSValue* WindowProtoFuncOpen::callAsFunction(ExecState* exec, JSObject* thisObj,
 
     // Because FrameTree::find() returns true for empty strings, we must check for empty framenames.
     // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker.
-    if (!allowPopUp(frame) && (frameName.isEmpty() || !frame->tree()->find(frameName)))
+    if (!allowPopUp(exec) && (frameName.isEmpty() || !frame->tree()->find(frameName)))
         return jsUndefined();
 
     // Get the target frame for the special cases of _top and _parent.  In those
index d82dd39..3ac2a39 100644 (file)
@@ -1,3 +1,23 @@
+2008-01-09  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Darin, Sam and Adam.
+
+        -<rdar://problem/5654486> REGRESSION (Safari 3.0.4-TOT): clicking on
+        link in gmail message displays JavaScript alert falsely complaining
+        about pop-up blocking.
+        - Added the ability to enable the pop-up blocker via the
+        LayoutTestController.
+
+        * DumpRenderTree/LayoutTestController.cpp:
+        (setPopupBlockingEnabledCallback):
+        (LayoutTestController::staticFunctions):
+        * DumpRenderTree/LayoutTestController.h:
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (setDefaultsToConsistentValuesForTesting):
+        (resetWebViewToConsistentStateBeforeTesting):
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::setPopupBlockingEnabled):
+
 2008-01-10  Lars Knoll  <lars@trolltech.com>
 
         Reviewed by Simon.
index 8183477..2767285 100644 (file)
@@ -523,6 +523,19 @@ static JSValueRef windowCountCallback(JSContextRef context, JSObjectRef function
     return JSValueMakeNumber(context, windows);
 }
 
+static JSValueRef setPopupBlockingEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    // Has mac & windows implementation
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(context);
+
+    LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    controller->setPopupBlockingEnabled(JSValueToBoolean(context, arguments[0]));
+
+    return JSValueMakeUndefined(context);
+}
+
+
 // Static Values
 
 static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
@@ -613,6 +626,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "setCustomPolicyDelegate", setCustomPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setMainFrameIsFirstResponder", setMainFrameIsFirstResponderCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setPrivateBrowsingEnabled", setPrivateBrowsingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "setPopupBlockingEnabled", setPopupBlockingEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setTabKeyCyclesThroughElements", setTabKeyCyclesThroughElementsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setUseDashboardCompatibilityMode", setUseDashboardCompatibilityModeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setUserStyleSheetEnabled", setUserStyleSheetEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 91aaae8..60f6107 100644 (file)
@@ -58,6 +58,7 @@ public:
     void setCustomPolicyDelegate(bool setDelegate);
     void setMainFrameIsFirstResponder(bool flag);
     void setPrivateBrowsingEnabled(bool flag);
+    void setPopupBlockingEnabled(bool flag);
     void setTabKeyCyclesThroughElements(bool cycles);
     void setUseDashboardCompatibilityMode(bool flag);
     void setUserStyleSheetEnabled(bool flag);
@@ -123,7 +124,7 @@ public:
 
     bool globalFlag() const { return m_globalFlag; }
     void setGlobalFlag(bool globalFlag) { m_globalFlag = globalFlag; }
-
+    
 private:
     bool m_dumpAsText;
     bool m_dumpBackForwardList;
index 82af22e..7656e4f 100644 (file)
@@ -191,6 +191,11 @@ void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
     // FIXME: implement
 }
 
+void LayoutTestController::setPopupBlockingEnabled(bool popupBlockingEnabled)
+{
+    // FIXME: implement
+}
+
 void LayoutTestController::execCommand(JSStringRef name, JSStringRef value)
 {
     // FIXME: implement
index 08d481a..55a6bcb 100644 (file)
@@ -256,7 +256,6 @@ static void setDefaultsToConsistentValuesForTesting()
     [preferences setDefaultFixedFontSize:13];
     [preferences setMinimumFontSize:1];
     [preferences setJavaEnabled:NO];
-    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
     [preferences setEditableLinkBehavior:WebKitEditableLinkOnlyLiveWithShiftKey];
     [preferences setTabsToLinks:NO];
     [preferences setDOMPasteAllowed:YES];
@@ -802,6 +801,7 @@ static void resetWebViewToConsistentStateBeforeTesting()
     WebPreferences *preferences = [webView preferences];
     [preferences setPrivateBrowsingEnabled:NO];
     [preferences setAuthorAndUserStylesEnabled:YES];
+    [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
 
     [WebView _setUsesTestModeFocusRingColor:YES];
 }
index 7194eda..6c1efc1 100644 (file)
@@ -186,6 +186,11 @@ void LayoutTestController::setPrivateBrowsingEnabled(bool privateBrowsingEnabled
     [[[mainFrame webView] preferences] setPrivateBrowsingEnabled:privateBrowsingEnabled];
 }
 
+void LayoutTestController::setPopupBlockingEnabled(bool popupBlockingEnabled)
+{
+    [[[mainFrame webView] preferences] setJavaScriptCanOpenWindowsAutomatically:!popupBlockingEnabled];
+}
+
 void LayoutTestController::setTabKeyCyclesThroughElements(bool cycles)
 {
     [[mainFrame webView] setTabKeyCyclesThroughElements:cycles];
index 9b13d05..589e33a 100644 (file)
@@ -281,6 +281,19 @@ void LayoutTestController::setPrivateBrowsingEnabled(bool privateBrowsingEnabled
     preferences->setPrivateBrowsingEnabled(privateBrowsingEnabled);
 }
 
+void LayoutTestController::setPopupBlockingEnabled(bool privateBrowsingEnabled)
+{
+    COMPtr<IWebView> webView;
+    if (FAILED(frame->webView(&webView)))
+        return;
+
+    COMPtr<IWebPreferences> preferences;
+    if (FAILED(webView->preferences(&preferences)))
+        return;
+
+    preferences->setJavaScriptCanOpenWindowsAutomatically(!privateBrowsingEnabled);
+}
+
 void LayoutTestController::setTabKeyCyclesThroughElements(bool shouldCycle)
 {
     COMPtr<IWebView> webView;