| 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/browser/devtools/protocol/forward.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/common/devtools_messages.h" | 17 #include "content/common/devtools_messages.h" |
| 17 #include "content/public/browser/devtools_agent_host.h" | 18 #include "content/public/browser/devtools_agent_host.h" |
| 18 | 19 |
| 19 namespace IPC { | 20 namespace IPC { |
| 20 class Message; | 21 class Message; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 class BrowserContext; | 26 class BrowserContext; |
| 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, |
| 31 public protocol::FrontendChannel { |
| 30 public: | 32 public: |
| 31 // Informs the hosted agent that a client host has attached. | 33 // Informs the hosted agent that a client host has attached. |
| 32 virtual void Attach() = 0; | 34 virtual void Attach() = 0; |
| 33 | 35 |
| 34 // Informs the hosted agent that a client host has detached. | 36 // Informs the hosted agent that a client host has detached. |
| 35 virtual void Detach() = 0; | 37 virtual void Detach() = 0; |
| 36 | 38 |
| 37 // DevToolsAgentHost implementation. | 39 // DevToolsAgentHost implementation. |
| 38 bool AttachClient(DevToolsAgentHostClient* client) override; | 40 bool AttachClient(DevToolsAgentHostClient* client) override; |
| 39 void ForceAttachClient(DevToolsAgentHostClient* client) override; | 41 void ForceAttachClient(DevToolsAgentHostClient* client) override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 52 WebContents* GetWebContents() override; | 54 WebContents* GetWebContents() override; |
| 53 void DisconnectWebContents() override; | 55 void DisconnectWebContents() override; |
| 54 void ConnectWebContents(WebContents* wc) override; | 56 void ConnectWebContents(WebContents* wc) override; |
| 55 | 57 |
| 56 bool Inspect(); | 58 bool Inspect(); |
| 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; |
| 64 void sendProtocolResponse(int callId, const std::string& message) override; |
| 65 void sendProtocolNotification(const std::string& message) override; |
| 66 void flushProtocolNotifications() override; |
| 62 | 67 |
| 63 protected: | 68 protected: |
| 64 DevToolsAgentHostImpl(const std::string& id); | 69 DevToolsAgentHostImpl(const std::string& id); |
| 65 ~DevToolsAgentHostImpl() override; | 70 ~DevToolsAgentHostImpl() override; |
| 66 | 71 |
| 67 static bool ShouldForceCreation(); | 72 static bool ShouldForceCreation(); |
| 68 | 73 |
| 69 virtual bool DispatchProtocolMessage(const std::string& message) = 0; | 74 virtual bool DispatchProtocolMessage(const std::string& message) = 0; |
| 70 virtual void InspectElement(int x, int y); | 75 virtual void InspectElement(int x, int y); |
| 71 | 76 |
| 72 void NotifyCreated(); | 77 void NotifyCreated(); |
| 73 void HostClosed(); | 78 void HostClosed(); |
| 74 void SendMessageToClient(int session_id, const std::string& message); | 79 void SendMessageToClient(int session_id, const std::string& message); |
| 75 devtools::DevToolsIOContext* GetIOContext() { return &io_context_; } | 80 DevToolsIOContext* GetIOContext() { return &io_context_; } |
| 76 | 81 |
| 77 int session_id() { DCHECK(client_); return session_id_; } | 82 int session_id() { DCHECK(client_); return session_id_; } |
| 78 | 83 |
| 79 private: | 84 private: |
| 80 friend class DevToolsAgentHost; // for static methods | 85 friend class DevToolsAgentHost; // for static methods |
| 81 bool InnerAttach(DevToolsAgentHostClient* client, bool force); | 86 bool InnerAttach(DevToolsAgentHostClient* client, bool force); |
| 82 void InnerDetach(); | 87 void InnerDetach(); |
| 83 void NotifyAttached(); | 88 void NotifyAttached(); |
| 84 void NotifyDetached(); | 89 void NotifyDetached(); |
| 85 void NotifyDestroyed(); | 90 void NotifyDestroyed(); |
| 86 | 91 |
| 87 const std::string id_; | 92 const std::string id_; |
| 88 int session_id_; | 93 int session_id_; |
| 89 DevToolsAgentHostClient* client_; | 94 DevToolsAgentHostClient* client_; |
| 90 devtools::DevToolsIOContext io_context_; | 95 DevToolsIOContext io_context_; |
| 91 static int s_attached_count_; | 96 static int s_attached_count_; |
| 92 static int s_force_creation_count_; | 97 static int s_force_creation_count_; |
| 93 }; | 98 }; |
| 94 | 99 |
| 95 class DevToolsMessageChunkProcessor { | 100 class DevToolsMessageChunkProcessor { |
| 96 public: | 101 public: |
| 97 using SendMessageCallback = base::Callback<void(int, const std::string&)>; | 102 using SendMessageCallback = base::Callback<void(int, const std::string&)>; |
| 98 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); | 103 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); |
| 99 ~DevToolsMessageChunkProcessor(); | 104 ~DevToolsMessageChunkProcessor(); |
| 100 | 105 |
| 101 std::string state_cookie() const { return state_cookie_; } | 106 std::string state_cookie() const { return state_cookie_; } |
| 102 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } | 107 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } |
| 103 int last_call_id() const { return last_call_id_; } | 108 int last_call_id() const { return last_call_id_; } |
| 104 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 109 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 105 | 110 |
| 106 private: | 111 private: |
| 107 SendMessageCallback callback_; | 112 SendMessageCallback callback_; |
| 108 std::string message_buffer_; | 113 std::string message_buffer_; |
| 109 uint32_t message_buffer_size_; | 114 uint32_t message_buffer_size_; |
| 110 std::string state_cookie_; | 115 std::string state_cookie_; |
| 111 int last_call_id_; | 116 int last_call_id_; |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 } // namespace content | 119 } // namespace content |
| 115 | 120 |
| 116 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 121 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
| OLD | NEW |