| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/devtools_client_impl.h" | 5 #include "chrome/test/chromedriver/devtools_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (!parser_func_.Run(message, expected_id, type, event, response)) | 153 if (!parser_func_.Run(message, expected_id, type, event, response)) |
| 154 return Status(kUnknownError, "bad inspector message: " + message); | 154 return Status(kUnknownError, "bad inspector message: " + message); |
| 155 if (*type == internal::kEventMessageType) | 155 if (*type == internal::kEventMessageType) |
| 156 return NotifyEventListeners(event->method, *event->params); | 156 return NotifyEventListeners(event->method, *event->params); |
| 157 if (*type == internal::kCommandResponseMessageType) { | 157 if (*type == internal::kCommandResponseMessageType) { |
| 158 if (cmd_response_map_.count(response->id) == 0) { | 158 if (cmd_response_map_.count(response->id) == 0) { |
| 159 return Status(kUnknownError, "unexpected command message"); | 159 return Status(kUnknownError, "unexpected command message"); |
| 160 } else if (response->result) { | 160 } else if (response->result) { |
| 161 cmd_response_map_[response->id] = response->result.release(); | 161 cmd_response_map_[response->id] = response->result.release(); |
| 162 } else { | 162 } else { |
| 163 scoped_ptr<base::Value> error(base::JSONReader::Read(response->error)); |
| 164 base::DictionaryValue* error_dict; |
| 165 if (!error || !error->GetAsDictionary(&error_dict)) |
| 166 return Status(kUnknownError, "inspector error with no error code"); |
| 167 int error_code; |
| 168 if (error_dict->GetInteger("code", &error_code) && |
| 169 error_code == internal::kContextIdNotFound) { |
| 170 cmd_response_map_.erase(response->id); |
| 171 return Status(kNoSuchFrame); |
| 172 } |
| 163 return Status(kUnknownError, "inspector error: " + response->error); | 173 return Status(kUnknownError, "inspector error: " + response->error); |
| 164 } | 174 } |
| 165 } | 175 } |
| 166 return Status(kOk); | 176 return Status(kOk); |
| 167 } | 177 } |
| 168 | 178 |
| 169 Status DevToolsClientImpl::NotifyEventListeners( | 179 Status DevToolsClientImpl::NotifyEventListeners( |
| 170 const std::string& method, | 180 const std::string& method, |
| 171 const base::DictionaryValue& params) { | 181 const base::DictionaryValue& params) { |
| 172 for (std::list<DevToolsEventListener*>::iterator iter = listeners_.begin(); | 182 for (std::list<DevToolsEventListener*>::iterator iter = listeners_.begin(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (unscoped_result) | 230 if (unscoped_result) |
| 221 command_response->result.reset(unscoped_result->DeepCopy()); | 231 command_response->result.reset(unscoped_result->DeepCopy()); |
| 222 else | 232 else |
| 223 base::JSONWriter::Write(unscoped_error, &command_response->error); | 233 base::JSONWriter::Write(unscoped_error, &command_response->error); |
| 224 return true; | 234 return true; |
| 225 } | 235 } |
| 226 return false; | 236 return false; |
| 227 } | 237 } |
| 228 | 238 |
| 229 } // namespace internal | 239 } // namespace internal |
| OLD | NEW |