OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "content/browser/devtools/devtools_io_context.h" | 13 #include "content/browser/devtools/devtools_io_context.h" |
14 #include "content/browser/devtools/protocol/devtools_protocol_delegate.h" | 14 #include "content/browser/devtools/protocol/devtools_protocol_delegate.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "content/common/devtools_messages.h" | 16 #include "content/common/devtools_messages.h" |
17 #include "content/public/browser/devtools_agent_host.h" | 17 #include "content/public/browser/devtools_agent_host.h" |
18 | 18 |
19 namespace IPC { | 19 namespace IPC { |
20 class Message; | 20 class Message; |
21 } | 21 } |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class BrowserContext; | 25 class BrowserContext; |
| 26 class DevToolsSession; |
26 | 27 |
27 // Describes interface for managing devtools agents from the browser process. | 28 // Describes interface for managing devtools agents from the browser process. |
28 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost, | 29 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost, |
29 public DevToolsProtocolDelegate { | 30 public DevToolsProtocolDelegate { |
30 public: | 31 public: |
31 // Informs the hosted agent that a client host has attached. | 32 // Informs the hosted agent that a client host has attached. |
32 virtual void Attach() = 0; | 33 virtual void Attach() = 0; |
33 | 34 |
34 // Informs the hosted agent that a client host has detached. | 35 // Informs the hosted agent that a client host has detached. |
35 virtual void Detach() = 0; | 36 virtual void Detach() = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
47 std::string GetDescription() override; | 48 std::string GetDescription() override; |
48 GURL GetFaviconURL() override; | 49 GURL GetFaviconURL() override; |
49 std::string GetFrontendURL() override; | 50 std::string GetFrontendURL() override; |
50 base::TimeTicks GetLastActivityTime() override; | 51 base::TimeTicks GetLastActivityTime() override; |
51 BrowserContext* GetBrowserContext() override; | 52 BrowserContext* GetBrowserContext() override; |
52 WebContents* GetWebContents() override; | 53 WebContents* GetWebContents() override; |
53 void DisconnectWebContents() override; | 54 void DisconnectWebContents() override; |
54 void ConnectWebContents(WebContents* wc) override; | 55 void ConnectWebContents(WebContents* wc) override; |
55 | 56 |
56 bool Inspect(); | 57 bool Inspect(); |
| 58 void SendMessageToClient(int session_id, const std::string& message); |
57 | 59 |
58 // DevToolsProtocolDelegate implementation. | 60 // DevToolsProtocolDelegate implementation. |
59 void SendProtocolResponse(int session_id, | 61 void SendProtocolResponse(int session_id, |
60 const std::string& message) override; | 62 const std::string& message) override; |
61 void SendProtocolNotification(const std::string& message) override; | 63 void SendProtocolNotification(const std::string& message) override; |
62 | 64 |
63 protected: | 65 protected: |
64 DevToolsAgentHostImpl(const std::string& id); | 66 DevToolsAgentHostImpl(const std::string& id); |
65 ~DevToolsAgentHostImpl() override; | 67 ~DevToolsAgentHostImpl() override; |
66 | 68 |
67 static bool ShouldForceCreation(); | 69 static bool ShouldForceCreation(); |
68 | 70 |
69 virtual bool DispatchProtocolMessage(const std::string& message) = 0; | 71 virtual bool DispatchProtocolMessage(const std::string& message) = 0; |
70 virtual void InspectElement(int x, int y); | 72 virtual void InspectElement(int x, int y); |
71 | 73 |
72 void NotifyCreated(); | 74 void NotifyCreated(); |
73 void HostClosed(); | 75 void HostClosed(); |
74 void SendMessageToClient(int session_id, const std::string& message); | |
75 devtools::DevToolsIOContext* GetIOContext() { return &io_context_; } | 76 devtools::DevToolsIOContext* GetIOContext() { return &io_context_; } |
76 | 77 |
77 int session_id() { DCHECK(client_); return session_id_; } | 78 DevToolsSession* session() { return session_.get(); } |
78 | 79 |
79 private: | 80 private: |
80 friend class DevToolsAgentHost; // for static methods | 81 friend class DevToolsAgentHost; // for static methods |
81 bool InnerAttach(DevToolsAgentHostClient* client, bool force); | 82 bool InnerAttach(DevToolsAgentHostClient* client, bool force); |
82 void InnerDetach(); | 83 void InnerDetach(); |
83 void NotifyAttached(); | 84 void NotifyAttached(); |
84 void NotifyDetached(); | 85 void NotifyDetached(); |
85 void NotifyDestroyed(); | 86 void NotifyDestroyed(); |
86 | 87 |
87 const std::string id_; | 88 const std::string id_; |
88 int session_id_; | 89 int session_id_; |
| 90 int last_session_id_; |
| 91 std::unique_ptr<DevToolsSession> session_; |
89 DevToolsAgentHostClient* client_; | 92 DevToolsAgentHostClient* client_; |
90 devtools::DevToolsIOContext io_context_; | 93 devtools::DevToolsIOContext io_context_; |
91 static int s_attached_count_; | 94 static int s_attached_count_; |
92 static int s_force_creation_count_; | 95 static int s_force_creation_count_; |
93 }; | 96 }; |
94 | 97 |
95 class DevToolsMessageChunkProcessor { | 98 class DevToolsMessageChunkProcessor { |
96 public: | 99 public: |
97 using SendMessageCallback = base::Callback<void(int, const std::string&)>; | 100 using SendMessageCallback = base::Callback<void(int, const std::string&)>; |
98 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); | 101 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); |
99 ~DevToolsMessageChunkProcessor(); | 102 ~DevToolsMessageChunkProcessor(); |
100 | 103 |
101 std::string state_cookie() const { return state_cookie_; } | 104 std::string state_cookie() const { return state_cookie_; } |
102 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } | 105 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } |
103 int last_call_id() const { return last_call_id_; } | 106 int last_call_id() const { return last_call_id_; } |
104 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 107 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
105 | 108 |
106 private: | 109 private: |
107 SendMessageCallback callback_; | 110 SendMessageCallback callback_; |
108 std::string message_buffer_; | 111 std::string message_buffer_; |
109 uint32_t message_buffer_size_; | 112 uint32_t message_buffer_size_; |
110 std::string state_cookie_; | 113 std::string state_cookie_; |
111 int last_call_id_; | 114 int last_call_id_; |
112 }; | 115 }; |
113 | 116 |
114 } // namespace content | 117 } // namespace content |
115 | 118 |
116 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 119 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
OLD | NEW |