Title: [270273] trunk
Revision
270273
Author
[email protected]
Date
2020-11-30 15:43:42 -0800 (Mon, 30 Nov 2020)

Log Message

sessionStorage should not be cloned when a window is opened with rel=noopener
https://bugs.webkit.org/show_bug.cgi?id=218804
<rdar://problem/71286606>

Reviewed by Alex Christensen.

Source/WebCore:

sessionStorage should not be cloned when a window is opened with rel=noopener, as per:
- https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage

Both Firefox and Chrome have already implemented this behavior.

* loader/EmptyFrameLoaderClient.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::continueLoadAfterNewWindowPolicy):
* loader/FrameLoaderClient.h:
* page/Chrome.cpp:
(WebCore::Chrome::createWindow const):

Source/WebKit:

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchCreatePage):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::dispatchCreatePage):

Source/WebKitLegacy/win:

* WebCoreSupport/WebFrameLoaderClient.cpp:
(WebFrameLoaderClient::dispatchCreatePage):
* WebCoreSupport/WebFrameLoaderClient.h:

Tools:

Add API test coverage.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/SessionStorage.mm: Added.
(-[SessionStorageUIDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
(-[SessionStorageUIDelegate webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
(createAndInitializeTestWebView):
(checkSessionStorageInNewWindow):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/confirm.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270272 => 270273)


--- trunk/Source/WebCore/ChangeLog	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebCore/ChangeLog	2020-11-30 23:43:42 UTC (rev 270273)
@@ -1,3 +1,23 @@
+2020-11-30  Chris Dumez  <[email protected]>
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener
+        https://bugs.webkit.org/show_bug.cgi?id=218804
+        <rdar://problem/71286606>
+
+        Reviewed by Alex Christensen.
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener, as per:
+        - https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage
+
+        Both Firefox and Chrome have already implemented this behavior.
+
+        * loader/EmptyFrameLoaderClient.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::continueLoadAfterNewWindowPolicy):
+        * loader/FrameLoaderClient.h:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::createWindow const):
+
 2020-11-30  Alex Christensen  <[email protected]>
 
         Allow blob URLs with fragments

Modified: trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h (270272 => 270273)


--- trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -95,7 +95,7 @@
     void dispatchDidReachLayoutMilestone(OptionSet<LayoutMilestone>) final { }
     void dispatchDidReachVisuallyNonEmptyState() final { }
 
-    Frame* dispatchCreatePage(const NavigationAction&) final { return nullptr; }
+    Frame* dispatchCreatePage(const NavigationAction&, NewFrameOpenerPolicy) final { return nullptr; }
     void dispatchShow() final { }
 
     void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, PolicyCheckIdentifier, const String&, FramePolicyFunction&&) final { }

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (270272 => 270273)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2020-11-30 23:43:42 UTC (rev 270273)
@@ -3523,7 +3523,7 @@
         return;
 
     Ref<Frame> frame(m_frame);
-    RefPtr<Frame> mainFrame = m_client->dispatchCreatePage(action);
+    RefPtr<Frame> mainFrame = m_client->dispatchCreatePage(action, openerPolicy);
     if (!mainFrame)
         return;
 

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (270272 => 270273)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -187,7 +187,7 @@
     virtual void dispatchDidReachLayoutMilestone(OptionSet<LayoutMilestone>) { }
     virtual void dispatchDidReachVisuallyNonEmptyState() { }
 
-    virtual Frame* dispatchCreatePage(const NavigationAction&) = 0;
+    virtual Frame* dispatchCreatePage(const NavigationAction&, NewFrameOpenerPolicy) = 0;
     virtual void dispatchShow() = 0;
 
     virtual void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, PolicyCheckIdentifier, const String& downloadAttribute, FramePolicyFunction&&) = 0;

Modified: trunk/Source/WebCore/page/Chrome.cpp (270272 => 270273)


--- trunk/Source/WebCore/page/Chrome.cpp	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebCore/page/Chrome.cpp	2020-11-30 23:43:42 UTC (rev 270273)
@@ -193,8 +193,10 @@
     if (!newPage)
         return nullptr;
 
