Title: [273817] trunk
Revision
273817
Author
you...@apple.com
Date
2021-03-03 08:55:05 -0800 (Wed, 03 Mar 2021)

Log Message

WebKitLegacy needs to keep JSDOMWindow even though it is used while its origin is not set
https://bugs.webkit.org/show_bug.cgi?id=222589
<rdar://problem/74258258>

Reviewed by Geoffrey Garen.

Source/WebCore:

Use the new flag to allow reuse of JSDOMWindow objects even though they are created at a time where its SecurityOrigin is not set yet.
This allows keeping WebKitLegacy existing functionality.

Covered by API test.

* bindings/js/JSWindowProxy.cpp:
(WebCore::JSWindowProxy::setWindow):

Source/WTF:

* Scripts/Preferences/WebPreferencesInternal.yaml:
Introduce a flag, on for WebKit and off for WebKitLegacy.

Tools:

* TestWebKitAPI/Tests/mac/JSWrapperForNodeInWebFrame.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (273816 => 273817)


--- trunk/Source/WTF/ChangeLog	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Source/WTF/ChangeLog	2021-03-03 16:55:05 UTC (rev 273817)
@@ -1,3 +1,14 @@
+2021-03-03  Youenn Fablet  <you...@apple.com>
+
+        WebKitLegacy needs to keep JSDOMWindow even though it is used while its origin is not set
+        https://bugs.webkit.org/show_bug.cgi?id=222589
+        <rdar://problem/74258258>
+
+        Reviewed by Geoffrey Garen.
+
+        * Scripts/Preferences/WebPreferencesInternal.yaml:
+        Introduce a flag, on for WebKit and off for WebKitLegacy.
+
 2021-03-02  Simon Fraser  <simon.fra...@apple.com>
 
         Rename ForcePageRenderingUpdatesAt60FPSEnabled preference to PreferPageRenderingUpdatesNear60FPSEnabled

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml (273816 => 273817)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml	2021-03-03 16:55:05 UTC (rev 273817)
@@ -885,6 +885,18 @@
     WebKit:
       default: true
 
+WindowObjectAlwaysInitializedWithSecurityOriginEnabled:
+  type: bool
+  humanReadableName: "Ensure Window object is initialized with a security origin"
+  humanReadableDescription: "Ensure Window object is initialized with a security origin"
+  defaultValue:
+    WebKitLegacy:
+      default: false
+    WebKit:
+      default: true
+    WebCore:
+      default: true
+
 ZoomOnDoubleTapWhenRoot:
   type: bool
   condition: PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/ChangeLog (273816 => 273817)


--- trunk/Source/WebCore/ChangeLog	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Source/WebCore/ChangeLog	2021-03-03 16:55:05 UTC (rev 273817)
@@ -1,3 +1,19 @@
+2021-03-03  Youenn Fablet  <you...@apple.com>
+
+        WebKitLegacy needs to keep JSDOMWindow even though it is used while its origin is not set
+        https://bugs.webkit.org/show_bug.cgi?id=222589
+        <rdar://problem/74258258>
+
+        Reviewed by Geoffrey Garen.
+
+        Use the new flag to allow reuse of JSDOMWindow objects even though they are created at a time where its SecurityOrigin is not set yet.
+        This allows keeping WebKitLegacy existing functionality.
+
+        Covered by API test.
+
+        * bindings/js/JSWindowProxy.cpp:
+        (WebCore::JSWindowProxy::setWindow):
+
 2021-03-03  Zalan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Enable simplified vertical alignment for empty inline boxes

Modified: trunk/Source/WebCore/bindings/js/JSWindowProxy.cpp (273816 => 273817)


