Title: [228309] trunk
Revision
228309
Author
[email protected]
Date
2018-02-08 20:16:52 -0800 (Thu, 08 Feb 2018)

Log Message

There should be a way to disable [OverrideBuiltins] behavior in a given DOMWrapperWorld
https://bugs.webkit.org/show_bug.cgi?id=182524
<rdar://problem/9057327>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Add new flag on DOMWrapperWorld indicating if the [OverrideBuiltins] behavior should
be enabled in this world or not. The behavior is enabled by default for Web-compatibility.
This flag is queried in accessVisibleNamedProperty() when doing the named property
lookup.

Covered by new API test.

* bindings/js/DOMWrapperWorld.h:
(WebCore::DOMWrapperWorld::disableOverrideBuiltinsBehavior):
(WebCore::DOMWrapperWorld::shouldDisableOverrideBuiltinsBehavior const):
* bindings/js/JSDOMAbstractOperations.h:
(WebCore::accessVisibleNamedProperty):

Source/WebKit:

Add C API on WKBundleScriptWorld and Cocoa API on WKWebProcessPlugInScriptWorld to
disable the [OverrideBuiltins] behavior on a given script world.

The [OverrideBuiltins] behavior [1] is legacy behavior that is needed for Web compatibility
but allowing the client to disable this behavior in a given world makes development easier
and running injected script on uncontrolled content a lot more reliable.

[1] https://heycam.github.io/webidl/#OverrideBuiltins

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.h:
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.mm:
(-[WKWebProcessPlugInScriptWorld disableOverrideBuiltinsBehavior]):
* WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp:
(WKBundleScriptWorldDisableOverrideBuiltinsBehavior):
* WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h:
* WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp:
(WebKit::InjectedBundleScriptWorld::disableOverrideBuiltinsBehavior):
* WebProcess/InjectedBundle/InjectedBundleScriptWorld.h:

Tools:

Add API test coverage.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior.cpp: Added.
(TestWebKitAPI::runJavaScriptAlert):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp: Added.
(TestWebKitAPI::InjectedBundleDisableOverrideBuiltinsBehaviorTest::InjectedBundleDisableOverrideBuiltinsBehaviorTest):
(TestWebKitAPI::InjectedBundleDisableOverrideBuiltinsBehaviorTest::initialize):
* TestWebKitAPI/Tests/WebKit/override-builtins-test.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228308 => 228309)


--- trunk/Source/WebCore/ChangeLog	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebCore/ChangeLog	2018-02-09 04:16:52 UTC (rev 228309)
@@ -1,3 +1,24 @@
+2018-02-08  Chris Dumez  <[email protected]>
+
+        There should be a way to disable [OverrideBuiltins] behavior in a given DOMWrapperWorld
+        https://bugs.webkit.org/show_bug.cgi?id=182524
+        <rdar://problem/9057327>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add new flag on DOMWrapperWorld indicating if the [OverrideBuiltins] behavior should
+        be enabled in this world or not. The behavior is enabled by default for Web-compatibility.
+        This flag is queried in accessVisibleNamedProperty() when doing the named property
+        lookup.
+
+        Covered by new API test.
+
+        * bindings/js/DOMWrapperWorld.h:
+        (WebCore::DOMWrapperWorld::disableOverrideBuiltinsBehavior):
+        (WebCore::DOMWrapperWorld::shouldDisableOverrideBuiltinsBehavior const):
+        * bindings/js/JSDOMAbstractOperations.h:
+        (WebCore::accessVisibleNamedProperty):
+
 2018-02-08  Per Arne Vollan  <[email protected]>
 
         Move WebVideoFullscreenController from WebCore to WebKitLegacy.

Modified: trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h (228308 => 228309)


--- trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2018-02-09 04:16:52 UTC (rev 228309)
@@ -47,6 +47,9 @@
     void setShadowRootIsAlwaysOpen() { m_shadowRootIsAlwaysOpen = true; }
     bool shadowRootIsAlwaysOpen() const { return m_shadowRootIsAlwaysOpen; }
 
+    void disableOverrideBuiltinsBehavior() { m_shouldDisableOverrideBuiltinsBehavior = true; }
+    bool shouldDisableOverrideBuiltinsBehavior() const { return m_shouldDisableOverrideBuiltinsBehavior; }
+
     DOMObjectWrapperMap& wrappers() { return m_wrappers; }
 
     bool isNormal() const { return m_isNormal; }
