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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 HeadlessDevToolsClientImpl* HeadlessDevToolsClientImpl::From( | 25 HeadlessDevToolsClientImpl* HeadlessDevToolsClientImpl::From( |
26 HeadlessDevToolsClient* client) { | 26 HeadlessDevToolsClient* client) { |
27 // This downcast is safe because there is only one implementation of | 27 // This downcast is safe because there is only one implementation of |
28 // HeadlessDevToolsClient. | 28 // HeadlessDevToolsClient. |
29 return static_cast<HeadlessDevToolsClientImpl*>(client); | 29 return static_cast<HeadlessDevToolsClientImpl*>(client); |
30 } | 30 } |
31 | 31 |
32 HeadlessDevToolsClientImpl::HeadlessDevToolsClientImpl() | 32 HeadlessDevToolsClientImpl::HeadlessDevToolsClientImpl() |
33 : agent_host_(nullptr), | 33 : agent_host_(nullptr), |
34 next_message_id_(0), | 34 next_message_id_(0), |
35 renderer_crashed_(false), | |
35 accessibility_domain_(this), | 36 accessibility_domain_(this), |
36 animation_domain_(this), | 37 animation_domain_(this), |
37 application_cache_domain_(this), | 38 application_cache_domain_(this), |
38 cache_storage_domain_(this), | 39 cache_storage_domain_(this), |
39 console_domain_(this), | 40 console_domain_(this), |
40 css_domain_(this), | 41 css_domain_(this), |
41 database_domain_(this), | 42 database_domain_(this), |
42 debugger_domain_(this), | 43 debugger_domain_(this), |
43 device_orientation_domain_(this), | 44 device_orientation_domain_(this), |
44 dom_debugger_domain_(this), | 45 dom_debugger_domain_(this), |
(...skipping 26 matching lines...) Expand all Loading... | |
71 void HeadlessDevToolsClientImpl::AttachToHost( | 72 void HeadlessDevToolsClientImpl::AttachToHost( |
72 content::DevToolsAgentHost* agent_host) { | 73 content::DevToolsAgentHost* agent_host) { |
73 DCHECK(!agent_host_); | 74 DCHECK(!agent_host_); |
74 agent_host_ = agent_host; | 75 agent_host_ = agent_host; |
75 agent_host_->AttachClient(this); | 76 agent_host_->AttachClient(this); |
76 } | 77 } |
77 | 78 |
78 void HeadlessDevToolsClientImpl::DetachFromHost( | 79 void HeadlessDevToolsClientImpl::DetachFromHost( |
79 content::DevToolsAgentHost* agent_host) { | 80 content::DevToolsAgentHost* agent_host) { |
80 DCHECK_EQ(agent_host_, agent_host); | 81 DCHECK_EQ(agent_host_, agent_host); |
81 agent_host_->DetachClient(this); | 82 if (!renderer_crashed_) |
83 agent_host_->DetachClient(this); | |
82 agent_host_ = nullptr; | 84 agent_host_ = nullptr; |
83 pending_messages_.clear(); | 85 pending_messages_.clear(); |
84 } | 86 } |
85 | 87 |
86 void HeadlessDevToolsClientImpl::DispatchProtocolMessage( | 88 void HeadlessDevToolsClientImpl::DispatchProtocolMessage( |
87 content::DevToolsAgentHost* agent_host, | 89 content::DevToolsAgentHost* agent_host, |
88 const std::string& json_message) { | 90 const std::string& json_message) { |
89 DCHECK_EQ(agent_host_, agent_host); | 91 DCHECK_EQ(agent_host_, agent_host); |
90 std::unique_ptr<base::Value> message = | 92 std::unique_ptr<base::Value> message = |
91 base::JSONReader::Read(json_message, base::JSON_PARSE_RFC); | 93 base::JSONReader::Read(json_message, base::JSON_PARSE_RFC); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 } | 128 } |
127 | 129 |
128 bool HeadlessDevToolsClientImpl::DispatchEvent( | 130 bool HeadlessDevToolsClientImpl::DispatchEvent( |
129 std::unique_ptr<base::Value> owning_message, | 131 std::unique_ptr<base::Value> owning_message, |
130 const base::DictionaryValue& message_dict) { | 132 const base::DictionaryValue& message_dict) { |
131 std::string method; | 133 std::string method; |
132 if (!message_dict.GetString("method", &method)) | 134 if (!message_dict.GetString("method", &method)) |
133 return false; | 135 return false; |
134 EventHandlerMap::const_iterator it = event_handlers_.find(method); | 136 EventHandlerMap::const_iterator it = event_handlers_.find(method); |
135 if (it == event_handlers_.end()) { | 137 if (it == event_handlers_.end()) { |
138 // Silently swallow errors related to the target crashing. This can be | |
139 // observed via HeadlessWebContents::Observer::RenderProcessExited. | |
140 if (method == "Inspector.targetCrashed") { | |
Sami
2016/11/18 18:37:22
Shouldn't we still emit this event in Headless She
alex clarke (OOO till 29th)
2016/11/21 10:44:01
Hmm so we do actually have an inspector domain - I
| |
141 renderer_crashed_ = true; | |
142 return true; | |
143 } | |
144 | |
136 NOTREACHED() << "Unknown event: " << method; | 145 NOTREACHED() << "Unknown event: " << method; |
137 return false; | 146 return false; |
138 } | 147 } |
139 if (!it->second.is_null()) { | 148 if (!it->second.is_null()) { |
140 const base::DictionaryValue* result_dict; | 149 const base::DictionaryValue* result_dict; |
141 if (!message_dict.GetDictionary("params", &result_dict)) { | 150 if (!message_dict.GetDictionary("params", &result_dict)) { |
142 NOTREACHED() << "Badly formed event parameters"; | 151 NOTREACHED() << "Badly formed event parameters"; |
143 return false; | 152 return false; |
144 } | 153 } |
145 // DevTools assumes event handling is async so we must post a task here or | 154 // DevTools assumes event handling is async so we must post a task here or |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 } | 294 } |
286 | 295 |
287 tracing::Domain* HeadlessDevToolsClientImpl::GetTracing() { | 296 tracing::Domain* HeadlessDevToolsClientImpl::GetTracing() { |
288 return &tracing_domain_; | 297 return &tracing_domain_; |
289 } | 298 } |
290 | 299 |
291 template <typename CallbackType> | 300 template <typename CallbackType> |
292 void HeadlessDevToolsClientImpl::FinalizeAndSendMessage( | 301 void HeadlessDevToolsClientImpl::FinalizeAndSendMessage( |
293 base::DictionaryValue* message, | 302 base::DictionaryValue* message, |
294 CallbackType callback) { | 303 CallbackType callback) { |
304 if (renderer_crashed_) | |
305 return; | |
295 DCHECK(agent_host_); | 306 DCHECK(agent_host_); |
296 int id = next_message_id_++; | 307 int id = next_message_id_++; |
297 message->SetInteger("id", id); | 308 message->SetInteger("id", id); |
298 std::string json_message; | 309 std::string json_message; |
299 base::JSONWriter::Write(*message, &json_message); | 310 base::JSONWriter::Write(*message, &json_message); |
300 pending_messages_[id] = Callback(callback); | 311 pending_messages_[id] = Callback(callback); |
301 agent_host_->DispatchProtocolMessage(this, json_message); | 312 agent_host_->DispatchProtocolMessage(this, json_message); |
302 } | 313 } |
303 | 314 |
304 template <typename CallbackType> | 315 template <typename CallbackType> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 HeadlessDevToolsClientImpl::Callback::Callback( | 374 HeadlessDevToolsClientImpl::Callback::Callback( |
364 base::Callback<void(const base::Value&)> callback) | 375 base::Callback<void(const base::Value&)> callback) |
365 : callback_with_result(callback) {} | 376 : callback_with_result(callback) {} |
366 | 377 |
367 HeadlessDevToolsClientImpl::Callback::~Callback() {} | 378 HeadlessDevToolsClientImpl::Callback::~Callback() {} |
368 | 379 |
369 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: | 380 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: |
370 operator=(Callback&& other) = default; | 381 operator=(Callback&& other) = default; |
371 | 382 |
372 } // namespace headless | 383 } // namespace headless |
OLD | NEW |