Changeset 64093 in webkit


Ignore:
Timestamp:
Jul 26, 2010 5:09:07 PM (14 years ago)
Author:
andersca@apple.com
Message:

Plug-in views should be able to return JSObjects directly
https://bugs.webkit.org/show_bug.cgi?id=43019

Reviewed by Sam Weinig.

  • bindings/js/JSHTMLAppletElementCustom.cpp:

(WebCore::JSHTMLAppletElement::putDelegate):
(WebCore::JSHTMLAppletElement::getCallData):

  • bindings/js/JSHTMLEmbedElementCustom.cpp:

(WebCore::JSHTMLEmbedElement::putDelegate):
(WebCore::JSHTMLEmbedElement::getCallData):

  • bindings/js/JSHTMLObjectElementCustom.cpp:

(WebCore::JSHTMLObjectElement::putDelegate):
(WebCore::JSHTMLObjectElement::getCallData):
runtimeObjectCustomPut and runtimeObjectGetCallData now take a JSHTMLElement instead of a HTMLElement.

  • bindings/js/JSPluginElementFunctions.cpp:

(WebCore::pluginScriptObject):
First, ask the PluginViewBase for a JSObject and fall back to getting the JSObject from the instance.

(WebCore::runtimeObjectPropertyGetter):
(WebCore::runtimeObjectCustomGetOwnPropertySlot):
(WebCore::runtimeObjectCustomGetOwnPropertyDescriptor):
Call pluginScriptObject.

(WebCore::runtimeObjectCustomPut):
Change to take a JSHTMLElement. Call pluginScriptObject.

(WebCore::runtimeObjectGetCallData):
Change to take a JSHTMLElement.

  • bridge/jsc/BridgeJSC.cpp:
  • bridge/jsc/BridgeJSC.h:

(JSC::Bindings::Instance::createRuntimeObject):
Change this to return a JSObject.

  • html/HTMLPlugInElement.cpp:

(WebCore::HTMLPlugInElement::getInstance):
Call pluginWidget.

(WebCore::HTMLPlugInElement::pluginWidget):
Return the plug-in widget for this element.

  • html/HTMLPlugInElement.h:
  • plugins/PluginViewBase.h:

(WebCore::PluginViewBase::scriptObject):
Add default implementation of scriptObject.

