Changeset 126103 in webkit


Ignore:
Timestamp:
Aug 20, 2012 5:31:09 PM (12 years ago)
Author:
haraken@chromium.org
Message:

[V8] Move retrieve{Window,Frame,PerContextData}() from V8Proxy to V8Binding
https://bugs.webkit.org/show_bug.cgi?id=94460

Reviewed by Adam Barth.

To kill V8Proxy, we move retrieve{Window,Frame,PerContextData}()
from V8Proxy to V8Binding. Also, this patch renames these methods as follows:

  • retrieveWindow() -> toDOMWindow()
  • retrieveFrame() -> toFrameIfNotDetached()
  • retrievePerContextData() -> perContextDataForCurrentWorld()

No tests. No change in behavior.

Source/WebCore:

  • bindings/v8/BindingState.cpp:

(WebCore::activeDOMWindow):
(WebCore::firstDOMWindow):
(WebCore::activeFrame):
(WebCore::firstFrame):
(WebCore::currentFrame):
(WebCore::currentDocument):

  • bindings/v8/PageScriptDebugServer.cpp:

(WebCore::retrieveFrameWithGlobalObjectCheck):
(WebCore::PageScriptDebugServer::getDebugListenerForContext):
(WebCore::PageScriptDebugServer::runMessageLoopOnPause):

  • bindings/v8/V8Binding.cpp:

(WebCore::retrieveWindow):
(WebCore):
(WebCore::retrieveFrame):
(WebCore::retrievePerContextData):

  • bindings/v8/V8Binding.h:

(WebCore):

  • bindings/v8/V8DOMWrapper.cpp:

(WebCore::V8DOMWrapper::constructorForType):

  • bindings/v8/V8NPUtils.cpp:

(WebCore::convertV8ObjectToNPVariant):

  • bindings/v8/V8Proxy.cpp:

(WebCore::V8Proxy::handleOutOfMemory):
(WebCore::V8Proxy::context):
(WebCore::V8Proxy::matchesCurrentContext):

  • bindings/v8/V8Proxy.h:

(V8Proxy):

Source/WebKit/chromium:

  • src/WebBindings.cpp:

(WebKit::makeIntArrayImpl):
(WebKit::makeStringArrayImpl):

  • src/WebFrameImpl.cpp:

