2011-01-20 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jan 2011 17:15:50 +0000 (17:15 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jan 2011 17:15:50 +0000 (17:15 +0000)
        Reviewed by Adam Roben.

        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
        https://bugs.webkit.org/show_bug.cgi?id=42327

        * platform/mac-wk2/Skipped: Unskip the tests that needed this.
2011-01-20  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Adam Roben.

        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
        https://bugs.webkit.org/show_bug.cgi?id=42327

        Added a new API call, WKBundleFrameForJavaScriptContext, that gets the WKBundleFrameRef
        that corresponds to a JSContextRef (or null if none).

        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
        (WKBundleFrameForJavaScriptContext): Simple wrapper, defers to a WebFrame
        static method.
        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
        * WebProcess/WebPage/WebFrame.cpp:
        (WebKit::WebFrame::frameForContext): Follow the maze of twisty pointers.
        * WebProcess/WebPage/WebFrame.h:
2011-01-20  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Adam Roben.

        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
        https://bugs.webkit.org/show_bug.cgi?id=42327

        * WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm: Add support
        for methods that take their normal arguments but also a JSContextRef.
        * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl: IDL definition
        for evaluateScriptInIsolatedWorld.
        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
        (WTR::InjectedBundlePage::didClearWindowForFrame): Set a magic variable only if
        this call is for an isolated world.
        * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
        (WTR::worldMap): Helper to create a world map.
        (WTR::LayoutTestController::worldIDForWorld): Map from an ID to a world.
        (WTR::LayoutTestController::evaluateScriptInIsolatedWorld): The newly
        added LayoutTestController API.
        * WebKitTestRunner/InjectedBundle/LayoutTestController.h:

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/Skipped
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/WebFrame.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm
Tools/WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.cpp
Tools/WebKitTestRunner/InjectedBundle/LayoutTestController.h

index 36a300b1049e1a19f2b6b275770626e8e939b2a3..11562cfb3b244b95d27a9adb8454ab2638e92516 100644 (file)
@@ -1,3 +1,12 @@
+2011-01-20  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adam Roben.
+
+        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
+        https://bugs.webkit.org/show_bug.cgi?id=42327
+
+        * platform/mac-wk2/Skipped: Unskip the tests that needed this.
+
 2011-01-19  Adam Roben  <aroben@apple.com>
 
         Add a test that scrolls composited content that has already been painted
index 42c6f1af4bca8607d17ad9aa71dd3800b83a1bfe..3839cc62b51aa686b6beb288eb9c03cc8e97dcdc 100644 (file)
@@ -56,6 +56,8 @@ compositing/iframes/iframe-src-change.html
 
 # WebKitTestRunner needs an implementation of eventSender
 # <https://bugs.webkit.org/show_bug.cgi?id=42194>
+http/tests/security/isolatedWorld/events.html
+http/tests/security/isolatedWorld/userGestureEvents.html
 http/tests/misc/isindex-with-no-form-base-href.html
 plugins/clicking-missing-plugin-fires-delegate.html
 editing/deleting/delete-by-word-001.html
@@ -1284,36 +1286,6 @@ webarchive/test-table-background.html
 webarchive/test-td-background.html
 webarchive/test-xml-stylesheet.xml
 
-# WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
-# <https://bugs.webkit.org/show_bug.cgi?id=42327>
-http/tests/security/isolatedWorld/all-window-properties.html
-http/tests/security/isolatedWorld/all-window-prototypes.html
-http/tests/security/isolatedWorld/body-properties.html
-http/tests/security/isolatedWorld/body-prototype.html
-http/tests/security/isolatedWorld/click-event.html
-http/tests/security/isolatedWorld/didClearWindowObject.html
-http/tests/security/isolatedWorld/dispatchEvent.html
-http/tests/security/isolatedWorld/document-open.html
-http/tests/security/isolatedWorld/document-properties.html
-http/tests/security/isolatedWorld/document-prototype.html
-http/tests/security/isolatedWorld/events.html
-http/tests/security/isolatedWorld/global-variables.html
-http/tests/security/isolatedWorld/image-properties.html
-http/tests/security/isolatedWorld/image-prototype.html
-http/tests/security/isolatedWorld/location-properties.html
-http/tests/security/isolatedWorld/location-prototype.html
-http/tests/security/isolatedWorld/number-prototype.html
-http/tests/security/isolatedWorld/object-prototype.html
-http/tests/security/isolatedWorld/storage-properties.html
-http/tests/security/isolatedWorld/storage-prototype.html
-http/tests/security/isolatedWorld/string-prototype.html
-http/tests/security/isolatedWorld/top-properties.html
-http/tests/security/isolatedWorld/userGestureEvents.html
-http/tests/security/isolatedWorld/window-properties.html
-http/tests/security/isolatedWorld/window-setTimeout-function.html
-http/tests/security/isolatedWorld/window-setTimeout-string.html
-http/tests/security/isolatedWorld/world-reuse.html
-
 # WebKitTestRunner needs to support layoutTestController.setJavaScriptProfilingEnabled
 # <https://bugs.webkit.org/show_bug.cgi?id=42328>
 fast/profiler
index fd72c752931347170cd9cabef7dfc8dd77a32942..1e6c768d5826ee744e159e465af8fd4953a94ada 100644 (file)
@@ -1,3 +1,21 @@
+2011-01-20  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adam Roben.
+
+        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
+        https://bugs.webkit.org/show_bug.cgi?id=42327
+        
+        Added a new API call, WKBundleFrameForJavaScriptContext, that gets the WKBundleFrameRef
+        that corresponds to a JSContextRef (or null if none).
+
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
+        (WKBundleFrameForJavaScriptContext): Simple wrapper, defers to a WebFrame
+        static method.
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::frameForContext): Follow the maze of twisty pointers.
+        * WebProcess/WebPage/WebFrame.h:
+
 2011-01-20  Alejandro G. Castro  <alex@igalia.com>
 
         Fix compilation error in GTK WebKit2.
