| 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 <stddef.h> | 9 #include <stddef.h> |
| 10 |
| 10 #include <map> | 11 #include <map> |
| 12 #include <memory> |
| 11 #include <set> | 13 #include <set> |
| 12 #include <utility> | 14 #include <utility> |
| 13 | 15 |
| 14 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
| 15 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 16 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
| 17 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
| 18 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 19 #include "base/macros.h" | 21 #include "base/macros.h" |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/memory/singleton.h" | 22 #include "base/memory/singleton.h" |
| 22 #include "base/scoped_observer.h" | 23 #include "base/scoped_observer.h" |
| 23 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/devtools/devtools_target_impl.h" | 29 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 29 #include "chrome/browser/devtools/global_confirm_info_bar.h" | 30 #include "chrome/browser/devtools/global_confirm_info_bar.h" |
| 30 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 31 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return infobar; | 206 return infobar; |
| 206 } | 207 } |
| 207 | 208 |
| 208 ExtensionDevToolsInfoBar::ExtensionDevToolsInfoBar( | 209 ExtensionDevToolsInfoBar::ExtensionDevToolsInfoBar( |
| 209 const std::string& extension_id, | 210 const std::string& extension_id, |
| 210 const std::string& extension_name) | 211 const std::string& extension_name) |
| 211 : extension_id_(extension_id) { | 212 : extension_id_(extension_id) { |
| 212 g_extension_info_bars.Get()[extension_id] = this; | 213 g_extension_info_bars.Get()[extension_id] = this; |
| 213 | 214 |
| 214 // This class closes the |infobar_|, so it's safe to pass Unretained(this). | 215 // This class closes the |infobar_|, so it's safe to pass Unretained(this). |
| 215 scoped_ptr<ExtensionDevToolsInfoBarDelegate> delegate( | 216 std::unique_ptr<ExtensionDevToolsInfoBarDelegate> delegate( |
| 216 new ExtensionDevToolsInfoBarDelegate( | 217 new ExtensionDevToolsInfoBarDelegate( |
| 217 base::Bind(&ExtensionDevToolsInfoBar::InfoBarDismissed, | 218 base::Bind(&ExtensionDevToolsInfoBar::InfoBarDismissed, |
| 218 base::Unretained(this)), | 219 base::Unretained(this)), |
| 219 extension_name)); | 220 extension_name)); |
| 220 infobar_ = GlobalConfirmInfoBar::Show(std::move(delegate)); | 221 infobar_ = GlobalConfirmInfoBar::Show(std::move(delegate)); |
| 221 } | 222 } |
| 222 | 223 |
| 223 ExtensionDevToolsInfoBar::~ExtensionDevToolsInfoBar() { | 224 ExtensionDevToolsInfoBar::~ExtensionDevToolsInfoBar() { |
| 224 g_extension_info_bars.Get().erase(extension_id_); | 225 g_extension_info_bars.Get().erase(extension_id_); |
| 225 if (infobar_) | 226 if (infobar_) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void ExtensionDevToolsClientHost::InfoBarDismissed() { | 393 void ExtensionDevToolsClientHost::InfoBarDismissed() { |
| 393 detach_reason_ = api::debugger::DETACH_REASON_CANCELED_BY_USER; | 394 detach_reason_ = api::debugger::DETACH_REASON_CANCELED_BY_USER; |
| 394 SendDetachedEvent(); | 395 SendDetachedEvent(); |
| 395 Close(); | 396 Close(); |
| 396 } | 397 } |
| 397 | 398 |
| 398 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 399 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
| 399 if (!EventRouter::Get(profile_)) | 400 if (!EventRouter::Get(profile_)) |
| 400 return; | 401 return; |
| 401 | 402 |
| 402 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee_, | 403 std::unique_ptr<base::ListValue> args( |
| 403 detach_reason_)); | 404 OnDetach::Create(debuggee_, detach_reason_)); |
| 404 scoped_ptr<Event> event(new Event(events::DEBUGGER_ON_DETACH, | 405 std::unique_ptr<Event> event(new Event( |
| 405 OnDetach::kEventName, std::move(args))); | 406 events::DEBUGGER_ON_DETACH, OnDetach::kEventName, std::move(args))); |
| 406 event->restrict_to_browser_context = profile_; | 407 event->restrict_to_browser_context = profile_; |
| 407 EventRouter::Get(profile_) | 408 EventRouter::Get(profile_) |
| 408 ->DispatchEventToExtension(extension_id_, std::move(event)); | 409 ->DispatchEventToExtension(extension_id_, std::move(event)); |
| 409 } | 410 } |
| 410 | 411 |
| 411 void ExtensionDevToolsClientHost::OnExtensionUnloaded( | 412 void ExtensionDevToolsClientHost::OnExtensionUnloaded( |
| 412 content::BrowserContext* browser_context, | 413 content::BrowserContext* browser_context, |
| 413 const Extension* extension, | 414 const Extension* extension, |
| 414 UnloadedExtensionInfo::Reason reason) { | 415 UnloadedExtensionInfo::Reason reason) { |
| 415 if (extension->id() == extension_id_) | 416 if (extension->id() == extension_id_) |
| 416 Close(); | 417 Close(); |
| 417 } | 418 } |
| 418 | 419 |
| 419 void ExtensionDevToolsClientHost::Observe( | 420 void ExtensionDevToolsClientHost::Observe( |
| 420 int type, | 421 int type, |
| 421 const content::NotificationSource& source, | 422 const content::NotificationSource& source, |
| 422 const content::NotificationDetails& details) { | 423 const content::NotificationDetails& details) { |
| 423 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); | 424 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); |
| 424 Close(); | 425 Close(); |
| 425 } | 426 } |
| 426 | 427 |
| 427 void ExtensionDevToolsClientHost::DispatchProtocolMessage( | 428 void ExtensionDevToolsClientHost::DispatchProtocolMessage( |
| 428 DevToolsAgentHost* agent_host, const std::string& message) { | 429 DevToolsAgentHost* agent_host, const std::string& message) { |
| 429 DCHECK(agent_host == agent_host_.get()); | 430 DCHECK(agent_host == agent_host_.get()); |
| 430 if (!EventRouter::Get(profile_)) | 431 if (!EventRouter::Get(profile_)) |
| 431 return; | 432 return; |
| 432 | 433 |
| 433 scoped_ptr<base::Value> result = base::JSONReader::Read(message); | 434 std::unique_ptr<base::Value> result = base::JSONReader::Read(message); |
| 434 if (!result->IsType(base::Value::TYPE_DICTIONARY)) | 435 if (!result->IsType(base::Value::TYPE_DICTIONARY)) |
| 435 return; | 436 return; |
| 436 base::DictionaryValue* dictionary = | 437 base::DictionaryValue* dictionary = |
| 437 static_cast<base::DictionaryValue*>(result.get()); | 438 static_cast<base::DictionaryValue*>(result.get()); |
| 438 | 439 |
| 439 int id; | 440 int id; |
| 440 if (!dictionary->GetInteger("id", &id)) { | 441 if (!dictionary->GetInteger("id", &id)) { |
| 441 std::string method_name; | 442 std::string method_name; |
| 442 if (!dictionary->GetString("method", &method_name)) | 443 if (!dictionary->GetString("method", &method_name)) |
| 443 return; | 444 return; |
| 444 | 445 |
| 445 OnEvent::Params params; | 446 OnEvent::Params params; |
| 446 base::DictionaryValue* params_value; | 447 base::DictionaryValue* params_value; |
| 447 if (dictionary->GetDictionary("params", ¶ms_value)) | 448 if (dictionary->GetDictionary("params", ¶ms_value)) |
| 448 params.additional_properties.Swap(params_value); | 449 params.additional_properties.Swap(params_value); |
| 449 | 450 |
| 450 scoped_ptr<base::ListValue> args( | 451 std::unique_ptr<base::ListValue> args( |
| 451 OnEvent::Create(debuggee_, method_name, params)); | 452 OnEvent::Create(debuggee_, method_name, params)); |
| 452 scoped_ptr<Event> event(new Event(events::DEBUGGER_ON_EVENT, | 453 std::unique_ptr<Event> event(new Event( |
| 453 OnEvent::kEventName, std::move(args))); | 454 events::DEBUGGER_ON_EVENT, OnEvent::kEventName, std::move(args))); |
| 454 event->restrict_to_browser_context = profile_; | 455 event->restrict_to_browser_context = profile_; |
| 455 EventRouter::Get(profile_) | 456 EventRouter::Get(profile_) |
| 456 ->DispatchEventToExtension(extension_id_, std::move(event)); | 457 ->DispatchEventToExtension(extension_id_, std::move(event)); |
| 457 } else { | 458 } else { |
| 458 DebuggerSendCommandFunction* function = pending_requests_[id].get(); | 459 DebuggerSendCommandFunction* function = pending_requests_[id].get(); |
| 459 if (!function) | 460 if (!function) |
| 460 return; | 461 return; |
| 461 | 462 |
| 462 function->SendResponseBody(dictionary); | 463 function->SendResponseBody(dictionary); |
| 463 pending_requests_.erase(id); | 464 pending_requests_.erase(id); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 565 |
| 565 // DebuggerAttachFunction ----------------------------------------------------- | 566 // DebuggerAttachFunction ----------------------------------------------------- |
| 566 | 567 |
| 567 DebuggerAttachFunction::DebuggerAttachFunction() { | 568 DebuggerAttachFunction::DebuggerAttachFunction() { |
| 568 } | 569 } |
| 569 | 570 |
| 570 DebuggerAttachFunction::~DebuggerAttachFunction() { | 571 DebuggerAttachFunction::~DebuggerAttachFunction() { |
| 571 } | 572 } |
| 572 | 573 |
| 573 bool DebuggerAttachFunction::RunAsync() { | 574 bool DebuggerAttachFunction::RunAsync() { |
| 574 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); | 575 std::unique_ptr<Attach::Params> params(Attach::Params::Create(*args_)); |
| 575 EXTENSION_FUNCTION_VALIDATE(params.get()); | 576 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 576 | 577 |
| 577 CopyDebuggee(&debuggee_, params->target); | 578 CopyDebuggee(&debuggee_, params->target); |
| 578 if (!InitAgentHost()) | 579 if (!InitAgentHost()) |
| 579 return false; | 580 return false; |
| 580 | 581 |
| 581 if (!DevToolsAgentHost::IsSupportedProtocolVersion( | 582 if (!DevToolsAgentHost::IsSupportedProtocolVersion( |
| 582 params->required_version)) { | 583 params->required_version)) { |
| 583 error_ = ErrorUtils::FormatErrorMessage( | 584 error_ = ErrorUtils::FormatErrorMessage( |
| 584 keys::kProtocolVersionNotSupportedError, | 585 keys::kProtocolVersionNotSupportedError, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 601 | 602 |
| 602 // DebuggerDetachFunction ----------------------------------------------------- | 603 // DebuggerDetachFunction ----------------------------------------------------- |
| 603 | 604 |
| 604 DebuggerDetachFunction::DebuggerDetachFunction() { | 605 DebuggerDetachFunction::DebuggerDetachFunction() { |
| 605 } | 606 } |
| 606 | 607 |
| 607 DebuggerDetachFunction::~DebuggerDetachFunction() { | 608 DebuggerDetachFunction::~DebuggerDetachFunction() { |
| 608 } | 609 } |
| 609 | 610 |
| 610 bool DebuggerDetachFunction::RunAsync() { | 611 bool DebuggerDetachFunction::RunAsync() { |
| 611 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); | 612 std::unique_ptr<Detach::Params> params(Detach::Params::Create(*args_)); |
| 612 EXTENSION_FUNCTION_VALIDATE(params.get()); | 613 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 613 | 614 |
| 614 CopyDebuggee(&debuggee_, params->target); | 615 CopyDebuggee(&debuggee_, params->target); |
| 615 if (!InitClientHost()) | 616 if (!InitClientHost()) |
| 616 return false; | 617 return false; |
| 617 | 618 |
| 618 client_host_->Close(); | 619 client_host_->Close(); |
| 619 SendResponse(true); | 620 SendResponse(true); |
| 620 return true; | 621 return true; |
| 621 } | 622 } |
| 622 | 623 |
| 623 | 624 |
| 624 // DebuggerSendCommandFunction ------------------------------------------------ | 625 // DebuggerSendCommandFunction ------------------------------------------------ |
| 625 | 626 |
| 626 DebuggerSendCommandFunction::DebuggerSendCommandFunction() { | 627 DebuggerSendCommandFunction::DebuggerSendCommandFunction() { |
| 627 } | 628 } |
| 628 | 629 |
| 629 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() { | 630 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() { |
| 630 } | 631 } |
| 631 | 632 |
| 632 bool DebuggerSendCommandFunction::RunAsync() { | 633 bool DebuggerSendCommandFunction::RunAsync() { |
| 633 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); | 634 std::unique_ptr<SendCommand::Params> params( |
| 635 SendCommand::Params::Create(*args_)); |
| 634 EXTENSION_FUNCTION_VALIDATE(params.get()); | 636 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 635 | 637 |
| 636 CopyDebuggee(&debuggee_, params->target); | 638 CopyDebuggee(&debuggee_, params->target); |
| 637 if (!InitClientHost()) | 639 if (!InitClientHost()) |
| 638 return false; | 640 return false; |
| 639 | 641 |
| 640 client_host_->SendMessageToBackend(this, params->method, | 642 client_host_->SendMessageToBackend(this, params->method, |
| 641 params->command_params.get()); | 643 params->command_params.get()); |
| 642 return true; | 644 return true; |
| 643 } | 645 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 std::vector<DevToolsTargetImpl*> list = DevToolsTargetImpl::EnumerateAll(); | 718 std::vector<DevToolsTargetImpl*> list = DevToolsTargetImpl::EnumerateAll(); |
| 717 content::BrowserThread::PostTask( | 719 content::BrowserThread::PostTask( |
| 718 content::BrowserThread::UI, | 720 content::BrowserThread::UI, |
| 719 FROM_HERE, | 721 FROM_HERE, |
| 720 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list)); | 722 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list)); |
| 721 return true; | 723 return true; |
| 722 } | 724 } |
| 723 | 725 |
| 724 void DebuggerGetTargetsFunction::SendTargetList( | 726 void DebuggerGetTargetsFunction::SendTargetList( |
| 725 const std::vector<DevToolsTargetImpl*>& target_list) { | 727 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 726 scoped_ptr<base::ListValue> result(new base::ListValue()); | 728 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
| 727 for (size_t i = 0; i < target_list.size(); ++i) | 729 for (size_t i = 0; i < target_list.size(); ++i) |
| 728 result->Append(SerializeTarget(*target_list[i])); | 730 result->Append(SerializeTarget(*target_list[i])); |
| 729 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 731 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 730 SetResult(result.release()); | 732 SetResult(result.release()); |
| 731 SendResponse(true); | 733 SendResponse(true); |
| 732 } | 734 } |
| 733 | 735 |
| 734 } // namespace extensions | 736 } // namespace extensions |
| OLD | NEW |