Title: [149936] trunk
Revision
149936
Author
[email protected]
Date
2013-05-11 12:09:01 -0700 (Sat, 11 May 2013)

Log Message

Disallow a window to focus itself via _javascript_ URLs or using target _self
https://bugs.webkit.org/show_bug.cgi?id=115906

Reviewed by Geoffrey Garen.

Source/WebCore:

Test: fast/dom/Window/window-focus-self.html

* loader/FrameLoader.cpp:
(WebCore::createWindow):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::focus):

LayoutTests:

* fast/dom/Window/window-focus-self-expected.txt: Added.
* fast/dom/Window/window-focus-self.html: Added.
* platform/wk2/TestExpectations: test uses unimplemented setWindowIsKey.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (149935 => 149936)


--- trunk/LayoutTests/ChangeLog	2013-05-11 19:07:55 UTC (rev 149935)
+++ trunk/LayoutTests/ChangeLog	2013-05-11 19:09:01 UTC (rev 149936)
@@ -1,3 +1,14 @@
+2013-05-11  Jochen Eisinger  <[email protected]>
+
+        Disallow a window to focus itself via _javascript_ URLs or using target _self
+        https://bugs.webkit.org/show_bug.cgi?id=115906
+
+        Reviewed by Geoffrey Garen.
+
+        * fast/dom/Window/window-focus-self-expected.txt: Added.
+        * fast/dom/Window/window-focus-self.html: Added.
+        * platform/wk2/TestExpectations: test uses unimplemented setWindowIsKey.
+
 2013-03-17  Robert Hogan  <[email protected]>
 
         Text flow broken in elements with vertical align top/bottom and inline elements taller than line-height

Added: trunk/LayoutTests/fast/dom/Window/window-focus-self-expected.txt (0 => 149936)


--- trunk/LayoutTests/fast/dom/Window/window-focus-self-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Window/window-focus-self-expected.txt	2013-05-11 19:09:01 UTC (rev 149936)
@@ -0,0 +1,2 @@
+This tests that a window cannot focus itself by using _javascript_: urls.
+Window was blurred

Added: trunk/LayoutTests/fast/dom/Window/window-focus-self.html (0 => 149936)


--- trunk/LayoutTests/fast/dom/Window/window-focus-self.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Window/window-focus-self.html	2013-05-11 19:09:01 UTC (rev 149936)
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function runTest() {
+    window._onfocus_ = windowFocused;
+    window._onblur_ = windowBlurred;
+
+    if (window.testRunner) {
+        testRunner.waitUntilDone();
+        testRunner.dumpAsText();
+        testRunner.setWindowIsKey(false);
+        window.open('_javascript_:window.focus()', '_self', '');
+        setTimeout(function() { testRunner.notifyDone(); }, 0);
+    }
+}
+
+function log(message) {
+    var console = document.getElementById("console");
+    var li = document.createElement("li");
+    var text = document.createTextNode(message);
+
+    console.appendChild(li);
+    li.appendChild(text);
+}
+
+function windowFocused() {
+    log("FAIL: Window was focused");
+}
+
+function windowBlurred() {
+    log("Window was blurred");
+}
+</script>
+</head>
+<body>
+    This tests that a window cannot focus itself by using _javascript_: urls.
+    <ul id="console"></ul>
+    <script>runTest();</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (149935 => 149936)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2013-05-11 19:07:55 UTC (rev 149935)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2013-05-11 19:09:01 UTC (rev 149936)
@@ -252,6 +252,7 @@
 # https://bugs.webkit.org/show_bug.cgi?id=81736 rdar://problem/11088268
 fast/events/blur-focus-window-should-blur-focus-element.html
 fast/selectors/selection-window-inactive.html
+fast/dom/Window/window-focus-self.html
 
 # WebKit2 needs an implementation of InspectorClient::overrideDeviceMetrics() and
 # autoZoomPageToFitWidth().

Modified: trunk/Source/WebCore/ChangeLog (149935 => 149936)


--- trunk/Source/WebCore/ChangeLog	2013-05-11 19:07:55 UTC (rev 149935)
+++ trunk/Source/WebCore/ChangeLog	2013-05-11 19:09:01 UTC (rev 149936)
@@ -1,3 +1,17 @@
+2013-05-11  Jochen Eisinger  <[email protected]>
+
+        Disallow a window to focus itself via _javascript_ URLs or using target _self
+        https://bugs.webkit.org/show_bug.cgi?id=115906
+
+        Reviewed by Geoffrey Garen.
+
+        Test: fast/dom/Window/window-focus-self.html
+
+        * loader/FrameLoader.cpp:
+        (WebCore::createWindow):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::focus):
+
 2013-05-11  Christophe Dumez  <[email protected]>
 
         Fix several style warnings in generated bindings

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (149935 => 149936)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2013-05-11 19:07:55 UTC (rev 149935)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2013-05-11 19:09:01 UTC (rev 149936)
@@ -3335,8 +3335,10 @@
 
     if (!request.frameName().isEmpty() && request.frameName() != "_blank") {
         if (Frame* frame = lookupFrame->loader()->findFrameForNavigation(request.frameName(), openerFrame->document())) {
-            if (Page* page = frame->page())
-                page->chrome()->focus();
+            if (request.frameName() != "_self") {
+                if (Page* page = frame->page())
+                    page->chrome()->focus();
+            }
             created = false;
             return frame;
         }

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (149935 => 149936)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2013-05-11 19:07:55 UTC (rev 149935)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2013-05-11 19:09:01 UTC (rev 149936)
@@ -941,7 +941,7 @@
     if (context) {
         ASSERT(isMainThread());
         Document* activeDocument = toDocument(context);
-        if (opener() && activeDocument->domWindow() == opener())
+        if (opener() && opener() != this && activeDocument->domWindow() == opener())
             allowFocus = true;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to