Support "noreferrer" for window.open()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Apr 2019 19:05:17 +0000 (19:05 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Apr 2019 19:05:17 +0000 (19:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194533

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline WPT test now that all checks are passing.

* web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer-expected.txt:

Source/WebCore:

Support "noreferrer" for window.open() as per:
- https://github.com/whatwg/html/pull/4331

Tests: imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer.html
       http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html

* page/DOMWindow.cpp:
(WebCore::DOMWindow::createWindow):
* page/WindowFeatures.cpp:
(WebCore::setWindowFeature):
* page/WindowFeatures.h:

LayoutTests:

Add equivalent test to imported/w3c/web-platform-tests/html/browsers/the-window-object/window-open-noopener.html
but which relies on localStorage instead of BroadcastChannel so that it works with WebKit.

* http/wpt/html/browsers/the-window-object/support/noreferrer-target-webkit.html: Added.
* http/wpt/html/browsers/the-window-object/window-open-noopener-webkit-expected.txt: Added.
* http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/wpt/html/browsers/the-window-object/support/noreferrer-target-webkit.html [new file with mode: 0644]
LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit-expected.txt [new file with mode: 0644]
LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/WindowFeatures.cpp
Source/WebCore/page/WindowFeatures.h

index 3195227..5867777 100644 (file)
@@ -1,3 +1,17 @@
+2019-04-01  Chris Dumez  <cdumez@apple.com>
+
+        Support "noreferrer" for window.open()
+        https://bugs.webkit.org/show_bug.cgi?id=194533
+
+        Reviewed by Geoffrey Garen.
+
+        Add equivalent test to imported/w3c/web-platform-tests/html/browsers/the-window-object/window-open-noopener.html
+        but which relies on localStorage instead of BroadcastChannel so that it works with WebKit.
+
+        * http/wpt/html/browsers/the-window-object/support/noreferrer-target-webkit.html: Added.
+        * http/wpt/html/browsers/the-window-object/window-open-noopener-webkit-expected.txt: Added.
+        * http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html: Added.
+
 2019-04-01  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         SVGMatrix.IDL methods do not conform to the specs
diff --git a/LayoutTests/http/wpt/html/browsers/the-window-object/support/noreferrer-target-webkit.html b/LayoutTests/http/wpt/html/browsers/the-window-object/support/noreferrer-target-webkit.html
new file mode 100644 (file)
index 0000000..f9f0378
--- /dev/null
@@ -0,0 +1,6 @@
+<script>
+const uniqueTestId = location.search.substr(1);
+localStorage.setItem(uniqueTestId + "-referrer", document.referrer);
+localStorage.setItem(uniqueTestId + "-hasOpener", window.opener !== null);
+localStorage.setItem(uniqueTestId + "-name", window.name);
+</script>
diff --git a/LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit-expected.txt b/LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit-expected.txt
new file mode 100644 (file)
index 0000000..860e302
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS window.open() with "noreferrer" tests 
+
diff --git a/LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html b/LayoutTests/http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html
new file mode 100644 (file)
index 0000000..886e900
--- /dev/null
@@ -0,0 +1,23 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>window.open() with "noreferrer" tests</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+async_test(t => {
+  var uniqueTestId = Math.floor((Math.random() * 1000000000000));
+  w = window.open("support/noreferrer-target-webkit.html?" + uniqueTestId, "", "noreferrer");
+  assert_equals(w, null);
+  handle = setInterval(() => {
+    if (localStorage.getItem(uniqueTestId + "-name") === null)
+        return;
+
+    clearInterval(handle);
+    assert_equals(localStorage.getItem(uniqueTestId + "-name"), "");
+    assert_equals(localStorage.getItem(uniqueTestId + "-referrer"), "");
+    assert_equals(localStorage.getItem(uniqueTestId + "-hasOpener"), "false");
+
+    t.done();
+  }, 10);
+});
+</script>
index a646372..b5166d5 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-01  Chris Dumez  <cdumez@apple.com>
+
+        Support "noreferrer" for window.open()
+        https://bugs.webkit.org/show_bug.cgi?id=194533
+
+        Reviewed by Geoffrey Garen.
+
+        Rebaseline WPT test now that all checks are passing.
+
+        * web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer-expected.txt:
+
 2019-04-01  Emilio Cobos Ãlvarez  <emilio@crisal.io>
 
         Be less strict about closing blocks in attribute and functional pseudo-element selectors.
index 6c914e0..bed82c1 100644 (file)
@@ -1,10 +1,10 @@
 
-FAIL Tokenization of "noreferrer" should skip window features separators before feature assert_equals: " noreferrer" should activate feature "noreferrer" expected null but got object "[object Window]"
-FAIL Feature "noreferrer" should be converted to ASCII lowercase assert_equals: "NOREFERRER" should activate feature "noreferrer" expected null but got object "[object Window]"
-FAIL After "noreferrer", tokenization should skip window features separators that are not "=" or "," assert_equals: "noreferrer" should activate feature "noreferrer" expected null but got object "[object Window]"
-FAIL Tokenizing "noreferrer" should ignore window feature separators except "," after initial "=" and before value assert_equals: "noreferrer=  yes" should activate feature "noreferrer" expected null but got object "[object Window]"
-FAIL Tokenizing "noreferrer" should read characters until first window feature separator as `value` assert_equals: "noreferrer=1" should set "noreferrer" expected null but got object "[object Window]"
-FAIL Integer values other than 0 should activate the feature assert_equals: "noreferrer=1" should activate feature "noreferrer" expected null but got object "[object Window]"
+PASS Tokenization of "noreferrer" should skip window features separators before feature 
+PASS Feature "noreferrer" should be converted to ASCII lowercase 
+PASS After "noreferrer", tokenization should skip window features separators that are not "=" or "," 
+PASS Tokenizing "noreferrer" should ignore window feature separators except "," after initial "=" and before value 
+PASS Tokenizing "noreferrer" should read characters until first window feature separator as `value` 
+PASS Integer values other than 0 should activate the feature 
 PASS Integer value of 0 should not activate "noreferrer" 
 PASS Invalid feature names should not tokenize as "noreferrer" 
 
index bd061a7..9df44ec 100644 (file)
@@ -1,3 +1,22 @@
+2019-04-01  Chris Dumez  <cdumez@apple.com>
+
+        Support "noreferrer" for window.open()
+        https://bugs.webkit.org/show_bug.cgi?id=194533
+
+        Reviewed by Geoffrey Garen.
+
+        Support "noreferrer" for window.open() as per:
+        - https://github.com/whatwg/html/pull/4331
+
+        Tests: imported/w3c/web-platform-tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/open-features-tokenization-noreferrer.html
+               http/wpt/html/browsers/the-window-object/window-open-noopener-webkit.html
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::createWindow):
+        * page/WindowFeatures.cpp:
+        (WebCore::setWindowFeature):
+        * page/WindowFeatures.h:
+
 2019-04-01  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         SVGMatrix.IDL methods do not conform to the specs
index 4c044dc..5f01c37 100644 (file)
@@ -2288,7 +2288,7 @@ ExceptionOr<RefPtr<Frame>> DOMWindow::createWindow(const String& urlString, cons
         return Exception { SyntaxError };
 
     // For whatever reason, Firefox uses the first frame to determine the outgoingReferrer. We replicate that behavior here.
-    String referrer = SecurityPolicy::generateReferrerHeader(firstFrame.document()->referrerPolicy(), completedURL, firstFrame.loader().outgoingReferrer());
+    String referrer = windowFeatures.noreferrer ? String() : SecurityPolicy::generateReferrerHeader(firstFrame.document()->referrerPolicy(), completedURL, firstFrame.loader().outgoingReferrer());
     auto initiatedByMainFrame = activeFrame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown;
 
     ResourceRequest resourceRequest { completedURL, referrer };
@@ -2302,14 +2302,15 @@ ExceptionOr<RefPtr<Frame>> DOMWindow::createWindow(const String& urlString, cons
     if (!newFrame)
         return RefPtr<Frame> { nullptr };
 
-    if (!windowFeatures.noopener)
+    bool noopener = windowFeatures.noopener || windowFeatures.noreferrer;
+    if (!noopener)
         newFrame->loader().setOpener(&openerFrame);
 
     if (created)
         newFrame->page()->setOpenedByDOM();
 
     if (newFrame->document()->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
-        return windowFeatures.noopener ? RefPtr<Frame> { nullptr } : newFrame;
+        return noopener ? RefPtr<Frame> { nullptr } : newFrame;
 
     if (prepareDialogFunction)
         prepareDialogFunction(*newFrame->document()->domWindow());
@@ -2328,7 +2329,7 @@ ExceptionOr<RefPtr<Frame>> DOMWindow::createWindow(const String& urlString, cons
     if (!newFrame->page())
         return RefPtr<Frame> { nullptr };
 
-    return windowFeatures.noopener ? RefPtr<Frame> { nullptr } : newFrame;
+    return noopener ? RefPtr<Frame> { nullptr } : newFrame;
 }
 
 ExceptionOr<RefPtr<WindowProxy>> DOMWindow::open(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& urlString, const AtomicString& frameName, const String& windowFeaturesString)
index 078f897..9003d97 100644 (file)
@@ -159,6 +159,8 @@ static void setWindowFeature(WindowFeatures& features, StringView key, StringVie
         features.scrollbarsVisible = numericValue;
     else if (equalLettersIgnoringASCIICase(key, "noopener"))
         features.noopener = numericValue;
+    else if (equalLettersIgnoringASCIICase(key, "noreferrer"))
+        features.noreferrer = numericValue;
     else if (numericValue == 1)
         features.additionalFeatures.append(key.toString());
 }
index c23aab8..d780d28 100644 (file)
@@ -55,6 +55,7 @@ struct WindowFeatures {
     bool fullscreen { false };
     bool dialog { false };
     bool noopener { false };
+    bool noreferrer { false };
 
     Vector<String> additionalFeatures;
 };