Changeset 87992 in webkit


Ignore:
Timestamp:
Jun 3, 2011 12:23:53 AM (13 years ago)
Author:
yurys@chromium.org
Message:

2011-06-02 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: add an option for automatically attaching to new workers
https://bugs.webkit.org/show_bug.cgi?id=61930

Worker list is extended with a checkbox that makes inspector attach to each
new worker. Whenever a new worker context starts a new inspector window will
be opened for it.

Also worker agent and worker list will be updated when worker context is terminated.

  • inspector/Inspector.json:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController):
  • inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerContextTerminatedImpl):
  • inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerContextTerminated):
  • inspector/InspectorWorkerAgent.cpp: (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::~WorkerFrontendChannel): (WebCore::InspectorWorkerAgent::create): (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::clearFrontend): (WebCore::InspectorWorkerAgent::setAutoconnectToWorkers): (WebCore::InspectorWorkerAgent::didStartWorkerContext): (WebCore::InspectorWorkerAgent::workerContextTerminated):
  • inspector/InspectorWorkerAgent.h:
  • inspector/front-end/WorkerManager.js: (WebInspector.WorkerManager.prototype._workerCreated): (WebInspector.WorkerManager.prototype._workerTerminated): (WebInspector.WorkerManager.prototype.openWorkerInspector): (WebInspector.WorkerManager.prototype._openInspectorWindow): (WebInspector.WorkerManager.prototype.reset): (WebInspector.WorkerMessageForwarder.prototype.workerCreated): (WebInspector.WorkerMessageForwarder.prototype.workerTerminated):
  • inspector/front-end/WorkersSidebarPane.js: (WebInspector.WorkerListSidebarPane): (WebInspector.WorkerListSidebarPane.prototype._workerAdded): (WebInspector.WorkerListSidebarPane.prototype._workerRemoved): (WebInspector.WorkerListSidebarPane.prototype._workersCleared): (WebInspector.WorkerListSidebarPane.prototype._addWorker): (WebInspector.WorkerListSidebarPane.prototype._workerItemClicked): (WebInspector.WorkerListSidebarPane.prototype._autoattachToWorkersClicked):
  • inspector/front-end/inspector.js: (WebInspector.reset):

2011-06-02 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: add an option for automatically attaching to new workers
https://bugs.webkit.org/show_bug.cgi?id=61930

