这是indexloc提供的服务,不要输入任何密码

Changeset 49036 in webkit


Ignore:
Timestamp:
Oct 2, 2009, 1:01:46 PM (16 years ago)
Author:
bweinstein@apple.com
Message:

2009-10-02 Brian Weinstein <bweinstein@apple.com>

Reviewed by Timothy Hatcher.

Fixes <http://webkit.org/b/14370>.
Inspector's timeline should record when certain DOM events fired.


This patch adds calls into the Web Inspector when the main frame
fires an load event, and when the document fires its DOMContent
event. Once these values are passed in, they are sent to the Web Inspector
as a timing change, and these are denoted by vertical lines in the resources
panel (blue for DOM Content, red for load event).

  • English.lproj/localizedStrings.js: Added tooltip text.
  • dom/Document.cpp: (WebCore::Document::finishedParsing): Added an Inspector callback for DOM Content.
  • inspector/InspectorController.cpp: (WebCore::InspectorController::mainResourceFiredDOMContentEvent): Tell the main resource it got the event. (WebCore::InspectorController::mainResourceFiredLoadEvent): Ditto.
  • inspector/InspectorController.h:
  • inspector/InspectorResource.cpp: (WebCore::InspectorResource::InspectorResource): Added new variables. (WebCore::InspectorResource::updateScriptObject): Send new variables to inspector.js. (WebCore::InspectorResource::markDOMContentEventTime): Send a TimingChange event. (WebCore::InspectorResource::markLoadEventTime): Ditto.
  • inspector/InspectorResource.h:
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourcesPanel.prototype.get mainResourceLoadTime): (WebInspector.ResourcesPanel.prototype.set mainResourceLoadTime): (WebInspector.ResourcesPanel.prototype.get mainResourceDOMContentTime): (WebInspector.ResourcesPanel.prototype.set mainResourceDOMContentTime): (WebInspector.ResourcesPanel.prototype.reset): (WebInspector.ResourcesPanel.prototype._updateGraphDividersIfNeeded): Draw dividers for event timings. (WebInspector.ResourceTimeCalculator.prototype.computePercentageFromEventTime):
  • inspector/front-end/inspector.css:
  • inspector/front-end/inspector.js: (WebInspector.updateResource):
  • page/DOMWindow.cpp: (WebCore::DOMWindow::dispatchLoadEvent): Add an Inspector callback for the Load event.
