OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "android_webview/browser/aw_dev_tools_discovery_provider.h" | 5 #include "android_webview/browser/aw_dev_tools_discovery_provider.h" |
6 | 6 |
7 #include "android_webview/browser/browser_view_renderer.h" | 7 #include "android_webview/browser/browser_view_renderer.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 description.SetBoolean("empty", screen_rect.size().IsEmpty()); | 33 description.SetBoolean("empty", screen_rect.size().IsEmpty()); |
34 if (!screen_rect.size().IsEmpty()) { | 34 if (!screen_rect.size().IsEmpty()) { |
35 description.SetInteger("width", screen_rect.width()); | 35 description.SetInteger("width", screen_rect.width()); |
36 description.SetInteger("height", screen_rect.height()); | 36 description.SetInteger("height", screen_rect.height()); |
37 } | 37 } |
38 std::string json; | 38 std::string json; |
39 base::JSONWriter::Write(description, &json); | 39 base::JSONWriter::Write(description, &json); |
40 return json; | 40 return json; |
41 } | 41 } |
42 | 42 |
43 class TargetDescriptor : public devtools_discovery::BasicTargetDescriptor { | |
44 public: | |
45 explicit TargetDescriptor(scoped_refptr<DevToolsAgentHost> agent_host); | |
46 | |
47 // devtools_discovery::BasicTargetDescriptor overrides. | |
48 std::string GetDescription() const override { return description_; } | |
49 | |
50 private: | |
51 std::string description_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(TargetDescriptor); | |
54 }; | |
55 | |
56 TargetDescriptor::TargetDescriptor(scoped_refptr<DevToolsAgentHost> agent_host) | |
57 : BasicTargetDescriptor(agent_host) { | |
58 if (WebContents* web_contents = agent_host->GetWebContents()) | |
59 description_ = GetViewDescription(web_contents); | |
60 } | |
61 | |
62 } // namespace | 43 } // namespace |
63 | 44 |
64 namespace android_webview { | 45 namespace android_webview { |
65 | 46 |
66 // static | 47 // static |
67 void AwDevToolsDiscoveryProvider::Install() { | 48 void AwDevToolsDiscoveryProvider::Install() { |
68 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 49 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = |
69 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 50 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); |
70 discovery_manager->AddProvider( | 51 discovery_manager->AddProvider( |
71 base::WrapUnique(new AwDevToolsDiscoveryProvider())); | 52 base::WrapUnique(new AwDevToolsDiscoveryProvider())); |
72 } | 53 } |
73 | 54 |
74 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { | 55 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { |
75 } | 56 } |
76 | 57 |
77 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { | 58 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { |
78 } | 59 } |
79 | 60 |
80 devtools_discovery::DevToolsTargetDescriptor::List | 61 devtools_discovery::DevToolsTargetDescriptor::List |
81 AwDevToolsDiscoveryProvider::GetDescriptors() { | 62 AwDevToolsDiscoveryProvider::GetDescriptors() { |
82 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); | 63 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); |
83 devtools_discovery::DevToolsTargetDescriptor::List result; | 64 devtools_discovery::DevToolsTargetDescriptor::List result; |
84 result.reserve(agent_hosts.size()); | 65 result.reserve(agent_hosts.size()); |
85 for (const auto& agent_host : agent_hosts) | 66 for (auto& agent_host : agent_hosts) { |
86 result.push_back(new TargetDescriptor(agent_host)); | 67 agent_host->SetDescriptionOverride( |
| 68 GetViewDescription(agent_host->GetWebContents())); |
| 69 result.push_back(new devtools_discovery::BasicTargetDescriptor(agent_host)); |
| 70 } |
87 return result; | 71 return result; |
88 } | 72 } |
89 | 73 |
90 } // namespace android_webview | 74 } // namespace android_webview |
OLD | NEW |