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 #include "headless/lib/browser/headless_devtools_client_impl.h" | 5 #include "headless/lib/browser/headless_devtools_client_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void HeadlessDevToolsClientImpl::AttachToHost( | 65 void HeadlessDevToolsClientImpl::AttachToHost( |
66 content::DevToolsAgentHost* agent_host) { | 66 content::DevToolsAgentHost* agent_host) { |
67 DCHECK(!agent_host_); | 67 DCHECK(!agent_host_); |
68 agent_host_ = agent_host; | 68 agent_host_ = agent_host; |
69 agent_host_->AttachClient(this); | 69 agent_host_->AttachClient(this); |
70 } | 70 } |
71 | 71 |
72 void HeadlessDevToolsClientImpl::DetachFromHost( | 72 void HeadlessDevToolsClientImpl::DetachFromHost( |
73 content::DevToolsAgentHost* agent_host) { | 73 content::DevToolsAgentHost* agent_host) { |
74 DCHECK_EQ(agent_host_, agent_host); | 74 DCHECK_EQ(agent_host_, agent_host); |
75 agent_host_->DetachClient(); | 75 agent_host_->DetachClient(this); |
76 agent_host_ = nullptr; | 76 agent_host_ = nullptr; |
77 pending_messages_.clear(); | 77 pending_messages_.clear(); |
78 } | 78 } |
79 | 79 |
80 void HeadlessDevToolsClientImpl::DispatchProtocolMessage( | 80 void HeadlessDevToolsClientImpl::DispatchProtocolMessage( |
81 content::DevToolsAgentHost* agent_host, | 81 content::DevToolsAgentHost* agent_host, |
82 const std::string& json_message) { | 82 const std::string& json_message) { |
83 DCHECK_EQ(agent_host_, agent_host); | 83 DCHECK_EQ(agent_host_, agent_host); |
84 std::unique_ptr<base::Value> message = | 84 std::unique_ptr<base::Value> message = |
85 base::JSONReader::Read(json_message, base::JSON_PARSE_RFC); | 85 base::JSONReader::Read(json_message, base::JSON_PARSE_RFC); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 template <typename CallbackType> | 265 template <typename CallbackType> |
266 void HeadlessDevToolsClientImpl::FinalizeAndSendMessage( | 266 void HeadlessDevToolsClientImpl::FinalizeAndSendMessage( |
267 base::DictionaryValue* message, | 267 base::DictionaryValue* message, |
268 CallbackType callback) { | 268 CallbackType callback) { |
269 DCHECK(agent_host_); | 269 DCHECK(agent_host_); |
270 int id = next_message_id_++; | 270 int id = next_message_id_++; |
271 message->SetInteger("id", id); | 271 message->SetInteger("id", id); |
272 std::string json_message; | 272 std::string json_message; |
273 base::JSONWriter::Write(*message, &json_message); | 273 base::JSONWriter::Write(*message, &json_message); |
274 pending_messages_[id] = Callback(callback); | 274 pending_messages_[id] = Callback(callback); |
275 agent_host_->DispatchProtocolMessage(json_message); | 275 agent_host_->DispatchProtocolMessage(this, json_message); |
276 } | 276 } |
277 | 277 |
278 template <typename CallbackType> | 278 template <typename CallbackType> |
279 void HeadlessDevToolsClientImpl::SendMessageWithParams( | 279 void HeadlessDevToolsClientImpl::SendMessageWithParams( |
280 const char* method, | 280 const char* method, |
281 std::unique_ptr<base::Value> params, | 281 std::unique_ptr<base::Value> params, |
282 CallbackType callback) { | 282 CallbackType callback) { |
283 base::DictionaryValue message; | 283 base::DictionaryValue message; |
284 message.SetString("method", method); | 284 message.SetString("method", method); |
285 message.Set("params", std::move(params)); | 285 message.Set("params", std::move(params)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 HeadlessDevToolsClientImpl::Callback::Callback( | 337 HeadlessDevToolsClientImpl::Callback::Callback( |
338 base::Callback<void(const base::Value&)> callback) | 338 base::Callback<void(const base::Value&)> callback) |
339 : callback_with_result(callback) {} | 339 : callback_with_result(callback) {} |
340 | 340 |
341 HeadlessDevToolsClientImpl::Callback::~Callback() {} | 341 HeadlessDevToolsClientImpl::Callback::~Callback() {} |
342 | 342 |
343 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: | 343 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: |
344 operator=(Callback&& other) = default; | 344 operator=(Callback&& other) = default; |
345 | 345 |
346 } // namespace headless | 346 } // namespace headless |
OLD | NEW |