OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef InspectorBaseAgent_h | 31 #ifndef InspectorBaseAgent_h |
32 #define InspectorBaseAgent_h | 32 #define InspectorBaseAgent_h |
33 | 33 |
34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
35 #include "core/InstrumentingAgents.h" | 35 #include "core/InstrumentingAgents.h" |
36 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
37 #include "platform/inspector_protocol/Backend.h" | 37 #include "platform/inspector_protocol/DispatcherBase.h" |
38 #include "platform/inspector_protocol/Dispatcher.h" | |
39 #include "platform/inspector_protocol/Frontend.h" | |
40 #include "platform/inspector_protocol/TypeBuilder.h" | 38 #include "platform/inspector_protocol/TypeBuilder.h" |
41 #include "platform/inspector_protocol/Values.h" | 39 #include "platform/inspector_protocol/Values.h" |
42 #include "wtf/Forward.h" | 40 #include "wtf/Forward.h" |
43 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
44 | 42 |
45 namespace blink { | 43 namespace blink { |
46 | 44 |
47 class LocalFrame; | 45 class LocalFrame; |
48 | 46 |
49 using protocol::Maybe; | 47 using protocol::Maybe; |
50 | 48 |
51 class CORE_EXPORT InspectorAgent : public GarbageCollectedFinalized<InspectorAge
nt> { | 49 class CORE_EXPORT InspectorAgent : public GarbageCollectedFinalized<InspectorAge
nt> { |
52 public: | 50 public: |
53 InspectorAgent() { } | 51 InspectorAgent() { } |
54 virtual ~InspectorAgent() { } | 52 virtual ~InspectorAgent() { } |
55 DEFINE_INLINE_VIRTUAL_TRACE() { } | 53 DEFINE_INLINE_VIRTUAL_TRACE() { } |
56 | 54 |
57 virtual void disable(ErrorString*) { } | |
58 virtual void restore() { } | 55 virtual void restore() { } |
59 virtual void didCommitLoadForLocalFrame(LocalFrame*) { } | 56 virtual void didCommitLoadForLocalFrame(LocalFrame*) { } |
60 virtual void flushPendingProtocolNotifications() { } | 57 virtual void flushPendingProtocolNotifications() { } |
61 | 58 |
62 virtual void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispa
tcher*, protocol::DictionaryValue*) = 0; | 59 virtual void init(InstrumentingAgents*, protocol::UberDispatcher*, protocol:
:DictionaryValue*) = 0; |
63 virtual void dispose() = 0; | 60 virtual void dispose() = 0; |
64 }; | 61 }; |
65 | 62 |
66 template<typename AgentClass, typename FrontendClass> | 63 template<typename DomainMetainfo> |
67 class InspectorBaseAgent : public InspectorAgent { | 64 class InspectorBaseAgent : public InspectorAgent, public DomainMetainfo::Backend
Class { |
68 public: | 65 public: |
69 ~InspectorBaseAgent() override { } | 66 ~InspectorBaseAgent() override { } |
70 | 67 |
71 void init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* fron
tend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state) overri
de | 68 void init(InstrumentingAgents* instrumentingAgents, protocol::UberDispatcher
* dispatcher, protocol::DictionaryValue* state) override |
72 { | 69 { |
73 m_instrumentingAgents = instrumentingAgents; | 70 m_instrumentingAgents = instrumentingAgents; |
74 m_frontend = FrontendClass::from(frontend); | 71 m_frontend.reset(new typename DomainMetainfo::FrontendClass(dispatcher->
channel())); |
75 dispatcher->registerAgent(static_cast<AgentClass*>(this)); | 72 DomainMetainfo::DispatcherClass::wire(dispatcher, this); |
76 | 73 |
77 m_state = state->getObject(m_name); | 74 m_state = state->getObject(DomainMetainfo::domainName); |
78 if (!m_state) { | 75 if (!m_state) { |
79 std::unique_ptr<protocol::DictionaryValue> newState = protocol::Dict
ionaryValue::create(); | 76 std::unique_ptr<protocol::DictionaryValue> newState = protocol::Dict
ionaryValue::create(); |
80 m_state = newState.get(); | 77 m_state = newState.get(); |
81 state->setObject(m_name, std::move(newState)); | 78 state->setObject(DomainMetainfo::domainName, std::move(newState)); |
82 } | 79 } |
83 } | 80 } |
84 | 81 |
| 82 void disable(ErrorString*) override { } |
| 83 |
85 void dispose() override | 84 void dispose() override |
86 { | 85 { |
87 ErrorString error; | 86 ErrorString error; |
88 disable(&error); | 87 disable(&error); |
89 m_frontend = nullptr; | 88 m_frontend.reset(); |
90 m_state = nullptr; | 89 m_state = nullptr; |
91 m_instrumentingAgents = nullptr; | 90 m_instrumentingAgents = nullptr; |
92 } | 91 } |
93 | 92 |
94 DEFINE_INLINE_VIRTUAL_TRACE() | 93 DEFINE_INLINE_VIRTUAL_TRACE() |
95 { | 94 { |
96 visitor->trace(m_instrumentingAgents); | 95 visitor->trace(m_instrumentingAgents); |
97 InspectorAgent::trace(visitor); | 96 InspectorAgent::trace(visitor); |
98 } | 97 } |
99 | 98 |
100 protected: | 99 protected: |
101 explicit InspectorBaseAgent(const String& name) | 100 InspectorBaseAgent() { } |
102 : InspectorAgent() | |
103 , m_name(name) | |
104 , m_frontend(nullptr) | |
105 { | |
106 } | |
107 | 101 |
108 FrontendClass* frontend() const { return m_frontend; } | 102 typename DomainMetainfo::FrontendClass* frontend() const { return m_frontend
.get(); } |
109 Member<InstrumentingAgents> m_instrumentingAgents; | 103 Member<InstrumentingAgents> m_instrumentingAgents; |
110 protocol::DictionaryValue* m_state; | 104 protocol::DictionaryValue* m_state; |
111 | 105 |
112 private: | 106 private: |
113 String m_name; | 107 std::unique_ptr<typename DomainMetainfo::FrontendClass> m_frontend; |
114 FrontendClass* m_frontend; | |
115 }; | 108 }; |
116 | 109 |
117 } // namespace blink | 110 } // namespace blink |
118 | 111 |
119 #endif // !defined(InspectorBaseAgent_h) | 112 #endif // !defined(InspectorBaseAgent_h) |
OLD | NEW |