1 /* 2 * Copyright (C) 2011 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 InspectorBaseAgent_h 32 #define InspectorBaseAgent_h 33 34 #include "core/InspectorBackendDispatcher.h" 35 #include "core/inspector/InstrumentingAgents.h" 36 #include "platform/heap/Handle.h" 37 #include "wtf/Forward.h" 38 #include "wtf/Vector.h" 39 #include "wtf/text/WTFString.h" 40 41 namespace blink { 42 43 class InspectorFrontend; 44 class InspectorCompositeState; 45 class InspectorState; 46 class InstrumentingAgents; 47 48 class InspectorAgent : public NoBaseWillBeGarbageCollectedFinalized<InspectorAgent> { 49 public: 50 explicit InspectorAgent(const String&); 51 virtual ~InspectorAgent(); 52 virtual void trace(Visitor*); 53 54 virtual void init() { } 55 virtual void setFrontend(InspectorFrontend*) { } 56 virtual void clearFrontend() { } 57 virtual void restore() { } 58 virtual void registerInDispatcher(InspectorBackendDispatcher*) = 0; 59 virtual void discardAgent() { } 60 virtual void didCommitLoadForMainFrame() { } 61 virtual void flushPendingFrontendMessages() { } 62 63 String name() { return m_name; } 64 void appended(InstrumentingAgents*, InspectorState*); 65 66 protected: 67 RawPtrWillBeMember<InstrumentingAgents> m_instrumentingAgents; 68 RawPtrWillBeMember<InspectorState> m_state; 69 70 private: 71 String m_name; 72 }; 73 74 class InspectorAgentRegistry FINAL { 75 DISALLOW_ALLOCATION(); 76 public: 77 InspectorAgentRegistry(InstrumentingAgents*, InspectorCompositeState*); 78 void append(PassOwnPtrWillBeRawPtr<InspectorAgent>); 79 80 void setFrontend(InspectorFrontend*); 81 void clearFrontend(); 82 void restore(); 83 void registerInDispatcher(InspectorBackendDispatcher*); 84 void discardAgents(); 85 void flushPendingFrontendMessages(); 86 void didCommitLoadForMainFrame(); 87 88 void trace(Visitor*); 89 90 private: 91 RawPtrWillBeMember<InstrumentingAgents> m_instrumentingAgents; 92 RawPtrWillBeMember<InspectorCompositeState> m_inspectorState; 93 WillBeHeapVector<OwnPtrWillBeMember<InspectorAgent> > m_agents; 94 }; 95 96 template<typename T> 97 class InspectorBaseAgent : public InspectorAgent { 98 public: 99 virtual ~InspectorBaseAgent() { } 100 101 virtual void registerInDispatcher(InspectorBackendDispatcher* dispatcher) OVERRIDE FINAL 102 { 103 dispatcher->registerAgent(static_cast<T*>(this)); 104 } 105 106 protected: 107 explicit InspectorBaseAgent(const String& name) : InspectorAgent(name) 108 { 109 } 110 }; 111 112 inline bool asBool(const bool* const b) 113 { 114 return b ? *b : false; 115 } 116 117 } // namespace blink 118 119 #endif // !defined(InspectorBaseAgent_h) 120