Changeset 52847 in webkit


Ignore:
Timestamp:
Jan 5, 2010 7:09:24 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-01-05 Adam Barth <abarth@webkit.org>

Reviewed by Dimitri Glazkov.

[v8] Move V8DOMWindowShell to ScriptController
https://bugs.webkit.org/show_bug.cgi?id=33232

This patch moves V8DOMWindow shell to ScriptController, where the
window shells live in JSC land. The next step will be to allow for
more than one window shell per script controller.

  • bindings/v8/ScriptController.cpp: (WebCore::ScriptController::ScriptController): (WebCore::ScriptController::~ScriptController): (WebCore::ScriptController::updateSecurityOrigin): (WebCore::ScriptController::evaluateInIsolatedWorld): (WebCore::ScriptController::haveInterpreter): (WebCore::ScriptController::mainWorldWindowShell): (WebCore::ScriptController::clearWindowShell): (WebCore::ScriptController::clearForClose): (WebCore::ScriptController::destroyWindowShell): (WebCore::ScriptController::updateDocument):
  • bindings/v8/ScriptController.h:
  • bindings/v8/V8DOMWindowShell.cpp: (WebCore::V8DOMWindowShell::~V8DOMWindowShell):
  • bindings/v8/V8DOMWindowShell.h: (WebCore::V8DOMWindowShell::localHandleForContext):
  • bindings/v8/V8DOMWrapper.cpp: (WebCore::V8DOMWrapper::instantiateV8Object): (WebCore::V8DOMWrapper::convertDocumentToV8Object): (WebCore::V8DOMWrapper::convertNewNodeToV8Object):
  • bindings/v8/V8IsolatedContext.cpp: (WebCore::V8IsolatedContext::V8IsolatedContext):
  • bindings/v8/V8Proxy.cpp: (WebCore::V8Proxy::V8Proxy): (WebCore::V8Proxy::~V8Proxy): (WebCore::V8Proxy::handleOutOfMemory): (WebCore::V8Proxy::evaluateInIsolatedWorld): (WebCore::V8Proxy::setInjectedScriptContextDebugId): (WebCore::V8Proxy::context): (WebCore::V8Proxy::mainWorldContext): (WebCore::V8Proxy::currentContext): (WebCore::V8Proxy::setContextDebugId):
  • bindings/v8/V8Proxy.h:
  • bindings/v8/WorldContextHandle.cpp: (WebCore::WorldContextHandle::adjustedContext):

2010-01-05 Adam Barth <abarth@webkit.org>

Reviewed by Dimitri Glazkov.

[v8] Move V8DOMWindowShell to ScriptController
https://bugs.webkit.org/show_bug.cgi?id=33232

