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 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <set> | 13 #include <set> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
19 #include "base/json/json_writer.h" | 19 #include "base/json/json_writer.h" |
20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/memory/singleton.h" | 22 #include "base/memory/singleton.h" |
23 #include "base/scoped_observer.h" | 23 #include "base/scoped_observer.h" |
24 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
25 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" | 29 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
30 #include "chrome/browser/devtools/devtools_target_impl.h" | |
31 #include "chrome/browser/devtools/global_confirm_info_bar.h" | 30 #include "chrome/browser/devtools/global_confirm_info_bar.h" |
32 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 31 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
33 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
34 #include "chrome/browser/extensions/extension_tab_util.h" | 33 #include "chrome/browser/extensions/extension_tab_util.h" |
35 #include "chrome/browser/infobars/infobar_service.h" | 34 #include "chrome/browser/infobars/infobar_service.h" |
36 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
38 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 37 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
39 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 const char kTargetIdField[] = "id"; | 670 const char kTargetIdField[] = "id"; |
672 const char kTargetTypeField[] = "type"; | 671 const char kTargetTypeField[] = "type"; |
673 const char kTargetTitleField[] = "title"; | 672 const char kTargetTitleField[] = "title"; |
674 const char kTargetAttachedField[] = "attached"; | 673 const char kTargetAttachedField[] = "attached"; |
675 const char kTargetUrlField[] = "url"; | 674 const char kTargetUrlField[] = "url"; |
676 const char kTargetFaviconUrlField[] = "faviconUrl"; | 675 const char kTargetFaviconUrlField[] = "faviconUrl"; |
677 const char kTargetTabIdField[] = "tabId"; | 676 const char kTargetTabIdField[] = "tabId"; |
678 const char kTargetExtensionIdField[] = "extensionId"; | 677 const char kTargetExtensionIdField[] = "extensionId"; |
679 const char kTargetTypeWorker[] = "worker"; | 678 const char kTargetTypeWorker[] = "worker"; |
680 | 679 |
681 base::Value* SerializeTarget(const DevToolsTargetImpl& target) { | 680 base::Value* SerializeTarget(scoped_refptr<DevToolsAgentHost> host) { |
682 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 681 base::DictionaryValue* dictionary = new base::DictionaryValue(); |
683 scoped_refptr<DevToolsAgentHost> host = target.GetAgentHost(); | |
684 dictionary->SetString(kTargetIdField, host->GetId()); | 682 dictionary->SetString(kTargetIdField, host->GetId()); |
685 dictionary->SetString(kTargetTitleField, host->GetTitle()); | 683 dictionary->SetString(kTargetTitleField, host->GetTitle()); |
686 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached()); | 684 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached()); |
687 dictionary->SetString(kTargetUrlField, host->GetURL().spec()); | 685 dictionary->SetString(kTargetUrlField, host->GetURL().spec()); |
688 | 686 |
689 std::string type = host->GetType(); | 687 std::string type = host->GetType(); |
690 if (type == DevToolsAgentHost::kTypePage) { | 688 if (type == DevToolsAgentHost::kTypePage) { |
691 int tab_id = | 689 int tab_id = |
692 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents()); | 690 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents()); |
693 dictionary->SetInteger(kTargetTabIdField, tab_id); | 691 dictionary->SetInteger(kTargetTabIdField, tab_id); |
(...skipping 17 matching lines...) Expand all Loading... |
711 | 709 |
712 } // namespace | 710 } // namespace |
713 | 711 |
714 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { | 712 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { |
715 } | 713 } |
716 | 714 |
717 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() { | 715 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() { |
718 } | 716 } |
719 | 717 |
720 bool DebuggerGetTargetsFunction::RunAsync() { | 718 bool DebuggerGetTargetsFunction::RunAsync() { |
721 std::vector<DevToolsTargetImpl*> list = DevToolsTargetImpl::EnumerateAll(); | 719 content::DevToolsAgentHost::List list = DevToolsAgentHost::GetOrCreateAll(); |
722 content::BrowserThread::PostTask( | 720 content::BrowserThread::PostTask( |
723 content::BrowserThread::UI, | 721 content::BrowserThread::UI, |
724 FROM_HERE, | 722 FROM_HERE, |
725 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list)); | 723 base::Bind(&DebuggerGetTargetsFunction::SendTargetList, this, list)); |
726 return true; | 724 return true; |
727 } | 725 } |
728 | 726 |
729 void DebuggerGetTargetsFunction::SendTargetList( | 727 void DebuggerGetTargetsFunction::SendTargetList( |
730 const std::vector<DevToolsTargetImpl*>& target_list) { | 728 const content::DevToolsAgentHost::List& target_list) { |
731 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 729 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
732 for (size_t i = 0; i < target_list.size(); ++i) | 730 for (size_t i = 0; i < target_list.size(); ++i) |
733 result->Append(SerializeTarget(*target_list[i])); | 731 result->Append(SerializeTarget(target_list[i])); |
734 base::STLDeleteContainerPointers(target_list.begin(), target_list.end()); | |
735 SetResult(std::move(result)); | 732 SetResult(std::move(result)); |
736 SendResponse(true); | 733 SendResponse(true); |
737 } | 734 } |
738 | 735 |
739 } // namespace extensions | 736 } // namespace extensions |
OLD | NEW |