Title: [131629] trunk
Revision
131629
Author
[email protected]
Date
2012-10-17 12:34:18 -0700 (Wed, 17 Oct 2012)

Log Message

Bind isolatedWorldSecurityOrigin to world
https://bugs.webkit.org/show_bug.cgi?id=99582

Patch by Dan Carney <[email protected]> on 2012-10-17
Reviewed by Adam Barth.

Source/WebCore:

Security origin of isolated worlds was not previously set at the world
level, although it could have been.

No new tests. No change in functionality.

* bindings/v8/DOMWrapperWorld.cpp:
(WebCore::DOMWrapperWorld::deallocate):
(WebCore):
(WebCore::isolatedWorldSecurityOrigins):
(WebCore::DOMWrapperWorld::isolatedWorldSecurityOrigin):
(WebCore::DOMWrapperWorld::setIsolatedWorldSecurityOrigin):
(WebCore::DOMWrapperWorld::clearIsolatedWorldSecurityOrigin):
* bindings/v8/DOMWrapperWorld.h:
(DOMWrapperWorld):
(WebCore::DOMWrapperWorld::isIsolatedWorldId):
(WebCore::DOMWrapperWorld::isIsolatedWorld):
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::resetIsolatedWorlds):
(WebCore::ScriptController::evaluateInIsolatedWorld):
(WebCore::ScriptController::collectIsolatedContexts):
* bindings/v8/ScriptController.h:
(ScriptController):
(WebCore::ScriptController::setIsolatedWorldSecurityOrigin):
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::initializeIfNeeded):
* bindings/v8/V8DOMWindowShell.h:
(V8DOMWindowShell):
* bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
(WebCore::V8XMLHttpRequest::constructorCallback):

Tools:

Added ability to unset isolatedWorldSecurityOrigin.

* DumpRenderTree/chromium/DRTTestRunner.cpp:
(DRTTestRunner::setIsolatedWorldSecurityOrigin):

LayoutTests:

Clean up of isolated worlds added after test completion.

* http/tests/security/isolatedWorld/cross-origin-xhr.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (131628 => 131629)


--- trunk/LayoutTests/ChangeLog	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/LayoutTests/ChangeLog	2012-10-17 19:34:18 UTC (rev 131629)
@@ -1,3 +1,14 @@
+2012-10-17  Dan Carney  <[email protected]>
+
+        Bind isolatedWorldSecurityOrigin to world
+        https://bugs.webkit.org/show_bug.cgi?id=99582
+
+        Reviewed by Adam Barth.
+
+        Clean up of isolated worlds added after test completion.
+
+        * http/tests/security/isolatedWorld/cross-origin-xhr.html:
+
 2012-10-17  Simon Fraser  <[email protected]>
 
         GraphicsLayer visible rect computation needs to use the current animating transform

Modified: trunk/LayoutTests/http/tests/security/isolatedWorld/cross-origin-xhr.html (131628 => 131629)


