| 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 "base/containers/flat_set.h" | 13 #include "base/containers/flat_set.h" |
| 14 #include "content/browser/devtools/devtools_io_context.h" | 14 #include "content/browser/devtools/devtools_io_context.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 content { | 19 namespace content { |
| 20 | 20 |
| 21 class BrowserContext; | 21 class BrowserContext; |
| 22 class DevToolsSession; | 22 class DevToolsSession; |
| 23 | 23 |
| 24 // Describes interface for managing devtools agents from the browser process. | 24 // Describes interface for managing devtools agents from the browser process. |
| 25 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { | 25 class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost { |
| 26 public: | 26 public: |
| 27 // DevToolsAgentHost implementation. | 27 // DevToolsAgentHost implementation. |
| 28 bool AttachClient(DevToolsAgentHostClient* client) override; | 28 bool AttachClient(DevToolsAgentHostClient* client) override; |
| 29 void ForceAttachClient(DevToolsAgentHostClient* client) override; | 29 void ForceAttachClient(DevToolsAgentHostClient* client) override; |
| 30 bool AttachMultiClient(DevToolsAgentHostClient* client) override; |
| 30 bool DetachClient(DevToolsAgentHostClient* client) override; | 31 bool DetachClient(DevToolsAgentHostClient* client) override; |
| 31 bool DispatchProtocolMessage(DevToolsAgentHostClient* client, | 32 bool DispatchProtocolMessage(DevToolsAgentHostClient* client, |
| 32 const std::string& message) override; | 33 const std::string& message) override; |
| 33 bool IsAttached() override; | 34 bool IsAttached() override; |
| 34 void InspectElement(DevToolsAgentHostClient* client, int x, int y) override; | 35 void InspectElement(DevToolsAgentHostClient* client, int x, int y) override; |
| 35 std::string GetId() override; | 36 std::string GetId() override; |
| 36 std::string GetParentId() override; | 37 std::string GetParentId() override; |
| 37 std::string GetDescription() override; | 38 std::string GetDescription() override; |
| 38 GURL GetFaviconURL() override; | 39 GURL GetFaviconURL() override; |
| 39 std::string GetFrontendURL() override; | 40 std::string GetFrontendURL() override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 52 static bool ShouldForceCreation(); | 53 static bool ShouldForceCreation(); |
| 53 | 54 |
| 54 virtual void AttachSession(DevToolsSession* session) = 0; | 55 virtual void AttachSession(DevToolsSession* session) = 0; |
| 55 virtual void DetachSession(int session_id) = 0; | 56 virtual void DetachSession(int session_id) = 0; |
| 56 virtual bool DispatchProtocolMessage( | 57 virtual bool DispatchProtocolMessage( |
| 57 DevToolsSession* session, | 58 DevToolsSession* session, |
| 58 const std::string& message) = 0; | 59 const std::string& message) = 0; |
| 59 virtual void InspectElement(DevToolsSession* session, int x, int y); | 60 virtual void InspectElement(DevToolsSession* session, int x, int y); |
| 60 | 61 |
| 61 void NotifyCreated(); | 62 void NotifyCreated(); |
| 62 void ForceDetach(bool replaced); | 63 void ForceDetachAllClients(bool replaced); |
| 63 DevToolsIOContext* GetIOContext() { return &io_context_; } | 64 DevToolsIOContext* GetIOContext() { return &io_context_; } |
| 64 | 65 const base::flat_map<int, DevToolsSession*>& sessions() { |
| 65 // TODO(dgozman): remove this accessor. | 66 return session_by_id_; |
| 66 DevToolsSession* session() { return session_; } | 67 } |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 friend class DevToolsAgentHost; // for static methods | 70 friend class DevToolsAgentHost; // for static methods |
| 70 friend class DevToolsSession; | 71 friend class DevToolsSession; |
| 71 bool InnerAttachClient(DevToolsAgentHostClient* client, bool force); | 72 void InnerAttachClient(DevToolsAgentHostClient* client); |
| 72 void InnerDetachClient(); | 73 void InnerDetachClient(DevToolsAgentHostClient* client); |
| 73 void NotifyAttached(); | 74 void NotifyAttached(); |
| 74 void NotifyDetached(); | 75 void NotifyDetached(); |
| 75 void NotifyDestroyed(); | 76 void NotifyDestroyed(); |
| 76 | 77 |
| 77 const std::string id_; | 78 const std::string id_; |
| 78 int last_session_id_; | 79 int last_session_id_; |
| 79 // TODO(dgozman): remove this together with accessor above. | 80 base::flat_map<DevToolsAgentHostClient*, std::unique_ptr<DevToolsSession>> |
| 80 DevToolsSession* session_; | 81 session_by_client_; |
| 81 base::flat_set<std::unique_ptr<DevToolsSession>> sessions_; | 82 base::flat_map<int, DevToolsSession*> session_by_id_; |
| 82 DevToolsIOContext io_context_; | 83 DevToolsIOContext io_context_; |
| 83 static int s_attached_count_; | 84 static int s_attached_count_; |
| 84 static int s_force_creation_count_; | 85 static int s_force_creation_count_; |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 class DevToolsMessageChunkProcessor { | 88 class DevToolsMessageChunkProcessor { |
| 88 public: | 89 public: |
| 89 using SendMessageCallback = base::Callback<void(int, const std::string&)>; | 90 using SendMessageCallback = base::Callback<void(int, const std::string&)>; |
| 90 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); | 91 explicit DevToolsMessageChunkProcessor(const SendMessageCallback& callback); |
| 91 ~DevToolsMessageChunkProcessor(); | 92 ~DevToolsMessageChunkProcessor(); |
| 92 | 93 |
| 93 std::string state_cookie() const { return state_cookie_; } | 94 std::string state_cookie() const { return state_cookie_; } |
| 94 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } | 95 void set_state_cookie(const std::string& cookie) { state_cookie_ = cookie; } |
| 95 int last_call_id() const { return last_call_id_; } | 96 int last_call_id() const { return last_call_id_; } |
| 96 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 97 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 SendMessageCallback callback_; | 100 SendMessageCallback callback_; |
| 100 std::string message_buffer_; | 101 std::string message_buffer_; |
| 101 uint32_t message_buffer_size_; | 102 uint32_t message_buffer_size_; |
| 102 std::string state_cookie_; | 103 std::string state_cookie_; |
| 103 int last_call_id_; | 104 int last_call_id_; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 } // namespace content | 107 } // namespace content |
| 107 | 108 |
| 108 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ | 109 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_ |
| OLD | NEW |