@@ -63,6 +66,7 @@
 
     bool m_isNormal;
     bool m_shadowRootIsAlwaysOpen { false };
+    bool m_shouldDisableOverrideBuiltinsBehavior { false };
 };
 
 DOMWrapperWorld& normalWorld(JSC::VM&);

Modified: trunk/Source/WebCore/bindings/js/JSDOMAbstractOperations.h (228308 => 228309)


--- trunk/Source/WebCore/bindings/js/JSDOMAbstractOperations.h	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebCore/bindings/js/JSDOMAbstractOperations.h	2018-02-09 04:16:52 UTC (rev 228309)
@@ -104,7 +104,7 @@
         return std::nullopt;
 
     // 3. If O implements an interface that has the [OverrideBuiltins] extended attribute, then return true.
-    if (overrideBuiltins == OverrideBuiltins::Yes)
+    if (overrideBuiltins == OverrideBuiltins::Yes && !worldForDOMObject(thisObject).shouldDisableOverrideBuiltinsBehavior())
         return result;
 
     // 4. Initialize prototype to be the value of the internal [[Prototype]] property of O.

Modified: trunk/Source/WebKit/ChangeLog (228308 => 228309)


--- trunk/Source/WebKit/ChangeLog	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/ChangeLog	2018-02-09 04:16:52 UTC (rev 228309)
@@ -1,3 +1,30 @@
+2018-02-08  Chris Dumez  <[email protected]>
+
+        There should be a way to disable [OverrideBuiltins] behavior in a given DOMWrapperWorld
+        https://bugs.webkit.org/show_bug.cgi?id=182524
+        <rdar://problem/9057327>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add C API on WKBundleScriptWorld and Cocoa API on WKWebProcessPlugInScriptWorld to
+        disable the [OverrideBuiltins] behavior on a given script world.
+
+        The [OverrideBuiltins] behavior [1] is legacy behavior that is needed for Web compatibility
+        but allowing the client to disable this behavior in a given world makes development easier
+        and running injected script on uncontrolled content a lot more reliable.
+
+        [1] https://heycam.github.io/webidl/#OverrideBuiltins
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.h:
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.mm:
+        (-[WKWebProcessPlugInScriptWorld disableOverrideBuiltinsBehavior]):
+        * WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp:
+        (WKBundleScriptWorldDisableOverrideBuiltinsBehavior):
+        * WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h:
+        * WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp:
+        (WebKit::InjectedBundleScriptWorld::disableOverrideBuiltinsBehavior):
+        * WebProcess/InjectedBundle/InjectedBundleScriptWorld.h:
+
 2018-02-08  Ross Kirsling  <[email protected]>
 
         Remove WebProcessPool::platformInitialize stub.

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.h (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.h	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.h	2018-02-09 04:16:52 UTC (rev 228309)
@@ -39,6 +39,7 @@
 
 - (void)clearWrappers;
 - (void)makeAllShadowRootsOpen WK_API_AVAILABLE(macosx(10.12), ios(10.0));
+- (void)disableOverrideBuiltinsBehavior WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.mm (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.mm	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInScriptWorld.mm	2018-02-09 04:16:52 UTC (rev 228309)
@@ -61,6 +61,11 @@
     _world->makeAllShadowRootsOpen();
 }
 
+- (void)disableOverrideBuiltinsBehavior
+{
+    _world->disableOverrideBuiltinsBehavior();
+}
+
 - (NSString *)name
 {
     return _world->name();

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp	2018-02-09 04:16:52 UTC (rev 228309)
@@ -58,6 +58,11 @@
     toImpl(scriptWorldRef)->makeAllShadowRootsOpen();
 }
 
+void WKBundleScriptWorldDisableOverrideBuiltinsBehavior(WKBundleScriptWorldRef scriptWorldRef)
+{
+    toImpl(scriptWorldRef)->disableOverrideBuiltinsBehavior();
+}
+
 WKStringRef WKBundleScriptWorldCopyName(WKBundleScriptWorldRef scriptWorldRef)
 {
     return toCopiedAPI(toImpl(scriptWorldRef)->name());

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h	2018-02-09 04:16:52 UTC (rev 228309)
@@ -38,6 +38,7 @@
 WK_EXPORT WKBundleScriptWorldRef WKBundleScriptWorldNormalWorld();
 WK_EXPORT void WKBundleScriptWorldClearWrappers(WKBundleScriptWorldRef scriptWorld);
 WK_EXPORT void WKBundleScriptWorldMakeAllShadowRootsOpen(WKBundleScriptWorldRef scriptWorld);
+WK_EXPORT void WKBundleScriptWorldDisableOverrideBuiltinsBehavior(WKBundleScriptWorldRef scriptWorld);
 WK_EXPORT WKStringRef WKBundleScriptWorldCopyName(WKBundleScriptWorldRef scriptWorld);
 
 #ifdef __cplusplus

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp	2018-02-09 04:16:52 UTC (rev 228309)
@@ -112,4 +112,9 @@
     m_world->setShadowRootIsAlwaysOpen();
 }
 
+void InjectedBundleScriptWorld::disableOverrideBuiltinsBehavior()
+{
+    m_world->disableOverrideBuiltinsBehavior();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h (228308 => 228309)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h	2018-02-09 04:16:52 UTC (rev 228309)
@@ -51,6 +51,7 @@
 
     void clearWrappers();
     void makeAllShadowRootsOpen();
+    void disableOverrideBuiltinsBehavior();
 
     const String& name() const { return m_name; }
 

Modified: trunk/Tools/ChangeLog (228308 => 228309)


--- trunk/Tools/ChangeLog	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Tools/ChangeLog	2018-02-09 04:16:52 UTC (rev 228309)
@@ -1,3 +1,22 @@
+2018-02-08  Chris Dumez  <[email protected]>
+
+        There should be a way to disable [OverrideBuiltins] behavior in a given DOMWrapperWorld
+        https://bugs.webkit.org/show_bug.cgi?id=182524
+        <rdar://problem/9057327>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior.cpp: Added.
+        (TestWebKitAPI::runJavaScriptAlert):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp: Added.
+        (TestWebKitAPI::InjectedBundleDisableOverrideBuiltinsBehaviorTest::InjectedBundleDisableOverrideBuiltinsBehaviorTest):
+        (TestWebKitAPI::InjectedBundleDisableOverrideBuiltinsBehaviorTest::initialize):
+        * TestWebKitAPI/Tests/WebKit/override-builtins-test.html: Added.
+
 2018-02-08  Michael Catanzaro  <[email protected]>
 
         TestController should not exercise cocoa-specific resource load statistics APIs

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (228308 => 228309)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-02-09 03:30:45 UTC (rev 228308)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-02-09 04:16:52 UTC (rev 228309)
@@ -534,6 +534,9 @@
 		7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */; };
 		7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
 		7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
+		83148B06202AC6A400BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83148B05202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior.cpp */; };
+		83148B07202AC6AD00BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83148B04202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp */; };
+		83148B09202AC78D00BADE99 /* override-builtins-test.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 83148B08202AC76800BADE99 /* override-builtins-test.html */; };
 		8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */; };
 		8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */; };
 		835CF9671D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 835CF9661D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp */; };