(WebKit::WebFrame::frameForContext):

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126100 r126103  
     12012-08-20  Kentaro Hara  <haraken@chromium.org>
     2
     3        [V8] Move retrieve{Window,Frame,PerContextData}() from V8Proxy to V8Binding
     4        https://bugs.webkit.org/show_bug.cgi?id=94460
     5
     6        Reviewed by Adam Barth.
     7
     8        To kill V8Proxy, we move retrieve{Window,Frame,PerContextData}()
     9        from V8Proxy to V8Binding. Also, this patch renames these methods as follows:
     10
     11        - retrieveWindow() -> toDOMWindow()
     12        - retrieveFrame() -> toFrameIfNotDetached()
     13        - retrievePerContextData() -> perContextDataForCurrentWorld()
     14
     15        No tests. No change in behavior.
     16
     17        * bindings/v8/BindingState.cpp:
     18        (WebCore::activeDOMWindow):
     19        (WebCore::firstDOMWindow):
     20        (WebCore::activeFrame):
     21        (WebCore::firstFrame):
     22        (WebCore::currentFrame):
     23        (WebCore::currentDocument):
     24        * bindings/v8/PageScriptDebugServer.cpp:
     25        (WebCore::retrieveFrameWithGlobalObjectCheck):
     26        (WebCore::PageScriptDebugServer::getDebugListenerForContext):
     27        (WebCore::PageScriptDebugServer::runMessageLoopOnPause):
     28        * bindings/v8/V8Binding.cpp:
     29        (WebCore::retrieveWindow):
     30        (WebCore):
     31        (WebCore::retrieveFrame):
     32        (WebCore::retrievePerContextData):
     33        * bindings/v8/V8Binding.h:
     34        (WebCore):
     35        * bindings/v8/V8DOMWrapper.cpp:
     36        (WebCore::V8DOMWrapper::constructorForType):
     37        * bindings/v8/V8NPUtils.cpp:
     38        (WebCore::convertV8ObjectToNPVariant):
     39        * bindings/v8/V8Proxy.cpp:
     40        (WebCore::V8Proxy::handleOutOfMemory):
     41        (WebCore::V8Proxy::context):
     42        (WebCore::V8Proxy::matchesCurrentContext):
     43        * bindings/v8/V8Proxy.h:
     44        (V8Proxy):
     45
    1462012-08-20  Abhishek Arya  <inferno@chromium.org>
    247
  • trunk/Source/WebCore/bindings/v8/BindingState.cpp

    r125592 r126103  
    3535#include "Frame.h"
    3636#include "ScriptController.h"
    37 #include "V8Proxy.h"
     37#include "V8Binding.h"
    3838#include <wtf/StdLibExtras.h>
    3939
     
    5959DOMWindow* activeDOMWindow(BindingState*)
    6060{
    61     return V8Proxy::retrieveWindow(activeContext());
     61    return toDOMWindow(activeContext());
    6262}
    6363
    6464DOMWindow* firstDOMWindow(BindingState*)
    6565{
    66     return V8Proxy::retrieveWindow(v8::Context::GetEntered());
     66    return toDOMWindow(v8::Context::GetEntered());
    6767}
    6868
     
    7272    if (context.IsEmpty())
    7373        return 0;
    74     return V8Proxy::retrieveFrame(context);
     74    return toFrameIfNotDetached(context);
    7575}
    7676
     
    8080    if (context.IsEmpty())
    8181        return 0;
    82     return V8Proxy::retrieveFrame(context);
     82    return toFrameIfNotDetached(context);
    8383}
    8484
     
    8888    if (context.IsEmpty())
    8989        return 0;
    90     return V8Proxy::retrieveFrame(context);
     90    return toFrameIfNotDetached(context);
    9191}
    9292
    9393Document* currentDocument(BindingState*)
    9494{
    95     DOMWindow* current = V8Proxy::retrieveWindow(v8::Context::GetCurrent());
     95    DOMWindow* current = toDOMWindow(v8::Context::GetCurrent());
    9696    if (!current)
    9797        return 0;
  • trunk/Source/WebCore/bindings/v8/PageScriptDebugServer.cpp

    r124583 r126103  
    4848namespace WebCore {
    4949
    50 static Frame* retrieveFrame(v8::Handle<v8::Context> context)
     50static Frame* retrieveFrameWithGlobalObjectCheck(v8::Handle<v8::Context> context)
    5151{
    5252    if (context.IsEmpty())
     
    6262        return 0;
    6363
    64     return V8Proxy::retrieveFrame(context);
     64    return toFrameIfNotDetached(context);
    6565}
    6666
     
    168168{
    169169    v8::HandleScope scope;
    170     Frame* frame = retrieveFrame(context);
     170    Frame* frame = retrieveFrameWithGlobalObjectCheck(context);
    171171    if (!frame)
    172172        return 0;
     
    177177{
    178178    v8::HandleScope scope;
    179     Frame* frame = retrieveFrame(context);
     179    Frame* frame = retrieveFrameWithGlobalObjectCheck(context);
    180180    m_pausedPage = frame->page();
    181181
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r126004 r126103  
    3535#include "DOMStringList.h"
    3636#include "Element.h"
     37#include "Frame.h"
    3738#include "MemoryInstrumentation.h"
    3839#include "PlatformString.h"
    3940#include "QualifiedName.h"
    4041#include "V8DOMStringList.h"
     42#include "V8DOMWindow.h"
    4143#include "V8Element.h"
    4244#include "V8ObjectConstructor.h"
    43 #include "V8Proxy.h"
    4445
    4546#include <wtf/MathExtras.h>
     
    382383}
    383384
     385DOMWindow* toDOMWindow(v8::Handle<v8::Context> context)
     386{
     387    v8::Handle<v8::Object> global = context->Global();
     388    ASSERT(!global.IsEmpty());
     389    global = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global);
     390    ASSERT(!global.IsEmpty());
     391    return V8DOMWindow::toNative(global);
     392}
     393
     394Frame* toFrameIfNotDetached(v8::Handle<v8::Context> context)
     395{
     396    DOMWindow* window = toDOMWindow(context);
     397    if (window->isCurrentlyDisplayedInFrame())
     398        return window->frame();
     399    // We return 0 here because |context| is detached from the Frame. If we
     400    // did return |frame| we could get in trouble because the frame could be
     401    // navigated to another security origin.
     402    return 0;
     403}
     404
     405V8PerContextData* perContextDataForCurrentWorld(Frame* frame)
     406{
     407    V8IsolatedContext* isolatedContext;
     408    if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered())))
     409        return isolatedContext->perContextData();
     410    return frame->script()->windowShell()->perContextData();
     411}
     412
    384413void crashIfV8IsDead()
    385414{
  • trunk/Source/WebCore/bindings/v8/V8Binding.h

    r126004 r126103  
    369369    PassRefPtr<DOMStringList> toDOMStringList(v8::Handle<v8::Value>);
    370370
     371    // Returns the window object associated with a context.
     372    DOMWindow* toDOMWindow(v8::Handle<v8::Context>);
     373
     374    // Returns the frame object of the window object associated with
     375    // a context, if the window is currently being displayed in the Frame.
     376    Frame* toFrameIfNotDetached(v8::Handle<v8::Context>);
     377
     378    // Returns the PerContextData associated with a frame for the current isolated world.
     379    V8PerContextData* perContextDataForCurrentWorld(Frame*);
     380
    371381    void crashIfV8IsDead();
    372382
  • trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp

    r125995 r126103  
    9696        return v8::Local<v8::Function>();
    9797
    98     if (V8PerContextData* contextData = V8Proxy::retrievePerContextData(frame))
     98    if (V8PerContextData* contextData = perContextDataForCurrentWorld(frame))
    9999        return contextData->constructorForType(type);
    100100
  • trunk/Source/WebCore/bindings/v8/V8NPUtils.cpp

    r124542 r126103  
    7070        STRINGN_TO_NPVARIANT(utf8Chars, length-1, *result);
    7171    } else if (object->IsObject()) {
    72         DOMWindow* window = V8Proxy::retrieveWindow(v8::Context::GetCurrent());
     72        DOMWindow* window = toDOMWindow(v8::Context::GetCurrent());
    7373        NPObject* npobject = npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(object), window);
    7474        if (npobject)
  • trunk/Source/WebCore/bindings/v8/V8Proxy.cpp

    r126086 r126103  
    141141
    142142    // Warning, error, disable JS for this frame?
    143     Frame* frame = V8Proxy::retrieveFrame(context);
     143    Frame* frame = toFrameIfNotDetached(context);
    144144    if (!frame)
    145145        return true;
     
    320320}
    321321
    322 DOMWindow* V8Proxy::retrieveWindow(v8::Handle<v8::Context> context)
    323 {
    324     v8::Handle<v8::Object> global = context->Global();
    325     ASSERT(!global.IsEmpty());
    326     global = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global);
    327     ASSERT(!global.IsEmpty());
    328     return V8DOMWindow::toNative(global);
    329 }
    330 
    331 Frame* V8Proxy::retrieveFrame(v8::Handle<v8::Context> context)
    332 {
    333     DOMWindow* window = retrieveWindow(context);
    334     if (window->isCurrentlyDisplayedInFrame())
    335         return window->frame();
    336     // We return 0 here because |context| is detached from the Frame.  If we
    337     // did return |frame| we could get in trouble because the frame could be
    338     // navigated to another security origin.
    339     return 0;
    340 }
    341 
    342 V8PerContextData* V8Proxy::retrievePerContextData(Frame* frame)
    343 {
    344     V8IsolatedContext* isolatedContext;
    345     if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered())))
    346         return isolatedContext->perContextData();
    347     return frame->script()->windowShell()->perContextData();
    348 }
    349 
    350322v8::Local<v8::Context> V8Proxy::context(Frame* frame)
    351323{
     
    356328    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
    357329        context = v8::Local<v8::Context>::New(isolatedContext->context());
    358         if (frame != V8Proxy::retrieveFrame(context))
     330        if (frame != toFrameIfNotDetached(context))
    359331            return v8::Local<v8::Context>();
    360332    }
     
    367339    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
    368340        RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext();
    369         if (m_frame != V8Proxy::retrieveFrame(context->get()))
     341        if (m_frame != toFrameIfNotDetached(context->get()))
    370342            return v8::Local<v8::Context>();
    371343        return v8::Local<v8::Context>::New(context->get());
     
    387359    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
    388360        context = isolatedContext->sharedContext()->get();
    389         if (m_frame != V8Proxy::retrieveFrame(context))
     361        if (m_frame != toFrameIfNotDetached(context))
    390362            return false;
    391363    } else {
  • trunk/Source/WebCore/bindings/v8/V8Proxy.h

    r126086 r126103  
    104104        v8::Local<v8::Value> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
    105105
    106         // Returns the window object associated with a context.
    107         static DOMWindow* retrieveWindow(v8::Handle<v8::Context>);
    108 
    109         // Returns the frame object of the window object associated with
    110         // a context.
    111         static Frame* retrieveFrame(v8::Handle<v8::Context>);
    112 
    113         static V8PerContextData* retrievePerContextData(Frame*);
    114 
    115106        // Returns V8 Context of a frame. If none exists, creates
    116107        // a new context. It is potentially slow and consumes memory.
  • trunk/Source/WebKit/chromium/ChangeLog

    r126099 r126103  
     12012-08-20  Kentaro Hara  <haraken@chromium.org>
     2
     3        [V8] Move retrieve{Window,Frame,PerContextData}() from V8Proxy to V8Binding
     4        https://bugs.webkit.org/show_bug.cgi?id=94460
     5
     6        Reviewed by Adam Barth.
     7
     8        To kill V8Proxy, we move retrieve{Window,Frame,PerContextData}()
     9        from V8Proxy to V8Binding. Also, this patch renames these methods as follows:
     10
     11        - retrieveWindow() -> toDOMWindow()
     12        - retrieveFrame() -> toFrameIfNotDetached()
     13        - retrievePerContextData() -> perContextDataForCurrentWorld()
     14
     15        No tests. No change in behavior.
     16
     17        * src/WebBindings.cpp:
     18        (WebKit::makeIntArrayImpl):
     19        (WebKit::makeStringArrayImpl):
     20        * src/WebFrameImpl.cpp:
     21        (WebKit::WebFrame::frameForContext):
     22
    1232012-08-20  James Robinson  <jamesr@chromium.org>
    224
  • trunk/Source/WebKit/chromium/src/WebBindings.cpp

    r124931 r126103  
    291291        result->Set(i, v8::Number::New(data[i]));
    292292
    293     DOMWindow* window = V8Proxy::retrieveWindow(v8::Context::GetCurrent());
     293    DOMWindow* window = toDOMWindow(v8::Context::GetCurrent());
    294294    return npCreateV8ScriptObject(0, result, window);
    295295}
     
    302302        result->Set(i, data[i].data() ? v8::String::New(reinterpret_cast<const uint16_t*>((data[i].data())), data[i].length()) : v8::String::New(""));
    303303
    304     DOMWindow* window = V8Proxy::retrieveWindow(v8::Context::GetCurrent());
     304    DOMWindow* window = toDOMWindow(v8::Context::GetCurrent());
    305305    return npCreateV8ScriptObject(0, result, window);
    306306}
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r126098 r126103  
    584584#if WEBKIT_USING_V8
    585585WebFrame* WebFrame::frameForContext(v8::Handle<v8::Context> context)
    586 {
    587     return WebFrameImpl::fromFrame(V8Proxy::retrieveFrame(context));
     586{ 
     587   return WebFrameImpl::fromFrame(toFrameIfNotDetached(context));
    588588}
    589589#endif
Note: See TracChangeset for help on using the changeset viewer.