index 9410642b7aba1c7d23bccce4eacd02c6cc40dc75..ec1c7bd9a68ee286998563c515f570d9b7ae4d8c 100644 (file)
@@ -85,6 +85,11 @@ JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frameRef)
     return toImpl(frameRef)->jsContext();
 }
 
+WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context)
+{
+    return toAPI(WebFrame::frameForContext(context));
+}
+
 JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frameRef, WKBundleScriptWorldRef worldRef)
 {
     return toImpl(frameRef)->jsContextForWorld(toImpl(worldRef));
index a6a20b282b31f4dd35794f15997d66f44b956de8..eff82d96b9b575c967e45f5fc6c4d36fd5fd6598 100644 (file)
@@ -46,6 +46,8 @@ WK_EXPORT WKURLRef WKBundleFrameCopyProvisionalURL(WKBundleFrameRef frame);
 WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frame);
 WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frame, WKBundleScriptWorldRef world);
 
+WK_EXPORT WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context);
+
 WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frame, WKBundleNodeHandleRef nodeHandle, WKBundleScriptWorldRef world);
 WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frame, WKBundleRangeHandleRef rangeHandle, WKBundleScriptWorldRef world);
 
index c5f117e69f1a819cc77343a403eae74c334675e6..8dcabf0db0e2b242440a90ec7c6436f27afa55b4 100644 (file)
@@ -34,6 +34,7 @@
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include <JavaScriptCore/APICast.h>
+#include <JavaScriptCore/JSContextRef.h>
 #include <JavaScriptCore/JSLock.h>
 #include <JavaScriptCore/JSValueRef.h>
 #include <WebCore/AnimationController.h>
@@ -455,6 +456,17 @@ JSGlobalContextRef WebFrame::jsContextForWorld(InjectedBundleScriptWorld* world)
     return toGlobalRef(m_coreFrame->script()->globalObject(world->coreWorld())->globalExec());
 }
 
