OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/inspector/InspectorSession.h" | 5 #include "core/inspector/InspectorSession.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptController.h" | 7 #include "bindings/core/v8/ScriptController.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
10 #include "core/inspector/InspectorBaseAgent.h" | 10 #include "core/inspector/InspectorBaseAgent.h" |
11 #include "core/inspector/InspectorInstrumentation.h" | 11 #include "core/inspector/InspectorInstrumentation.h" |
12 #include "core/inspector/V8InspectorStringConversion.h" | |
12 #include "platform/v8_inspector/public/V8Inspector.h" | 13 #include "platform/v8_inspector/public/V8Inspector.h" |
13 #include "platform/v8_inspector/public/V8InspectorSession.h" | 14 #include "platform/v8_inspector/public/V8InspectorSession.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kV8StateKey[] = "v8"; | 19 const char kV8StateKey[] = "v8"; |
19 } | 20 } |
20 | 21 |
21 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro upId, const String* savedState) | 22 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro upId, const String* savedState) |
22 : m_client(client) | 23 : m_client(client) |
23 , m_v8Session(nullptr) | 24 , m_v8Session(nullptr) |
24 , m_sessionId(sessionId) | 25 , m_sessionId(sessionId) |
25 , m_disposed(false) | 26 , m_disposed(false) |
26 , m_instrumentingAgents(instrumentingAgents) | 27 , m_instrumentingAgents(instrumentingAgents) |
27 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) | 28 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) |
28 { | 29 { |
29 if (savedState) { | 30 if (savedState) { |
30 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState ); | 31 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState ); |
31 if (state) | 32 if (state) |
32 m_state = protocol::DictionaryValue::cast(std::move(state)); | 33 m_state = protocol::DictionaryValue::cast(std::move(state)); |
33 if (!m_state) | 34 if (!m_state) |
34 m_state = protocol::DictionaryValue::create(); | 35 m_state = protocol::DictionaryValue::create(); |
35 } else { | 36 } else { |
36 m_state = protocol::DictionaryValue::create(); | 37 m_state = protocol::DictionaryValue::create(); |
37 } | 38 } |
38 | 39 |
39 String16 v8State; | 40 String v8State; |
40 m_state->getString(kV8StateKey, &v8State); | 41 m_state->getString(kV8StateKey, &v8State); |
41 m_v8Session = inspector->connect(contextGroupId, this, savedState ? &v8State : nullptr); | 42 v8_inspector::String16 v8State16 = toV8InspectorString(v8State); |
43 m_v8Session = inspector->connect(contextGroupId, this, savedState ? &v8State 16 : nullptr); | |
42 } | 44 } |
43 | 45 |
44 InspectorSession::~InspectorSession() | 46 InspectorSession::~InspectorSession() |
45 { | 47 { |
46 DCHECK(m_disposed); | 48 DCHECK(m_disposed); |
47 } | 49 } |
48 | 50 |
49 void InspectorSession::append(InspectorAgent* agent) | 51 void InspectorSession::append(InspectorAgent* agent) |
50 { | 52 { |
51 m_agents.append(agent); | 53 m_agents.append(agent); |
(...skipping 14 matching lines...) Expand all Loading... | |
66 m_inspectorBackendDispatcher.reset(); | 68 m_inspectorBackendDispatcher.reset(); |
67 for (size_t i = m_agents.size(); i > 0; i--) | 69 for (size_t i = m_agents.size(); i > 0; i--) |
68 m_agents[i - 1]->dispose(); | 70 m_agents[i - 1]->dispose(); |
69 m_agents.clear(); | 71 m_agents.clear(); |
70 m_v8Session.reset(); | 72 m_v8Session.reset(); |
71 } | 73 } |
72 | 74 |
73 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin g& message) | 75 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin g& message) |
74 { | 76 { |
75 DCHECK(!m_disposed); | 77 DCHECK(!m_disposed); |
76 if (v8_inspector::V8InspectorSession::canDispatchMethod(method)) | 78 if (v8_inspector::V8InspectorSession::canDispatchMethod(toV8InspectorString( method))) |
77 m_v8Session->dispatchProtocolMessage(message); | 79 m_v8Session->dispatchProtocolMessage(toV8InspectorString(message)); |
78 else | 80 else |
79 m_inspectorBackendDispatcher->dispatch(message); | 81 m_inspectorBackendDispatcher->dispatch(message); |
80 } | 82 } |
81 | 83 |
82 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) | 84 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) |
83 { | 85 { |
84 for (size_t i = 0; i < m_agents.size(); i++) | 86 for (size_t i = 0; i < m_agents.size(); i++) |
85 m_agents[i]->didCommitLoadForLocalFrame(frame); | 87 m_agents[i]->didCommitLoadForLocalFrame(frame); |
86 } | 88 } |
87 | 89 |
88 void InspectorSession::sendProtocolResponse(int callId, const protocol::String16 & message) | 90 void InspectorSession::sendProtocolResponse(int callId, const String& message) |
89 { | 91 { |
90 if (m_disposed) | 92 if (m_disposed) |
91 return; | 93 return; |
92 flushProtocolNotifications(); | 94 flushProtocolNotifications(); |
93 m_state->setString(kV8StateKey, m_v8Session->stateJSON()); | 95 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); |
94 String stateToSend = m_state->toJSONString(); | 96 String stateToSend = m_state->toJSONString(); |
95 if (stateToSend == m_lastSentState) | 97 if (stateToSend == m_lastSentState) |
96 stateToSend = String(); | 98 stateToSend = String(); |
97 else | 99 else |
98 m_lastSentState = stateToSend; | 100 m_lastSentState = stateToSend; |
99 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); | 101 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); |
100 } | 102 } |
101 | 103 |
102 void InspectorSession::sendProtocolNotification(const protocol::String16& messag e) | 104 void InspectorSession::sendProtocolResponse(int callId, const v8_inspector::Stri ng16& message) |
105 { | |
106 sendProtocolResponse(callId, toCoreString(message)); | |
caseq
2016/08/19 02:50:36
Ouch. So it's an extra copy for everything that is
| |
107 } | |
108 | |
109 void InspectorSession::sendProtocolNotification(const String& message) | |
103 { | 110 { |
104 if (m_disposed) | 111 if (m_disposed) |
105 return; | 112 return; |
106 m_notificationQueue.append(message); | 113 m_notificationQueue.append(message); |
107 } | 114 } |
108 | 115 |
116 void InspectorSession::sendProtocolNotification(const v8_inspector::String16& me ssage) | |
117 { | |
118 sendProtocolNotification(toCoreString(message)); | |
119 } | |
120 | |
109 void InspectorSession::flushProtocolNotifications() | 121 void InspectorSession::flushProtocolNotifications() |
110 { | 122 { |
111 if (m_disposed) | 123 if (m_disposed) |
112 return; | 124 return; |
113 for (size_t i = 0; i < m_agents.size(); i++) | 125 for (size_t i = 0; i < m_agents.size(); i++) |
114 m_agents[i]->flushPendingProtocolNotifications(); | 126 m_agents[i]->flushPendingProtocolNotifications(); |
115 for (size_t i = 0; i < m_notificationQueue.size(); ++i) | 127 for (size_t i = 0; i < m_notificationQueue.size(); ++i) |
116 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], St ring()); | 128 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], St ring()); |
117 m_notificationQueue.clear(); | 129 m_notificationQueue.clear(); |
118 } | 130 } |
119 | 131 |
120 DEFINE_TRACE(InspectorSession) | 132 DEFINE_TRACE(InspectorSession) |
121 { | 133 { |
122 visitor->trace(m_instrumentingAgents); | 134 visitor->trace(m_instrumentingAgents); |
123 visitor->trace(m_agents); | 135 visitor->trace(m_agents); |
124 } | 136 } |
125 | 137 |
126 } // namespace blink | 138 } // namespace blink |
127 | 139 |
OLD | NEW |