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