Update FrameLoaderClientImpl.cpp to call clearForClose on
ScriptController instead of on V8Proxy.

  • src/FrameLoaderClientImpl.cpp: (WebKit::FrameLoaderClientImpl::detachedFromParent3):
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52846 r52847  
     12010-01-05  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        [v8] Move V8DOMWindowShell to ScriptController
     6        https://bugs.webkit.org/show_bug.cgi?id=33232
     7
     8        This patch moves V8DOMWindow shell to ScriptController, where the
     9        window shells live in JSC land.  The next step will be to allow for
     10        more than one window shell per script controller.
     11
     12        * bindings/v8/ScriptController.cpp:
     13        (WebCore::ScriptController::ScriptController):
     14        (WebCore::ScriptController::~ScriptController):
     15        (WebCore::ScriptController::updateSecurityOrigin):
     16        (WebCore::ScriptController::evaluateInIsolatedWorld):
     17        (WebCore::ScriptController::haveInterpreter):
     18        (WebCore::ScriptController::mainWorldWindowShell):
     19        (WebCore::ScriptController::clearWindowShell):
     20        (WebCore::ScriptController::clearForClose):
     21        (WebCore::ScriptController::destroyWindowShell):
     22        (WebCore::ScriptController::updateDocument):
     23        * bindings/v8/ScriptController.h:
     24        * bindings/v8/V8DOMWindowShell.cpp:
     25        (WebCore::V8DOMWindowShell::~V8DOMWindowShell):
     26        * bindings/v8/V8DOMWindowShell.h:
     27        (WebCore::V8DOMWindowShell::localHandleForContext):
     28        * bindings/v8/V8DOMWrapper.cpp:
     29        (WebCore::V8DOMWrapper::instantiateV8Object):
     30        (WebCore::V8DOMWrapper::convertDocumentToV8Object):
     31        (WebCore::V8DOMWrapper::convertNewNodeToV8Object):
     32        * bindings/v8/V8IsolatedContext.cpp:
     33        (WebCore::V8IsolatedContext::V8IsolatedContext):
     34        * bindings/v8/V8Proxy.cpp:
     35        (WebCore::V8Proxy::V8Proxy):
     36        (WebCore::V8Proxy::~V8Proxy):
     37        (WebCore::V8Proxy::handleOutOfMemory):
     38        (WebCore::V8Proxy::evaluateInIsolatedWorld):
     39        (WebCore::V8Proxy::setInjectedScriptContextDebugId):
     40        (WebCore::V8Proxy::context):
     41        (WebCore::V8Proxy::mainWorldContext):
     42        (WebCore::V8Proxy::currentContext):
     43        (WebCore::V8Proxy::setContextDebugId):
     44        * bindings/v8/V8Proxy.h:
     45        * bindings/v8/WorldContextHandle.cpp:
     46        (WebCore::WorldContextHandle::adjustedContext):
     47
    1482010-01-05  Kent Tamura  <tkent@chromium.org>
    249
  • trunk/WebCore/bindings/v8/ScriptController.cpp

    r52811 r52847  
    107107    , m_paused(false)
    108108    , m_proxy(new V8Proxy(frame))
     109    , m_windowShell(V8DOMWindowShell::create(frame))
    109110#if ENABLE(NETSCAPE_PLUGIN_API)
    110111    , m_windowScriptNPObject(0)
     
    117118{
    118119    m_proxy->disconnectFrame();
     120    m_windowShell.clear();
    119121}
    120122
     
    141143void ScriptController::updateSecurityOrigin()
    142144{
    143     m_proxy->windowShell()->updateSecurityOrigin();
     145    m_windowShell->updateSecurityOrigin();
    144146}
    145147
     
    206208void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources)
    207209{
     210    // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
     211    m_windowShell->initContextIfNeeded();
    208212    m_proxy->evaluateInIsolatedWorld(worldID, sources, 0);
    209213}
     
    292296bool ScriptController::haveInterpreter() const
    293297{
    294     return m_proxy->windowShell()->isContextInitialized();
     298    return m_windowShell->isContextInitialized();
    295299}
    296300
     
    436440}
    437441
     442V8DOMWindowShell* ScriptController::mainWorldWindowShell() const
     443{
     444    m_windowShell->initContextIfNeeded();
     445    return m_windowShell.get();
     446}
    438447
    439448void ScriptController::clearWindowShell()
    440449{
    441450    m_mainWorldScriptState.clear();
     451    m_proxy->resetIsolatedWorlds();
    442452
    443453    // V8 binding expects ScriptController::clearWindowShell only be called
    444     // when a frame is loading a new page. V8Proxy::clearForNavigation
     454    // when a frame is loading a new page. V8DOMWindowShell::clearForNavigation
    445455    // creates a new context for the new page.
    446     m_proxy->clearForNavigation();
     456    m_windowShell->clearForNavigation();
     457}
     458
     459void ScriptController::clearForClose()
     460{
     461    m_windowShell->clearForClose();
     462}
     463
     464void ScriptController::destroyWindowShell()
     465{
     466    m_windowShell->clearForClose();
     467    m_windowShell->destroyGlobal();
    447468}
    448469
     
    454475void ScriptController::updateDocument()
    455476{
    456     m_proxy->windowShell()->updateDocument();
     477    m_windowShell->updateDocument();
    457478}
    458479
  • trunk/WebCore/bindings/v8/ScriptController.h

    r52823 r52847  
    6464    V8Proxy* proxy() { return m_proxy.get(); }
    6565
     66    V8DOMWindowShell* mainWorldWindowShell() const;
     67
    6668    ScriptValue executeScript(const ScriptSourceCode&);
    6769    ScriptValue executeScript(const String& script, bool forceUserGesture = false);
     
    154156    void updateDocument();
    155157
     158    void clearForClose();
     159
     160    // This is very destructive (e.g., out of memory).
     161    void destroyWindowShell();
     162
    156163    void updateSecurityOrigin();
    157164    void clearScriptObjects();
     
    183190    bool m_paused;
    184191
     192    // FIXME: V8Proxy should eventually be removed.
    185193    OwnPtr<V8Proxy> m_proxy;
     194
     195    // For the moment, we have one of these.  Soon we will have one per DOMWrapperWorld.
     196    RefPtr<V8DOMWindowShell> m_windowShell;
     197
    186198    typedef HashMap<Widget*, NPObject*> PluginObjectMap;
    187199
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r52811 r52847  
    9999    : m_frame(frame)
    100100{
     101}
     102
     103V8DOMWindowShell::~V8DOMWindowShell()
     104{
     105    clearForClose();
     106    destroyGlobal();
    101107}
    102108
  • trunk/WebCore/bindings/v8/V8DOMWindowShell.h

    r52666 r52847  
    4747    static PassRefPtr<V8DOMWindowShell> create(Frame*);
    4848
     49    virtual ~V8DOMWindowShell();
     50
    4951    v8::Handle<v8::Context> context() const { return m_context; }
     52
     53    // This method is slower than |context()|, but sometimes we need local handles.
     54    v8::Local<v8::Context> localHandleForContext() const { return v8::Local<v8::Context>::New(m_context); }
    5055
    5156    // Update document object of the frame.
     
    6671    void clearForNavigation();
    6772    void clearForClose();
    68 
    6973    void destroyGlobal();
    7074
  • trunk/WebCore/bindings/v8/V8DOMWrapper.cpp

    r52811 r52847  
    803803    if (proxy)
    804804        // FIXME: Fix this to work properly with isolated worlds (see above).
    805         instance = proxy->windowShell()->createWrapperFromCache(descriptorType);
     805        instance = proxy->frame()->script()->mainWorldWindowShell()->createWrapperFromCache(descriptorType);
    806806    else {
    807807        v8::Local<v8::Function> function = getTemplate(descriptorType)->GetFunction();
     
    12051205    // checking if the node already has a wrapper.
    12061206    V8Proxy* proxy = V8Proxy::retrieve(document->frame());
    1207     if (proxy)
    1208         proxy->windowShell()->initContextIfNeeded();
     1207    if (proxy) {
     1208        // This code looks wacky:
     1209        // 1) The test for |proxy| above is really a test whether JavaScript
     1210        //    is enabled in this frame.  I have no idea if that's needed.
     1211        // 2) Calling initContextIfNeeded here is redundant becase just
     1212        //    grabbing mainWorldWindowShell() already calls initContextIfNeeded.
     1213        // FIXME: I bet we can clean this up a bit!
     1214        proxy->frame()->script()->mainWorldWindowShell()->initContextIfNeeded();
     1215    }
    12091216
    12101217    DOMWrapperMap<Node>& domNodeMap = getDOMNodeMap();
     
    12951302
    12961303    if (isDocument) {
    1297         if (proxy)
    1298             proxy->windowShell()->updateDocumentWrapper(result);
     1304        if (proxy) {
     1305            // FIXME: Don't we need to do this for every world?
     1306            proxy->frame()->script()->mainWorldWindowShell()->updateDocumentWrapper(result);
     1307        }
    12991308
    13001309        if (type == V8ClassIndex::HTMLDOCUMENT) {
  • trunk/WebCore/bindings/v8/V8IsolatedContext.cpp

    r52811 r52847  
    5454    : m_world(IsolatedWorld::create())
    5555{
     56    // FIXME: None of this code belongs here! Basically, ScriptController
     57    // should create a new DOMWrapperWorld and a new windowShell and then
     58    // evaluate the script.
     59
     60    V8DOMWindowShell* mainWorldWindowShell = proxy->frame()->script()->mainWorldWindowShell();
     61
    5662    v8::HandleScope scope;
    5763    // FIXME: We should be creating a new V8DOMWindowShell here instead of riping out the context.
    58     m_context = SharedPersistent<v8::Context>::create(proxy->windowShell()->createNewContext(v8::Handle<v8::Object>(), extensionGroup));
     64    m_context = SharedPersistent<v8::Context>::create(mainWorldWindowShell->createNewContext(v8::Handle<v8::Object>(), extensionGroup));
    5965    if (m_context->get().IsEmpty())
    6066        return;
     
    6773    V8DOMWindowShell::installHiddenObjectPrototype(m_context->get());
    6874    // FIXME: This will go away once we have a windowShell for the isolated world.
    69     proxy->windowShell()->installDOMWindow(m_context->get(), proxy->frame()->domWindow());
     75    mainWorldWindowShell->installDOMWindow(m_context->get(), proxy->frame()->domWindow());
    7076
    7177    // Using the default security token means that the canAccess is always
  • trunk/WebCore/bindings/v8/V8Proxy.cpp

    r52811 r52847  
    214214V8Proxy::V8Proxy(Frame* frame)
    215215    : m_frame(frame)
    216     , m_windowShell(V8DOMWindowShell::create(frame))
    217216    , m_inlineCode(false)
    218217    , m_timerCallback(false)
     
    223222V8Proxy::~V8Proxy()
    224223{
    225     clearForClose();
    226     windowShell()->destroyGlobal();
     224    resetIsolatedWorlds();
    227225}
    228226
     
    247245    Frame* frame = V8Proxy::retrieveFrame(context);
    248246
    249     V8Proxy* proxy = V8Proxy::retrieve(frame);
    250     if (proxy) {
    251         // Clean m_context, and event handlers.
    252         proxy->clearForClose();
    253 
    254         proxy->windowShell()->destroyGlobal();
    255     }
     247    frame->script()->destroyWindowShell();
    256248
    257249    ChromiumBridge::notifyJSOutOfMemory(frame);
     
    267259void V8Proxy::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup)
    268260{
    269     // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
    270     windowShell()->initContextIfNeeded();
    271 
    272261    v8::HandleScope handleScope;
    273262    V8IsolatedContext* isolatedContext = 0;
     
    315304    // Setup context id for JS debugger.
    316305    v8::Context::Scope contextScope(targetContext);
    317     v8::Handle<v8::Context> context = windowShell()->context();
     306    v8::Handle<v8::Context> context = m_frame->script()->mainWorldWindowShell()->localHandleForContext();
    318307    if (context.IsEmpty())
    319308        return false;
     
    583572    }
    584573    m_isolatedWorlds.clear();
    585 }
    586 
    587 void V8Proxy::clearForClose()
    588 {
    589     resetIsolatedWorlds();
    590     windowShell()->clearForClose();
    591 }
    592 
    593 void V8Proxy::clearForNavigation()
    594 {
    595     resetIsolatedWorlds();
    596     windowShell()->clearForNavigation();
    597574}
    598575
     
    656633v8::Local<v8::Context> V8Proxy::context(Frame* frame)
    657634{
     635    // FIXME: Move this function to ScriptController.
    658636    v8::Local<v8::Context> context = V8Proxy::mainWorldContext(frame);
    659637    if (context.IsEmpty())
     
    671649v8::Local<v8::Context> V8Proxy::context()
    672650{
     651    // FIXME: Move this function to ScriptController.
    673652    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
    674653        RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext();
     
    677656        return v8::Local<v8::Context>::New(context->get());
    678657    }
    679     return mainWorldContext();
    680 }
    681 
    682 v8::Local<v8::Context> V8Proxy::mainWorldContext()
    683 {
    684     windowShell()->initContextIfNeeded();
    685     return v8::Local<v8::Context>::New(windowShell()->context());
     658    return m_frame->script()->mainWorldWindowShell()->localHandleForContext();
    686659}
    687660
    688661v8::Local<v8::Context> V8Proxy::mainWorldContext(Frame* frame)
    689662{
    690     V8Proxy* proxy = retrieve(frame);
    691     if (!proxy)
     663    // FIXME: Move this function to ScriptController.
     664    if (!frame->script()->isEnabled())
    692665        return v8::Local<v8::Context>();
    693666
    694     return proxy->mainWorldContext();
     667    return frame->script()->mainWorldWindowShell()->localHandleForContext();
    695668}
    696669
    697670v8::Local<v8::Context> V8Proxy::currentContext()
    698671{
     672    // FIXME: Why does this function exist?
    699673    return v8::Context::GetCurrent();
    700674}
     
    831805{
    832806    ASSERT(debugId > 0);
    833     v8::Handle<v8::Context> context = windowShell()->context();
     807    v8::Local<v8::Context> context = m_frame->script()->mainWorldWindowShell()->localHandleForContext();
    834808    if (context.IsEmpty())
    835809        return false;
  • trunk/WebCore/bindings/v8/V8Proxy.h

    r52811 r52847  
    153153        Frame* frame() { return m_frame; }
    154154
    155         void clearForNavigation();
    156         void clearForClose();
    157 
    158155        // FIXME: Need comment. User Gesture related.
    159156        bool inlineCode() const { return m_inlineCode; }
     
    310307
    311308        v8::Local<v8::Context> context();
    312         v8::Local<v8::Context> mainWorldContext();
    313 
    314         // FIXME: This should eventually take DOMWrapperWorld argument!
    315         V8DOMWindowShell* windowShell() const { return m_windowShell.get(); }
    316309
    317310        bool setContextDebugId(int id);
     
    336329        static void reportUnsafeAccessTo(Frame* target, DelayReporting delay);
    337330
     331        // FIXME: This should move to ScriptController.
     332        void resetIsolatedWorlds();
     333
    338334    private:
    339335        // If m_recursionCount is 0, let LocalStorage know so we can release
    340336        // the storage mutex.
    341337        void releaseStorageMutex();
    342 
    343         void resetIsolatedWorlds();
    344338
    345339        // Returns false when we're out of memory in V8.
     
    371365        Frame* m_frame;
    372366
    373         // For the moment, we have one of these.  Soon we will have one per DOMWrapperWorld.
    374         RefPtr<V8DOMWindowShell> m_windowShell;
    375        
    376367        // Utility context holding JavaScript functions used internally.
    377368        static v8::Persistent<v8::Context> m_utilityContext;
  • trunk/WebCore/bindings/v8/WorldContextHandle.cpp

    r52811 r52847  
    3232#include "WorldContextHandle.h"
    3333
     34#include "Frame.h"
    3435#include "V8IsolatedContext.h"
    3536
     
    4950{
    5051    if (m_worldToUse == UseMainWorld)
    51         return proxy->mainWorldContext();
     52        return proxy->frame()->script()->mainWorldWindowShell()->localHandleForContext();
    5253    if (!m_context || m_context->get().IsEmpty())
    5354        return proxy->context();
  • trunk/WebKit/chromium/ChangeLog

    r52845 r52847  
     12010-01-05  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        [v8] Move V8DOMWindowShell to ScriptController
     6        https://bugs.webkit.org/show_bug.cgi?id=33232
     7
     8        Update FrameLoaderClientImpl.cpp to call clearForClose on
     9        ScriptController instead of on V8Proxy.
     10
     11        * src/FrameLoaderClientImpl.cpp:
     12        (WebKit::FrameLoaderClientImpl::detachedFromParent3):
     13
    1142010-01-05  Rachel Petterson  <rlp@google.com>
    215
  • trunk/WebKit/chromium/src/FrameLoaderClientImpl.cpp

    r52791 r52847  
    216216    // go to a page and then navigate to a new page without getting any asserts
    217217    // or crashes.
    218     m_webFrame->frame()->script()->proxy()->clearForClose();
    219    
     218    m_webFrame->frame()->script()->clearForClose();
     219
    220220    // Stop communicating with the WebFrameClient at this point since we are no
    221221    // longer associated with the Page.
Note: See TracChangeset for help on using the changeset viewer.