-    if (auto* oldSessionStorage = m_page.sessionStorage(false))
-        newPage->setSessionStorage(oldSessionStorage->copy(*newPage));
+    if (!features.noopener && !features.noreferrer) {
+        if (auto* oldSessionStorage = m_page.sessionStorage(false))
+            newPage->setSessionStorage(oldSessionStorage->copy(*newPage));
+    }
 
     return newPage;
 }

Modified: trunk/Source/WebKit/ChangeLog (270272 => 270273)


--- trunk/Source/WebKit/ChangeLog	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKit/ChangeLog	2020-11-30 23:43:42 UTC (rev 270273)
@@ -1,3 +1,15 @@
+2020-11-30  Chris Dumez  <[email protected]>
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener
+        https://bugs.webkit.org/show_bug.cgi?id=218804
+        <rdar://problem/71286606>
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchCreatePage):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
+
 2020-11-30  Youenn Fablet  <[email protected]>
 
         Introduce an experimental flag specific to VP9 profile 2

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (270272 => 270273)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2020-11-30 23:43:42 UTC (rev 270273)
@@ -784,7 +784,7 @@
     }
 }
 
-Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
+Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction, NewFrameOpenerPolicy newFrameOpenerPolicy)
 {
     WebPage* webPage = m_frame->page();
     if (!webPage)
@@ -791,7 +791,9 @@
         return nullptr;
 
     // Just call through to the chrome client.
-    Page* newPage = webPage->corePage()->chrome().createWindow(*m_frame->coreFrame(), { }, navigationAction);
+    WindowFeatures windowFeatures;
+    windowFeatures.noopener = newFrameOpenerPolicy == NewFrameOpenerPolicy::Suppress;
+    Page* newPage = webPage->corePage()->chrome().createWindow(*m_frame->coreFrame(), windowFeatures, navigationAction);
     if (!newPage)
         return nullptr;
     

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (270272 => 270273)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -126,7 +126,7 @@
     void dispatchDidReachVisuallyNonEmptyState() final;
     void dispatchDidLayout() final;
 
-    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
+    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&, WebCore::NewFrameOpenerPolicy) final;
     void dispatchShow() final;
     
     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&, WebCore::FramePolicyFunction&&) final;

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (270272 => 270273)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2020-11-30 23:43:42 UTC (rev 270273)
@@ -1,3 +1,15 @@
+2020-11-30  Chris Dumez  <[email protected]>
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener
+        https://bugs.webkit.org/show_bug.cgi?id=218804
+        <rdar://problem/71286606>
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebFrameLoaderClient.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::dispatchCreatePage):
+
 2020-11-21  Simon Fraser  <[email protected]>
 
         Add an Experimental Features for wheel event gestures becoming non-blocking

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h (270272 => 270273)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -122,7 +122,7 @@
     void dispatchDidFinishLoad() final;
     void dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) final;
 
-    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) final;
+    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&, WebCore::NewFrameOpenerPolicy) final;
     void dispatchShow() final;
 
     void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::PolicyCheckIdentifier, const String&,  WebCore::FramePolicyFunction&&) final;

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm (270272 => 270273)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2020-11-30 23:43:42 UTC (rev 270273)
@@ -833,7 +833,7 @@
     }
 }
 
-WebCore::Frame* WebFrameLoaderClient::dispatchCreatePage(const WebCore::NavigationAction&)
+WebCore::Frame* WebFrameLoaderClient::dispatchCreatePage(const WebCore::NavigationAction&, WebCore::NewFrameOpenerPolicy)
 {
     WebView *currentWebView = getWebView(m_webFrame.get());
     NSDictionary *features = [[NSDictionary alloc] init];

Modified: trunk/Source/WebKitLegacy/win/ChangeLog (270272 => 270273)


--- trunk/Source/WebKitLegacy/win/ChangeLog	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/win/ChangeLog	2020-11-30 23:43:42 UTC (rev 270273)
@@ -1,3 +1,15 @@
+2020-11-30  Chris Dumez  <[email protected]>
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener
+        https://bugs.webkit.org/show_bug.cgi?id=218804
+        <rdar://problem/71286606>
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebFrameLoaderClient::dispatchCreatePage):
+        * WebCoreSupport/WebFrameLoaderClient.h:
+
 2020-11-19  Fujii Hironori  <[email protected]>
 
         [TextureMapper] Remove m_textureMapper from TextureMapperLayer

