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/CSSStyleSheet.h"
     37 #include "core/dom/Element.h"
     38 #include "core/dom/EventContext.h"
     39 #include "core/dom/ScriptExecutionContext.h"
     40 #include "core/inspector/ConsoleAPITypes.h"
     41 #include "core/page/Frame.h"
     42 #include "core/page/Page.h"
     43 #include "core/platform/network/FormData.h"
     44 #include "core/rendering/HitTestResult.h"
     45 #include "core/storage/StorageArea.h"
     46 #include "modules/websockets/WebSocketFrame.h"
     47 #include "modules/websockets/WebSocketHandshakeRequest.h"
     48 #include "modules/websockets/WebSocketHandshakeResponse.h"
     49 #include "wtf/RefPtr.h"
     50 
     51 namespace WebCore {
     52 
     53 struct CSSParserString;
     54 class Document;
     55 class Element;
     56 class DeviceOrientationData;
     57 class GeolocationPosition;
     58 class GraphicsContext;
     59 class InspectorTimelineAgent;
     60 class InstrumentingAgents;
     61 class RenderLayer;
     62 class ScriptExecutionContext;
     63 class ThreadableLoaderClient;
     64 class WorkerGlobalScope;
     65 class WorkerGlobalScopeProxy;
     66 
     67 #define FAST_RETURN_IF_NO_FRONTENDS(value) if (!hasFrontends()) return value;
     68 
     69 class InspectorInstrumentationCookie {
     70 public:
     71     InspectorInstrumentationCookie();
     72     InspectorInstrumentationCookie(InstrumentingAgents*, int);
     73     InspectorInstrumentationCookie(const InspectorInstrumentationCookie&);
     74     InspectorInstrumentationCookie& operator=(const InspectorInstrumentationCookie&);
     75     ~InspectorInstrumentationCookie();
     76 
     77     InstrumentingAgents* instrumentingAgents() const { return m_instrumentingAgents.get(); }
     78     bool isValid() const { return !!m_instrumentingAgents; }
     79     bool hasMatchingTimelineAgentId(int id) const { return m_timelineAgentId == id; }
     80 
     81 private:
     82     RefPtr<InstrumentingAgents> m_instrumentingAgents;
     83     int m_timelineAgentId;
     84 };
     85 
     86 namespace InspectorInstrumentation {
     87 
     88 class FrontendCounter {
     89 private:
     90     friend void frontendCreated();
     91     friend void frontendDeleted();
     92     friend bool hasFrontends();
     93     static int s_frontendCounter;
     94 };
     95 
     96 inline void frontendCreated() { FrontendCounter::s_frontendCounter += 1; }
     97 inline void frontendDeleted() { FrontendCounter::s_frontendCounter -= 1; }
     98 inline bool hasFrontends() { return FrontendCounter::s_frontendCounter; }
     99 
    100 void registerInstrumentingAgents(InstrumentingAgents*);
    101 void unregisterInstrumentingAgents(InstrumentingAgents*);
    102 
    103 InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie&);
    104 
    105 InstrumentingAgents* instrumentingAgentsForPage(Page*);
    106 InstrumentingAgents* instrumentingAgentsForFrame(Frame*);
    107 InstrumentingAgents* instrumentingAgentsForScriptExecutionContext(ScriptExecutionContext*);
    108 InstrumentingAgents* instrumentingAgentsForDocument(Document*);
    109 InstrumentingAgents* instrumentingAgentsForRenderObject(RenderObject*);
    110 InstrumentingAgents* instrumentingAgentsForElement(Element*);
    111 
    112 InstrumentingAgents* instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope*);
    113 InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ScriptExecutionContext*);
    114 
    115 }  // namespace InspectorInstrumentation
    116 
    117 namespace InstrumentationEvents {
    118 extern const char PaintSetup[];
    119 extern const char PaintLayer[];
    120 extern const char RasterTask[];
    121 extern const char ImageDecodeTask[];
    122 extern const char Paint[];
    123 extern const char Layer[];
    124 extern const char BeginFrame[];
    125 extern const char UpdateLayer[];
    126 };
    127 
    128 namespace InstrumentationEventArguments {
    129 extern const char LayerId[];
    130 extern const char LayerTreeId[];
    131 extern const char NodeId[];
    132 extern const char PageId[];
    133 };
    134 
    135 namespace InspectorInstrumentation {
    136 
    137 inline InstrumentingAgents* instrumentingAgentsForScriptExecutionContext(ScriptExecutionContext* context)
    138 {
    139     if (!context)
    140         return 0;
    141     if (context->isDocument())
    142         return instrumentingAgentsForPage(toDocument(context)->page());
    143     return instrumentingAgentsForNonDocumentContext(context);
    144 }
    145 
    146 inline InstrumentingAgents* instrumentingAgentsForFrame(Frame* frame)
    147 {
    148     return frame ? instrumentingAgentsForPage(frame->page()) : 0;
    149 }
    150 
    151 inline InstrumentingAgents* instrumentingAgentsForDocument(Document* document)
    152 {
    153     if (document) {
    154         Page* page = document->page();
    155         if (!page && document->templateDocumentHost())
    156             page = document->templateDocumentHost()->page();
    157         return instrumentingAgentsForPage(page);
    158     }
    159     return 0;
    160 }
    161 
    162 inline InstrumentingAgents* instrumentingAgentsForElement(Element* element)
    163 {
    164     return element ? instrumentingAgentsForDocument(element->document()) : 0;
    165 }
    166 
    167 bool cssErrorFilter(const CSSParserString& content, int propertyId, int errorType);
    168 
    169 } // namespace InspectorInstrumentation
    170 
    171 InstrumentingAgents* instrumentationForPage(Page*);
    172 
    173 InstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope*);
    174 
    175 } // namespace WebCore
    176 
    177 // This file will soon be generated
    178 #include "InspectorInstrumentationInl.h"
    179 
    180 #include "InspectorInstrumentationCustomInl.h"
    181 
    182 #include "InspectorOverridesInl.h"
    183 
    184 #endif // !defined(InspectorInstrumentation_h)
    185