Home | History | Annotate | Download | only in inspector
      1 /*
      2 * Copyright (C) 2010 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 InspectorInstrumentation_h
     32 #define InspectorInstrumentation_h
     33 
     34 #include "bindings/v8/ScriptString.h"
     35 #include "core/css/CSSSelector.h"
     36 #include "core/css/CSSStyleDeclaration.h"
     37 #include "core/css/CSSStyleSheet.h"
     38 #include "core/dom/CharacterData.h"
     39 #include "core/dom/Element.h"
     40 #include "core/dom/ExecutionContext.h"
     41 #include "core/events/EventContext.h"
     42 #include "core/frame/Frame.h"
     43 #include "core/inspector/ConsoleAPITypes.h"
     44 #include "core/page/Page.h"
     45 #include "core/rendering/HitTestResult.h"
     46 #include "core/rendering/RenderImage.h"
     47 #include "core/storage/StorageArea.h"
     48 #include "modules/websockets/WebSocketFrame.h"
     49 #include "platform/network/FormData.h"
     50 #include "platform/network/WebSocketHandshakeRequest.h"
     51 #include "platform/network/WebSocketHandshakeResponse.h"
     52 #include "wtf/RefPtr.h"
     53 
     54 namespace WebCore {
     55 
     56 struct CSSParserString;
     57 class Document;
     58 class Element;
     59 class DeviceOrientationData;
     60 class GeolocationPosition;
     61 class GraphicsContext;
     62 class GraphicsLayer;
     63 class InspectorTimelineAgent;
     64 class InstrumentingAgents;
     65 class RenderLayer;
     66 class ExecutionContext;
     67 class ThreadableLoaderClient;
     68 class WorkerGlobalScope;
     69 class WorkerGlobalScopeProxy;
     70 
     71 #define FAST_RETURN_IF_NO_FRONTENDS(value) if (!hasFrontends()) return value;
     72 
     73 class InspectorInstrumentationCookie {
     74 public:
     75     InspectorInstrumentationCookie();
     76     InspectorInstrumentationCookie(InstrumentingAgents*, int);
     77     InspectorInstrumentationCookie(const InspectorInstrumentationCookie&);
     78     InspectorInstrumentationCookie& operator=(const InspectorInstrumentationCookie&);
     79     ~InspectorInstrumentationCookie();
     80 
     81     InstrumentingAgents* instrumentingAgents() const { return m_instrumentingAgents.get(); }
     82     bool isValid() const { return !!m_instrumentingAgents; }
     83     bool hasMatchingTimelineAgentId(int id) const { return m_timelineAgentId == id; }
     84 
     85 private:
     86     RefPtr<InstrumentingAgents> m_instrumentingAgents;
     87     int m_timelineAgentId;
     88 };
     89 
     90 namespace InspectorInstrumentation {
     91 
     92 class FrontendCounter {
     93 private:
     94     friend void frontendCreated();
     95     friend void frontendDeleted();
     96     friend bool hasFrontends();
     97     static int s_frontendCounter;
     98 };
     99 
    100 inline void frontendCreated() { FrontendCounter::s_frontendCounter += 1; }
    101 inline void frontendDeleted() { FrontendCounter::s_frontendCounter -= 1; }
    102 inline bool hasFrontends() { return FrontendCounter::s_frontendCounter; }
    103 
    104 void registerInstrumentingAgents(InstrumentingAgents*);
    105 void unregisterInstrumentingAgents(InstrumentingAgents*);
    106 
    107 InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
    108 
    109 // Called from generated instrumentation code.
    110 InstrumentingAgents* instrumentingAgentsFor(Page*);
    111 InstrumentingAgents* instrumentingAgentsFor(Frame*);
    112 InstrumentingAgents* instrumentingAgentsFor(ExecutionContext*);
    113 InstrumentingAgents* instrumentingAgentsFor(Document&);
    114 InstrumentingAgents* instrumentingAgentsFor(Document*);
    115 InstrumentingAgents* instrumentingAgentsFor(RenderObject*);
    116 InstrumentingAgents* instrumentingAgentsFor(Node*);
    117 InstrumentingAgents* instrumentingAgentsFor(WorkerGlobalScope*);
    118 
    119 // Helper for the one above.
    120 InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ExecutionContext*);
    121 
    122 }  // namespace InspectorInstrumentation
    123 
    124 namespace InstrumentationEvents {
    125 extern const char PaintSetup[];
    126 extern const char RasterTask[];
    127 extern const char Paint[];
    128 extern const char Layer[];
    129 extern const char BeginFrame[];
    130 extern const char ActivateLayerTree[];
    131 };
    132 
    133 namespace InstrumentationEventArguments {
    134 extern const char FrameId[];
    135 extern const char LayerId[];
    136 extern const char LayerTreeId[];
    137 extern const char PageId[];
    138 };
    139 
    140 namespace InspectorInstrumentation {
    141 
    142 inline InstrumentingAgents* instrumentingAgentsFor(ExecutionContext* context)
    143 {
    144     if (!context)
    145         return 0;
    146     return context->isDocument() ? instrumentingAgentsFor(*toDocument(context)) : instrumentingAgentsForNonDocumentContext(context);
    147 }
    148 
    149 inline InstrumentingAgents* instrumentingAgentsFor(Frame* frame)
    150 {
    151     return frame ? instrumentingAgentsFor(frame->page()) : 0;
    152 }
    153 
    154 inline InstrumentingAgents* instrumentingAgentsFor(Document& document)
    155 {
    156     Page* page = document.page();
    157     if (!page && document.templateDocumentHost())
    158         page = document.templateDocumentHost()->page();
    159     return instrumentingAgentsFor(page);
    160 }
    161 
    162 inline InstrumentingAgents* instrumentingAgentsFor(Document* document)
    163 {
    164     return document ? instrumentingAgentsFor(*document) : 0;
    165 }
    166 
    167 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleSheet* styleSheet)
    168 {
    169     return styleSheet ? instrumentingAgentsFor(styleSheet->ownerDocument()) : 0;
    170 }
    171 
    172 inline InstrumentingAgents* instrumentingAgentsFor(Node* node)
    173 {
    174     return node ? instrumentingAgentsFor(node->document()) : 0;
    175 }
    176 
    177 inline InstrumentingAgents* instrumentingAgentsFor(CSSStyleDeclaration* declaration)
    178 {
    179     return declaration ? instrumentingAgentsFor(declaration->parentStyleSheet()) : 0;
    180 }
    181 
    182 } // namespace InspectorInstrumentation
    183 
    184 InstrumentingAgents* instrumentationForPage(Page*);
    185 
    186 InstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope*);
    187 
    188 } // namespace WebCore
    189 
    190 // This file will soon be generated
    191 #include "InspectorInstrumentationInl.h"
    192 
    193 #include "InspectorInstrumentationCustomInl.h"
    194 
    195 #include "InspectorOverridesInl.h"
    196 
    197 #endif // !defined(InspectorInstrumentation_h)
    198