Modified: trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp (270272 => 270273)


--- trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp	2020-11-30 23:43:42 UTC (rev 270273)
@@ -496,7 +496,7 @@
     }
 }
 
-Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
+Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction, NewFrameOpenerPolicy)
 {
     WebView* webView = m_webFrame->webView();
 

Modified: trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h (270272 => 270273)


--- trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -111,7 +111,7 @@
     void revertToProvisionalState(WebCore::DocumentLoader*) override;
     bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int length) override;
 
-    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&) override;
+    WebCore::Frame* dispatchCreatePage(const WebCore::NavigationAction&, WebCore::NewFrameOpenerPolicy) override;
     void dispatchShow() override;
 
     void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&) override;

Modified: trunk/Tools/ChangeLog (270272 => 270273)


--- trunk/Tools/ChangeLog	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Tools/ChangeLog	2020-11-30 23:43:42 UTC (rev 270273)
@@ -1,3 +1,22 @@
+2020-11-30  Chris Dumez  <[email protected]>
+
+        sessionStorage should not be cloned when a window is opened with rel=noopener
+        https://bugs.webkit.org/show_bug.cgi?id=218804
+        <rdar://problem/71286606>
+
+        Reviewed by Alex Christensen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/SessionStorage.mm: Added.
+        (-[SessionStorageUIDelegate webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:]):
+        (-[SessionStorageUIDelegate webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (createAndInitializeTestWebView):
+        (checkSessionStorageInNewWindow):
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/confirm.html: Added.
+
 2020-11-30  Jonathan Bedard  <[email protected]>
 
         [git transition] Add old aliases to contributors.json

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (270272 => 270273)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-11-30 23:43:42 UTC (rev 270273)
@@ -259,8 +259,10 @@
 		468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 468BC454226539C800A36C96 /* open-window-then-write-to-it.html */; };
 		468F2F942368DAF100F4B864 /* window-open-then-document-open.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 468F2F932368DAA700F4B864 /* window-open-then-document-open.html */; };
 		46918EFC2237283C00468DFE /* DeviceOrientation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46918EFB2237283500468DFE /* DeviceOrientation.mm */; };
+		46A46A1A2575645600A1B118 /* SessionStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A46A192575645600A1B118 /* SessionStorage.mm */; };
 		46A911592108E6780078D40D /* CustomUserAgent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A911582108E66B0078D40D /* CustomUserAgent.mm */; };
 		46AE5A3720F9066D00E0873E /* SimpleServiceWorkerRegistrations-4.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-4.sqlite3 */; };
+		46C1EA9825758820005E409E /* alert.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46C1EA9725758805005E409E /* alert.html */; };
 		46C3AEB323D0E529001B0680 /* beforeunload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46C3AEB223D0E50F001B0680 /* beforeunload.html */; };
 		46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */; };
 		46C519E61D3563FD00DAA51A /* LocalStorageNullEntries.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */; };
@@ -1294,6 +1296,7 @@
 				379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
 				725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */,
 				1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
+				46C1EA9825758820005E409E /* alert.html in Copy Resources */,
 				1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */,
 				C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
 				F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */,
