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