OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_ | |
6 #define COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" | |
13 #include "mojo/public/cpp/bindings/binding.h" | |
14 #include "third_party/WebKit/public/web/WebDevToolsAgentClient.h" | |
15 | |
16 namespace blink { | |
17 class WebLocalFrame; | |
18 } | |
19 | |
20 namespace html_viewer { | |
21 | |
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; | |
32 | |
33 void BindToRequest(mojo::InterfaceRequest<DevToolsAgent> request); | |
34 | |
35 private: | |
36 // devtools_service::DevToolsAgent implementation. | |
37 void SetClient(devtools_service::DevToolsAgentClientPtr client) override; | |
38 void DispatchProtocolMessage(const mojo::String& message) override; | |
39 | |
40 // blink::WebDevToolsAgentClient implementation. | |
41 void sendProtocolMessage(int session_id, | |
42 int call_id, | |
43 const blink::WebString& response, | |
44 const blink::WebString& state) override; | |
45 | |
46 void OnConnectionError(); | |
47 | |
48 blink::WebLocalFrame* const frame_; | |
49 const std::string id_; | |
50 | |
51 mojo::Binding<DevToolsAgent> binding_; | |
52 devtools_service::DevToolsAgentClientPtr client_; | |
53 | |
54 // If we restore the agent's internal state using serialized state data from a | |
55 // previous agent, the agent may generate messages before |client_| is set. | |
56 // In that case, we need to cache messages for the client. | |
57 bool cache_until_client_ready_; | |
58 | |
59 struct CachedClientMessage { | |
60 int call_id; | |
61 mojo::String response; | |
62 mojo::String state; | |
63 }; | |
64 std::vector<CachedClientMessage> cached_client_messages_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentImpl); | |
67 }; | |
68 | |
69 } // namespace html_viewer | |
70 | |
71 #endif // COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_ | |
OLD | NEW |