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/extension_debugger_api.h" | 7 #include "chrome/browser/extensions/extension_debugger_api.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 Value* params) { | 239 Value* params) { |
240 DictionaryValue protocol_request; | 240 DictionaryValue protocol_request; |
241 int request_id = ++last_request_id_; | 241 int request_id = ++last_request_id_; |
242 pending_requests_[request_id] = function; | 242 pending_requests_[request_id] = function; |
243 protocol_request.SetInteger("id", request_id); | 243 protocol_request.SetInteger("id", request_id); |
244 protocol_request.SetString("method", method); | 244 protocol_request.SetString("method", method); |
245 if (params) | 245 if (params) |
246 protocol_request.Set("params", params->DeepCopy()); | 246 protocol_request.Set("params", params->DeepCopy()); |
247 | 247 |
248 std::string json_args; | 248 std::string json_args; |
249 base::JSONWriter::Write(&protocol_request, false, &json_args); | 249 base::JSONWriter::Write(&protocol_request, &json_args); |
250 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); | 250 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); |
251 } | 251 } |
252 | 252 |
253 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 253 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
254 Profile* profile = | 254 Profile* profile = |
255 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 255 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
256 if (profile != NULL && profile->GetExtensionEventRouter()) { | 256 if (profile != NULL && profile->GetExtensionEventRouter()) { |
257 ListValue args; | 257 ListValue args; |
258 args.Append(CreateDebuggeeId(tab_id_)); | 258 args.Append(CreateDebuggeeId(tab_id_)); |
259 | 259 |
260 std::string json_args; | 260 std::string json_args; |
261 base::JSONWriter::Write(&args, false, &json_args); | 261 base::JSONWriter::Write(&args, &json_args); |
262 | 262 |
263 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 263 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
264 extension_id_, keys::kOnDetach, json_args, profile, GURL()); | 264 extension_id_, keys::kOnDetach, json_args, profile, GURL()); |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 void ExtensionDevToolsClientHost::Observe( | 268 void ExtensionDevToolsClientHost::Observe( |
269 int type, | 269 int type, |
270 const content::NotificationSource& source, | 270 const content::NotificationSource& source, |
271 const content::NotificationDetails& details) { | 271 const content::NotificationDetails& details) { |
(...skipping 23 matching lines...) Expand all Loading... |
295 return; | 295 return; |
296 | 296 |
297 ListValue args; | 297 ListValue args; |
298 args.Append(CreateDebuggeeId(tab_id_)); | 298 args.Append(CreateDebuggeeId(tab_id_)); |
299 args.Append(Value::CreateStringValue(method_name)); | 299 args.Append(Value::CreateStringValue(method_name)); |
300 Value* params_value; | 300 Value* params_value; |
301 if (dictionary->Get("params", ¶ms_value)) | 301 if (dictionary->Get("params", ¶ms_value)) |
302 args.Append(params_value->DeepCopy()); | 302 args.Append(params_value->DeepCopy()); |
303 | 303 |
304 std::string json_args; | 304 std::string json_args; |
305 base::JSONWriter::Write(&args, false, &json_args); | 305 base::JSONWriter::Write(&args, &json_args); |
306 | 306 |
307 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 307 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
308 extension_id_, keys::kOnEvent, json_args, profile, GURL()); | 308 extension_id_, keys::kOnEvent, json_args, profile, GURL()); |
309 } else { | 309 } else { |
310 SendCommandDebuggerFunction* function = pending_requests_[id]; | 310 SendCommandDebuggerFunction* function = pending_requests_[id]; |
311 if (!function) | 311 if (!function) |
312 return; | 312 return; |
313 | 313 |
314 function->SendResponseBody(dictionary); | 314 function->SendResponseBody(dictionary); |
315 pending_requests_.erase(id); | 315 pending_requests_.erase(id); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 params = NULL; | 475 params = NULL; |
476 | 476 |
477 client_host_->SendMessageToBackend(this, method, params); | 477 client_host_->SendMessageToBackend(this, method, params); |
478 return true; | 478 return true; |
479 } | 479 } |
480 | 480 |
481 void SendCommandDebuggerFunction::SendResponseBody( | 481 void SendCommandDebuggerFunction::SendResponseBody( |
482 DictionaryValue* dictionary) { | 482 DictionaryValue* dictionary) { |
483 Value* error_body; | 483 Value* error_body; |
484 if (dictionary->Get("error", &error_body)) { | 484 if (dictionary->Get("error", &error_body)) { |
485 base::JSONWriter::Write(error_body, false, &error_); | 485 base::JSONWriter::Write(error_body, &error_); |
486 SendResponse(false); | 486 SendResponse(false); |
487 return; | 487 return; |
488 } | 488 } |
489 | 489 |
490 Value* result_body; | 490 Value* result_body; |
491 if (dictionary->Get("result", &result_body)) | 491 if (dictionary->Get("result", &result_body)) |
492 result_.reset(result_body->DeepCopy()); | 492 result_.reset(result_body->DeepCopy()); |
493 else | 493 else |
494 result_.reset(new DictionaryValue()); | 494 result_.reset(new DictionaryValue()); |
495 SendResponse(true); | 495 SendResponse(true); |
496 } | 496 } |
OLD | NEW |