@@ -1020,6 +1023,7 @@
 				CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */,
 				7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
 				290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
+				83148B09202AC78D00BADE99 /* override-builtins-test.html in Copy Resources */,
 				CEBCA1391E3A807A00C73293 /* page-with-csp-iframe.html in Copy Resources */,
 				CEBCA1381E3A807A00C73293 /* page-with-csp.html in Copy Resources */,
 				CEBCA13B1E3A807A00C73293 /* page-without-csp-iframe.html in Copy Resources */,
@@ -1522,6 +1526,9 @@
 		7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
 		7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
 		81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
+		83148B04202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp; sourceTree = "<group>"; };
+		83148B05202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleDisableOverrideBuiltinsBehavior.cpp; sourceTree = "<group>"; };
+		83148B08202AC76800BADE99 /* override-builtins-test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "override-builtins-test.html"; sourceTree = "<group>"; };
 		8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuDownload.mm; sourceTree = "<group>"; };
 		8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "link-with-download-attribute.html"; sourceTree = "<group>"; };
 		835CF9661D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RestoreSessionStateWithoutNavigation.cpp; sourceTree = "<group>"; };
@@ -2585,6 +2592,8 @@
 				4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */,
 				BC575AAC126E83B9006F0F12 /* InjectedBundleBasic.cpp */,
 				BC575AAF126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp */,
