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 // Implements the Chrome Extensions Debugger API. | 5 // Implements the Chrome Extensions Debugger API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" | 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (rvh && WebContents::FromRenderViewHost(rvh) == contents) | 169 if (rvh && WebContents::FromRenderViewHost(rvh) == contents) |
170 return static_cast<ExtensionDevToolsClientHost*>(*it); | 170 return static_cast<ExtensionDevToolsClientHost*>(*it); |
171 } | 171 } |
172 return NULL; | 172 return NULL; |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 std::set<DevToolsClientHost*> client_hosts_; | 176 std::set<DevToolsClientHost*> client_hosts_; |
177 }; | 177 }; |
178 | 178 |
| 179 scoped_ptr<base::DictionaryValue> ValueMapToDictionary( |
| 180 const std::map<std::string, linked_ptr<base::Value> >& values) { |
| 181 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 182 for (std::map<std::string, linked_ptr<base::Value> >::const_iterator it = |
| 183 values.begin(); |
| 184 it != values.end(); ++it) { |
| 185 dict->SetWithoutPathExpansion(it->first, it->second->DeepCopy()); |
| 186 } |
| 187 return dict.Pass(); |
| 188 } |
| 189 |
| 190 std::map<std::string, linked_ptr<base::Value> > DictionaryToValueMap( |
| 191 const base::DictionaryValue& dict) { |
| 192 std::map<std::string, linked_ptr<base::Value> > values; |
| 193 for (DictionaryValue::Iterator it(dict); it.HasNext(); it.Advance()) |
| 194 values[it.key()] = make_linked_ptr(it.value().DeepCopy()); |
| 195 return values; |
| 196 } |
| 197 |
179 } // namespace | 198 } // namespace |
180 | 199 |
181 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 200 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
182 WebContents* web_contents, | 201 WebContents* web_contents, |
183 const std::string& extension_id, | 202 const std::string& extension_id, |
184 const std::string& extension_name, | 203 const std::string& extension_name, |
185 int tab_id) | 204 int tab_id) |
186 : web_contents_(web_contents), | 205 : web_contents_(web_contents), |
187 extension_id_(extension_id), | 206 extension_id_(extension_id), |
188 tab_id_(tab_id), | 207 tab_id_(tab_id), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void ExtensionDevToolsClientHost::SendMessageToBackend( | 271 void ExtensionDevToolsClientHost::SendMessageToBackend( |
253 SendCommandDebuggerFunction* function, | 272 SendCommandDebuggerFunction* function, |
254 const std::string& method, | 273 const std::string& method, |
255 SendCommand::Params::CommandParams* command_params) { | 274 SendCommand::Params::CommandParams* command_params) { |
256 DictionaryValue protocol_request; | 275 DictionaryValue protocol_request; |
257 int request_id = ++last_request_id_; | 276 int request_id = ++last_request_id_; |
258 pending_requests_[request_id] = function; | 277 pending_requests_[request_id] = function; |
259 protocol_request.SetInteger("id", request_id); | 278 protocol_request.SetInteger("id", request_id); |
260 protocol_request.SetString("method", method); | 279 protocol_request.SetString("method", method); |
261 if (command_params) { | 280 if (command_params) { |
262 protocol_request.Set("params", | 281 protocol_request.Set( |
263 command_params->additional_properties.DeepCopy()); | 282 "params", |
| 283 ValueMapToDictionary(command_params->additional_properties).release()); |
264 } | 284 } |
265 | 285 |
266 std::string json_args; | 286 std::string json_args; |
267 base::JSONWriter::Write(&protocol_request, &json_args); | 287 base::JSONWriter::Write(&protocol_request, &json_args); |
268 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); | 288 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); |
269 } | 289 } |
270 | 290 |
271 void ExtensionDevToolsClientHost::MarkAsDismissed() { | 291 void ExtensionDevToolsClientHost::MarkAsDismissed() { |
272 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; | 292 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; |
273 } | 293 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 std::string method_name; | 348 std::string method_name; |
329 if (!dictionary->GetString("method", &method_name)) | 349 if (!dictionary->GetString("method", &method_name)) |
330 return; | 350 return; |
331 | 351 |
332 Debuggee debuggee; | 352 Debuggee debuggee; |
333 debuggee.tab_id = tab_id_; | 353 debuggee.tab_id = tab_id_; |
334 | 354 |
335 OnEvent::Params params; | 355 OnEvent::Params params; |
336 DictionaryValue* params_value; | 356 DictionaryValue* params_value; |
337 if (dictionary->GetDictionary("params", ¶ms_value)) | 357 if (dictionary->GetDictionary("params", ¶ms_value)) |
338 params.additional_properties.Swap(params_value); | 358 params.additional_properties = DictionaryToValueMap(*params_value); |
339 | 359 |
340 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); | 360 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); |
341 scoped_ptr<extensions::Event> event(new extensions::Event( | 361 scoped_ptr<extensions::Event> event(new extensions::Event( |
342 keys::kOnEvent, args.Pass())); | 362 keys::kOnEvent, args.Pass())); |
343 event->restrict_to_profile = profile; | 363 event->restrict_to_profile = profile; |
344 extensions::ExtensionSystem::Get(profile)->event_router()-> | 364 extensions::ExtensionSystem::Get(profile)->event_router()-> |
345 DispatchEventToExtension(extension_id_, event.Pass()); | 365 DispatchEventToExtension(extension_id_, event.Pass()); |
346 } else { | 366 } else { |
347 SendCommandDebuggerFunction* function = pending_requests_[id]; | 367 SendCommandDebuggerFunction* function = pending_requests_[id]; |
348 if (!function) | 368 if (!function) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 Value* error_body; | 556 Value* error_body; |
537 if (response->Get("error", &error_body)) { | 557 if (response->Get("error", &error_body)) { |
538 base::JSONWriter::Write(error_body, &error_); | 558 base::JSONWriter::Write(error_body, &error_); |
539 SendResponse(false); | 559 SendResponse(false); |
540 return; | 560 return; |
541 } | 561 } |
542 | 562 |
543 DictionaryValue* result_body; | 563 DictionaryValue* result_body; |
544 SendCommand::Results::Result result; | 564 SendCommand::Results::Result result; |
545 if (response->GetDictionary("result", &result_body)) | 565 if (response->GetDictionary("result", &result_body)) |
546 result.additional_properties.Swap(result_body); | 566 result.additional_properties = DictionaryToValueMap(*result_body); |
547 | 567 |
548 results_ = SendCommand::Results::Create(result); | 568 results_ = SendCommand::Results::Create(result); |
549 SendResponse(true); | 569 SendResponse(true); |
550 } | 570 } |
OLD | NEW |