| 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/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/common/devtools_messages.h" | 15 #include "content/common/devtools_messages.h" |
| 16 #include "content/public/browser/devtools_agent_host.h" | 16 #include "content/public/browser/devtools_agent_host.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 class BrowserContext; | 20 class BrowserContext; |
| 21 class DevToolsSession; | 21 class DevToolsSession; |
| 22 | 22 |
| 23 // Describes interface for managing devtools agents from the browser process. | 23 // Describes interface for managing devtools agents from the browser process. |
| 24 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { | 24 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { |
| 25 public: | 25 public: |
| 26 // Informs the hosted agent that a client host has attached. | |
| 27 virtual void Attach() = 0; | |
| 28 | |
| 29 // Informs the hosted agent that a client host has detached. | |
| 30 virtual void Detach() = 0; | |
| 31 | |
| 32 // DevToolsAgentHost implementation. | 26 // DevToolsAgentHost implementation. |
| 33 bool AttachClient(DevToolsAgentHostClient* client) override; | 27 bool AttachClient(DevToolsAgentHostClient* client) override; |
| 34 void ForceAttachClient(DevToolsAgentHostClient* client) override; | 28 void ForceAttachClient(DevToolsAgentHostClient* client) override; |
| 35 bool DetachClient(DevToolsAgentHostClient* client) override; | 29 bool DetachClient(DevToolsAgentHostClient* client) override; |
| 36 bool DispatchProtocolMessage(DevToolsAgentHostClient* client, | 30 bool DispatchProtocolMessage(DevToolsAgentHostClient* client, |
| 37 const std::string& message) override; | 31 const std::string& message) override; |
| 38 bool IsAttached() override; | 32 bool IsAttached() override; |
| 39 void InspectElement(DevToolsAgentHostClient* client, int x, int y) override; | 33 void InspectElement(DevToolsAgentHostClient* client, int x, int y) override; |
| 40 std::string GetId() override; | 34 std::string GetId() override; |
| 41 std::string GetParentId() override; | 35 std::string GetParentId() override; |
| 42 std::string GetDescription() override; | 36 std::string GetDescription() override; |
| 43 GURL GetFaviconURL() override; | 37 GURL GetFaviconURL() override; |
| 44 std::string GetFrontendURL() override; | 38 std::string GetFrontendURL() override; |
| 45 base::TimeTicks GetLastActivityTime() override; | 39 base::TimeTicks GetLastActivityTime() override; |
| 46 BrowserContext* GetBrowserContext() override; | 40 BrowserContext* GetBrowserContext() override; |
| 47 WebContents* GetWebContents() override; | 41 WebContents* GetWebContents() override; |
| 48 void DisconnectWebContents() override; | 42 void DisconnectWebContents() override; |
| 49 void ConnectWebContents(WebContents* wc) override; | 43 void ConnectWebContents(WebContents* wc) override; |
| 50 | 44 |
| 51 bool Inspect(); | 45 bool Inspect(); |
| 52 void SendMessageToClient(int session_id, const std::string& message); | 46 void SendMessageToClient(int session_id, const std::string& message); |
| 53 | 47 |
| 54 protected: | 48 protected: |
| 55 DevToolsAgentHostImpl(const std::string& id); | 49 DevToolsAgentHostImpl(const std::string& id); |
| 56 ~DevToolsAgentHostImpl() override; | 50 ~DevToolsAgentHostImpl() override; |
| 57 | 51 |
| 58 static bool ShouldForceCreation(); | 52 static bool ShouldForceCreation(); |
| 59 | 53 |
| 60 virtual bool DispatchProtocolMessage(const std::string& message) = 0; | 54 virtual void AttachSession(DevToolsSession* session) = 0; |
| 61 virtual void InspectElement(int x, int y); | 55 virtual void DetachSession(int session_id) = 0; |
| 56 virtual bool DispatchProtocolMessage( |
| 57 DevToolsSession* session, |
| 58 const std::string& message) = 0; |
| 59 virtual void InspectElement(DevToolsSession* session, int x, int y); |
| 62 | 60 |
| 63 void NotifyCreated(); | 61 void NotifyCreated(); |
| 64 void HostClosed(); | 62 void ForceDetach(bool replaced); |
| 65 DevToolsIOContext* GetIOContext() { return &io_context_; } | 63 DevToolsIOContext* GetIOContext() { return &io_context_; } |
| 66 | 64 |
| 65 // TODO(dgozman): remove this accessor. |
| 67 DevToolsSession* session() { return session_.get(); } | 66 DevToolsSession* session() { return session_.get(); } |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 friend class DevToolsAgentHost; // for static methods | 69 friend class DevToolsAgentHost; // for static methods |
| 71 bool InnerAttach(DevToolsAgentHostClient* client, bool force); | 70 bool InnerAttachClient(DevToolsAgentHostClient* client, bool force); |
| 72 void InnerDetach(); | 71 void InnerDetachClient(); |
| 73 void NotifyAttached(); | 72 void NotifyAttached(); |
| 74 void NotifyDetached(); | 73 void NotifyDetached(); |
| 75 void NotifyDestroyed(); | 74 void NotifyDestroyed(); |
| 76 | 75 |
| 77 const std::string id_; | 76 const std::string id_; |
| 78 int session_id_; | |
| 79 int last_session_id_; | 77 int last_session_id_; |
| 80 std::unique_ptr<DevToolsSession> session_; | 78 std::unique_ptr<DevToolsSession> session_; |
| 81 DevToolsAgentHostClient* client_; | |
| 82 DevToolsIOContext io_context_; | 79 DevToolsIOContext io_context_; |
| 83 static int s_attached_count_; | 80 static int s_attached_count_; |
| 84 static int s_force_creation_count_; | 81 static int s_force_creation_count_; |
| 85 }; | 82 }; |
| 86 | 83 |
| 87 class DevToolsMessageChunkProcessor { | 84 class DevToolsMessageChunkProcessor { |
| 88 public: | 85 public: |
| 89 using SendMessageCallback = base::Callback<void(int, const std::string&)>; | 86 using SendMessageCallback = base::Callback<void(int, const std::string&)>; |
| 90 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); | 87 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); |
| 91 ~DevToolsMessageChunkProcessor(); | 88 ~DevToolsMessageChunkProcessor(); |
| 92 | 89 |
| 93 std::string state_cookie() const { return state_cookie_; } | 90 std::string state_cookie() const { return state_cookie_; } |
| 94 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } | 91 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } |
| 95 int last_call_id() const { return last_call_id_; } | 92 int last_call_id() const { return last_call_id_; } |
| 96 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 93 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 97 | 94 |
| 98 private: | 95 private: |
| 99 SendMessageCallback callback_; | 96 SendMessageCallback callback_; |
| 100 std::string message_buffer_; | 97 std::string message_buffer_; |
| 101 uint32_t message_buffer_size_; | 98 uint32_t message_buffer_size_; |
| 102 std::string state_cookie_; | 99 std::string state_cookie_; |
| 103 int last_call_id_; | 100 int last_call_id_; |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 } // namespace content | 103 } // namespace content |
| 107 | 104 |
| 108 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 105 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
| OLD | NEW |