+WebFrame* WebFrame::frameForContext(JSContextRef context)
+{
+    JSObjectRef globalObjectRef = JSContextGetGlobalObject(context);
+    JSC::JSObject* globalObjectObj = toJS(globalObjectRef);
+    if (strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell") != 0)
+        return 0;
+
+    Frame* coreFrame = static_cast<JSDOMWindowShell*>(globalObjectObj)->window()->impl()->frame();
+    return static_cast<WebFrameLoaderClient*>(coreFrame->loader()->client())->webFrame();
+}
+
 JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleNodeHandle* nodeHandle, InjectedBundleScriptWorld* world)
 {
     JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(world->coreWorld());
index 3ded6f65a6d57d7404b6f386a198d2b3a053d4de..0115deef9ff9c3fa62fe352e1531011ad867618e 100644 (file)
@@ -90,6 +90,8 @@ public:
     JSGlobalContextRef jsContext();
     JSGlobalContextRef jsContextForWorld(InjectedBundleScriptWorld*);
 
+    static WebFrame* frameForContext(JSContextRef);
+
     JSValueRef jsWrapperForWorld(InjectedBundleNodeHandle*, InjectedBundleScriptWorld*);
     JSValueRef jsWrapperForWorld(InjectedBundleRangeHandle*, InjectedBundleScriptWorld*);
 
index 12e4c172b17dc92314187682097a6a26c6a7336c..4aea0a2a0a9abd25a0e1e535c2f2fd100cf6a6f7 100644 (file)
@@ -1,3 +1,24 @@
+2011-01-20  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adam Roben.
+
+        WebKitTestRunner needs to support layoutTestController.evaluateScriptInIsolatedWorld
+        https://bugs.webkit.org/show_bug.cgi?id=42327
+
+        * WebKitTestRunner/InjectedBundle/Bindings/CodeGeneratorTestRunner.pm: Add support
+        for methods that take their normal arguments but also a JSContextRef.
+        * WebKitTestRunner/InjectedBundle/Bindings/LayoutTestController.idl: IDL definition
+        for evaluateScriptInIsolatedWorld.
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::didClearWindowForFrame): Set a magic variable only if
+        this call is for an isolated world.
+        * WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
+        (WTR::worldMap): Helper to create a world map.
+        (WTR::LayoutTestController::worldIDForWorld): Map from an ID to a world.
+        (WTR::LayoutTestController::evaluateScriptInIsolatedWorld): The newly
+        added LayoutTestController API.
+        * WebKitTestRunner/InjectedBundle/LayoutTestController.h:
+
 2011-01-19  Adam Roben  <aroben@apple.com>
 
         Convert paths in environment variables back to msys-style inside commit-log-editor
index 0de2fd0456e450067512ccf5e131fd0f34cdc845..2f5c66f107134016b256612601dad5db81239575 100644 (file)
@@ -256,6 +256,10 @@ EOF
 
                 $self->_includeHeaders(\%contentsIncludes, $function->signature->type, $function->signature);
 
+                if ($function->signature->extendedAttributes->{"PassContext"}) {
+                    push(@parameters, "context");
+                }
+
                 foreach my $i (0..$#specifiedParameters) {
                     my $parameter = $specifiedParameters[$i];
 
index acc2f47e90583a95362cdb42eb966f2fd1a7f267..a88a838d4dde5740705550755f30c7e0afa1629d 100644 (file)
@@ -76,6 +76,9 @@ module WTR {
 
         // Text search testing.
         boolean findString(in DOMString target, in object optionsArray);
+
+        // Evaluating script in a special context
+        [PassContext] void evaluateScriptInIsolatedWorld(in unsigned long worldID, in DOMString script)
     };
 
 }