--- trunk/Source/WebCore/bindings/js/JSWindowProxy.cpp	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Source/WebCore/bindings/js/JSWindowProxy.cpp	2021-03-03 16:55:05 UTC (rev 273817)
@@ -106,7 +106,7 @@
         auto& localWindow = downcast<DOMWindow>(domWindow);
         auto& windowStructure = *JSDOMWindow::createStructure(vm, nullptr, prototype);
         window = JSDOMWindow::create(vm, &windowStructure, localWindow, this);
-        if (!localWindow.document()->haveInitializedSecurityOrigin())
+        if (!localWindow.document()->haveInitializedSecurityOrigin() && localWindow.document()->settings().windowObjectAlwaysInitializedWithSecurityOriginEnabled())
             localWindow.setAsWrappedWithoutInitializedSecurityOrigin();
     }
 

Modified: trunk/Tools/ChangeLog (273816 => 273817)


--- trunk/Tools/ChangeLog	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Tools/ChangeLog	2021-03-03 16:55:05 UTC (rev 273817)
@@ -1,3 +1,14 @@
+2021-03-03  Youenn Fablet  <you...@apple.com>
+
+        WebKitLegacy needs to keep JSDOMWindow even though it is used while its origin is not set
+        https://bugs.webkit.org/show_bug.cgi?id=222589
+        <rdar://problem/74258258>
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/mac/JSWrapperForNodeInWebFrame.mm:
+        (TestWebKitAPI::TEST):
+
 2021-03-03  Don Olmstead  <don.olmst...@sony.com>
 
         [CMake] _javascript_Core GLib headers should be copies

Modified: trunk/Tools/TestWebKitAPI/Tests/mac/JSWrapperForNodeInWebFrame.mm (273816 => 273817)


--- trunk/Tools/TestWebKitAPI/Tests/mac/JSWrapperForNodeInWebFrame.mm	2021-03-03 16:37:24 UTC (rev 273816)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/JSWrapperForNodeInWebFrame.mm	2021-03-03 16:55:05 UTC (rev 273817)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "PlatformUtilities.h"
 #import <WebKit/WebFramePrivate.h>
+#import <WebKit/WebPreferencesPrivate.h>
 #import <WebKit/WebScriptWorld.h>
 #import <_javascript_Core/JSContextRef.h>
 #import <_javascript_Core/JSRetainPtr.h>
@@ -95,4 +96,27 @@
     EXPECT_TRUE(JSValueIsUndefined(isolatedCtx, JSObjectGetProperty(isolatedCtx, isolatedNodeJSObject, normalPropertyJSString.get(), 0)));
 }
 
+TEST(WebKitLegacy, JSDOMWindowWrapperBeforeOriginInitialization)
+{
+    auto webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    auto frameLoadDelegate = adoptNS([[JSWrapperForNodeFrameLoadDelegate alloc] init]);
+
+    webView.get().frameLoadDelegate = frameLoadDelegate.get();
+    auto *mainFrame = webView.get().mainFrame;
+    [mainFrame loadHTMLString:@"<div id=\"target\"</div>" baseURL:[NSURL URLWithString:@"http://localhost"]];
+
+    auto *normalWorld = [WebScriptWorld standardWorld];
+    auto normalCtx = [mainFrame _globalContextForScriptWorld:normalWorld];
+
+    [mainFrame _stringByEvaluatingJavaScriptFromString:@"window.caches = 1" withGlobalObject:JSContextGetGlobalObject(normalCtx) inScriptWorld:normalWorld];
+
+    auto result = [mainFrame _stringByEvaluatingJavaScriptFromString:@"window.caches" withGlobalObject:JSContextGetGlobalObject(normalCtx) inScriptWorld:normalWorld];
+    EXPECT_WK_STREQ(result, @"1");
+
+    Util::run(&didFinishLoad);
+
+    result = [mainFrame _stringByEvaluatingJavaScriptFromString:@"window.caches" withGlobalObject:JSContextGetGlobalObject(normalCtx) inScriptWorld:normalWorld];
+    EXPECT_WK_STREQ(result, @"1");
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to