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