1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
10 #include "base/compiler_specific.h"
11 #include "content/browser/devtools/devtools_io_context.h"
12 #include "content/common/content_export.h"
13 #include "content/common/devtools_messages.h"
14 #include "content/public/browser/devtools_agent_host.h"
24 // Describes interface for managing devtools agents from the browser process.
25 class CONTENT_EXPORT DevToolsAgentHostImpl
: public DevToolsAgentHost
{
27 // Informs the hosted agent that a client host has attached.
28 virtual void Attach() = 0;
30 // Informs the hosted agent that a client host has detached.
31 virtual void Detach() = 0;
33 // Opens the inspector for this host.
34 void Inspect(BrowserContext
* browser_context
);
36 // DevToolsAgentHost implementation.
37 void AttachClient(DevToolsAgentHostClient
* client
) override
;
38 void DetachClient() override
;
39 bool IsAttached() override
;
40 void InspectElement(int x
, int y
) override
;
41 std::string
GetId() override
;
42 BrowserContext
* GetBrowserContext() override
;
43 WebContents
* GetWebContents() override
;
44 void DisconnectWebContents() override
;
45 void ConnectWebContents(WebContents
* wc
) override
;
48 DevToolsAgentHostImpl();
49 ~DevToolsAgentHostImpl() override
;
52 void SendMessageToClient(const std::string
& message
);
53 devtools::DevToolsIOContext
* GetIOContext() { return &io_context_
; }
55 static void NotifyCallbacks(DevToolsAgentHostImpl
* agent_host
, bool attached
);
58 friend class DevToolsAgentHost
; // for static methods
61 const std::string id_
;
62 DevToolsAgentHostClient
* client_
;
63 devtools::DevToolsIOContext io_context_
;
66 class DevToolsMessageChunkProcessor
{
68 using SendMessageCallback
= base::Callback
<void(const std::string
&)>;
69 explicit DevToolsMessageChunkProcessor(const SendMessageCallback
& callback
);
70 ~DevToolsMessageChunkProcessor();
72 std::string
state_cookie() const { return state_cookie_
; }
73 void set_state_cookie(const std::string
& cookie
) { state_cookie_
= cookie
; }
74 int last_call_id() const { return last_call_id_
; }
75 void ProcessChunkedMessageFromAgent(const DevToolsMessageChunk
& chunk
);
78 SendMessageCallback callback_
;
79 std::string message_buffer_
;
80 uint32 message_buffer_size_
;
81 std::string state_cookie_
;
85 } // namespace content
87 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_