1 // Copyright 2015 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 COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_
6 #define COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_
11 #include "base/macros.h"
12 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h"
13 #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
20 namespace html_viewer
{
22 class DevToolsAgentImpl
: public devtools_service::DevToolsAgent
,
23 public blink::WebDevToolsAgentClient
{
25 // |frame| must outlive this object.
26 // This agent should restore its internal state using |state| if it is not
28 DevToolsAgentImpl(blink::WebLocalFrame
* frame
,
29 const std::string
& id
,
30 const std::string
* state
);
31 ~DevToolsAgentImpl() override
;
33 void BindToRequest(mojo::InterfaceRequest
<DevToolsAgent
> request
);
36 // devtools_service::DevToolsAgent implementation.
37 void SetClient(devtools_service::DevToolsAgentClientPtr client
) override
;
38 void DispatchProtocolMessage(const mojo::String
& message
) override
;
40 // blink::WebDevToolsAgentClient implementation.
41 void sendProtocolMessage(int call_id
,
42 const blink::WebString
& response
,
43 const blink::WebString
& state
);
45 void OnConnectionError();
47 blink::WebLocalFrame
* const frame_
;
48 const std::string id_
;
50 mojo::Binding
<DevToolsAgent
> binding_
;
51 devtools_service::DevToolsAgentClientPtr client_
;
53 // If we restore the agent's internal state using serialized state data from a
54 // previous agent, the agent may generate messages before |client_| is set.
55 // In that case, we need to cache messages for the client.
56 bool cache_until_client_ready_
;
58 struct CachedClientMessage
{
60 mojo::String response
;
63 std::vector
<CachedClientMessage
> cached_client_messages_
;
65 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentImpl
);
68 } // namespace html_viewer
70 #endif // COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_