--- trunk/LayoutTests/http/tests/security/isolatedWorld/cross-origin-xhr.html	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/LayoutTests/http/tests/security/isolatedWorld/cross-origin-xhr.html	2012-10-17 19:34:18 UTC (rev 131629)
@@ -46,8 +46,11 @@
             switch (message.type) {
                 case 'test-done':
                     currentTest++;
-                    if (currentTest == tests.length)
+                    if (currentTest == tests.length) {
+                        testRunner.setIsolatedWorldSecurityOrigin(1, null);
+                        testRunner.setIsolatedWorldSecurityOrigin(2, null);
                         finishJSTest();
+                    }
                     else
                         tests[currentTest]();
                     break;

Modified: trunk/Source/WebCore/ChangeLog (131628 => 131629)


--- trunk/Source/WebCore/ChangeLog	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/ChangeLog	2012-10-17 19:34:18 UTC (rev 131629)
@@ -1,3 +1,40 @@
+2012-10-17  Dan Carney  <[email protected]>
+
+        Bind isolatedWorldSecurityOrigin to world
+        https://bugs.webkit.org/show_bug.cgi?id=99582
+
+        Reviewed by Adam Barth.
+
+        Security origin of isolated worlds was not previously set at the world
+        level, although it could have been. 
+
+        No new tests. No change in functionality.
+
+        * bindings/v8/DOMWrapperWorld.cpp:
+        (WebCore::DOMWrapperWorld::deallocate):
+        (WebCore):
+        (WebCore::isolatedWorldSecurityOrigins):
+        (WebCore::DOMWrapperWorld::isolatedWorldSecurityOrigin):
+        (WebCore::DOMWrapperWorld::setIsolatedWorldSecurityOrigin):
+        (WebCore::DOMWrapperWorld::clearIsolatedWorldSecurityOrigin):
+        * bindings/v8/DOMWrapperWorld.h:
+        (DOMWrapperWorld):
+        (WebCore::DOMWrapperWorld::isIsolatedWorldId):
+        (WebCore::DOMWrapperWorld::isIsolatedWorld):
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::resetIsolatedWorlds):
+        (WebCore::ScriptController::evaluateInIsolatedWorld):
+        (WebCore::ScriptController::collectIsolatedContexts):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+        (WebCore::ScriptController::setIsolatedWorldSecurityOrigin):
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::initializeIfNeeded):
+        * bindings/v8/V8DOMWindowShell.h:
+        (V8DOMWindowShell):
+        * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
+        (WebCore::V8XMLHttpRequest::constructorCallback):
+
 2012-10-17  Simon Fraser  <[email protected]>
 
         GraphicsLayer visible rect computation needs to use the current animating transform

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-10-17 19:34:18 UTC (rev 131629)
@@ -112,4 +112,35 @@
     return world.release();
 }
 
+typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap;
+static IsolatedWorldSecurityOriginMap& isolatedWorldSecurityOrigins()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(IsolatedWorldSecurityOriginMap, map, ());
+    return map;
+}
+
+SecurityOrigin* DOMWrapperWorld::isolatedWorldSecurityOrigin()
+{
+    ASSERT(this->isIsolatedWorld());
+    IsolatedWorldSecurityOriginMap& origins = isolatedWorldSecurityOrigins();
+    IsolatedWorldSecurityOriginMap::iterator it = origins.find(worldId());
+    return it == origins.end() ? 0 : it->value.get();
+}
+
+void DOMWrapperWorld::setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> securityOrigin)
+{
+    ASSERT(DOMWrapperWorld::isIsolatedWorldId(worldID));
+    if (securityOrigin)
+        isolatedWorldSecurityOrigins().set(worldID, securityOrigin);
+    else
+        isolatedWorldSecurityOrigins().remove(worldID);
+}
+
+void DOMWrapperWorld::clearIsolatedWorldSecurityOrigin(int worldID)
+{
+    ASSERT(DOMWrapperWorld::isIsolatedWorldId(worldID));
+    isolatedWorldSecurityOrigins().remove(worldID);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-10-17 19:34:18 UTC (rev 131629)
@@ -32,6 +32,7 @@
 #define DOMWrapperWorld_h
 
 #include "DOMDataStore.h"
+#include "SecurityOrigin.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -45,14 +46,22 @@
     static const int mainWorldExtensionGroup = 0;
     static const int uninitializedWorldId = -1;
     static const int uninitializedExtensionGroup = -1;
-    // If 0 is passed as worldId, the world will be assigned a temporary id instead.
+    // If uninitializedWorldId is passed as worldId, the world will be assigned a temporary id instead.
     static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup);
     static bool isolatedWorldsExist() { return isolatedWorldCount; }
+    static bool isIsolatedWorldId(int worldId) { return worldId != mainWorldId && worldId != uninitializedWorldId; }
+    // Associates an isolated world (see above for description) with a security
+    // origin. XMLHttpRequest instances used in that world will be considered
+    // to come from that origin, not the frame's.
+    static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
+    static void clearIsolatedWorldSecurityOrigin(int worldID);
+    SecurityOrigin* isolatedWorldSecurityOrigin();
     // FIXME: this is a workaround for a problem in WebViewImpl.
     // Do not use this anywhere else!!
     static PassRefPtr<DOMWrapperWorld> createUninitializedWorld();
 
     bool isMainWorld() { return m_worldId == mainWorldId; }
