| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ |
| 6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 | 9 |
| 10 #include "content/public/browser/devtools_agent_host_client.h" | 10 #include "content/public/browser/devtools_agent_host_client.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void SendMessage(const char* method, | 100 void SendMessage(const char* method, |
| 101 std::unique_ptr<base::Value> params, | 101 std::unique_ptr<base::Value> params, |
| 102 base::Callback<void(const base::Value&)> callback) override; | 102 base::Callback<void(const base::Value&)> callback) override; |
| 103 void SendMessage(const char* method, | 103 void SendMessage(const char* method, |
| 104 std::unique_ptr<base::Value> params, | 104 std::unique_ptr<base::Value> params, |
| 105 base::Callback<void()> callback) override; | 105 base::Callback<void()> callback) override; |
| 106 void SendMessage(const char* method, | 106 void SendMessage(const char* method, |
| 107 base::Callback<void(const base::Value&)> callback) override; | 107 base::Callback<void(const base::Value&)> callback) override; |
| 108 void SendMessage(const char* method, | 108 void SendMessage(const char* method, |
| 109 base::Callback<void()> callback) override; | 109 base::Callback<void()> callback) override; |
| 110 void RegisterEventHandler(const char* method, |
| 111 base::Callback<void()> callback) override; |
| 112 void RegisterEventHandler( |
| 113 const char* method, |
| 114 base::Callback<void(const base::Value&)> callback) override; |
| 110 | 115 |
| 111 void AttachToHost(content::DevToolsAgentHost* agent_host); | 116 void AttachToHost(content::DevToolsAgentHost* agent_host); |
| 112 void DetachFromHost(content::DevToolsAgentHost* agent_host); | 117 void DetachFromHost(content::DevToolsAgentHost* agent_host); |
| 113 | 118 |
| 114 private: | 119 private: |
| 115 // Represents a message for which we are still waiting for a reply. Contains | 120 // Contains a callback with or without a result parameter depending on the |
| 116 // a callback with or without a result parameter depending on the message that | 121 // message type. |
| 117 // is pending. | 122 struct Callback { |
| 118 struct PendingMessage { | 123 Callback(); |
| 119 PendingMessage(); | 124 Callback(Callback&& other); |
| 120 PendingMessage(PendingMessage&& other); | 125 explicit Callback(base::Callback<void()> callback); |
| 121 explicit PendingMessage(base::Callback<void()> callback); | 126 explicit Callback(base::Callback<void(const base::Value&)> callback); |
| 122 explicit PendingMessage(base::Callback<void(const base::Value&)> callback); | 127 ~Callback(); |
| 123 ~PendingMessage(); | |
| 124 | 128 |
| 125 PendingMessage& operator=(PendingMessage&& other); | 129 Callback& operator=(Callback&& other); |
| 126 | 130 |
| 127 // TODO(skyostil): Use a class union once allowed. | |
| 128 base::Callback<void()> callback; | 131 base::Callback<void()> callback; |
| 129 base::Callback<void(const base::Value&)> callback_with_result; | 132 base::Callback<void(const base::Value&)> callback_with_result; |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 template <typename CallbackType> | 135 template <typename CallbackType> |
| 133 void FinalizeAndSendMessage(base::DictionaryValue* message, | 136 void FinalizeAndSendMessage(base::DictionaryValue* message, |
| 134 CallbackType callback); | 137 CallbackType callback); |
| 135 | 138 |
| 136 template <typename CallbackType> | 139 template <typename CallbackType> |
| 137 void SendMessageWithParams(const char* method, | 140 void SendMessageWithParams(const char* method, |
| 138 std::unique_ptr<base::Value> params, | 141 std::unique_ptr<base::Value> params, |
| 139 CallbackType callback); | 142 CallbackType callback); |
| 140 | 143 |
| 141 template <typename CallbackType> | 144 template <typename CallbackType> |
| 142 void SendMessageWithoutParams(const char* method, CallbackType callback); | 145 void SendMessageWithoutParams(const char* method, CallbackType callback); |
| 143 | 146 |
| 147 bool DispatchMessageReply(const base::DictionaryValue& message_dict); |
| 148 bool DispatchEvent(const base::DictionaryValue& message_dict); |
| 149 |
| 144 content::DevToolsAgentHost* agent_host_; // Not owned. | 150 content::DevToolsAgentHost* agent_host_; // Not owned. |
| 145 int next_message_id_; | 151 int next_message_id_; |
| 146 std::unordered_map<int, PendingMessage> pending_messages_; | 152 std::unordered_map<int, Callback> pending_messages_; |
| 153 std::unordered_map<std::string, Callback> event_handlers_; |
| 147 | 154 |
| 148 accessibility::Domain accessibility_domain_; | 155 accessibility::Domain accessibility_domain_; |
| 149 animation::Domain animation_domain_; | 156 animation::Domain animation_domain_; |
| 150 application_cache::Domain application_cache_domain_; | 157 application_cache::Domain application_cache_domain_; |
| 151 cache_storage::Domain cache_storage_domain_; | 158 cache_storage::Domain cache_storage_domain_; |
| 152 console::Domain console_domain_; | 159 console::Domain console_domain_; |
| 153 css::Domain css_domain_; | 160 css::Domain css_domain_; |
| 154 database::Domain database_domain_; | 161 database::Domain database_domain_; |
| 155 debugger::Domain debugger_domain_; | 162 debugger::Domain debugger_domain_; |
| 156 device_orientation::Domain device_orientation_domain_; | 163 device_orientation::Domain device_orientation_domain_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 service_worker::Domain service_worker_domain_; | 181 service_worker::Domain service_worker_domain_; |
| 175 tracing::Domain tracing_domain_; | 182 tracing::Domain tracing_domain_; |
| 176 worker::Domain worker_domain_; | 183 worker::Domain worker_domain_; |
| 177 | 184 |
| 178 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl); | 185 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl); |
| 179 }; | 186 }; |
| 180 | 187 |
| 181 } // namespace headless | 188 } // namespace headless |
| 182 | 189 |
| 183 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ | 190 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ |
| OLD | NEW |