Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598
[chromium-blink-merge.git] / components / html_viewer / devtools_agent_impl.h
blobf062b31de5e5ea2f08dfd065b1a3b29e1b42939f
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_
8 #include <string>
9 #include <vector>
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"
16 namespace blink {
17 class WebLocalFrame;
20 namespace html_viewer {
22 class DevToolsAgentImpl : public devtools_service::DevToolsAgent,
23 public blink::WebDevToolsAgentClient {
24 public:
25 // |frame| must outlive this object.
26 // This agent should restore its internal state using |state| if it is not
27 // null.
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);
35 private:
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 {
59 int call_id;
60 mojo::String response;
61 mojo::String state;
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_