1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/devtools/ipc_devtools_agent_host.h"
9 void IPCDevToolsAgentHost::Attach() {
10 SendMessageToAgent(new DevToolsAgentMsg_Attach(MSG_ROUTING_NONE
, GetId()));
11 OnClientAttached(false);
14 void IPCDevToolsAgentHost::Detach() {
15 SendMessageToAgent(new DevToolsAgentMsg_Detach(MSG_ROUTING_NONE
));
19 bool IPCDevToolsAgentHost::DispatchProtocolMessage(
20 const std::string
& message
) {
21 if (DevToolsAgentHostImpl::DispatchProtocolMessage(message
))
24 SendMessageToAgent(new DevToolsAgentMsg_DispatchOnInspectorBackend(
25 MSG_ROUTING_NONE
, message
));
29 void IPCDevToolsAgentHost::InspectElement(int x
, int y
) {
30 SendMessageToAgent(new DevToolsAgentMsg_InspectElement(MSG_ROUTING_NONE
,
34 IPCDevToolsAgentHost::IPCDevToolsAgentHost()
35 : message_buffer_size_(0) {
38 IPCDevToolsAgentHost::~IPCDevToolsAgentHost() {
41 void IPCDevToolsAgentHost::Reattach() {
42 SendMessageToAgent(new DevToolsAgentMsg_Reattach(
43 MSG_ROUTING_NONE
, GetId(), state_cookie_
));
44 OnClientAttached(true);
47 void IPCDevToolsAgentHost::ProcessChunkedMessageFromAgent(
48 const DevToolsMessageChunk
& chunk
) {
49 if (chunk
.is_last
&& !chunk
.post_state
.empty())
50 state_cookie_
= chunk
.post_state
;
52 if (chunk
.is_first
&& chunk
.is_last
) {
53 CHECK(message_buffer_size_
== 0);
54 SendMessageToClient(chunk
.data
);
59 message_buffer_
= std::string();
60 message_buffer_
.reserve(chunk
.message_size
);
61 message_buffer_size_
= chunk
.message_size
;
64 CHECK(message_buffer_
.size() + chunk
.data
.size() <=
65 message_buffer_size_
);
66 message_buffer_
.append(chunk
.data
);
69 CHECK(message_buffer_
.size() == message_buffer_size_
);
70 SendMessageToClient(message_buffer_
);
71 message_buffer_
= std::string();
72 message_buffer_size_
= 0;
76 } // namespace content