Changeset 135765 in webkit


Ignore:
Timestamp:
Nov 26, 2012 2:24:31 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Refactor V8 bindings to allow content scripts to access subframes
https://bugs.webkit.org/show_bug.cgi?id=93646

Patch by Dan Carney <dcarney@google.com> on 2012-11-26
Reviewed by Adam Barth.

Source/WebCore:

Isolated window shells are now initialized on the fly
as needed.

No new tests. Existing test modified.

  • bindings/v8/DOMWrapperWorld.cpp:

(WebCore::DOMWrapperWorld::ensureIsolatedWorld):

  • bindings/v8/DOMWrapperWorld.h:

(WebCore::DOMWrapperWorld::createdFromUnitializedWorld):
(DOMWrapperWorld):

  • bindings/v8/ScriptController.cpp:

(WebCore::ScriptController::currentWorldContext):

LayoutTests:

Test modified to check isolated world access across frames.

  • http/tests/security/isolatedWorld/world-reuse-expected.txt:
  • http/tests/security/isolatedWorld/world-reuse.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r135753 r135765  
     12012-11-26  Dan Carney  <dcarney@google.com>
     2
     3        Refactor V8 bindings to allow content scripts to access subframes
     4        https://bugs.webkit.org/show_bug.cgi?id=93646
     5
     6        Reviewed by Adam Barth.
     7
     8        Test modified to check isolated world access across frames.
     9
     10        * http/tests/security/isolatedWorld/world-reuse-expected.txt:
     11        * http/tests/security/isolatedWorld/world-reuse.html:
     12
    1132012-11-26  Tony Chang  <tony@chromium.org>
    214
  • trunk/LayoutTests/http/tests/security/isolatedWorld/world-reuse-expected.txt

    r49963 r135765  
    33Expecting bar: bar
    44Expecting undefined: undefined
     5Expecting true: true
     6Expecting true: true
    57Expecting undefined,undefined: undefined,undefined
    68Expecting undefined,undefined: undefined,undefined
  • trunk/LayoutTests/http/tests/security/isolatedWorld/world-reuse.html

    r120174 r135765  
    3131  document.body.insertBefore(document.createElement("br"), iframe.nextSibling);
    3232  var iframeComplete = function(result) {
     33
     34    // Isolated world executing in frame should be able to to access parent content.
     35    testRunner.evaluateScriptInIsolatedWorld(1,
     36      "parent.document.body.appendChild(parent.document.createTextNode('Expecting true: ' + (parent.frames[0].document == this.document)));" +
     37      "parent.document.body.appendChild(parent.document.createElement('br'));");
     38
    3339    document.body.appendChild(document.createTextNode('Expecting undefined,undefined: ' + result));
    3440    document.body.appendChild(document.createElement('br'));
    3541    reloadFrame();
    3642  }
     43
     44  // Isolated world executing in window should be able to to access frame content.
     45  testRunner.evaluateScriptInIsolatedWorld(1,
     46    "document.body.appendChild(document.createTextNode('Expecting true: ' + !!frames[0].document));" +
     47    "document.body.appendChild(document.createElement('br'));");
     48
    3749  iframe.src = "resources/iframe.html";
    3850 
  • trunk/Source/WebCore/ChangeLog

    r135763 r135765  
     12012-11-26  Dan Carney  <dcarney@google.com>
     2
     3        Refactor V8 bindings to allow content scripts to access subframes
     4        https://bugs.webkit.org/show_bug.cgi?id=93646
     5
     6        Reviewed by Adam Barth.
     7
     8        Isolated window shells are now initialized on the fly
     9        as needed.
     10
     11        No new tests. Existing test modified.
     12
     13        * bindings/v8/DOMWrapperWorld.cpp:
     14        (WebCore::DOMWrapperWorld::ensureIsolatedWorld):
     15        * bindings/v8/DOMWrapperWorld.h:
     16        (WebCore::DOMWrapperWorld::createdFromUnitializedWorld):
     17        (DOMWrapperWorld):
     18        * bindings/v8/ScriptController.cpp:
     19        (WebCore::ScriptController::currentWorldContext):
     20
    1212012-11-26  Alex Christensen  <alex.christensen@flexsim.com>
    222
  • trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp

    r135601 r135765  
    138138{
    139139    ASSERT(worldId != mainWorldId);
     140    ASSERT(worldId >= uninitializedWorldId);
    140141
    141142    WorldMap& map = isolatedWorldMap();
  • trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h

    r135601 r135765  
    9797    bool isMainWorld() const { return m_worldId == mainWorldId; }
    9898    bool isIsolatedWorld() const { return isIsolatedWorldId(m_worldId); }
     99    bool createdFromUnitializedWorld() const { return m_worldId < uninitializedWorldId; }
     100
    99101    int worldId() const { return m_worldId; }
    100102    int extensionGroup() const { return m_extensionGroup; }
  • trunk/Source/WebCore/bindings/v8/ScriptController.cpp

    r135687 r135765  
    437437v8::Local<v8::Context> ScriptController::currentWorldContext()
    438438{
    439     if (v8::Context::InContext()) {
    440         v8::Handle<v8::Context> context = v8::Context::GetEntered();
    441         if (DOMWrapperWorld::isolated(context)) {
    442             if (m_frame == toFrameIfNotDetached(context))
    443                 return v8::Local<v8::Context>::New(context);
    444             return v8::Local<v8::Context>();
    445         }
    446     }
    447     return v8::Local<v8::Context>::New(windowShell(mainThreadNormalWorld())->context());
     439    if (!v8::Context::InContext())
     440        return v8::Local<v8::Context>::New(windowShell(mainThreadNormalWorld())->context());
     441
     442    v8::Handle<v8::Context> context = v8::Context::GetEntered();
     443    DOMWrapperWorld* isolatedWorld = DOMWrapperWorld::isolated(context);
     444    if (!isolatedWorld)
     445        return v8::Local<v8::Context>::New(windowShell(mainThreadNormalWorld())->context());
     446
     447    Frame* frame = toFrameIfNotDetached(context);
     448    if (!m_frame)
     449        return v8::Local<v8::Context>();
     450
     451    if (m_frame == frame)
     452        return v8::Local<v8::Context>::New(context);
     453
     454    // FIXME: Need to handle weak isolated worlds correctly.
     455    if (isolatedWorld->createdFromUnitializedWorld())
     456        return v8::Local<v8::Context>();
     457
     458    return v8::Local<v8::Context>::New(windowShell(isolatedWorld)->context());
    448459}
    449460
Note: See TracChangeset for help on using the changeset viewer.