Changeset 87803 in webkit


Ignore:
Timestamp:
Jun 1, 2011 7:34:11 AM (13 years ago)
Author:
yurys@chromium.org
Message:

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

Reviewed by Pavel Feldman.

Web Inspector: allow opening inspector for existing workers
https://bugs.webkit.org/show_bug.cgi?id=61853

Added sidebar pane with a list of all workers. Each worker has a check box
that allows opening inspector for the worker.

  • inspector/Inspector.json:
  • inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didStartWorkerContextImpl):
  • inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::didStartWorkerContext):
  • inspector/InspectorWorkerAgent.cpp: (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::WorkerFrontendChannel): (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::~WorkerFrontendChannel): (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::connectToWorkerContext): (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::disconnectFromWorkerContext): (WebCore::InspectorWorkerAgent::clearFrontend): (WebCore::InspectorWorkerAgent::connectToWorker): (WebCore::InspectorWorkerAgent::disconnectFromWorker): (WebCore::InspectorWorkerAgent::didStartWorkerContext):
  • inspector/InspectorWorkerAgent.h:
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel):
  • inspector/front-end/Settings.js:
  • inspector/front-end/WorkerManager.js: (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype._workerCreated): (WebInspector.WorkerManager.prototype._sendMessageToWorkerInspector): (WebInspector.WorkerManager.prototype.openWorkerInspector): (WebInspector.WorkerManager.prototype.closeWorkerInspector): (WebInspector.WorkerManager.prototype._workerInspectorClosing): (WebInspector.WorkerMessageForwarder): (WebInspector.WorkerMessageForwarder.prototype.workerCreated): (WebInspector.WorkerMessageForwarder.prototype.dispatchMessageFromWorker):
  • inspector/front-end/WorkersSidebarPane.js: (WebInspector.WorkersSidebarPane): (WebInspector.WorkersSidebarPane.prototype.addWorker): (WebInspector.WorkerListSidebarPane): (WebInspector.WorkerListSidebarPane.prototype._workerAdded): (WebInspector.WorkerListSidebarPane.prototype._workerRemoved): (WebInspector.WorkerListSidebarPane.prototype._workerInspectorClosed): (WebInspector.WorkerListSidebarPane.prototype._addWorker): (WebInspector.WorkerListSidebarPane.prototype._createCheckbox): (WebInspector.WorkerListSidebarPane.prototype._workerItemClicked):
  • workers/Worker.cpp: (WebCore::Worker::notifyFinished):
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87802 r87803  
     12011-06-01  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: allow opening inspector for existing workers
     6        https://bugs.webkit.org/show_bug.cgi?id=61853
     7
     8        Added sidebar pane with a list of all workers. Each worker has a check box
     9        that allows opening inspector for the worker.
     10
     11        * inspector/Inspector.json:
     12        * inspector/InspectorInstrumentation.cpp:
     13        (WebCore::InspectorInstrumentation::didStartWorkerContextImpl):
     14        * inspector/InspectorInstrumentation.h:
     15        (WebCore::InspectorInstrumentation::didStartWorkerContext):
     16        * inspector/InspectorWorkerAgent.cpp:
     17        (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::WorkerFrontendChannel):
     18        (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::~WorkerFrontendChannel):
     19        (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::connectToWorkerContext):
     20        (WebCore::InspectorWorkerAgent::WorkerFrontendChannel::disconnectFromWorkerContext):
     21        (WebCore::InspectorWorkerAgent::clearFrontend):
     22        (WebCore::InspectorWorkerAgent::connectToWorker):
     23        (WebCore::InspectorWorkerAgent::disconnectFromWorker):
     24        (WebCore::InspectorWorkerAgent::didStartWorkerContext):
     25        * inspector/InspectorWorkerAgent.h:
     26        * inspector/front-end/ScriptsPanel.js:
     27        (WebInspector.ScriptsPanel):
     28        * inspector/front-end/Settings.js:
     29        * inspector/front-end/WorkerManager.js:
     30        (WebInspector.WorkerManager):
     31        (WebInspector.WorkerManager.prototype._workerCreated):
     32        (WebInspector.WorkerManager.prototype._sendMessageToWorkerInspector):
     33        (WebInspector.WorkerManager.prototype.openWorkerInspector):
     34        (WebInspector.WorkerManager.prototype.closeWorkerInspector):
     35        (WebInspector.WorkerManager.prototype._workerInspectorClosing):
     36        (WebInspector.WorkerMessageForwarder):
     37        (WebInspector.WorkerMessageForwarder.prototype.workerCreated):
     38        (WebInspector.WorkerMessageForwarder.prototype.dispatchMessageFromWorker):
     39        * inspector/front-end/WorkersSidebarPane.js:
     40        (WebInspector.WorkersSidebarPane):
     41        (WebInspector.WorkersSidebarPane.prototype.addWorker):
     42        (WebInspector.WorkerListSidebarPane):
     43        (WebInspector.WorkerListSidebarPane.prototype._workerAdded):
     44        (WebInspector.WorkerListSidebarPane.prototype._workerRemoved):
     45        (WebInspector.WorkerListSidebarPane.prototype._workerInspectorClosed):
     46        (WebInspector.WorkerListSidebarPane.prototype._addWorker):
     47        (WebInspector.WorkerListSidebarPane.prototype._createCheckbox):
     48        (WebInspector.WorkerListSidebarPane.prototype._workerItemClicked):
     49        * workers/Worker.cpp:
     50        (WebCore::Worker::notifyFinished):
     51
    1522011-06-01  Shishir Agrawal  <shishir@chromium.org>
    253
  • trunk/Source/WebCore/inspector/Inspector.json

    r86959 r87803  
    17271727                    { "name": "message", "type": "object" }
    17281728                ]
     1729            },
     1730            {
     1731                "name": "connectToWorker",
     1732                "parameters": [
     1733                    { "name": "workerId", "type": "integer" }
     1734                ]
     1735            },
     1736            {
     1737                "name": "disconnectFromWorker",
     1738                "parameters": [
     1739                    { "name": "workerId", "type": "integer" }
     1740                ]
    17291741            }
    17301742        ],
     
    17331745                "name": "workerCreated",
    17341746                "parameters": [
    1735                     { "name": "workerId", "type": "integer" }
     1747                    { "name": "workerId", "type": "integer" },
     1748                    { "name": "url", "type": "string" }
    17361749                ]
    17371750            },
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r87681 r87803  
    717717
    718718#if ENABLE(WORKERS)
    719 void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy)
     719void InspectorInstrumentation::didStartWorkerContextImpl(InstrumentingAgents* instrumentingAgents, WorkerContextProxy* workerContextProxy, const KURL& url)
    720720{
    721721    if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent())
    722         workerAgent->didStartWorkerContext(workerContextProxy);
     722        workerAgent->didStartWorkerContext(workerContextProxy, url);
    723723}
    724724
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r86752 r87803  
    162162#if ENABLE(WORKERS)
    163163    static bool willStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*);
    164     static void didStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*, bool paused);
     164    static void didStartWorkerContext(ScriptExecutionContext*, WorkerContextProxy*, bool paused, const KURL&);
    165165    static void didCreateWorker(ScriptExecutionContext*, intptr_t id, const String& url, bool isSharedWorker);
    166166    static void didDestroyWorker(ScriptExecutionContext*, intptr_t id);
     
    284284
    285285#if ENABLE(WORKERS)
    286     static void didStartWorkerContextImpl(InstrumentingAgents*, WorkerContextProxy*);
     286    static void didStartWorkerContextImpl(InstrumentingAgents*, WorkerContextProxy*, const KURL&);
    287287    static void didCreateWorkerImpl(InstrumentingAgents*, intptr_t id, const String& url, bool isSharedWorker);
    288288    static void didDestroyWorkerImpl(InstrumentingAgents*, intptr_t id);
     
    857857}
    858858
    859 inline void InspectorInstrumentation::didStartWorkerContext(ScriptExecutionContext* context, WorkerContextProxy* proxy, bool paused)
     859inline void InspectorInstrumentation::didStartWorkerContext(ScriptExecutionContext* context, WorkerContextProxy* proxy, bool paused, const KURL& url)
    860860{
    861861#if ENABLE(INSPECTOR)
     
    864864    FAST_RETURN_IF_NO_FRONTENDS(void());
    865865    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
    866         didStartWorkerContextImpl(instrumentingAgents, proxy);
     866        didStartWorkerContextImpl(instrumentingAgents, proxy, url);
    867867#endif
    868868}
  • trunk/Source/WebCore/inspector/InspectorWorkerAgent.cpp

    r87074 r87803  
    3939#include "InspectorValues.h"
    4040#include "InstrumentingAgents.h"
     41#include "KURL.h"
    4142#include "WorkerContextProxy.h"
    4243#include <wtf/PassOwnPtr.h>
     
    5152        , m_proxy(proxy)
    5253        , m_id(s_nextId++)
     54        , m_connected(false)
    5355    {
    5456    }
    55     virtual ~WorkerFrontendChannel() { }
     57    virtual ~WorkerFrontendChannel()
     58    {
     59        disconnectFromWorkerContext();
     60    }
    5661
    5762    int id() const { return m_id; }
    5863    WorkerContextProxy* proxy() const { return m_proxy; }
     64
     65    void connectToWorkerContext()
     66    {
     67        if (m_connected)
     68            return;
     69        m_connected = true;
     70        m_proxy->connectToInspector(this);
     71    }
     72
     73    void disconnectFromWorkerContext()
     74    {
     75        if (!m_connected)
     76            return;
     77        m_connected = false;
     78        m_proxy->disconnectFromInspector();
     79    }
    5980
    6081private:
     
    7495    WorkerContextProxy* m_proxy;
    7596    int m_id;
     97    bool m_connected;
    7698    static int s_nextId;
    7799};
     
    105127    m_inspectorFrontend = 0;
    106128    m_instrumentingAgents->setInspectorWorkerAgent(0);
     129    deleteAllValues(m_idToChannel);
     130    m_idToChannel.clear();
     131}
     132
     133void InspectorWorkerAgent::connectToWorker(ErrorString* error, int workerId)
     134{
     135    WorkerFrontendChannel* channel = m_idToChannel.get(workerId);
     136    if (channel)
     137        channel->connectToWorkerContext();
     138    else
     139        *error = "Worker is gone";
     140}
     141
     142void InspectorWorkerAgent::disconnectFromWorker(ErrorString* error, int workerId)
     143{
     144    WorkerFrontendChannel* channel = m_idToChannel.get(workerId);
     145    if (channel)
     146        channel->disconnectFromWorkerContext();
     147    else
     148        *error = "Worker is gone";
    107149}
    108150
     
    116158}
    117159
    118 void InspectorWorkerAgent::didStartWorkerContext(WorkerContextProxy* workerContextProxy)
     160void InspectorWorkerAgent::didStartWorkerContext(WorkerContextProxy* workerContextProxy, const KURL& url)
    119161{
    120162    WorkerFrontendChannel* channel = new WorkerFrontendChannel(m_inspectorFrontend, workerContextProxy);
    121163    m_idToChannel.set(channel->id(), channel);
    122164
    123     workerContextProxy->connectToInspector(channel);
    124     if (m_inspectorFrontend)
    125         m_inspectorFrontend->worker()->workerCreated(channel->id());
     165    ASSERT(m_inspectorFrontend);
     166    m_inspectorFrontend->worker()->workerCreated(channel->id(), url.string());
    126167}
    127168
  • trunk/Source/WebCore/inspector/InspectorWorkerAgent.h

    r87074 r87803  
    4141class InspectorObject;
    4242class InstrumentingAgents;
     43class KURL;
    4344class WorkerContextProxy;
    4445
     
    5455
    5556    // Called from InspectorInstrumentation
    56     void didStartWorkerContext(WorkerContextProxy*);
     57    void didStartWorkerContext(WorkerContextProxy*, const KURL&);
    5758
    5859    // Called from InspectorBackendDispatcher
     60    void connectToWorker(ErrorString*, int workerId);
     61    void disconnectFromWorker(ErrorString*, int workerId);
    5962    void sendMessageToWorker(ErrorString*, int workerId, PassRefPtr<InspectorObject> message);
    6063
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r87166 r87803  
    108108
    109109    this.sidebarPanes.workers = new WebInspector.WorkersSidebarPane();
     110    if (Preferences.canInspectWorkers && WebInspector.workerManager)
     111        this.sidebarPanes.workerList = new WebInspector.WorkerListSidebarPane(WebInspector.workerManager);
     112
    110113
    111114    for (var pane in this.sidebarPanes)
  • trunk/Source/WebCore/inspector/front-end/Settings.js

    r85312 r87803  
    5252    detailedHeapProfiles: false,
    5353    saveAsAvailable: false,
    54     useLowerCaseMenuTitlesOnWindows: false
     54    useLowerCaseMenuTitlesOnWindows: false,
     55    canInspectWorkers: false,
    5556}
    5657
  • trunk/Source/WebCore/inspector/front-end/WorkerManager.js

    r85847 r87803  
    3131WebInspector.WorkerManager = function()
    3232{
     33    this._workerIdToWindow = {};
     34    InspectorBackend.registerDomainDispatcher("Worker", new WebInspector.WorkerMessageForwarder(this));
    3335}
    3436
     
    4244    var workerId = WebInspector.queryParamsObject["workerId"];
    4345    if (!workerId) {
    44         InspectorBackend.registerDomainDispatcher("Worker", new WebInspector.WorkerMessageForwarder());
     46        WebInspector.workerManager = new WebInspector.WorkerManager();
    4547        return;
    4648    }
    47 
    4849
    4950    function receiveMessage(event)
     
    6667}
    6768
     69WebInspector.WorkerManager.Events = {
     70    WorkerAdded: "worker-added",
     71    WorkerRemoved: "worker-removed",
     72    WorkerInspectorClosed: "worker-inspector-closed"
     73}
    6874
    69 WebInspector.WorkerMessageForwarder = function()
     75WebInspector.WorkerManager.prototype = {
     76    _workerCreated: function(workerId, url)
     77    {
     78        this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerAdded, {workerId: workerId, url: url});
     79    },
     80
     81    _sendMessageToWorkerInspector: function(workerId, message)
     82    {
     83        var workerInspectorWindow = this._workerIdToWindow[workerId];
     84        if (workerInspectorWindow)
     85            workerInspectorWindow.postMessage(message, "*");
     86    },
     87
     88    openWorkerInspector: function(workerId)
     89    {
     90        var url = location.href + "&workerId=" + workerId;
     91        url = url.replace("docked=true&", "");
     92        var workerInspectorWindow = window.open(url);
     93        this._workerIdToWindow[workerId] = workerInspectorWindow;
     94        workerInspectorWindow.addEventListener("beforeunload", this._workerInspectorClosing.bind(this, workerId), true);
     95        WorkerAgent.connectToWorker(workerId);
     96    },
     97
     98    closeWorkerInspector: function(workerId)
     99    {
     100        var workerInspectorWindow = this._workerIdToWindow[workerId];
     101        if (workerInspectorWindow)
     102            workerInspectorWindow.close();
     103    },
     104
     105    _workerInspectorClosing: function(workerId, event)
     106    {
     107        delete this._workerIdToWindow[workerId];
     108        WorkerAgent.disconnectFromWorker(workerId);
     109        this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerInspectorClosed, workerId);
     110    }
     111}
     112
     113WebInspector.WorkerManager.prototype.__proto__ = WebInspector.Object.prototype;
     114
     115WebInspector.WorkerMessageForwarder = function(workerManager)
    70116{
     117    this._workerManager = workerManager;
    71118    window.addEventListener("message", this._receiveMessage.bind(this), true);
    72     this._workerIdToWindow = {};
    73119}
    74120
     
    85131    },
    86132
    87     workerCreated: function(workerId)
     133    workerCreated: function(workerId, url)
    88134    {
    89         var url = location.href + "&workerId=" + workerId;
    90         url = url.replace("docked=true&", "");
    91         this._workerIdToWindow[workerId] = window.open(url);
     135        this._workerManager._workerCreated(workerId, url);
    92136    },
    93137
    94138    dispatchMessageFromWorker: function(workerId, message)
    95139    {
    96         var win = this._workerIdToWindow[workerId];
    97         if (win)
    98             win.postMessage(message, "*");
     140        this._workerManager._sendMessageToWorkerInspector(workerId, message);
    99141    }
    100142}
  • trunk/Source/WebCore/inspector/front-end/WorkersSidebarPane.js

    r82281 r87803  
    3232{
    3333    WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
    34    
     34
    3535    this._workers = {};
    3636
     
    5454    addWorker: function(id, url, isShared)
    5555    {
    56         if (id in this._workers) 
     56        if (id in this._workers)
    5757            return;
    5858        var worker = new WebInspector.Worker(id, url, isShared);
     
    101101    this.shared = shared;
    102102}
     103
     104
     105
     106WebInspector.WorkerListSidebarPane = function(workerManager)
     107{
     108    WebInspector.SidebarPane.call(this, WebInspector.UIString("Worker inspectors"));
     109
     110    this._workerListElement = document.createElement("ol");
     111    this._workerListElement.tabIndex = 0;
     112    this._workerListElement.addStyleClass("properties-tree");
     113    this._workerListTreeOutline = new TreeOutline(this._workerListElement);
     114    this.bodyElement.appendChild(this._workerListElement);
     115
     116    this._idToWorkerItem = {};
     117    this._workerManager = workerManager;
     118
     119    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
     120    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
     121    workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerInspectorClosed, this._workerInspectorClosed, this);
     122}
     123
     124WebInspector.WorkerListSidebarPane.prototype = {
     125    _workerAdded: function(event)
     126    {
     127        this._addWorker(event.data.workerId, event.data.url);
     128    },
     129
     130    _workerRemoved: function(event)
     131    {
     132        var workerItem = this._idToWorkerItem[event.data];
     133        workerItem.element.parentElement.removeChild(workerItem.element);
     134    },
     135
     136    _workerInspectorClosed: function(event)
     137    {
     138        var workerItem = this._idToWorkerItem[event.data];
     139        workerItem.checkbox.checked = false;
     140    },
     141
     142    _addWorker: function(workerId, url)
     143    {
     144        var workerItem = {};
     145        workerItem.workerId = workerId;
     146        workerItem.element = new TreeElement(url);
     147        this._workerListTreeOutline.appendChild(workerItem.element);
     148        workerItem.element.selectable = true;
     149
     150        workerItem.checkbox = this._createCheckbox(workerItem.element);
     151        workerItem.checkbox.addEventListener("click", this._workerItemClicked.bind(this, workerItem), true);
     152
     153        this._idToWorkerItem[workerId] = workerItem;
     154    },
     155
     156    _createCheckbox: function(treeElement)
     157    {
     158        var checkbox = document.createElement("input");
     159        checkbox.className = "checkbox-elem";
     160        checkbox.type = "checkbox";
     161        treeElement.listItemElement.insertBefore(checkbox, treeElement.listItemElement.firstChild);
     162        return checkbox;
     163    },
     164
     165    _workerItemClicked: function(workerItem, event)
     166    {
     167        if (event.target.checked)
     168            this._workerManager.openWorkerInspector(workerItem.workerId);
     169        else
     170            this._workerManager.closeWorkerInspector(workerItem.workerId);
     171    }
     172}
     173
     174WebInspector.WorkerListSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  • trunk/Source/WebCore/workers/Worker.cpp

    r85020 r87803  
    134134        bool shouldStartPaused = InspectorInstrumentation::willStartWorkerContext(scriptExecutionContext(), m_contextProxy);
    135135        m_contextProxy->startWorkerContext(m_scriptLoader->url(), scriptExecutionContext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script());
    136         InspectorInstrumentation::didStartWorkerContext(scriptExecutionContext(), m_contextProxy, shouldStartPaused);
     136        InspectorInstrumentation::didStartWorkerContext(scriptExecutionContext(), m_contextProxy, shouldStartPaused, m_scriptLoader->url());
    137137        InspectorInstrumentation::scriptImported(scriptExecutionContext(), m_scriptLoader->identifier(), m_scriptLoader->script());
    138138    }
Note: See TracChangeset for help on using the changeset viewer.