Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: headless/lib/browser/headless_devtools_client_impl.h

Issue 1907533002: headless: Implement DevTools events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add parameters to all events Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
111 const char* method,
112 base::Callback<void(const base::Value&)> callback) override;
110 113
111 void AttachToHost(content::DevToolsAgentHost* agent_host); 114 void AttachToHost(content::DevToolsAgentHost* agent_host);
112 void DetachFromHost(content::DevToolsAgentHost* agent_host); 115 void DetachFromHost(content::DevToolsAgentHost* agent_host);
113 116
114 private: 117 private:
115 // Represents a message for which we are still waiting for a reply. Contains 118 // 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 119 // message type.
117 // is pending. 120 struct Callback {
118 struct PendingMessage { 121 Callback();
119 PendingMessage(); 122 Callback(Callback&& other);
120 PendingMessage(PendingMessage&& other); 123 explicit Callback(base::Callback<void()> callback);
121 explicit PendingMessage(base::Callback<void()> callback); 124 explicit Callback(base::Callback<void(const base::Value&)> callback);
122 explicit PendingMessage(base::Callback<void(const base::Value&)> callback); 125 ~Callback();
123 ~PendingMessage();
124 126
125 PendingMessage& operator=(PendingMessage&& other); 127 Callback& operator=(Callback&& other);
126 128
127 // TODO(skyostil): Use a class union once allowed.
128 base::Callback<void()> callback; 129 base::Callback<void()> callback;
129 base::Callback<void(const base::Value&)> callback_with_result; 130 base::Callback<void(const base::Value&)> callback_with_result;
130 }; 131 };
131 132
132 template <typename CallbackType> 133 template <typename CallbackType>
133 void FinalizeAndSendMessage(base::DictionaryValue* message, 134 void FinalizeAndSendMessage(base::DictionaryValue* message,
134 CallbackType callback); 135 CallbackType callback);
135 136
136 template <typename CallbackType> 137 template <typename CallbackType>
137 void SendMessageWithParams(const char* method, 138 void SendMessageWithParams(const char* method,
138 std::unique_ptr<base::Value> params, 139 std::unique_ptr<base::Value> params,
139 CallbackType callback); 140 CallbackType callback);
140 141
141 template <typename CallbackType> 142 template <typename CallbackType>
142 void SendMessageWithoutParams(const char* method, CallbackType callback); 143 void SendMessageWithoutParams(const char* method, CallbackType callback);
143 144
145 bool DispatchMessageReply(const base::DictionaryValue& message_dict);
146 bool DispatchEvent(const base::DictionaryValue& message_dict);
147
144 content::DevToolsAgentHost* agent_host_; // Not owned. 148 content::DevToolsAgentHost* agent_host_; // Not owned.
145 int next_message_id_; 149 int next_message_id_;
146 std::unordered_map<int, PendingMessage> pending_messages_; 150 std::unordered_map<int, Callback> pending_messages_;
151 std::unordered_map<std::string, base::Callback<void(const base::Value&)>>
152 event_handlers_;
147 153
148 accessibility::Domain accessibility_domain_; 154 accessibility::Domain accessibility_domain_;
149 animation::Domain animation_domain_; 155 animation::Domain animation_domain_;
150 application_cache::Domain application_cache_domain_; 156 application_cache::Domain application_cache_domain_;
151 cache_storage::Domain cache_storage_domain_; 157 cache_storage::Domain cache_storage_domain_;
152 console::Domain console_domain_; 158 console::Domain console_domain_;
153 css::Domain css_domain_; 159 css::Domain css_domain_;
154 database::Domain database_domain_; 160 database::Domain database_domain_;
155 debugger::Domain debugger_domain_; 161 debugger::Domain debugger_domain_;
156 device_orientation::Domain device_orientation_domain_; 162 device_orientation::Domain device_orientation_domain_;
(...skipping 17 matching lines...) Expand all
174 service_worker::Domain service_worker_domain_; 180 service_worker::Domain service_worker_domain_;
175 tracing::Domain tracing_domain_; 181 tracing::Domain tracing_domain_;
176 worker::Domain worker_domain_; 182 worker::Domain worker_domain_;
177 183
178 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl); 184 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsClientImpl);
179 }; 185 };
180 186
181 } // namespace headless 187 } // namespace headless
182 188
183 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_ 189 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_CLIENT_IMPL_H_
OLDNEW
« no previous file with comments | « headless/lib/browser/domain_h.template ('k') | headless/lib/browser/headless_devtools_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698