@@ -1990,7 +1993,9 @@
 		468BC454226539C800A36C96 /* open-window-then-write-to-it.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "open-window-then-write-to-it.html"; sourceTree = "<group>"; };
 		468F2F932368DAA700F4B864 /* window-open-then-document-open.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "window-open-then-document-open.html"; sourceTree = "<group>"; };
 		46918EFB2237283500468DFE /* DeviceOrientation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceOrientation.mm; sourceTree = "<group>"; };
+		46A46A192575645600A1B118 /* SessionStorage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SessionStorage.mm; sourceTree = "<group>"; };
 		46A911582108E66B0078D40D /* CustomUserAgent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomUserAgent.mm; sourceTree = "<group>"; };
+		46C1EA9725758805005E409E /* alert.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = alert.html; sourceTree = "<group>"; };
 		46C3AEB223D0E50F001B0680 /* beforeunload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = beforeunload.html; sourceTree = "<group>"; };
 		46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageNullEntries.mm; sourceTree = "<group>"; };
 		46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LocalStorageNullEntries.html; sourceTree = "<group>"; };
@@ -3385,6 +3390,7 @@
 				CE0947362063223B003C9BA0 /* SchemeRegistry.mm */,
 				51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
 				5C683471235ACC7C0041E6B1 /* ServiceWorkerTCPServer.h */,
+				46A46A192575645600A1B118 /* SessionStorage.mm */,
 				5CCB10DF2134579D00AC5AF0 /* ShouldGoToBackForwardListItem.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
@@ -3717,6 +3723,7 @@
 				55A817FE218101DF0004A39A /* 100x100-red.tga */,
 				55A817FD218101DF0004A39A /* 400x400-green.png */,
 				F4CFCDD9249FC9D900527482 /* Ahem.ttf */,
+				46C1EA9725758805005E409E /* alert.html */,
 				C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
 				F4A9202E1FEE34C800F59590 /* apple-data-url.html */,
 				A1798B8A2243611A000764BD /* apple-pay-active-session.html */,
@@ -5453,6 +5460,7 @@
 				9B4B5EA522DEBE19001E3D5A /* SelectionModifyByParagraphBoundary.mm in Sources */,
 				5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */,
 				51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,
