Changeset 53119 in webkit


Ignore:
Timestamp:
Jan 12, 2010 12:18:48 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-01-12 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Geoffrey Garen.

Allow creating injected script for the inspected script state. The InjectedScript is
cached on the inspected ExecState global object and will be garbage collected when the
object is collected. Each InjectedScript object is assigned unique id.

https://bugs.webkit.org/show_bug.cgi?id=33469

  • bindings/js/JSDOMGlobalObject.cpp: (WebCore::JSDOMGlobalObject::markChildren): (WebCore::JSDOMGlobalObject::setInjectedScript): (WebCore::JSDOMGlobalObject::injectedScript):
  • bindings/js/JSDOMGlobalObject.h: InjectedScript is cached on the global object as a field that is not visible from the inspected code. This InjectedScript should be alive as long as the global object is alive and should be accessible from Web Inspector's native code. (WebCore::JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData):
  • bindings/js/JSInjectedScriptHostCustom.cpp: (WebCore::createInjectedScript): Creates injected script using the lexical global object of the inspected ScriptState. Reference to the object is stored on the global DOM object. (WebCore::InjectedScriptHost::injectedScriptFor):
  • inspector/InjectedScriptHost.cpp: (WebCore::InjectedScriptHost::InjectedScriptHost): (WebCore::InjectedScriptHost::injectedScriptForId): (WebCore::InjectedScriptHost::discardInjectedScripts): This method is expected to be called when the the InjectedScript are no longer needed. In particular, this should be called before frame navigation.
  • inspector/InjectedScriptHost.h: (WebCore::InjectedScriptHost::setInjectedScriptSource): This allows to provide injected script source. The source may be loaded in a platform specific way.
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53114 r53119  
     12010-01-12  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Allow creating injected script for the inspected script state. The InjectedScript is
     6        cached on the inspected ExecState global object and will be garbage collected when the
     7        object is collected. Each InjectedScript object is assigned unique id.
     8
     9        https://bugs.webkit.org/show_bug.cgi?id=33469
     10
     11        * bindings/js/JSDOMGlobalObject.cpp:
     12        (WebCore::JSDOMGlobalObject::markChildren):
     13        (WebCore::JSDOMGlobalObject::setInjectedScript):
     14        (WebCore::JSDOMGlobalObject::injectedScript):
     15        * bindings/js/JSDOMGlobalObject.h: InjectedScript is cached on the global object as a
     16        field that is not visible from the inspected code. This InjectedScript should be alive as long as
     17        the global object is alive and should be accessible from Web Inspector's native code.
     18        (WebCore::JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData):
     19        * bindings/js/JSInjectedScriptHostCustom.cpp:
     20        (WebCore::createInjectedScript): Creates injected script using the lexical global object of the
     21        inspected ScriptState. Reference to the object is stored on the global DOM object.
     22        (WebCore::InjectedScriptHost::injectedScriptFor):
     23        * inspector/InjectedScriptHost.cpp:
     24        (WebCore::InjectedScriptHost::InjectedScriptHost):
     25        (WebCore::InjectedScriptHost::injectedScriptForId):
     26        (WebCore::InjectedScriptHost::discardInjectedScripts): This method is expected to be called when the
     27        the InjectedScript are no longer needed. In particular, this should be called before frame navigation.
     28        * inspector/InjectedScriptHost.h:
     29        (WebCore::InjectedScriptHost::setInjectedScriptSource): This allows to provide injected script source.
     30        The source may be loaded in a platform specific way.
     31
    1322010-01-11  Darin Adler  <darin@apple.com>
    233
  • trunk/WebCore/bindings/js/JSDOMGlobalObject.cpp

    r49963 r53119  
    5757    for (JSDOMConstructorMap::iterator it2 = constructors().begin(); it2 != end2; ++it2)
    5858        markStack.append(it2->second);
     59
     60    if (d()->m_injectedScript)
     61        markStack.append(d()->m_injectedScript);
    5962}
    6063
     
    7578{
    7679    return d()->evt;
     80}
     81
     82void JSDOMGlobalObject::setInjectedScript(JSObject* injectedScript)
     83{
     84    d()->m_injectedScript = injectedScript;
     85}
     86
     87JSObject* JSDOMGlobalObject::injectedScript() const
     88{
     89    return d()->m_injectedScript;
    7790}
    7891
  • trunk/WebCore/bindings/js/JSDOMGlobalObject.h

    r51330 r53119  
    6565        Event* currentEvent() const;
    6666
     67        void setInjectedScript(JSObject*);
     68        JSObject* injectedScript() const;
     69
    6770        virtual void markChildren(JSC::MarkStack&);
    6871
     
    7578                , evt(0)
    7679                , m_world(world)
     80                , m_injectedScript(0)
    7781            {
    7882            }
     
    8387            Event* evt;
    8488            RefPtr<DOMWrapperWorld> m_world;
     89            JSObject* m_injectedScript;
    8590        };
    8691
  • trunk/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp

    r52556 r53119  
    6060#include "TextIterator.h"
    6161#include "VisiblePosition.h"
     62#include <parser/SourceCode.h>
    6263#include <runtime/JSArray.h>
    6364#include <runtime/JSLock.h>
     
    7475namespace WebCore {
    7576
     77static ScriptObject createInjectedScript(const String& source, InjectedScriptHost* injectedScriptHost, ScriptState* scriptState, long id)
     78{
     79    SourceCode sourceCode = makeSource(source);
     80    JSLock lock(SilenceAssertionsOnly);
     81    JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
     82    JSValue globalThisValue = scriptState->globalThisValue();
     83    Completion comp = JSC::evaluate(scriptState, globalObject->globalScopeChain(), sourceCode, globalThisValue);
     84    if (comp.complType() != JSC::Normal && comp.complType() != JSC::ReturnValue)
     85        return ScriptObject();
     86    JSValue functionValue = comp.value();
     87    CallData callData;
     88    CallType callType = functionValue.getCallData(callData);
     89    if (callType == CallTypeNone)
     90        return ScriptObject();
     91
     92    MarkedArgumentBuffer args;
     93    args.append(toJS(scriptState, globalObject, injectedScriptHost));
     94    args.append(globalThisValue);
     95    args.append(jsNumber(scriptState, id));
     96    JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args);
     97    if (result.isObject())
     98        return ScriptObject(scriptState, result.getObject());
     99    return ScriptObject();
     100}
     101
    76102#if ENABLE(DATABASE)
    77103JSValue JSInjectedScriptHost::databaseForId(ExecState* exec, const ArgList& args)
     
    216242#endif
    217243
     244ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* scriptState)
     245{
     246    JSLock lock(SilenceAssertionsOnly);
     247    JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject());
     248    JSObject* injectedScript = globalObject->injectedScript();
     249    if (injectedScript)
     250        return ScriptObject(scriptState, injectedScript);
     251
     252    ASSERT(!m_injectedScriptSource.isEmpty());
     253    ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, scriptState, m_nextInjectedScriptId);
     254    globalObject->setInjectedScript(injectedScriptObject.jsObject());
     255    m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject);
     256    m_nextInjectedScriptId++;
     257    return injectedScriptObject;
     258}
     259
    218260} // namespace WebCore
    219261
  • trunk/WebCore/inspector/InjectedScriptHost.cpp

    r52556 r53119  
    7373InjectedScriptHost::InjectedScriptHost(InspectorController* inspectorController)
    7474    : m_inspectorController(inspectorController)
     75    , m_nextInjectedScriptId(1)
    7576{
    7677}
     
    181182}
    182183
     184ScriptObject InjectedScriptHost::injectedScriptForId(long id)
     185{
     186    return m_idToInjectedScript.get(id);
     187}
     188
     189void InjectedScriptHost::discardInjectedScripts()
     190{
     191    m_idToInjectedScript.clear();
     192}
     193
    183194InspectorDOMAgent* InjectedScriptHost::inspectorDOMAgent()
    184195{
  • trunk/WebCore/inspector/InjectedScriptHost.h

    r52556 r53119  
    3434#include "InspectorController.h"
    3535#include "PlatformString.h"
     36#include "ScriptState.h"
    3637
     38#include <wtf/HashMap.h>
    3739#include <wtf/RefCounted.h>
    3840
     
    5557
    5658    ~InjectedScriptHost();
     59
     60    void setInjectedScriptSource(const String& source) { m_injectedScriptSource = source; }
    5761
    5862    InspectorController* inspectorController() { return m_inspectorController; }
     
    8286    void reportDidDispatchOnInjectedScript(long callId, const String& result, bool isException);
    8387
     88    ScriptObject injectedScriptFor(ScriptState*);
     89    ScriptObject injectedScriptForId(long);
     90    void discardInjectedScripts();
     91
    8492private:
    8593    InjectedScriptHost(InspectorController* inspectorController);
     
    8896
    8997    InspectorController* m_inspectorController;
     98    String m_injectedScriptSource;
     99    long m_nextInjectedScriptId;
     100    typedef HashMap<long, ScriptObject> IdToInjectedScriptMap;
     101    IdToInjectedScriptMap m_idToInjectedScript;
    90102};
    91103
Note: See TracChangeset for help on using the changeset viewer.