| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "content/browser/devtools/devtools_io_context.h" | 11 #include "content/browser/devtools/devtools_io_context.h" |
| 12 #include "content/browser/devtools/protocol/devtools_protocol_delegate.h" |
| 12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 13 #include "content/common/devtools_messages.h" | 14 #include "content/common/devtools_messages.h" |
| 14 #include "content/public/browser/devtools_agent_host.h" | 15 #include "content/public/browser/devtools_agent_host.h" |
| 15 | 16 |
| 16 namespace IPC { | 17 namespace IPC { |
| 17 class Message; | 18 class Message; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 class BrowserContext; | 23 class BrowserContext; |
| 23 | 24 |
| 24 // Describes interface for managing devtools agents from the browser process. | 25 // Describes interface for managing devtools agents from the browser process. |
| 25 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { | 26 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost, |
| 27 public DevToolsProtocolDelegate { |
| 26 public: | 28 public: |
| 27 // Informs the hosted agent that a client host has attached. | 29 // Informs the hosted agent that a client host has attached. |
| 28 virtual void Attach() = 0; | 30 virtual void Attach() = 0; |
| 29 | 31 |
| 30 // Informs the hosted agent that a client host has detached. | 32 // Informs the hosted agent that a client host has detached. |
| 31 virtual void Detach() = 0; | 33 virtual void Detach() = 0; |
| 32 | 34 |
| 33 // Opens the inspector for this host. | 35 // Opens the inspector for this host. |
| 34 void Inspect(BrowserContext* browser_context); | 36 void Inspect(BrowserContext* browser_context); |
| 35 | 37 |
| 36 // DevToolsAgentHost implementation. | 38 // DevToolsAgentHost implementation. |
| 37 void AttachClient(DevToolsAgentHostClient* client) override; | 39 void AttachClient(DevToolsAgentHostClient* client) override; |
| 38 void DetachClient() override; | 40 void DetachClient() override; |
| 39 bool IsAttached() override; | 41 bool IsAttached() override; |
| 40 void InspectElement(int x, int y) override; | 42 void InspectElement(int x, int y) override; |
| 41 std::string GetId() override; | 43 std::string GetId() override; |
| 42 BrowserContext* GetBrowserContext() override; | 44 BrowserContext* GetBrowserContext() override; |
| 43 WebContents* GetWebContents() override; | 45 WebContents* GetWebContents() override; |
| 44 void DisconnectWebContents() override; | 46 void DisconnectWebContents() override; |
| 45 void ConnectWebContents(WebContents* wc) override; | 47 void ConnectWebContents(WebContents* wc) override; |
| 46 | 48 |
| 49 // DevToolsProtocolDelegate implementation. |
| 50 void SendProtocolResponse(int session_id, |
| 51 const std::string& message) override; |
| 52 void SendProtocolNotification(const std::string& message) override; |
| 53 |
| 47 protected: | 54 protected: |
| 48 DevToolsAgentHostImpl(); | 55 DevToolsAgentHostImpl(); |
| 49 ~DevToolsAgentHostImpl() override; | 56 ~DevToolsAgentHostImpl() override; |
| 50 | 57 |
| 51 void HostClosed(); | 58 void HostClosed(); |
| 52 void SendMessageToClient(const std::string& message); | 59 void SendMessageToClient(int session_id, const std::string& message); |
| 53 devtools::DevToolsIOContext* GetIOContext() { return &io_context_; } | 60 devtools::DevToolsIOContext* GetIOContext() { return &io_context_; } |
| 54 | 61 |
| 62 int session_id() { DCHECK(client_); return session_id_; } |
| 63 |
| 55 static void NotifyCallbacks(DevToolsAgentHostImpl* agent_host, bool attached); | 64 static void NotifyCallbacks(DevToolsAgentHostImpl* agent_host, bool attached); |
| 56 | 65 |
| 57 private: | 66 private: |
| 58 friend class DevToolsAgentHost; // for static methods | 67 friend class DevToolsAgentHost; // for static methods |
| 59 void InnerDetach(); | 68 void InnerDetach(); |
| 60 | 69 |
| 61 const std::string id_; | 70 const std::string id_; |
| 71 int session_id_; |
| 62 DevToolsAgentHostClient* client_; | 72 DevToolsAgentHostClient* client_; |
| 63 devtools::DevToolsIOContext io_context_; | 73 devtools::DevToolsIOContext io_context_; |
| 64 }; | 74 }; |
| 65 | 75 |
| 66 class DevToolsMessageChunkProcessor { | 76 class DevToolsMessageChunkProcessor { |
| 67 public: | 77 public: |
| 68 using SendMessageCallback = base::Callback<void(const std::string&)>; | 78 using SendMessageCallback = base::Callback<void(int, const std::string&)>; |
| 69 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); | 79 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); |
| 70 ~DevToolsMessageChunkProcessor(); | 80 ~DevToolsMessageChunkProcessor(); |
| 71 | 81 |
| 72 std::string state_cookie() const { return state_cookie_; } | 82 std::string state_cookie() const { return state_cookie_; } |
| 73 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } | 83 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } |
| 74 int last_call_id() const { return last_call_id_; } | 84 int last_call_id() const { return last_call_id_; } |
| 75 void ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 85 void ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 76 | 86 |
| 77 private: | 87 private: |
| 78 SendMessageCallback callback_; | 88 SendMessageCallback callback_; |
| 79 std::string message_buffer_; | 89 std::string message_buffer_; |
| 80 uint32 message_buffer_size_; | 90 uint32 message_buffer_size_; |
| 81 std::string state_cookie_; | 91 std::string state_cookie_; |
| 82 int last_call_id_; | 92 int last_call_id_; |
| 83 }; | 93 }; |
| 84 | 94 |
| 85 } // namespace content | 95 } // namespace content |
| 86 | 96 |
| 87 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 97 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
| OLD | NEW |