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" | |
30 #include "chrome/browser/devtools/devtools_target_impl.h" | 29 #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" |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 // DebuggerGetTargetsFunction ------------------------------------------------- | 666 // DebuggerGetTargetsFunction ------------------------------------------------- |
668 | 667 |
669 namespace { | 668 namespace { |
670 | 669 |
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"; |
| 676 const char kTargetTypePage[] = "page"; |
| 677 const char kTargetTypeBackgroundPage[] = "background_page"; |
| 678 const char kTargetTypeWorker[] = "worker"; |
| 679 const char kTargetTypeOther[] = "other"; |
677 const char kTargetTabIdField[] = "tabId"; | 680 const char kTargetTabIdField[] = "tabId"; |
678 const char kTargetExtensionIdField[] = "extensionId"; | 681 const char kTargetExtensionIdField[] = "extensionId"; |
679 const char kTargetTypeWorker[] = "worker"; | |
680 | 682 |
681 base::Value* SerializeTarget(const DevToolsTargetImpl& target) { | 683 base::Value* SerializeTarget(const DevToolsTargetImpl& target) { |
682 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 684 base::DictionaryValue* dictionary = new base::DictionaryValue(); |
683 scoped_refptr<DevToolsAgentHost> host = target.GetAgentHost(); | |
684 dictionary->SetString(kTargetIdField, host->GetId()); | |
685 dictionary->SetString(kTargetTitleField, host->GetTitle()); | |
686 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached()); | |
687 dictionary->SetString(kTargetUrlField, host->GetURL().spec()); | |
688 | 685 |
689 std::string type = host->GetType(); | 686 dictionary->SetString(kTargetIdField, target.GetId()); |
690 if (type == DevToolsAgentHost::kTypePage) { | 687 dictionary->SetString(kTargetTitleField, target.GetTitle()); |
691 int tab_id = | 688 dictionary->SetBoolean(kTargetAttachedField, target.IsAttached()); |
692 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents()); | 689 dictionary->SetString(kTargetUrlField, target.GetURL().spec()); |
693 dictionary->SetInteger(kTargetTabIdField, tab_id); | 690 |
694 } else if (type == ChromeDevToolsManagerDelegate::kTypeBackgroundPage) { | 691 std::string type = target.GetType(); |
695 dictionary->SetString(kTargetExtensionIdField, host->GetURL().host()); | 692 if (type == kTargetTypePage) { |
| 693 dictionary->SetInteger(kTargetTabIdField, target.GetTabId()); |
| 694 } else if (type == kTargetTypeBackgroundPage) { |
| 695 dictionary->SetString(kTargetExtensionIdField, target.GetExtensionId()); |
| 696 } else if (type != kTargetTypeWorker) { |
| 697 // DevToolsTargetImpl may support more types than the debugger API. |
| 698 type = kTargetTypeOther; |
696 } | 699 } |
697 | |
698 if (type == DevToolsAgentHost::kTypeServiceWorker || | |
699 type == DevToolsAgentHost::kTypeSharedWorker) { | |
700 type = kTargetTypeWorker; | |
701 } | |
702 | |
703 dictionary->SetString(kTargetTypeField, type); | 700 dictionary->SetString(kTargetTypeField, type); |
704 | 701 |
705 GURL favicon_url = host->GetFaviconURL(); | 702 GURL favicon_url = target.GetFaviconURL(); |
706 if (favicon_url.is_valid()) | 703 if (favicon_url.is_valid()) |
707 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 704 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); |
708 | 705 |
709 return dictionary; | 706 return dictionary; |
710 } | 707 } |
711 | 708 |
712 } // namespace | 709 } // namespace |
713 | 710 |
714 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { | 711 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { |
715 } | 712 } |
(...skipping 14 matching lines...) Expand all Loading... |
730 const std::vector<DevToolsTargetImpl*>& target_list) { | 727 const std::vector<DevToolsTargetImpl*>& target_list) { |
731 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 728 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
732 for (size_t i = 0; i < target_list.size(); ++i) | 729 for (size_t i = 0; i < target_list.size(); ++i) |
733 result->Append(SerializeTarget(*target_list[i])); | 730 result->Append(SerializeTarget(*target_list[i])); |
734 base::STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 731 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 |