Location:
trunk/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r49033 r49036  
     12009-10-02  Brian Weinstein  <bweinstein@apple.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Fixes <http://webkit.org/b/14370>.
     6        Inspector's timeline should record when certain DOM events fired.
     7       
     8        This patch adds calls into the Web Inspector when the main frame
     9        fires an load event, and when the document fires its DOMContent
     10        event. Once these values are passed in, they are sent to the Web Inspector
     11        as a timing change, and these are denoted by vertical lines in the resources
     12        panel (blue for DOM Content, red for load event).
     13
     14        * English.lproj/localizedStrings.js: Added tooltip text.
     15        * dom/Document.cpp:
     16        (WebCore::Document::finishedParsing): Added an Inspector callback for DOM Content.
     17        * inspector/InspectorController.cpp:
     18        (WebCore::InspectorController::mainResourceFiredDOMContentEvent): Tell the main resource it got the event.
     19        (WebCore::InspectorController::mainResourceFiredLoadEvent): Ditto.
     20        * inspector/InspectorController.h:
     21        * inspector/InspectorResource.cpp:
     22        (WebCore::InspectorResource::InspectorResource): Added new variables.
     23        (WebCore::InspectorResource::updateScriptObject): Send new variables to inspector.js.
     24        (WebCore::InspectorResource::markDOMContentEventTime): Send a TimingChange event.
     25        (WebCore::InspectorResource::markLoadEventTime): Ditto.
     26        * inspector/InspectorResource.h:
     27        * inspector/front-end/ResourcesPanel.js:
     28        (WebInspector.ResourcesPanel.prototype.get mainResourceLoadTime):
     29        (WebInspector.ResourcesPanel.prototype.set mainResourceLoadTime):
     30        (WebInspector.ResourcesPanel.prototype.get mainResourceDOMContentTime):
     31        (WebInspector.ResourcesPanel.prototype.set mainResourceDOMContentTime):
     32        (WebInspector.ResourcesPanel.prototype.reset):
     33        (WebInspector.ResourcesPanel.prototype._updateGraphDividersIfNeeded): Draw dividers for event timings.
     34        (WebInspector.ResourceTimeCalculator.prototype.computePercentageFromEventTime):
     35        * inspector/front-end/inspector.css:
     36        * inspector/front-end/inspector.js:
     37        (WebInspector.updateResource):
     38        * page/DOMWindow.cpp:
     39        (WebCore::DOMWindow::dispatchLoadEvent): Add an Inspector callback for the Load event.
     40
    1412009-10-02  Dave Hyatt  <hyatt@apple.com>
    242
  • trunk/WebCore/dom/Document.cpp

    r49033 r49036  
    40174017    setParsing(false);
    40184018    dispatchEvent(Event::create(eventNames().DOMContentLoadedEvent, true, false));
    4019     if (Frame* f = frame())
     4019    if (Frame* f = frame()) {
    40204020        f->loader()->finishedParsing();
     4021
     4022        if (InspectorController* controller = page()->inspectorController())
     4023            controller->mainResourceFiredDOMContentEvent(f->loader()->documentLoader(), url());
     4024    }
    40214025}
    40224026
  • trunk/WebCore/inspector/InspectorController.cpp

    r48828 r49036  
    891891}
    892892
     893void InspectorController::mainResourceFiredDOMContentEvent(DocumentLoader* loader, const KURL& url)
     894{
     895    if (!enabled() || !isMainResourceLoader(loader, url))
     896        return;
     897
     898    if (m_mainResource)
     899        m_mainResource->markDOMContentEventTime();
     900}
     901
     902void InspectorController::mainResourceFiredLoadEvent(DocumentLoader* loader, const KURL& url)
     903{
     904    if (!enabled() || !isMainResourceLoader(loader, url))
     905        return;
     906
     907    if (m_mainResource)
     908        m_mainResource->markLoadEventTime();
     909}
     910
    893911bool InspectorController::isMainResourceLoader(DocumentLoader* loader, const KURL& requestUrl)
    894912{
  • trunk/WebCore/inspector/InspectorController.h

    r48798 r49036  
    230230    InspectorTimelineAgent* timelineAgent() { return m_timelineAgent.get(); }
    231231
     232    void mainResourceFiredLoadEvent(DocumentLoader*, const KURL&);
     233    void mainResourceFiredDOMContentEvent(DocumentLoader*, const KURL&);
     234
    232235#if ENABLE(DATABASE)
    233236    void didOpenDatabase(Database*, const String& domain, const String& name, const String& version);
  • trunk/WebCore/inspector/InspectorResource.cpp

    r48606 r49036  
    6060    , m_responseReceivedTime(-1.0)
    6161    , m_endTime(-1.0)
     62    , m_loadEventTime(-1.0)
     63    , m_domContentEventTime(-1.0)
    6264    , m_isMainResource(false)
    6365{
     
    201203        if (m_endTime > 0)
    202204            jsonObject.set("endTime", m_endTime);
     205        if (m_loadEventTime > 0)
     206            jsonObject.set("loadEventTime", m_loadEventTime);
     207        if (m_domContentEventTime > 0)
     208            jsonObject.set("domContentEventTime", m_domContentEventTime);
    203209        jsonObject.set("didTimingChange", true);
    204210    }
     
    321327}
    322328
     329void InspectorResource::markDOMContentEventTime()
     330{
     331    m_domContentEventTime = currentTime();
     332    m_changes.set(TimingChange);
     333}
     334
     335void InspectorResource::markLoadEventTime()
     336{
     337    m_loadEventTime = currentTime();
     338    m_changes.set(TimingChange);
     339}
     340
    323341void InspectorResource::markFailed()
    324342{
  • trunk/WebCore/inspector/InspectorResource.h

    r48606 r49036  
    104104        void startTiming();
    105105        void markResponseReceivedTime();
     106        void markLoadEventTime();
     107        void markDOMContentEventTime();
    106108        void endTiming();
    107109
     
    162164        double m_responseReceivedTime;
    163165        double m_endTime;
     166        double m_loadEventTime;
     167        double m_domContentEventTime;
    164168        ScriptString m_xmlHttpResponseText;
    165169        Changes m_changes;
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r48797 r49036  
    205205        return WebInspector.UIString("Resources");
    206206    },
     207   
     208    get mainResourceLoadTime()
     209    {
     210        return this._mainResourceLoadTime || -1;
     211    },
     212   
     213    set mainResourceLoadTime(x)
     214    {
     215        if (this._mainResourceLoadTime === x)
     216            return;
     217       
     218        this._mainResourceLoadTime = x;
     219       
     220        // Update the dividers to draw the new line
     221        this._updateGraphDividersIfNeeded(true);
     222    },
     223   
     224    get mainResourceDOMContentTime()
     225    {
     226        return this._mainResourceDOMContentTime || -1;
     227    },
     228   
     229    set mainResourceDOMContentTime(x)
     230    {
     231        if (this._mainResourceDOMContentTime === x)
     232            return;
     233       
     234        this._mainResourceDOMContentTime = x;
     235       
     236        this._updateGraphDividersIfNeeded(true);
     237    },
    207238
    208239    get statusBarItems()
     
    452483        this._resources = [];
    453484        this._staleResources = [];
     485       
     486        this.mainResourceLoadTime = -1;
     487        this.mainResourceDOMContentTime = -1;
    454488
    455489        this.resourcesTreeElement.removeChildren();
     
    722756            this.dividersLabelBarElement.appendChild(divider);
    723757        }
     758
     759        if (this.calculator.startAtZero) {
     760            // If our current sorting method starts at zero, that means it shows all
     761            // resources starting at the same point, and so onLoad event and DOMContent
     762            // event lines really wouldn't make much sense here, so don't render them.
     763            return;
     764        }
     765
     766        if (this.mainResourceLoadTime !== -1) {
     767            var percent = this.calculator.computePercentageFromEventTime(this.mainResourceLoadTime);
     768            var loadDivider = document.createElement("div");
     769            loadDivider.className = "resources-onload-divider";
     770            loadDivider.style.left = percent + "%";
     771            loadDivider.title = WebInspector.UIString("Load event fired");
     772            this.dividersElement.appendChild(loadDivider);
     773        }
     774       
     775        if (this.mainResourceDOMContentTime !== -1) {
     776            var percent = this.calculator.computePercentageFromEventTime(this.mainResourceDOMContentTime);
     777            var domContentDivider = document.createElement("div");
     778            domContentDivider.className = "resources-ondomcontent-divider";
     779            domContentDivider.title = WebInspector.UIString("DOMContent event fired");
     780            domContentDivider.style.left = percent + "%";
     781            this.dividersElement.appendChild(domContentDivider);
     782        }
    724783    },
    725784
     
    10491108        return {start: start, middle: middle, end: end};
    10501109    },
     1110   
     1111    computePercentageFromEventTime: function(eventTime)
     1112    {
     1113        // This function computes a percentage in terms of the total loading time
     1114        // of a specific event. If startAtZero is set, then this is useless, and we
     1115        // want to return 0.
     1116        if (eventTime !== -1 && !this.startAtZero)
     1117            return ((eventTime - this.minimumBoundary) / this.boundarySpan) * 100;
     1118
     1119        return 0;
     1120    },
    10511121
    10521122    computeBarGraphLabels: function(resource)
  • trunk/WebCore/inspector/front-end/inspector.css

    r48809 r49036  
    25792579}
    25802580
     2581.resources-onload-divider {
     2582    position: absolute;
     2583    width: 2px;
     2584    top: 0;
     2585    bottom: 0;
     2586    z-index: 300;
     2587    background-color: rgba(255, 0, 0, 0.5);
     2588}
     2589
     2590.resources-ondomcontent-divider {
     2591    position: absolute;
     2592    width: 2px;
     2593    top: 0;
     2594    bottom: 0;
     2595    z-index: 300;
     2596    background-color: rgba(0, 0, 255, 0.5);
     2597}
     2598
    25812599.resources-divider.last {
    25822600    background-color: transparent;
  • trunk/WebCore/inspector/front-end/inspector.js

    r48828 r49036  
    990990        if (payload.endTime)
    991991            resource.endTime = payload.endTime;
     992       
     993        if (payload.loadEventTime) {
     994            // This loadEventTime is for the main resource, and we want to show it
     995            // for all resources on this page. This means we want to set it as a member
     996            // of the resources panel instead of the individual resource.
     997            if (this.panels.resources)
     998                this.panels.resources.mainResourceLoadTime = payload.loadEventTime;
     999        }
     1000       
     1001        if (payload.domContentEventTime) {
     1002            // This domContentEventTime is for the main resource, so it should go in
     1003            // the resources panel for the same reasons as above.
     1004            if (this.panels.resources)
     1005                this.panels.resources.mainResourceDOMContentTime = payload.domContentEventTime;
     1006        }
    9921007    }
    9931008}
  • trunk/WebCore/page/DOMWindow.cpp

    r48745 r49036  
    12971297        ownerElement->dispatchGenericEvent(ownerEvent.release());
    12981298    }
     1299
     1300    if (InspectorController* controller = frame()->page()->inspectorController())
     1301        controller->mainResourceFiredLoadEvent(frame()->loader()->documentLoader(), url());
    12991302}
    13001303
Note: See TracChangeset for help on using the changeset viewer.