Location:
trunk/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64088 r64093  
     12010-07-26  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Plug-in views should be able to return JSObjects directly
     6        https://bugs.webkit.org/show_bug.cgi?id=43019
     7
     8        * bindings/js/JSHTMLAppletElementCustom.cpp:
     9        (WebCore::JSHTMLAppletElement::putDelegate):
     10        (WebCore::JSHTMLAppletElement::getCallData):
     11        * bindings/js/JSHTMLEmbedElementCustom.cpp:
     12        (WebCore::JSHTMLEmbedElement::putDelegate):
     13        (WebCore::JSHTMLEmbedElement::getCallData):
     14        * bindings/js/JSHTMLObjectElementCustom.cpp:
     15        (WebCore::JSHTMLObjectElement::putDelegate):
     16        (WebCore::JSHTMLObjectElement::getCallData):
     17        runtimeObjectCustomPut and runtimeObjectGetCallData now take a JSHTMLElement instead of a HTMLElement.
     18
     19        * bindings/js/JSPluginElementFunctions.cpp:
     20        (WebCore::pluginScriptObject):
     21        First, ask the PluginViewBase for a JSObject and fall back to getting the JSObject from the instance.
     22
     23        (WebCore::runtimeObjectPropertyGetter):
     24        (WebCore::runtimeObjectCustomGetOwnPropertySlot):
     25        (WebCore::runtimeObjectCustomGetOwnPropertyDescriptor):
     26        Call pluginScriptObject.
     27       
     28        (WebCore::runtimeObjectCustomPut):
     29        Change to take a JSHTMLElement. Call pluginScriptObject.
     30       
     31        (WebCore::runtimeObjectGetCallData):
     32        Change to take a JSHTMLElement.
     33
     34        * bridge/jsc/BridgeJSC.cpp:
     35        * bridge/jsc/BridgeJSC.h:
     36        (JSC::Bindings::Instance::createRuntimeObject):
     37        Change this to return a JSObject.
     38       
     39        * html/HTMLPlugInElement.cpp:
     40        (WebCore::HTMLPlugInElement::getInstance):
     41        Call pluginWidget.
     42
     43        (WebCore::HTMLPlugInElement::pluginWidget):
     44        Return the plug-in widget for this element.
     45
     46        * html/HTMLPlugInElement.h:
     47        * plugins/PluginViewBase.h:
     48        (WebCore::PluginViewBase::scriptObject):
     49        Add default implementation of scriptObject.
     50
    1512010-07-26  Chris Fleizach  <cfleizach@apple.com>
    252
  • trunk/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp

    r55104 r64093  
    4646bool JSHTMLAppletElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    4747{
    48     return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot);
     48    return runtimeObjectCustomPut(exec, propertyName, value, this, slot);
    4949}
    5050
    5151CallType JSHTMLAppletElement::getCallData(CallData& callData)
    5252{
    53     return runtimeObjectGetCallData(impl(), callData);
     53    return runtimeObjectGetCallData(this, callData);
    5454}
    5555
  • trunk/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp

    r55104 r64093  
    4646bool JSHTMLEmbedElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    4747{
    48     return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot);
     48    return runtimeObjectCustomPut(exec, propertyName, value, this, slot);
    4949}
    5050
    5151CallType JSHTMLEmbedElement::getCallData(CallData& callData)
    5252{
    53     return runtimeObjectGetCallData(impl(), callData);
     53    return runtimeObjectGetCallData(this, callData);
    5454}
    5555
  • trunk/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp

    r55104 r64093  
    4646bool JSHTMLObjectElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    4747{
    48     return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot);
     48    return runtimeObjectCustomPut(exec, propertyName, value, this, slot);
    4949}
    5050
    5151CallType JSHTMLObjectElement::getCallData(CallData& callData)
    5252{
    53     return runtimeObjectGetCallData(impl(), callData);
     53    return runtimeObjectGetCallData(this, callData);
    5454}
    5555
  • trunk/WebCore/bindings/js/JSPluginElementFunctions.cpp

    r60631 r64093  
    2525#include "HTMLPlugInElement.h"
    2626#include "JSHTMLElement.h"
    27 #include "runtime_object.h"
     27#include "PluginViewBase.h"
    2828
    2929using namespace JSC;
     
    5050}
    5151
    52 static RuntimeObject* getRuntimeObject(ExecState* exec, Node* node)
     52static JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement)
    5353{
    54     Instance* instance = pluginInstance(node);
    55     if (!instance)
     54    HTMLElement* element = jsHTMLElement->impl();
     55    if (!(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag)))
    5656        return 0;
     57
     58    HTMLPlugInElement* pluginElement = static_cast<HTMLPlugInElement*>(element);
     59
     60    // First, see if we can ask the plug-in view for its script object.
     61    if (Widget* pluginWidget = pluginElement->pluginWidget()) {
     62        if (pluginWidget->isPluginViewBase()) {
     63            PluginViewBase* pluginViewBase = static_cast<PluginViewBase*>(pluginWidget);
     64            if (JSObject* scriptObject = pluginViewBase->scriptObject(exec, jsHTMLElement->globalObject()))
     65                return scriptObject;
     66        }
     67    }
     68
     69    // Otherwise, fall back to getting the object from the instance.
     70
     71    // The plugin element holds an owning reference, so we don't have to.
     72    Instance* instance = pluginElement->getInstance().get();
     73    if (!instance || !instance->rootObject())
     74        return 0;
     75
    5776    return instance->createRuntimeObject(exec);
    5877}
    59 
     78   
    6079JSValue runtimeObjectPropertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
    6180{
    62     JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slotBase));
    63     HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
    64     RuntimeObject* runtimeObject = getRuntimeObject(exec, element);
    65     if (!runtimeObject)
     81    JSHTMLElement* element = static_cast<JSHTMLElement*>(asObject(slotBase));
     82    JSObject* scriptObject = pluginScriptObject(exec, element);
     83    if (!scriptObject)
    6684        return jsUndefined();
    67     return runtimeObject->get(exec, propertyName);
     85   
     86    return scriptObject->get(exec, propertyName);
    6887}
    6988
    7089bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* element)
    7190{
    72     RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl());
    73     if (!runtimeObject)
     91    JSObject* scriptObject = pluginScriptObject(exec, element);
     92    if (!scriptObject)
    7493        return false;
    75     if (!runtimeObject->hasProperty(exec, propertyName))
     94
     95    if (!scriptObject->hasProperty(exec, propertyName))
    7696        return false;
    7797    slot.setCustom(element, runtimeObjectPropertyGetter);
     
    81101bool runtimeObjectCustomGetOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, JSHTMLElement* element)
    82102{
    83     RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl());
    84     if (!runtimeObject)
     103    JSObject* scriptObject = pluginScriptObject(exec, element);
     104    if (!scriptObject)
    85105        return false;
    86     if (!runtimeObject->hasProperty(exec, propertyName))
     106    if (!scriptObject->hasProperty(exec, propertyName))
    87107        return false;
    88108    PropertySlot slot;
     
    95115}
    96116
    97 bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, HTMLElement* element, PutPropertySlot& slot)
     117bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, JSHTMLElement* element, PutPropertySlot& slot)
    98118{
    99     RuntimeObject* runtimeObject = getRuntimeObject(exec, element);
    100     if (!runtimeObject)
     119    JSObject* scriptObject = pluginScriptObject(exec, element);
     120    if (!scriptObject)
    101121        return 0;
    102     if (!runtimeObject->hasProperty(exec, propertyName))
     122    if (!scriptObject->hasProperty(exec, propertyName))
    103123        return false;
    104     runtimeObject->put(exec, propertyName, value, slot);
     124    scriptObject->put(exec, propertyName, value, slot);
    105125    return true;
    106126}
     
    115135}
    116136
    117 CallType runtimeObjectGetCallData(HTMLElement* element, CallData& callData)
     137CallType runtimeObjectGetCallData(JSHTMLElement* element, CallData& callData)
    118138{
    119     Instance* instance = pluginInstance(element);
     139    Instance* instance = pluginInstance(element->impl());
    120140    if (!instance || !instance->supportsInvokeDefaultMethod())
    121141        return CallTypeNone;
  • trunk/WebCore/bindings/js/JSPluginElementFunctions.h

    r55401 r64093  
    4141    bool runtimeObjectCustomGetOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&, JSHTMLElement*);
    4242    bool runtimeObjectCustomGetOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&, JSHTMLElement*);
    43     bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, HTMLElement*, JSC::PutPropertySlot&);
    44     JSC::CallType runtimeObjectGetCallData(HTMLElement*, JSC::CallData&);
     43    bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSHTMLElement*, JSC::PutPropertySlot&);
     44    JSC::CallType runtimeObjectGetCallData(JSHTMLElement*, JSC::CallData&);
    4545
    4646} // namespace WebCore
  • trunk/WebCore/bridge/jsc/BridgeJSC.cpp

    r59941 r64093  
    8484}
    8585
    86 RuntimeObject* Instance::createRuntimeObject(ExecState* exec)
     86JSObject* Instance::createRuntimeObject(ExecState* exec)
    8787{
    8888    ASSERT(m_rootObject);
  • trunk/WebCore/bridge/jsc/BridgeJSC.h

    r60392 r64093  
    8585
    8686    virtual Class* getClass() const = 0;
    87     RuntimeObject* createRuntimeObject(ExecState*);
     87    JSObject* createRuntimeObject(ExecState*);
    8888    void willInvalidateRuntimeObject();
    8989    void willDestroyRuntimeObject();
  • trunk/WebCore/html/HTMLPlugInElement.cpp

    r62875 r64093  
    9393        return m_instance;
    9494
    95     RenderWidget* renderWidget = renderWidgetForJSBindings();
    96     if (renderWidget && renderWidget->widget())
    97         m_instance = frame->script()->createScriptInstanceForWidget(renderWidget->widget());
     95    if (Widget* widget = pluginWidget())
     96        m_instance = frame->script()->createScriptInstanceForWidget(widget);
    9897
    9998    return m_instance;
     99}
     100
     101Widget* HTMLPlugInElement::pluginWidget() const
     102{
     103    RenderWidget* renderWidget = renderWidgetForJSBindings();
     104    if (!renderWidget)
     105        return 0;
     106
     107    return renderWidget->widget();
    100108}
    101109
  • trunk/WebCore/html/HTMLPlugInElement.h

    r62875 r64093  
    3434
    3535class RenderWidget;
     36class Widget;
    3637
    3738class HTMLPlugInElement : public HTMLFrameOwnerElement {
     
    4041
    4142    PassScriptInstance getInstance() const;
     43
     44    Widget* pluginWidget() const;
    4245
    4346#if ENABLE(NETSCAPE_PLUGIN_API)
  • trunk/WebCore/plugins/PluginViewBase.h

    r63638 r64093  
    2929#include "GraphicsLayer.h"
    3030
     31namespace JSC {
     32    class ExecState;
     33    class JSGlobalObject;
     34    class JSObject;
     35}
     36
    3137namespace WebCore {
    3238
     
    3844    virtual PlatformLayer* platformLayer() const { return 0; }
    3945#endif
     46
     47    JSC::JSObject* scriptObject(JSC::ExecState*, JSC::JSGlobalObject*) { return 0; }
    4048
    4149protected:
Note: See TracChangeset for help on using the changeset viewer.