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: http://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 36a300b..11562cf 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 42c6f1a..3839cc6 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 fd72c75..1e6c768 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 9410642..ec1c7bd 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 a6a20b2..eff82d9 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 c5f117e..8dcabf0 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 3ded6f6..0115dee 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 12e4c17..4aea0a2 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 0de2fd0..2f5c66f 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 acc2f47..a88a838 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 656f97a..c5f4909 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 c8a6f84..13c7b10 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 2aaad08..1f81970 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;