+    bool isIsolatedWorld() { return isIsolatedWorldId(m_worldId); }
     int worldId() const { return m_worldId; }
     int extensionGroup() const { return m_extensionGroup; }
     DOMDataStore* domDataStore() const

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-10-17 19:34:18 UTC (rev 131629)
@@ -149,7 +149,6 @@
         iter->value->destroyIsolatedShell();
     }
     m_isolatedWorlds.clear();
-    m_isolatedWorldSecurityOrigins.clear();
 }
 
 void ScriptController::clearForClose()
@@ -369,12 +368,6 @@
         v8::HandleScope evaluateHandleScope;
         V8DOMWindowShell* isolatedWorldShell = ensureIsolatedWorldContext(worldID, extensionGroup);
 
-        if (worldID != DOMWrapperWorld::uninitializedWorldId) {
-            IsolatedWorldSecurityOriginMap::iterator securityOriginIter = m_isolatedWorldSecurityOrigins.find(worldID);
-            if (securityOriginIter != m_isolatedWorldSecurityOrigins.end())
-                isolatedWorldShell->setIsolatedWorldSecurityOrigin(securityOriginIter->value);
-        }
-
         isolatedWorldShell->initializeIfNeeded();
         if (isolatedWorldShell->context().IsEmpty())
             return;
@@ -406,15 +399,6 @@
     }
 }
 
-void ScriptController::setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> securityOrigin)
-{
-    ASSERT(worldID);
-    m_isolatedWorldSecurityOrigins.set(worldID, securityOrigin);
-    IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldID);
-    if (iter != m_isolatedWorlds.end())
-        iter->value->setIsolatedWorldSecurityOrigin(securityOrigin);
-}
-
 TextPosition ScriptController::eventHandlerPosition() const
 {
     ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
@@ -667,13 +651,14 @@
     v8::HandleScope handleScope;
     for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isolatedWorlds.end(); ++it) {
         V8DOMWindowShell* isolatedWorldShell = it->value;
-        if (!isolatedWorldShell->isolatedWorldSecurityOrigin())
+        SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecurityOrigin();
+        if (!origin)
             continue;
         v8::Handle<v8::Context> v8Context = isolatedWorldShell->context();
         if (v8Context.IsEmpty())
             continue;
         ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(v8Context));
-        result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, isolatedWorldShell->isolatedWorldSecurityOrigin()));
+        result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, origin));
     }
 }
 #endif

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.h (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-10-17 19:34:18 UTC (rev 131629)
@@ -107,10 +107,11 @@
     // FIXME: Get rid of extensionGroup here.
     void evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
 
-    // Associates an isolated world (see above for description) with a security
-    // origin. XMLHttpRequest instances used in that world will be considered
-    // to come from that origin, not the frame's.
-    void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
+    // FIXME: Remove references to this call in chromium and delete it.
+    inline static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> origin)
+    {
+        DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, origin);
+    }
 
     // Creates a property of the global object of a frame.
     void bindToWindowObject(Frame*, const String& key, NPObject*);
@@ -190,7 +191,6 @@
     // reference to the v8 context it contains, which is not made weak until we
     // call world->destroyIsolatedShell().
     typedef HashMap<int, V8DOMWindowShell*> IsolatedWorldMap;
-    typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap;
 
     void resetIsolatedWorlds();
 
@@ -204,7 +204,6 @@
     // here so that they can be used again by future calls to
     // evaluateInIsolatedWorld().
     IsolatedWorldMap m_isolatedWorlds;
-    IsolatedWorldSecurityOriginMap m_isolatedWorldSecurityOrigins;
 
     bool m_paused;
 

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-10-17 19:34:18 UTC (rev 131629)
@@ -381,6 +381,12 @@
         //        document domain
         //        changes.
         m_context->UseDefaultSecurityToken();
+
+        SecurityOrigin* origin = m_world->isolatedWorldSecurityOrigin();
+        if (origin && InspectorInstrumentation::hasFrontends()) {
+            ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(m_context.get()));
+            InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptState, origin);
+        }
     }
     m_frame->loader()->client()->didCreateScriptContext(m_context.get(), m_world->extensionGroup(), m_world->worldId());
 
@@ -611,16 +617,4 @@
     setSecurityToken();
 }
 
