| 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/devtools_target_impl.h" | 30 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 30 #include "chrome/browser/devtools/global_confirm_info_bar.h" | 31 #include "chrome/browser/devtools/global_confirm_info_bar.h" |
| 31 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 32 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
| 32 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/extensions/extension_tab_util.h" | 34 #include "chrome/browser/extensions/extension_tab_util.h" |
| 34 #include "chrome/browser/infobars/infobar_service.h" | 35 #include "chrome/browser/infobars/infobar_service.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 37 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 38 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // DebuggerGetTargetsFunction ------------------------------------------------- | 667 // DebuggerGetTargetsFunction ------------------------------------------------- |
| 667 | 668 |
| 668 namespace { | 669 namespace { |
| 669 | 670 |
| 670 const char kTargetIdField[] = "id"; | 671 const char kTargetIdField[] = "id"; |
| 671 const char kTargetTypeField[] = "type"; | 672 const char kTargetTypeField[] = "type"; |
| 672 const char kTargetTitleField[] = "title"; | 673 const char kTargetTitleField[] = "title"; |
| 673 const char kTargetAttachedField[] = "attached"; | 674 const char kTargetAttachedField[] = "attached"; |
| 674 const char kTargetUrlField[] = "url"; | 675 const char kTargetUrlField[] = "url"; |
| 675 const char kTargetFaviconUrlField[] = "faviconUrl"; | 676 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"; | |
| 680 const char kTargetTabIdField[] = "tabId"; | 677 const char kTargetTabIdField[] = "tabId"; |
| 681 const char kTargetExtensionIdField[] = "extensionId"; | 678 const char kTargetExtensionIdField[] = "extensionId"; |
| 682 | 679 |
| 683 base::Value* SerializeTarget(const DevToolsTargetImpl& target) { | 680 base::Value* SerializeTarget(const DevToolsTargetImpl& target) { |
| 684 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 681 base::DictionaryValue* dictionary = new base::DictionaryValue(); |
| 682 scoped_refptr<DevToolsAgentHost> host = target.GetAgentHost(); |
| 683 dictionary->SetString(kTargetIdField, host->GetId()); |
| 684 dictionary->SetString(kTargetTitleField, host->GetTitle()); |
| 685 dictionary->SetBoolean(kTargetAttachedField, host->IsAttached()); |
| 686 dictionary->SetString(kTargetUrlField, host->GetURL().spec()); |
| 685 | 687 |
| 686 dictionary->SetString(kTargetIdField, target.GetId()); | 688 std::string type = host->GetType(); |
| 687 dictionary->SetString(kTargetTitleField, target.GetTitle()); | 689 if (type == DevToolsAgentHost::kTypePage) { |
| 688 dictionary->SetBoolean(kTargetAttachedField, target.IsAttached()); | 690 int tab_id = |
| 689 dictionary->SetString(kTargetUrlField, target.GetURL().spec()); | 691 extensions::ExtensionTabUtil::GetTabId(host->GetWebContents()); |
| 690 | 692 dictionary->SetInteger(kTargetTabIdField, tab_id); |
| 691 std::string type = target.GetType(); | 693 } else if (type == ChromeDevToolsManagerDelegate::kTypeBackgroundPage) { |
| 692 if (type == kTargetTypePage) { | 694 dictionary->SetString(kTargetExtensionIdField, host->GetURL().host()); |
| 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; | |
| 699 } | 695 } |
| 700 dictionary->SetString(kTargetTypeField, type); | 696 dictionary->SetString(kTargetTypeField, type); |
| 701 | 697 |
| 702 GURL favicon_url = target.GetFaviconURL(); | 698 GURL favicon_url = host->GetFaviconURL(); |
| 703 if (favicon_url.is_valid()) | 699 if (favicon_url.is_valid()) |
| 704 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 700 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); |
| 705 | 701 |
| 706 return dictionary; | 702 return dictionary; |
| 707 } | 703 } |
| 708 | 704 |
| 709 } // namespace | 705 } // namespace |
| 710 | 706 |
| 711 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { | 707 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() { |
| 712 } | 708 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 727 const std::vector<DevToolsTargetImpl*>& target_list) { | 723 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 728 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 724 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
| 729 for (size_t i = 0; i < target_list.size(); ++i) | 725 for (size_t i = 0; i < target_list.size(); ++i) |
| 730 result->Append(SerializeTarget(*target_list[i])); | 726 result->Append(SerializeTarget(*target_list[i])); |
| 731 base::STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 727 base::STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 732 SetResult(std::move(result)); | 728 SetResult(std::move(result)); |
| 733 SendResponse(true); | 729 SendResponse(true); |
| 734 } | 730 } |
| 735 | 731 |
| 736 } // namespace extensions | 732 } // namespace extensions |
| OLD | NEW |