Home | History | Annotate | Download | only in inspector
      1 /*
      2 * Copyright (C) 2009 Google Inc. All rights reserved.
      3 *
      4 * Redistribution and use in source and binary forms, with or without
      5 * modification, are permitted provided that the following conditions are
      6 * met:
      7 *
      8 *     * Redistributions of source code must retain the above copyright
      9 * notice, this list of conditions and the following disclaimer.
     10 *     * Redistributions in binary form must reproduce the above
     11 * copyright notice, this list of conditions and the following disclaimer
     12 * in the documentation and/or other materials provided with the
     13 * distribution.
     14 *     * Neither the name of Google Inc. nor the names of its
     15 * contributors may be used to endorse or promote products derived from
     16 * this software without specific prior written permission.
     17 *
     18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 */
     30 
     31 #ifndef InspectorTimelineAgent_h
     32 #define InspectorTimelineAgent_h
     33 
     34 #if ENABLE(INSPECTOR)
     35 
     36 #include "Document.h"
     37 #include "ScriptExecutionContext.h"
     38 #include "ScriptObject.h"
     39 #include "ScriptArray.h"
     40 #include <wtf/Vector.h>
     41 
     42 namespace WebCore {
     43     class Event;
     44     class InspectorFrontend;
     45     class IntRect;
     46     class ResourceRequest;
     47     class ResourceResponse;
     48 
     49     // Must be kept in sync with TimelineAgent.js
     50     enum TimelineRecordType {
     51         EventDispatchTimelineRecordType = 0,
     52         LayoutTimelineRecordType = 1,
     53         RecalculateStylesTimelineRecordType = 2,
     54         PaintTimelineRecordType = 3,
     55         ParseHTMLTimelineRecordType = 4,
     56         TimerInstallTimelineRecordType = 5,
     57         TimerRemoveTimelineRecordType = 6,
     58         TimerFireTimelineRecordType = 7,
     59         XHRReadyStateChangeRecordType = 8,
     60         XHRLoadRecordType = 9,
     61         EvaluateScriptTimelineRecordType = 10,
     62         MarkTimelineRecordType = 11,
     63         ResourceSendRequestTimelineRecordType = 12,
     64         ResourceReceiveResponseTimelineRecordType = 13,
     65         ResourceFinishTimelineRecordType = 14,
     66     };
     67 
     68     class InspectorTimelineAgent : public Noncopyable {
     69     public:
     70         InspectorTimelineAgent(InspectorFrontend* frontend);
     71         ~InspectorTimelineAgent();
     72 
     73         void reset();
     74         void resetFrontendProxyObject(InspectorFrontend*);
     75 
     76         // Methods called from WebCore.
     77         void willDispatchEvent(const Event&);
     78         void didDispatchEvent();
     79 
     80         void willLayout();
     81         void didLayout();
     82 
     83         void willRecalculateStyle();
     84         void didRecalculateStyle();
     85 
     86         void willPaint(const IntRect&);
     87         void didPaint();
     88 
     89         void willWriteHTML(unsigned int length, unsigned int startLine);
     90         void didWriteHTML(unsigned int endLine);
     91 
     92         void didInstallTimer(int timerId, int timeout, bool singleShot);
     93         void didRemoveTimer(int timerId);
     94         void willFireTimer(int timerId);
     95         void didFireTimer();
     96 
     97         void willChangeXHRReadyState(const String&, int);
     98         void didChangeXHRReadyState();
     99         void willLoadXHR(const String&);
    100         void didLoadXHR();
    101 
    102         void willEvaluateScript(const String&, int);
    103         void didEvaluateScript();
    104 
    105         void didMarkTimeline(const String&);
    106 
    107         void willSendResourceRequest(unsigned long, bool isMainResource, const ResourceRequest&);
    108         void didReceiveResourceResponse(unsigned long, const ResourceResponse&);
    109         void didFinishLoadingResource(unsigned long, bool didFail);
    110 
    111         static InspectorTimelineAgent* retrieve(ScriptExecutionContext*);
    112     private:
    113         struct TimelineRecordEntry {
    114             TimelineRecordEntry(ScriptObject record, ScriptObject data, ScriptArray children, TimelineRecordType type) : record(record), data(data), children(children), type(type) { }
    115             ScriptObject record;
    116             ScriptObject data;
    117             ScriptArray children;
    118             TimelineRecordType type;
    119         };
    120 
    121         void pushCurrentRecord(ScriptObject, TimelineRecordType);
    122 
    123         static double currentTimeInMilliseconds();
    124 
    125         void didCompleteCurrentRecord(TimelineRecordType);
    126 
    127         void addRecordToTimeline(ScriptObject, TimelineRecordType);
    128 
    129         InspectorFrontend* m_frontend;
    130 
    131         Vector< TimelineRecordEntry > m_recordStack;
    132     };
    133 
    134 inline InspectorTimelineAgent* InspectorTimelineAgent::retrieve(ScriptExecutionContext* context)
    135 {
    136     if (context && context->isDocument())
    137         return static_cast<Document*>(context)->inspectorTimelineAgent();
    138     return 0;
    139 }
    140 
    141 } // namespace WebCore
    142 
    143 #endif // !ENABLE(INSPECTOR)
    144 #endif // !defined(InspectorTimelineAgent_h)
    145