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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return false; | 119 return false; |
120 auto it = pending_messages_.find(id); | 120 auto it = pending_messages_.find(id); |
121 if (it == pending_messages_.end()) { | 121 if (it == pending_messages_.end()) { |
122 NOTREACHED() << "Unexpected reply"; | 122 NOTREACHED() << "Unexpected reply"; |
123 return false; | 123 return false; |
124 } | 124 } |
125 Callback callback = std::move(it->second); | 125 Callback callback = std::move(it->second); |
126 pending_messages_.erase(it); | 126 pending_messages_.erase(it); |
127 if (!callback.callback_with_result.is_null()) { | 127 if (!callback.callback_with_result.is_null()) { |
128 const base::DictionaryValue* result_dict; | 128 const base::DictionaryValue* result_dict; |
129 if (!message_dict.GetDictionary("result", &result_dict)) { | 129 if (message_dict.GetDictionary("result", &result_dict)) { |
130 NOTREACHED() << "Badly formed reply result"; | 130 callback.callback_with_result.Run(*result_dict); |
| 131 } else if (message_dict.GetDictionary("error", &result_dict)) { |
| 132 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
| 133 DLOG(ERROR) << "Error in method call result: " << *result_dict; |
| 134 callback.callback_with_result.Run(*null_value); |
| 135 } else { |
| 136 NOTREACHED() << "Reply has neither result nor error"; |
131 return false; | 137 return false; |
132 } | 138 } |
133 callback.callback_with_result.Run(*result_dict); | |
134 } else if (!callback.callback.is_null()) { | 139 } else if (!callback.callback.is_null()) { |
135 callback.callback.Run(); | 140 callback.callback.Run(); |
136 } | 141 } |
137 return true; | 142 return true; |
138 } | 143 } |
139 | 144 |
140 bool HeadlessDevToolsClientImpl::DispatchEvent( | 145 bool HeadlessDevToolsClientImpl::DispatchEvent( |
141 std::unique_ptr<base::Value> owning_message, | 146 std::unique_ptr<base::Value> owning_message, |
142 const base::DictionaryValue& message_dict) { | 147 const base::DictionaryValue& message_dict) { |
143 std::string method; | 148 std::string method; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 HeadlessDevToolsClientImpl::Callback::Callback( | 384 HeadlessDevToolsClientImpl::Callback::Callback( |
380 base::Callback<void(const base::Value&)> callback) | 385 base::Callback<void(const base::Value&)> callback) |
381 : callback_with_result(callback) {} | 386 : callback_with_result(callback) {} |
382 | 387 |
383 HeadlessDevToolsClientImpl::Callback::~Callback() {} | 388 HeadlessDevToolsClientImpl::Callback::~Callback() {} |
384 | 389 |
385 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: | 390 HeadlessDevToolsClientImpl::Callback& HeadlessDevToolsClientImpl::Callback:: |
386 operator=(Callback&& other) = default; | 391 operator=(Callback&& other) = default; |
387 | 392 |
388 } // namespace headless | 393 } // namespace headless |
OLD | NEW |