Changeset 56404 in webkit


Ignore:
Timestamp:
Mar 23, 2010 11:49:46 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-23 Andrey Kosyakov <caseq@chromium.org>

Reviewed by Dmitry Titov.

Change notification sent to inspector frontend on workers creation / destruction
to be posted asynchronously to avoid JS reenterability problems. Also, renamed
willDestroyWorker to didDestroyWorker to reflect that it gets called later and got
rid of explicit IDs for workers (use addresses instead).
https://bugs.webkit.org/show_bug.cgi?id=36213

  • inspector/InjectedScriptHost.cpp: (WebCore::InjectedScriptHost::didDestroyWorker):
  • inspector/InjectedScriptHost.h:
  • inspector/InjectedScriptHost.idl:
  • inspector/InspectorController.cpp: (WebCore::PostWorkerNotificationToFrontendTask::create): (WebCore::PostWorkerNotificationToFrontendTask::PostWorkerNotificationToFrontendTask): (WebCore::PostWorkerNotificationToFrontendTask::performTask): (WebCore::InspectorController::postWorkerNotificationToFrontend): (WebCore::InspectorController::didCreateWorker): (WebCore::InspectorController::didDestroyWorker):
  • inspector/InspectorController.h: (WebCore::InspectorController::):
  • inspector/InspectorFrontend.cpp: (WebCore::InspectorFrontend::didDestroyWorker):
  • inspector/InspectorFrontend.h:
  • inspector/InspectorWorkerResource.h: (WebCore::InspectorWorkerResource::create): (WebCore::InspectorWorkerResource::id): (WebCore::InspectorWorkerResource::InspectorWorkerResource):
  • inspector/front-end/InjectedFakeWorker.js: (InjectedFakeWorker.FakeWorker.prototype.terminate):
  • inspector/front-end/WorkersSidebarPane.js: (WebInspector.didDestroyWorker):
  • workers/AbstractWorker.cpp: (WebCore::AbstractWorker::AbstractWorker): (WebCore::AbstractWorker::onDestroyWorker):
  • workers/AbstractWorker.h: (WebCore::AbstractWorker::asID):
  • workers/SharedWorker.cpp: (WebCore::SharedWorker::SharedWorker):
  • workers/Worker.cpp: (WebCore::Worker::Worker):