Notification about worker context termination are now sent to the inspector.

  • src/WebWorkerClientImpl.cpp: (WebKit::WebWorkerClientImpl::terminateWorkerContext): (WebKit::WebWorkerClientImpl::disconnectFromInspector): (WebKit::WebWorkerClientImpl::workerContextDestroyed):
Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87991 r87992  
     12011-06-02  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: add an option for automatically attaching to new workers
     6        https://bugs.webkit.org/show_bug.cgi?id=61930
     7
     8        Worker list is extended with a checkbox that makes inspector attach to each
     9        new worker. Whenever a new worker context starts a new inspector window will
     10        be opened for it.
     11
     12        Also worker agent and worker list will be updated when worker context is terminated.
     13
     14        * inspector/Inspector.json:
     15        * inspector/InspectorController.cpp:
     16        (WebCore::InspectorController::InspectorController):
     17        * inspector/InspectorInstrumentation.cpp:
     18        (WebCore::InspectorInstrumentation::workerContextTerminatedImpl):
     19        * inspector/InspectorInstrumentation.h:
     20        (WebCore::InspectorInstrumentation::workerContextTerminated):
     21        * inspector/InspectorWorkerAgent.cpp:
     22        (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::~WorkerFrontendChannel):
     23        (WebCore::InspectorWorkerAgent::create):
     24        (WebCore::InspectorWorkerAgent::InspectorWorkerAgent):
     25        (WebCore::InspectorWorkerAgent::clearFrontend):
     26        (WebCore::InspectorWorkerAgent::setAutoconnectToWorkers):
     27        (WebCore::InspectorWorkerAgent::didStartWorkerContext):
     28        (WebCore::InspectorWorkerAgent::workerContextTerminated):
     29        * inspector/InspectorWorkerAgent.h:
     30        * inspector/front-end/WorkerManager.js:
     31        (WebInspector.WorkerManager.prototype._workerCreated):
     32        (WebInspector.WorkerManager.prototype._workerTerminated):
     33        (WebInspector.WorkerManager.prototype.openWorkerInspector):
     34        (WebInspector.WorkerManager.prototype._openInspectorWindow):
     35        (WebInspector.WorkerManager.prototype.reset):
     36        (WebInspector.WorkerMessageForwarder.prototype.workerCreated):
     37        (WebInspector.WorkerMessageForwarder.prototype.workerTerminated):
     38        * inspector/front-end/WorkersSidebarPane.js:
     39        (WebInspector.WorkerListSidebarPane):
     40        (WebInspector.WorkerListSidebarPane.prototype._workerAdded):
     41        (WebInspector.WorkerListSidebarPane.prototype._workerRemoved):
     42        (WebInspector.WorkerListSidebarPane.prototype._workersCleared):
     43        (WebInspector.WorkerListSidebarPane.prototype._addWorker):
     44        (WebInspector.WorkerListSidebarPane.prototype._workerItemClicked):
     45        (WebInspector.WorkerListSidebarPane.prototype._autoattachToWorkersClicked):
     46        * inspector/front-end/inspector.js:
     47        (WebInspector.reset):
     48
    1492011-06-02  Hayato Ito  <hayato@chromium.org>
    250
  • trunk/Source/WebCore/inspector/Inspector.json

    r87803 r87992  
    17391739                    { "name": "workerId", "type": "integer" }
    17401740                ]
    1741             }
     1741            },
     1742            {
     1743                "name": "setAutoconnectToWorkers",
     1744                "parameters": [
     1745                    { "name": "value", "type": "boolean" }
     1746                ]
     1747            }
     1748
    17421749        ],
    17431750        "events": [
     
    17461753                "parameters": [
    17471754                    { "name": "workerId", "type": "integer" },
    1748                     { "name": "url", "type": "string" }
     1755                    { "name": "url", "type": "string" },
     1756                    { "name": "inspectorConnected", "type": "boolean" }
     1757                ]
     1758            },
     1759            {
     1760                "name": "workerTerminated",
     1761                "parameters": [
     1762                    { "name": "workerId", "type": "integer" }
    17491763                ]
    17501764            },
  • trunk/Source/WebCore/inspector/InspectorController.cpp

    r86581 r87992  
    111111#endif
    112112#if ENABLE(WORKERS)
    113     , m_workerAgent(InspectorWorkerAgent::create(m_instrumentingAgents.get()))
     113    , m_workerAgent(InspectorWorkerAgent::create(m_instrumentingAgents.get(), m_state.get()))
    114114#endif
    115115    , m_page(page)
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r87803 r87992  
    734734        inspectorAgent->didDestroyWorker(id);
    735735}
     736
     737void InspectorInstrumentation::workerContextTerminatedImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* proxy)
     738{
     739    if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
     740        workerAgent->workerContextTerminated(proxy);
     741}
    736742#endif
    737743
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r87803 r87992  
    165165    static void didCreateWorker(ScriptExecutionContext*, intptr_t id, const String& url, bool isSharedWorker);
    166166    static void didDestroyWorker(ScriptExecutionContext*, intptr_t id);
     167    static void workerContextTerminated(ScriptExecutionContext*, WorkerContextProxy*);
    167168#endif
    168169
     
    287288    static void didCreateWorkerImpl(InstrumentingAgents*, intptr_t id, const String& url, bool isSharedWorker);
    288289    static void didDestroyWorkerImpl(InstrumentingAgents*, intptr_t id);
     290    static void workerContextTerminatedImpl(InstrumentingAgents*, WorkerContextProxy*);
    289291#endif
    290292
     
    885887#endif
    886888}
     889
     890inline void InspectorInstrumentation::workerContextTerminated(ScriptExecutionContext* context, WorkerContextProxy* proxy)
     891{
     892#if ENABLE(INSPECTOR)
     893    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
     894        workerContextTerminatedImpl(instrumentingAgents, proxy);
     895#endif
     896}
     897
    887898#endif
    888899
  • trunk/Source/WebCore/inspector/InspectorWorkerAgent.cpp

    r87803 r87992  
    3737#include "InspectorFrontend.h"
    3838#include "InspectorFrontendChannel.h"
     39#include "InspectorState.h"
    3940#include "InspectorValues.h"
    4041#include "InstrumentingAgents.h"
     
    4546
    4647namespace WebCore {
     48
     49namespace WorkerAgentState {
     50static const char autoconnectToWorkers[] = "autoconnectToWorkers";
     51};
    4752
    4853class InspectorWorkerAgent::WorkerFrontendChannel : public WorkerContextProxy::PageInspector {
     
    5762    virtual ~WorkerFrontendChannel()
    5863    {
    59         disconnectFromWorkerContext();
    6064    }
    6165
     
    101105int InspectorWorkerAgent::WorkerFrontendChannel::s_nextId = 1;
    102106
    103 PassOwnPtr<InspectorWorkerAgent> InspectorWorkerAgent::create(InstrumentingAgents* instrumentingAgents)
    104 {
    105     return adoptPtr(new InspectorWorkerAgent(instrumentingAgents));
    106 }
    107 
    108 InspectorWorkerAgent::InspectorWorkerAgent(InstrumentingAgents* instrumentingAgents)
     107PassOwnPtr<InspectorWorkerAgent> InspectorWorkerAgent::create(InstrumentingAgents* instrumentingAgents, InspectorState* inspectorState)
     108{
     109    return adoptPtr(new InspectorWorkerAgent(instrumentingAgents, inspectorState));
     110}
     111
     112InspectorWorkerAgent::InspectorWorkerAgent(InstrumentingAgents* instrumentingAgents, InspectorState* inspectorState)
    109113    : m_instrumentingAgents(instrumentingAgents)
    110114    , m_inspectorFrontend(0)
     115    , m_inspectorState(inspectorState)
    111116{
    112117}
     
    127132    m_inspectorFrontend = 0;
    128133    m_instrumentingAgents->setInspectorWorkerAgent(0);
    129     deleteAllValues(m_idToChannel);
     134    m_inspectorState->setBoolean(WorkerAgentState::autoconnectToWorkers, false);
     135    for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChannel.end(); ++it) {
     136        it->second->disconnectFromWorkerContext();
     137        delete it->second;
     138    }
    130139    m_idToChannel.clear();
    131140}
     
    158167}
    159168
     169void InspectorWorkerAgent::setAutoconnectToWorkers(ErrorString*, bool value)
     170{
     171    m_inspectorState->setBoolean(WorkerAgentState::autoconnectToWorkers, value);
     172}
     173
    160174void InspectorWorkerAgent::didStartWorkerContext(WorkerContextProxy* workerContextProxy, const KURL& url)
    161175{
     
    164178
    165179    ASSERT(m_inspectorFrontend);
    166     m_inspectorFrontend->worker()->workerCreated(channel->id(), url.string());
     180    bool autoconnectToWorkers = m_inspectorState->getBoolean(WorkerAgentState::autoconnectToWorkers);
     181    if (autoconnectToWorkers)
     182        channel->connectToWorkerContext();
     183    m_inspectorFrontend->worker()->workerCreated(channel->id(), url.string(), autoconnectToWorkers);
     184}
     185
     186void InspectorWorkerAgent::workerContextTerminated(WorkerContextProxy* proxy)
     187{
     188    for (WorkerChannels::iterator it = m_idToChannel.begin(); it != m_idToChannel.end(); ++it) {
     189        if (proxy == it->second->proxy()) {
     190            m_inspectorFrontend->worker()->workerTerminated(it->first);
     191            delete it->second;
     192            m_idToChannel.remove(it);
     193            return;
     194        }
     195    }
    167196}
    168197
  • trunk/Source/WebCore/inspector/InspectorWorkerAgent.h

    r87803 r87992  
    4040class InspectorFrontend;
    4141class InspectorObject;
     42class InspectorState;
    4243class InstrumentingAgents;
    4344class KURL;
     
    4849class InspectorWorkerAgent {
    4950public:
    50     static PassOwnPtr<InspectorWorkerAgent> create(InstrumentingAgents*);
     51    static PassOwnPtr<InspectorWorkerAgent> create(InstrumentingAgents*, InspectorState*);
    5152    ~InspectorWorkerAgent();
    5253
     
    5657    // Called from InspectorInstrumentation
    5758    void didStartWorkerContext(WorkerContextProxy*, const KURL&);
     59    void workerContextTerminated(WorkerContextProxy*);
    5860
    5961    // Called from InspectorBackendDispatcher
     
    6163    void disconnectFromWorker(ErrorString*, int workerId);
    6264    void sendMessageToWorker(ErrorString*, int workerId, PassRefPtr<InspectorObject> message);
     65    void setAutoconnectToWorkers(ErrorString*, bool value);
    6366
    6467private:
    65     explicit InspectorWorkerAgent(InstrumentingAgents*);
     68    InspectorWorkerAgent(InstrumentingAgents*, InspectorState*);
    6669
    6770    InstrumentingAgents* m_instrumentingAgents;
    6871    InspectorFrontend* m_inspectorFrontend;
     72    InspectorState* m_inspectorState;
    6973
    7074    class WorkerFrontendChannel;
    71     HashMap<int, WorkerFrontendChannel*> m_idToChannel;
     75    typedef HashMap<int, WorkerFrontendChannel*> WorkerChannels;
     76    WorkerChannels m_idToChannel;
    7277};
    7378
  • trunk/Source/WebCore/inspector/front-end/WorkerManager.js

    r87803 r87992  
    7070    WorkerAdded: "worker-added",
    7171    WorkerRemoved: "worker-removed",
     72    WorkersCleared: "workers-cleared",
    7273    WorkerInspectorClosed: "worker-inspector-closed"
    7374}
    7475
    7576WebInspector.WorkerManager.prototype = {
    76     _workerCreated: function(workerId, url)
    77     {
    78         this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerAdded, {workerId: workerId, url: url});
    79     },
     77    _workerCreated: function(workerId, url, inspectorConnected)
     78     {
     79        if (inspectorConnected)
     80            this._openInspectorWindow(workerId);
     81        this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerAdded, {workerId: workerId, url: url, inspectorConnected: inspectorConnected});
     82     },
     83
     84    _workerTerminated: function(workerId)
     85     {
     86        this.closeWorkerInspector(workerId);
     87        this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerRemoved, workerId);
     88     },
    8089
    8190    _sendMessageToWorkerInspector: function(workerId, message)
     
    8897    openWorkerInspector: function(workerId)
    8998    {
     99        this._openInspectorWindow(workerId);
     100        WorkerAgent.connectToWorker(workerId);
     101    },
     102
     103    _openInspectorWindow: function(workerId)
     104    {
    90105        var url = location.href + "&workerId=" + workerId;
    91106        url = url.replace("docked=true&", "");
     
    93108        this._workerIdToWindow[workerId] = workerInspectorWindow;
    94109        workerInspectorWindow.addEventListener("beforeunload", this._workerInspectorClosing.bind(this, workerId), true);
    95         WorkerAgent.connectToWorker(workerId);
    96110    },
    97111
     
    101115        if (workerInspectorWindow)
    102116            workerInspectorWindow.close();
     117    },
     118
     119    reset: function()
     120    {
     121        for (var workerId in this._workerIdToWindow)
     122            this.closeWorkerInspector(workerId);
     123        this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkersCleared);
    103124    },
    104125
     
    131152    },
    132153
    133     workerCreated: function(workerId, url)
     154    workerCreated: function(workerId, url, inspectorConnected)
    134155    {
    135         this._workerManager._workerCreated(workerId, url);
     156        this._workerManager._workerCreated(workerId, url, inspectorConnected);
     157    },
     158
     159    workerTerminated: function(workerId)
     160    {
     161        this._workerManager._workerTerminated(workerId);
    136162    },
    137163
  • trunk/Source/WebCore/inspector/front-end/WorkersSidebarPane.js

    r87803 r87992  
    108108    WebInspector.SidebarPane.call(this, WebInspector.UIString("Worker inspectors"));
    109109
     110    this._enableWorkersCheckbox = new WebInspector.Checkbox(
     111        WebInspector.UIString("Debug"),
     112        "sidebar-pane-subtitle",
     113        WebInspector.UIString("Automatically attach to new workers. Enabling this option will force opening inspector for all new workers."));
     114    this.titleElement.insertBefore(this._enableWorkersCheckbox.element, this.titleElement.firstChild);
     115    this._enableWorkersCheckbox.addEventListener(this._autoattachToWorkersClicked.bind(this));
     116    this._enableWorkersCheckbox.checked = false;
     117
    110118    this._workerListElement = document.createElement("ol");
    111119    this._workerListElement.tabIndex = 0;
     
    119127    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
    120128    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
     129    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
    121130    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerInspectorClosed, this._workerInspectorClosed, this);
    122131}
     
    125134    _workerAdded: function(event)
    126135    {
    127         this._addWorker(event.data.workerId, event.data.url);
     136        this._addWorker(event.data.workerId, event.data.url, event.data.inspectorConnected);
    128137    },
    129138
     
    131140    {
    132141        var workerItem = this._idToWorkerItem[event.data];
    133         workerItem.element.parentElement.removeChild(workerItem.element);
     142        delete this._idToWorkerItem[event.data];
     143        workerItem.element.parent.removeChild(workerItem.element);
    134144    },
    135145
     
    140150    },
    141151
    142     _addWorker: function(workerId, url)
     152    _workersCleared: function(event)
     153    {
     154        this._idToWorkerItem = {};
     155        this._workerListTreeOutline.removeChildren();
     156    },
     157
     158    _addWorker: function(workerId, url, inspectorConnected)
    143159    {
    144160        var workerItem = {};
     
    149165
    150166        workerItem.checkbox = this._createCheckbox(workerItem.element);
     167        workerItem.checkbox.checked = inspectorConnected;
    151168        workerItem.checkbox.addEventListener("click", this._workerItemClicked.bind(this, workerItem), true);
    152169
     
    169186        else
    170187            this._workerManager.closeWorkerInspector(workerItem.workerId);
     188    },
     189
     190    _autoattachToWorkersClicked: function(event)
     191    {
     192        WorkerAgent.setAutoconnectToWorkers(event.target.checked);
    171193    }
    172194}
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r87681 r87992  
    985985    this.console.clearMessages();
    986986    this.extensionServer.notifyInspectorReset();
     987    if (this.workerManager)
     988        this.workerManager.reset();
    987989}
    988990
  • trunk/Source/WebKit/chromium/ChangeLog

    r87965 r87992  
     12011-06-02  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: add an option for automatically attaching to new workers
     6        https://bugs.webkit.org/show_bug.cgi?id=61930
     7
     8        Notification about worker context termination are now sent to the inspector.
     9
     10        * src/WebWorkerClientImpl.cpp:
     11        (WebKit::WebWorkerClientImpl::terminateWorkerContext):
     12        (WebKit::WebWorkerClientImpl::disconnectFromInspector):
     13        (WebKit::WebWorkerClientImpl::workerContextDestroyed):
     14
    1152011-06-02  Aaron Colwell  <acolwell@chromium.org>
    216
  • trunk/Source/WebKit/chromium/src/WebWorkerClientImpl.cpp

    r87074 r87992  
    4040#include "Frame.h"
    4141#include "FrameLoaderClient.h"
     42#include "InspectorInstrumentation.h"
    4243#include "MessageEvent.h"
    4344#include "MessagePort.h"
     
    164165    }
    165166    m_webWorker->terminateWorkerContext();
     167    InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this);
    166168}
    167169
     
    218220void WebWorkerClientImpl::disconnectFromInspector()
    219221{
    220     m_webWorker->detachDevTools();
     222    if (!m_askedToTerminate)
     223        m_webWorker->detachDevTools();
    221224    m_pageInspector = 0;
    222225}
     
    329332void WebWorkerClientImpl::workerContextDestroyed()
    330333{
     334    InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.get(), this);
    331335}
    332336
Note: See TracChangeset for help on using the changeset viewer.