+				83148B05202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior.cpp */,
+				83148B04202AC68200BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp */,
 				378E64711632646D00B6C676 /* InjectedBundleFrameHitTest.cpp */,
 				378E64751632655D00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp */,
 				F660AA1215A619C8003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp */,
@@ -2810,6 +2819,7 @@
 				5797FE321EB15A8900B2F4A0 /* navigation-client-default-crypto.html */,
 				C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */,
 				CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
+				83148B08202AC76800BADE99 /* override-builtins-test.html */,
 				0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
 				F6FDDDD514241C48004F1729 /* push-state.html */,
 				0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */,
@@ -3476,6 +3486,7 @@
 				5198A2401EA7E59F008910B7 /* InitialWarmedProcessUsed.mm in Sources */,
 				7A95BDE11E9BEC5F00865498 /* InjectedBundleAppleEvent.cpp in Sources */,
 				7CCE7EFB1A411AE600447C4C /* InjectedBundleBasic.cpp in Sources */,
+				83148B06202AC6A400BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior.cpp in Sources */,
 				7CCE7EFC1A411AE600447C4C /* InjectedBundleFrameHitTest.cpp in Sources */,
 				7CCE7EFD1A411AE600447C4C /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
 				7C83E0B81D0A64BD00FEBCF3 /* InjectedBundleMakeAllShadowRootsOpen.cpp in Sources */,
@@ -3756,6 +3767,7 @@
 				BC575AB0126E83C8006F0F12 /* InjectedBundleBasic_Bundle.cpp in Sources */,
 				BC575AA2126E7660006F0F12 /* InjectedBundleController.cpp in Sources */,
 				1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */,