Location:
trunk/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56402 r56404  
     12010-03-23  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Change notification sent to inspector frontend on workers creation / destruction
     6        to be posted asynchronously to avoid JS reenterability problems. Also, renamed
     7        willDestroyWorker to didDestroyWorker to reflect that it gets called later and got
     8        rid of explicit IDs for workers (use addresses instead).
     9        https://bugs.webkit.org/show_bug.cgi?id=36213
     10
     11        * inspector/InjectedScriptHost.cpp:
     12        (WebCore::InjectedScriptHost::didDestroyWorker):
     13        * inspector/InjectedScriptHost.h:
     14        * inspector/InjectedScriptHost.idl:
     15        * inspector/InspectorController.cpp:
     16        (WebCore::PostWorkerNotificationToFrontendTask::create):
     17        (WebCore::PostWorkerNotificationToFrontendTask::PostWorkerNotificationToFrontendTask):
     18        (WebCore::PostWorkerNotificationToFrontendTask::performTask):
     19        (WebCore::InspectorController::postWorkerNotificationToFrontend):
     20        (WebCore::InspectorController::didCreateWorker):
     21        (WebCore::InspectorController::didDestroyWorker):
     22        * inspector/InspectorController.h:
     23        (WebCore::InspectorController::):
     24        * inspector/InspectorFrontend.cpp:
     25        (WebCore::InspectorFrontend::didDestroyWorker):
     26        * inspector/InspectorFrontend.h:
     27        * inspector/InspectorWorkerResource.h:
     28        (WebCore::InspectorWorkerResource::create):
     29        (WebCore::InspectorWorkerResource::id):
     30        (WebCore::InspectorWorkerResource::InspectorWorkerResource):
     31        * inspector/front-end/InjectedFakeWorker.js:
     32        (InjectedFakeWorker.FakeWorker.prototype.terminate):
     33        * inspector/front-end/WorkersSidebarPane.js:
     34        (WebInspector.didDestroyWorker):
     35        * workers/AbstractWorker.cpp:
     36        (WebCore::AbstractWorker::AbstractWorker):
     37        (WebCore::AbstractWorker::onDestroyWorker):
     38        * workers/AbstractWorker.h:
     39        (WebCore::AbstractWorker::asID):
     40        * workers/SharedWorker.cpp:
     41        (WebCore::SharedWorker::SharedWorker):
     42        * workers/Worker.cpp:
     43        (WebCore::Worker::Worker):
     44
    1452010-03-22  David Hyatt  <hyatt@apple.com>
    246
  • trunk/WebCore/inspector/InjectedScriptHost.cpp

    r55771 r56404  
    214214}
    215215
    216 void InjectedScriptHost::willDestroyWorker(long id)
    217 {
    218     if (m_inspectorController)
    219         m_inspectorController->willDestroyWorker(id);
     216void InjectedScriptHost::didDestroyWorker(long id)
     217{
     218    if (m_inspectorController)
     219        m_inspectorController->didDestroyWorker(id);
    220220}
    221221#endif // ENABLE(WORKERS)
  • trunk/WebCore/inspector/InjectedScriptHost.h

    r55771 r56404  
    8484    long nextWorkerId();
    8585    void didCreateWorker(long id, const String& url, bool isSharedWorker);
    86     void willDestroyWorker(long id);
     86    void didDestroyWorker(long id);
    8787#endif
    8888    void reportDidDispatchOnInjectedScript(long callId, SerializedScriptValue* result, bool isException);
  • trunk/WebCore/inspector/InjectedScriptHost.idl

    r55771 r56404  
    5858#if defined(ENABLE_WORKERS) && ENABLE_WORKERS
    5959        void didCreateWorker(in long id, in DOMString url, in boolean isFakeWorker);
    60         void willDestroyWorker(in long id);
     60        void didDestroyWorker(in long id);
    6161        long nextWorkerId();
    6262#endif
  • trunk/WebCore/inspector/InspectorController.cpp

    r56108 r56404  
    10581058
    10591059#if ENABLE(WORKERS)
    1060 void InspectorController::didCreateWorker(long id, const String& url, bool isSharedWorker)
     1060class PostWorkerNotificationToFrontendTask : public ScriptExecutionContext::Task {
     1061public:
     1062    static PassOwnPtr<PostWorkerNotificationToFrontendTask> create(PassRefPtr<InspectorWorkerResource> worker, InspectorController::WorkerAction action)
     1063    {
     1064        return new PostWorkerNotificationToFrontendTask(worker, action);
     1065    }
     1066
     1067private:
     1068    PostWorkerNotificationToFrontendTask(PassRefPtr<InspectorWorkerResource> worker, InspectorController::WorkerAction action)
     1069        : m_worker(worker)
     1070        , m_action(action)
     1071    {
     1072    }
     1073
     1074    virtual void performTask(ScriptExecutionContext* scriptContext)
     1075    {
     1076        if (InspectorController* inspector = scriptContext->inspectorController())
     1077            inspector->postWorkerNotificationToFrontend(*m_worker, m_action);
     1078    }
     1079
     1080private:
     1081    RefPtr<InspectorWorkerResource> m_worker;
     1082    InspectorController::WorkerAction m_action;
     1083};
     1084
     1085void InspectorController::postWorkerNotificationToFrontend(const InspectorWorkerResource& worker, InspectorController::WorkerAction action)
     1086{
     1087    if (!m_frontend)
     1088        return;
     1089    switch (action) {
     1090    case InspectorController::WorkerCreated:
     1091        m_frontend->didCreateWorker(worker);
     1092        break;
     1093    case InspectorController::WorkerDestroyed:
     1094        m_frontend->didDestroyWorker(worker);
     1095        break;
     1096    }
     1097}
     1098
     1099void InspectorController::didCreateWorker(intptr_t id, const String& url, bool isSharedWorker)
    10611100{
    10621101    if (!enabled())
     
    10651104    RefPtr<InspectorWorkerResource> workerResource(InspectorWorkerResource::create(id, url, isSharedWorker));
    10661105    m_workers.set(id, workerResource);
    1067     if (m_frontend)
    1068         m_frontend->didCreateWorker(*workerResource);
    1069 }
    1070 
    1071 void InspectorController::willDestroyWorker(long id)
     1106    if (m_inspectedPage && m_frontend)
     1107        m_inspectedPage->mainFrame()->document()->postTask(PostWorkerNotificationToFrontendTask::create(workerResource, InspectorController::WorkerCreated));
     1108}
     1109
     1110void InspectorController::didDestroyWorker(intptr_t id)
    10721111{
    10731112    if (!enabled())
     
    10771116    if (workerResource == m_workers.end())
    10781117        return;
    1079     if (m_frontend)
    1080         m_frontend->willDestroyWorker(*workerResource->second);
     1118    if (m_inspectedPage && m_frontend)
     1119        m_inspectedPage->mainFrame()->document()->postTask(PostWorkerNotificationToFrontendTask::create(workerResource->second, InspectorController::WorkerDestroyed));
    10811120    m_workers.remove(workerResource);
    10821121}
  • trunk/WebCore/inspector/InspectorController.h

    r56104 r56404  
    184184    void didModifyDOMAttr(Element*);
    185185#if ENABLE(WORKERS)
    186     void didCreateWorker(long id, const String& url, bool isSharedWorker);
    187     void willDestroyWorker(long id);
     186    enum WorkerAction { WorkerCreated, WorkerDestroyed };
     187
     188    void postWorkerNotificationToFrontend(const InspectorWorkerResource&, WorkerAction);
     189    void didCreateWorker(intptr_t, const String& url, bool isSharedWorker);
     190    void didDestroyWorker(intptr_t);
    188191#endif
    189192    void getCookies(long callId);
     
    362365#endif
    363366#if ENABLE(WORKERS)
    364     typedef HashMap<long, RefPtr<InspectorWorkerResource> > WorkersMap;
     367    typedef HashMap<intptr_t, RefPtr<InspectorWorkerResource> > WorkersMap;
    365368
    366369    WorkersMap m_workers;
  • trunk/WebCore/inspector/InspectorFrontend.cpp

    r56107 r56404  
    603603}
    604604
    605 void InspectorFrontend::willDestroyWorker(const InspectorWorkerResource& worker)
    606 {
    607     ScriptFunctionCall function(m_webInspector, "dispatch");
    608     function.appendArgument("willDestroyWorker");
     605void InspectorFrontend::didDestroyWorker(const InspectorWorkerResource& worker)
     606{
     607    ScriptFunctionCall function(m_webInspector, "dispatch");
     608    function.appendArgument("didDestroyWorker");
    609609    function.appendArgument(worker.id());
    610610    function.call();
  • trunk/WebCore/inspector/InspectorFrontend.h

    r56109 r56404  
    151151#if ENABLE(WORKERS)
    152152        void didCreateWorker(const InspectorWorkerResource&);
    153         void willDestroyWorker(const InspectorWorkerResource&);
     153        void didDestroyWorker(const InspectorWorkerResource&);
    154154#endif // ENABLE(WORKER)
    155155
  • trunk/WebCore/inspector/InspectorWorkerResource.h

    r55771 r56404  
    4343class InspectorWorkerResource : public RefCounted<InspectorWorkerResource> {
    4444public:
    45     static PassRefPtr<InspectorWorkerResource> create(long id, const String& url, bool isSharedWorker)
     45    static PassRefPtr<InspectorWorkerResource> create(intptr_t id, const String& url, bool isSharedWorker)
    4646    {
    4747        return adoptRef(new InspectorWorkerResource(id, url, isSharedWorker));
    4848    }
    4949
    50     long id() const { return m_id; }
     50    intptr_t id() const { return m_id; }
    5151    const String& url() const { return m_url; }
    5252    bool isSharedWorker() const { return m_isSharedWorker; }
    5353private:
    54     InspectorWorkerResource(long id, const String& url, bool isSharedWorker)
     54    InspectorWorkerResource(intptr_t id, const String& url, bool isSharedWorker)
    5555        : m_id(id)
    5656        , m_url(url)
     
    5959    }
    6060
    61     int m_id;
     61    intptr_t m_id;
    6262    String m_url;
    6363    bool m_isSharedWorker;
  • trunk/WebCore/inspector/front-end/InjectedFakeWorker.js

    r56374 r56404  
    6868    terminate: function()
    6969    {
    70         InjectedScriptHost.willDestroyWorker(this._id);
     70        InjectedScriptHost.didDestroyWorker(this._id);
    7171
    7272        if (this._frame != null) {
  • trunk/WebCore/inspector/front-end/WorkersSidebarPane.js

    r55771 r56404  
    108108}
    109109
    110 WebInspector.willDestroyWorker = function()
     110WebInspector.didDestroyWorker = function()
    111111{
    112112    var workersPane = WebInspector.panels.scripts.sidebarPanes.workers;
  • trunk/WebCore/workers/AbstractWorker.cpp

    r55771 r56404  
    4545namespace WebCore {
    4646
    47 long AbstractWorker::s_lastId;
    48 
    4947AbstractWorker::AbstractWorker(ScriptExecutionContext* context)
    5048    : ActiveDOMObject(context, this)
    51     , m_id(++s_lastId)
    5249{
    5350}
     
    6259#if ENABLE(INSPECTOR)
    6360    if (InspectorController* inspector = scriptExecutionContext() ? scriptExecutionContext()->inspectorController() : 0)
    64         inspector->willDestroyWorker(id());
     61        inspector->didDestroyWorker(asID());
    6562#endif
    6663}
  • trunk/WebCore/workers/AbstractWorker.h

    r55771 r56404  
    5858        using RefCounted<AbstractWorker>::deref;
    5959
    60         long id() const { return m_id; }
    6160        virtual void contextDestroyed();
    6261        AbstractWorker(ScriptExecutionContext*);
     
    6665        // Helper function that converts a URL to an absolute URL and checks the result for validity.
    6766        KURL resolveURL(const String& url, ExceptionCode& ec);
     67        intptr_t asID() const { return reinterpret_cast<intptr_t>(this); }
    6868
    6969    private:
     
    7575       
    7676        EventTargetData m_eventTargetData;
    77         long m_id;
    78 
    79         static long s_lastId;
    8077    };
    8178
  • trunk/WebCore/workers/SharedWorker.cpp

    r55771 r56404  
    5757#if ENABLE(INSPECTOR)
    5858    if (InspectorController* inspector = scriptExecutionContext()->inspectorController())
    59         inspector->didCreateWorker(id(), scriptUrl.string(), true);
     59        inspector->didCreateWorker(asID(), scriptUrl.string(), true);
    6060#endif
    6161}
  • trunk/WebCore/workers/Worker.cpp

    r55771 r56404  
    6464#if ENABLE(INSPECTOR)
    6565    if (InspectorController* inspector = scriptExecutionContext()->inspectorController())
    66         inspector->didCreateWorker(id(), scriptURL.string(), false);
     66        inspector->didCreateWorker(asID(), scriptURL.string(), false);
    6767#endif
    6868}
Note: See TracChangeset for help on using the changeset viewer.