+				46A46A1A2575645600A1B118 /* SessionStorage.mm in Sources */,
 				7CCE7ECB1A411A7E00447C4C /* SetAndUpdateCacheModel.mm in Sources */,
 				7CCE7ECC1A411A7E00447C4C /* SetDocumentURI.mm in Sources */,
 				CE6E81A020A6935F00E2C80F /* SetTimeoutFunction.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SessionStorage.mm (0 => 270273)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SessionStorage.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SessionStorage.mm	2020-11-30 23:43:42 UTC (rev 270273)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "TestUIDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKUIDelegatePrivate.h>
+#import <WebKit/WKWebViewConfiguration.h>
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <wtf/RetainPtr.h>
+
+enum class ShouldSessionBeCloned : bool { No, Yes };
+static void runSessionStorageInNewWindowTest(NSString* createWindowJS, ShouldSessionBeCloned shouldSessionBeCloned)
+{
+    __block RetainPtr<TestWKWebView> openedWebView;
+
+    auto uiDelegate = adoptNS([TestUIDelegate new]);
+    uiDelegate.get().createWebViewWithConfiguration = ^(WKWebViewConfiguration *configuration, WKNavigationAction *action, WKWindowFeatures *windowFeatures) {
+        openedWebView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
+        [openedWebView setUIDelegate:uiDelegate.get()];
+        return openedWebView.get();
+    };
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView setUIDelegate:uiDelegate.get()];
+    [webView configuration].preferences._javascript_CanOpenWindowsAutomatically = YES;
+
+    [webView loadTestPageNamed:@"alert"];
+    [uiDelegate waitForAlert];
+
+    bool ranScript = false;
+    [webView evaluateJavaScript:@"sessionStorage.setItem('foo', 'bar')" completionHandler: [&] (id result, NSError *error) {
+        EXPECT_TRUE(!error);
+        ranScript = true;
+    }];
+    TestWebKitAPI::Util::run(&ranScript);
+
+    // Create the new window.
+    [webView evaluateJavaScript:createWindowJS completionHandler: [&] (id result, NSError *error) {
+        EXPECT_TRUE(!error);
+        ranScript = true;
+    }];
+    [uiDelegate waitForAlert];
+    TestWebKitAPI::Util::run(&ranScript);
+    EXPECT_TRUE(!!openedWebView);
+
+    // Check if the session storage was cloned or not.
+    [openedWebView evaluateJavaScript:@"sessionStorage.getItem('foo') || ''" completionHandler: [&] (id result, NSError *error) {
+        EXPECT_TRUE(!error);
+        NSString* sessionValue = result;
+        if (shouldSessionBeCloned == ShouldSessionBeCloned::Yes)
+            EXPECT_WK_STREQ(@"bar", sessionValue);
+        else
+            EXPECT_WK_STREQ(@"", sessionValue);
+        ranScript = true;
+    }];
+    TestWebKitAPI::Util::run(&ranScript);
+}
+
+TEST(SessionStorage, WindowOpenClonesSession)
+{
+    runSessionStorageInNewWindowTest(@"open(document.URL) && true", ShouldSessionBeCloned::Yes);
+}
+
+TEST(SessionStorage, WindowOpenNoOpenerDoesNotCloneSession)
+{
+    runSessionStorageInNewWindowTest(@"open(document.URL, 'newWindow', 'noopener') && true", ShouldSessionBeCloned::No);
+}
+
+TEST(SessionStorage, WindowOpenNoReferrerDoesNotCloneSession)
+{
+    runSessionStorageInNewWindowTest(@"open(document.URL, 'newWindow', 'noreferrer') && true", ShouldSessionBeCloned::No);
+}
+
+// target=_blank implies rel=noopener.
+TEST(SessionStorage, BlankLinkTargetDoesNotCloneSession)
+{
+    runSessionStorageInNewWindowTest(@"a = document.createElement('a'); a.href = "" a.target = '_blank'; a.click()", ShouldSessionBeCloned::No);
+}
+
+TEST(SessionStorage, BlankLinkTargetRelOpenerClonesSession)
+{
+    runSessionStorageInNewWindowTest(@"a = document.createElement('a'); a.href = "" a.target = '_blank'; a.rel='opener'; a.click()", ShouldSessionBeCloned::Yes);
+}
+
+TEST(SessionStorage, NonBlankLinkTargetClonesSession)
+{
+    runSessionStorageInNewWindowTest(@"a = document.createElement('a'); a.href = "" a.target = 'newWindow'; a.click()", ShouldSessionBeCloned::Yes);
+}
+
+TEST(SessionStorage, NonBlankLinkTargetRelNoopenerDoesNotCloneSession)
+{
+    runSessionStorageInNewWindowTest(@"a = document.createElement('a'); a.href = "" a.target = 'newWindow'; a.rel='noopener'; a.click()", ShouldSessionBeCloned::No);
+}

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/alert.html (0 => 270273)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/alert.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/alert.html	2020-11-30 23:43:42 UTC (rev 270273)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+_onload_ = () => {
+    alert("foo");
+};
+</script>
+</body>
+</html>

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.h (270272 => 270273)


--- trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.h	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.h	2020-11-30 23:43:42 UTC (rev 270273)
@@ -27,6 +27,7 @@
 
 @interface TestUIDelegate : NSObject <WKUIDelegate>
 
+@property (nonatomic, copy) WKWebView* (^createWebViewWithConfiguration)(WKWebViewConfiguration *, WKNavigationAction *, WKWindowFeatures *);
 @property (nonatomic, copy) void (^runJavaScriptAlertPanelWithMessage)(WKWebView *, NSString *, WKFrameInfo *, void (^)(void));
 #if PLATFORM(MAC)
 @property (nonatomic, copy) void (^getContextMenuFromProposedMenu)(NSMenu *, _WKContextMenuElementInfo *, id <NSSecureCoding>, void (^)(NSMenu *));

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm (270272 => 270273)


--- trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm	2020-11-30 23:37:57 UTC (rev 270272)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm	2020-11-30 23:43:42 UTC (rev 270273)
@@ -32,6 +32,13 @@
 
 @implementation TestUIDelegate
 
+- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{
+    if (_createWebViewWithConfiguration)
+        return _createWebViewWithConfiguration(configuration, navigationAction, windowFeatures);
+    return nil;
+}
+
 - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
 {
     if (_runJavaScriptAlertPanelWithMessage)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to