+				83148B07202AC6AD00BADE99 /* InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp in Sources */,
 				378E64771632655E00B6C676 /* InjectedBundleFrameHitTest_Bundle.cpp in Sources */,
 				F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */,
 				BC575A97126E74F1006F0F12 /* InjectedBundleMain.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior.cpp (0 => 228309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior.cpp	2018-02-09 04:16:52 UTC (rev 228309)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static unsigned testNumber = 0;
+static bool done = false;
+
+static void runJavaScriptAlertEnabled(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
+{   
+    ASSERT_NOT_NULL(frame);    
+    EXPECT_EQ(page, WKFrameGetPage(frame));
+    
+    ++testNumber;
+    EXPECT_WK_STREQ("PASS: [OverrideBuiltins] was not disabled", alertText);
+    if (testNumber == 2)
+        done = true;
+}
+
+TEST(WebKit, InjectedBundleNoDisableOverrideBuiltinsBehaviorTest)
+{
+    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("InjectedBundleNoDisableOverrideBuiltinsBehaviorTestPageGroup")));
+
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleNoDisableOverrideBuiltinsBehaviorTest", pageGroup.get()));
+    PlatformWebView webView(context.get(), pageGroup.get());
+
+    WKPageUIClientV0 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 0;
+    uiClient.runJavaScriptAlert = runJavaScriptAlertEnabled;
+
+    WKPageSetPageUIClient(webView.page(), &uiClient.base);
+
+    testNumber = 0;
+    done = false;
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("override-builtins-test", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    Util::run(&done);
+}
+
+static void runJavaScriptAlertDisabled(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo)
+{   
+    ASSERT_NOT_NULL(frame);    
+    EXPECT_EQ(page, WKFrameGetPage(frame));
+
+    ++testNumber;
+    EXPECT_WK_STREQ("PASS: [OverrideBuiltins] was disabled", alertText);
+    if (testNumber == 2)
+        done = true;
+}
+
+TEST(WebKit, InjectedBundleDisableOverrideBuiltinsBehaviorTest)
+{
+    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("InjectedBundleDisableOverrideBuiltinsBehaviorTestPageGroup")));
+
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleDisableOverrideBuiltinsBehaviorTest", pageGroup.get()));
+    PlatformWebView webView(context.get(), pageGroup.get());
+
+    WKPageUIClientV0 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 0;
+    uiClient.runJavaScriptAlert = runJavaScriptAlertDisabled;
+
+    WKPageSetPageUIClient(webView.page(), &uiClient.base);
+
+    testNumber = 0;
+    done = false;
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("override-builtins-test", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    Util::run(&done);
+}
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp (0 => 228309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/InjectedBundleDisableOverrideBuiltinsBehavior_Bundle.cpp	2018-02-09 04:16:52 UTC (rev 228309)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "InjectedBundleTest.h"
+#include <WebKit/WKBundlePageGroup.h>
+#include <WebKit/WKBundlePrivate.h>
+#include <WebKit/WKBundleScriptWorld.h>
+#include <WebKit/WKRetainPtr.h>
+#include <assert.h>
+
+namespace TestWebKitAPI {
+
+class InjectedBundleNoDisableOverrideBuiltinsBehaviorTest : public InjectedBundleTest {
+public:
+    InjectedBundleNoDisableOverrideBuiltinsBehaviorTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    { }
+
+    virtual void initialize(WKBundleRef bundle, WKTypeRef userData)
+    {
+        assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID());
+        WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData);
+
+        WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString(
+            "window._onload_ = function () {\n"
+            "    const form = document.getElementById('test').parentNode;\n"
+            "    alert(form.tagName != 'FORM' ? 'PASS: [OverrideBuiltins] was not disabled' : 'FAIL: [OverrideBuiltins] was disabled');\n"
+            "}\n"));
+
+        auto normalWorld = WKBundleScriptWorldNormalWorld();
+        WKBundleAddUserScript(bundle, pageGroup, normalWorld, source.get(), 0, 0, 0, kWKInjectAtDocumentEnd, kWKInjectInAllFrames);
+
+        auto isolatedWorld = WKBundleScriptWorldCreateWorld();
+        WKBundleAddUserScript(bundle, pageGroup, isolatedWorld, source.get(), 0, 0, 0, kWKInjectAtDocumentEnd, kWKInjectInAllFrames);
+    }
+};
+
+class InjectedBundleDisableOverrideBuiltinsBehaviorTest : public InjectedBundleTest {
+public:
+    InjectedBundleDisableOverrideBuiltinsBehaviorTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    { }
+
+    virtual void initialize(WKBundleRef bundle, WKTypeRef userData)
+    {
+        assert(WKGetTypeID(userData) == WKBundlePageGroupGetTypeID());
+        WKBundlePageGroupRef pageGroup = static_cast<WKBundlePageGroupRef>(userData);
+
+        WKRetainPtr<WKStringRef> source(AdoptWK, WKStringCreateWithUTF8CString(
+            "window._onload_ = function () {\n"
+            "    const form = document.getElementById('test').parentNode;\n"
+            "    alert(form.tagName === 'FORM' ? 'PASS: [OverrideBuiltins] was disabled' : 'FAIL: [OverrideBuiltins] was not disabled');\n"
+            "}\n"));
+
+        auto normalWorld = WKBundleScriptWorldNormalWorld();
+        WKBundleScriptWorldDisableOverrideBuiltinsBehavior(normalWorld);
+        WKBundleAddUserScript(bundle, pageGroup, normalWorld, source.get(), 0, 0, 0, kWKInjectAtDocumentEnd, kWKInjectInAllFrames);
+
+        auto isolatedWorld = WKBundleScriptWorldCreateWorld();
+        WKBundleScriptWorldDisableOverrideBuiltinsBehavior(isolatedWorld);
+        WKBundleAddUserScript(bundle, pageGroup, isolatedWorld, source.get(), 0, 0, 0, kWKInjectAtDocumentEnd, kWKInjectInAllFrames);
+    }
+};
+
+static InjectedBundleTest::Register<InjectedBundleNoDisableOverrideBuiltinsBehaviorTest> registrar1("InjectedBundleNoDisableOverrideBuiltinsBehaviorTest");
+static InjectedBundleTest::Register<InjectedBundleDisableOverrideBuiltinsBehaviorTest> registrar2("InjectedBundleDisableOverrideBuiltinsBehaviorTest");
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/override-builtins-test.html (0 => 228309)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/override-builtins-test.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/override-builtins-test.html	2018-02-09 04:16:52 UTC (rev 228309)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<form>
+<input id="test" name="tagName">
+</form>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to