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 TimelineRecordFactory_h
     32 #define TimelineRecordFactory_h
     33 
     34 #include "core/InspectorTypeBuilder.h"
     35 #include "platform/JSONValues.h"
     36 #include "platform/weborigin/KURL.h"
     37 #include "wtf/Forward.h"
     38 #include "wtf/text/WTFString.h"
     39 
     40 namespace blink {
     41 
     42 class Event;
     43 class FloatQuad;
     44 class InspectorFrontend;
     45 class IntRect;
     46 class ResourceRequest;
     47 class ResourceResponse;
     48 
     49 class TimelineRecordFactory {
     50 public:
     51     static PassRefPtr<TypeBuilder::Timeline::TimelineEvent> createGenericRecord(double startTime, int maxCallStackDepth, const String& type, PassRefPtr<JSONObject> data);
     52     static PassRefPtr<TypeBuilder::Timeline::TimelineEvent> createBackgroundRecord(double startTime, const String& thread, const String& type, PassRefPtr<JSONObject> data);
     53 
     54     static PassRefPtr<JSONObject> createGCEventData(size_t usedHeapSizeDelta);
     55     static PassRefPtr<JSONObject> createFunctionCallData(int scriptId, const String& scriptName, int scriptLine);
     56     static PassRefPtr<JSONObject> createEventDispatchData(const Event&);
     57     static PassRefPtr<JSONObject> createGenericTimerData(int timerId);
     58     static PassRefPtr<JSONObject> createTimerInstallData(int timerId, int timeout, bool singleShot);
     59     static PassRefPtr<JSONObject> createXHRReadyStateChangeData(const String& url, int readyState);
     60     static PassRefPtr<JSONObject> createXHRLoadData(const String& url);
     61     static PassRefPtr<JSONObject> createEvaluateScriptData(const String&, double lineNumber);
     62     static PassRefPtr<JSONObject> createConsoleTimeData(const String&);
     63     static PassRefPtr<JSONObject> createTimeStampData(const String&);
     64     static PassRefPtr<JSONObject> createResourceSendRequestData(const String& requestId, const ResourceRequest&);
     65     static PassRefPtr<JSONObject> createResourceReceiveResponseData(const String& requestId, const ResourceResponse&);
     66     static PassRefPtr<JSONObject> createReceiveResourceData(const String& requestId, int length);
     67     static PassRefPtr<JSONObject> createResourceFinishData(const String& requestId, bool didFail, double finishTime);
     68     static PassRefPtr<JSONObject> createLayoutData(unsigned dirtyObjects, unsigned totalObjects, bool partialLayout);
     69     static PassRefPtr<JSONObject> createDecodeImageData(const String& imageType);
     70     static PassRefPtr<JSONObject> createResizeImageData(bool shouldCache);
     71     static PassRefPtr<JSONObject> createMarkData(bool isMainFrame);
     72     static PassRefPtr<JSONObject> createParseHTMLData(unsigned startLine);
     73     static PassRefPtr<JSONObject> createAnimationFrameData(int callbackId);
     74     static PassRefPtr<JSONObject> createNodeData(long long nodeId);
     75     static PassRefPtr<JSONObject> createLayerData(long long layerRootNodeId);
     76     static PassRefPtr<JSONObject> createFrameData(int frameId);
     77     static PassRefPtr<JSONObject> createGPUTaskData(bool foreign);
     78 
     79     static void setNodeData(JSONObject* data, long long nodeId);
     80     static void setLayerData(JSONObject* data, long long layerRootNodeId);
     81     static void setLayerTreeData(JSONObject* data, PassRefPtr<JSONValue> layerTree);
     82     static void setPaintData(JSONObject* data, const FloatQuad&, long long layerRootNodeId, int graphicsLayerId);
     83     static void setLayoutRoot(JSONObject* data, const FloatQuad&, long long rootNodeId);
     84     static void setStyleRecalcDetails(JSONObject* data, unsigned elementCount);
     85     static void setImageDetails(JSONObject* data, long long imageElementId, const String& url);
     86 
     87     static inline PassRefPtr<JSONObject> createWebSocketCreateData(unsigned long identifier, const KURL& url, const String& protocol)
     88     {
     89         RefPtr<JSONObject> data = JSONObject::create();
     90         data->setNumber("identifier", identifier);
     91         data->setString("url", url.string());
     92         if (!protocol.isNull())
     93             data->setString("webSocketProtocol", protocol);
     94         return data.release();
     95     }
     96 
     97     static inline PassRefPtr<JSONObject> createGenericWebSocketData(unsigned long identifier)
     98     {
     99         RefPtr<JSONObject> data = JSONObject::create();
    100         data->setNumber("identifier", identifier);
    101         return data.release();
    102     }
    103 
    104     static PassRefPtr<JSONObject> createEmbedderCallbackData(const String& callbackName);
    105 
    106     static String type(TypeBuilder::Timeline::TimelineEvent*);
    107 private:
    108     TimelineRecordFactory() { }
    109 };
    110 
    111 } // namespace blink
    112 
    113 #endif // !defined(TimelineRecordFactory_h)
    114