index 656f97ae786cb3eb9e8e74543499df89fb359977..c5f4909d5d34529caa9f35b09ee5ec30f375b2c2 100644 (file)
@@ -526,12 +526,14 @@ void InjectedBundlePage::didClearWindowForFrame(WKBundleFrameRef frame, WKBundle
     if (!InjectedBundle::shared().isTestRunning())
         return;
 
-    if (WKBundleScriptWorldNormalWorld() != world)
-        return;
-
     JSGlobalContextRef context = WKBundleFrameGetJavaScriptContextForWorld(frame, world);
     JSObjectRef window = JSContextGetGlobalObject(context);
 
+    if (WKBundleScriptWorldNormalWorld() != world) {
+        JSObjectSetProperty(context, window, toJS("__worldID").get(), JSValueMakeNumber(context, LayoutTestController::worldIDForWorld(world)), kJSPropertyAttributeReadOnly, 0);
+        return;
+    }
+
     JSValueRef exception = 0;
     InjectedBundle::shared().layoutTestController()->makeWindowObject(context, window, &exception);
     InjectedBundle::shared().gcController()->makeWindowObject(context, window, &exception);
index c8a6f84e9c82959809dbbec32a8edf2232b5da20..13c7b10cb791a9f77cfb8805ecd1356892f1579c 100644 (file)
@@ -37,6 +37,7 @@
 #include <WebKit2/WKBundlePrivate.h>
 #include <WebKit2/WKRetainPtr.h>
 #include <WebKit2/WebKit2.h>
+#include <wtf/HashMap.h>
 
 namespace WTR {
 
@@ -308,4 +309,44 @@ void LayoutTestController::makeWindowObject(JSContextRef context, JSObjectRef wi
     setProperty(context, windowObject, "layoutTestController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
 }
 
+typedef WTF::HashMap<unsigned, WKRetainPtr<WKBundleScriptWorldRef> > WorldMap;
+static WorldMap& worldMap()
+{
+    static WorldMap& map = *new WorldMap;
+    return map;
+}
+
+unsigned LayoutTestController::worldIDForWorld(WKBundleScriptWorldRef world)
+{
+    WorldMap::const_iterator end = worldMap().end();
+    for (WorldMap::const_iterator it = worldMap().begin(); it != end; ++it) {
+        if (it->second == world)
+            return it->first;
+    }
+
+    return 0;
+}
+
+void LayoutTestController::evaluateScriptInIsolatedWorld(JSContextRef context, unsigned worldID, JSStringRef script)
+{
+    // A worldID of 0 always corresponds to a new world. Any other worldID corresponds to a world
+    // that is created once and cached forever.
+    WKRetainPtr<WKBundleScriptWorldRef> world;
+    if (!worldID)
+        world.adopt(WKBundleScriptWorldCreateWorld());
+    else {
+        WKRetainPtr<WKBundleScriptWorldRef>& worldSlot = worldMap().add(worldID, 0).first->second;
+        if (!worldSlot)
+            worldSlot.adopt(WKBundleScriptWorldCreateWorld());
+        world = worldSlot;
+    }
+
+    WKBundleFrameRef frame = WKBundleFrameForJavaScriptContext(context);
+    if (!frame)
+        frame = WKBundlePageGetMainFrame(InjectedBundle::shared().page()->page());
+
+    JSGlobalContextRef jsContext = WKBundleFrameGetJavaScriptContextForWorld(frame, world.get());
+    JSEvaluateScript(jsContext, script, 0, 0, 0, 0); 
+}
+
 } // namespace WTR
index 2aaad084c457fdf227bee3504f837a71c1ce8381..1f81970a749334c37c2e86233655b6ee84aeff3a 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "JSWrappable.h"
 #include <JavaScriptCore/JSRetainPtr.h>
+#include <WebKit2/WKBundleScriptWorld.h>
 #include <string>
 #include <wtf/PassRefPtr.h>
 
@@ -122,6 +123,9 @@ public:
 
     bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
 
+    void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
+    static unsigned worldIDForWorld(WKBundleScriptWorldRef);
+
 private:
     static const double waitToDumpWatchdogTimerInterval;