-void V8DOMWindowShell::setIsolatedWorldSecurityOrigin(PassRefPtr<SecurityOrigin> securityOrigin)
-{
-    ASSERT(!m_world->isMainWorld());
-    // FIXME: Should this be here?
-    if (!m_isolatedWorldShellSecurityOrigin && !context().IsEmpty() && InspectorInstrumentation::runtimeAgentEnabled(m_frame)) {
-        v8::HandleScope handleScope;
-        ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(context()));
-        InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptState, securityOrigin.get());
-    }
-    m_isolatedWorldShellSecurityOrigin = securityOrigin;
-}
-
 } // WebCore

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-10-17 19:34:18 UTC (rev 131629)
@@ -83,13 +83,6 @@
 
     DOMWrapperWorld* world() { return m_world.get(); }
 
-    void setIsolatedWorldSecurityOrigin(PassRefPtr<SecurityOrigin>);
-    SecurityOrigin* isolatedWorldSecurityOrigin() const
-    {
-        ASSERT(!m_world->isMainWorld());
-        return m_isolatedWorldShellSecurityOrigin.get();
-    };
-
     // Returns the isolated world associated with
     // v8::Context::GetEntered(). Because worlds are isolated, the entire
     // _javascript_ call stack should be from the same isolated world.
@@ -136,9 +129,6 @@
     ScopedPersistent<v8::Context> m_context;
     ScopedPersistent<v8::Object> m_global;
     ScopedPersistent<v8::Object> m_document;
-
-    // FIXME: Either remove this or the map in ScriptController.
-    RefPtr<SecurityOrigin> m_isolatedWorldShellSecurityOrigin;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp (131628 => 131629)


--- trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp	2012-10-17 19:34:18 UTC (rev 131629)
@@ -56,7 +56,7 @@
 
     RefPtr<SecurityOrigin> securityOrigin;
     if (V8DOMWindowShell* isolatedWorldShell = V8DOMWindowShell::getEntered())
-        securityOrigin = isolatedWorldShell->isolatedWorldSecurityOrigin();
+        securityOrigin = isolatedWorldShell->world()->isolatedWorldSecurityOrigin();
 
     RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
 

Modified: trunk/Tools/ChangeLog (131628 => 131629)


--- trunk/Tools/ChangeLog	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Tools/ChangeLog	2012-10-17 19:34:18 UTC (rev 131629)
@@ -1,3 +1,15 @@
+2012-10-17  Dan Carney  <[email protected]>
+
+        Bind isolatedWorldSecurityOrigin to world
+        https://bugs.webkit.org/show_bug.cgi?id=99582
+
+        Reviewed by Adam Barth.
+
+        Added ability to unset isolatedWorldSecurityOrigin.
+
+        * DumpRenderTree/chromium/DRTTestRunner.cpp:
+        (DRTTestRunner::setIsolatedWorldSecurityOrigin):
+
 2012-10-17  Joseph Pecoraro  <[email protected]>
 
         Unreviewed watchlist addition.

Modified: trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp (131628 => 131629)


--- trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-10-17 19:02:30 UTC (rev 131628)
+++ trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-10-17 19:34:18 UTC (rev 131629)
@@ -1392,12 +1392,13 @@
 {
     result->setNull();
 
-    if (arguments.size() != 2 || !arguments[0].isNumber() || !arguments[1].isString())
+    if (arguments.size() != 2 || !arguments[0].isNumber() || !(arguments[1].isString() || arguments[1].isNull()))
         return;
 
-    m_shell->webView()->focusedFrame()->setIsolatedWorldSecurityOrigin(
-        arguments[0].toInt32(),
-        WebSecurityOrigin::createFromString(cppVariantToWebString(arguments[1])));
+    WebSecurityOrigin origin;
+    if (arguments[1].isString())
+        origin = WebSecurityOrigin::createFromString(cppVariantToWebString(arguments[1]));
+    m_shell->webView()->focusedFrame()->setIsolatedWorldSecurityOrigin(arguments[0].toInt32(), origin);
 }
 
 void DRTTestRunner::setAllowUniversalAccessFromFileURLs(const CppArgumentList& arguments, CppVariant* result)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to