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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/devtools_discovery/devtools_discovery_manager.h" | |
14 #include "content/public/browser/devtools_agent_host.h" | 13 #include "content/public/browser/devtools_agent_host.h" |
15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
16 | 15 |
17 using content::DevToolsAgentHost; | 16 using content::DevToolsAgentHost; |
18 using content::WebContents; | 17 using content::WebContents; |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 std::string GetViewDescription(WebContents* web_contents) { | 21 std::string GetViewDescription(WebContents* web_contents) { |
23 android_webview::BrowserViewRenderer* bvr = | 22 android_webview::BrowserViewRenderer* bvr = |
24 android_webview::BrowserViewRenderer::FromWebContents(web_contents); | 23 android_webview::BrowserViewRenderer::FromWebContents(web_contents); |
25 if (!bvr) return ""; | 24 if (!bvr) return ""; |
26 base::DictionaryValue description; | 25 base::DictionaryValue description; |
27 description.SetBoolean("attached", bvr->attached_to_window()); | 26 description.SetBoolean("attached", bvr->attached_to_window()); |
28 description.SetBoolean("visible", bvr->IsVisible()); | 27 description.SetBoolean("visible", bvr->IsVisible()); |
29 gfx::Rect screen_rect = bvr->GetScreenRect(); | 28 gfx::Rect screen_rect = bvr->GetScreenRect(); |
30 description.SetInteger("screenX", screen_rect.x()); | 29 description.SetInteger("screenX", screen_rect.x()); |
31 description.SetInteger("screenY", screen_rect.y()); | 30 description.SetInteger("screenY", screen_rect.y()); |
32 description.SetBoolean("empty", screen_rect.size().IsEmpty()); | 31 description.SetBoolean("empty", screen_rect.size().IsEmpty()); |
33 if (!screen_rect.size().IsEmpty()) { | 32 if (!screen_rect.size().IsEmpty()) { |
34 description.SetInteger("width", screen_rect.width()); | 33 description.SetInteger("width", screen_rect.width()); |
35 description.SetInteger("height", screen_rect.height()); | 34 description.SetInteger("height", screen_rect.height()); |
36 } | 35 } |
37 std::string json; | 36 std::string json; |
38 base::JSONWriter::Write(description, &json); | 37 base::JSONWriter::Write(description, &json); |
39 return json; | 38 return json; |
40 } | 39 } |
41 | 40 |
| 41 content::DevToolsAgentHost::List GetDescriptors() { |
| 42 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); |
| 43 for (auto& agent_host : agent_hosts) { |
| 44 agent_host->SetDescriptionOverride( |
| 45 GetViewDescription(agent_host->GetWebContents())); |
| 46 } |
| 47 return agent_hosts; |
| 48 } |
| 49 |
42 } // namespace | 50 } // namespace |
43 | 51 |
44 namespace android_webview { | 52 namespace android_webview { |
45 | 53 |
46 // static | 54 // static |
47 void AwDevToolsDiscoveryProvider::Install() { | 55 void AwDevToolsDiscoveryProvider::Install() { |
48 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 56 content::DevToolsAgentHost::AddDiscoveryProvider(base::Bind(&GetDescriptors)); |
49 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | |
50 discovery_manager->AddProvider( | |
51 base::WrapUnique(new AwDevToolsDiscoveryProvider())); | |
52 } | 57 } |
53 | 58 |
54 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { | 59 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { |
55 } | 60 } |
56 | 61 |
57 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { | 62 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { |
58 } | 63 } |
59 | 64 |
60 content::DevToolsAgentHost::List | |
61 AwDevToolsDiscoveryProvider::GetDescriptors() { | |
62 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); | |
63 for (auto& agent_host : agent_hosts) { | |
64 agent_host->SetDescriptionOverride( | |
65 GetViewDescription(agent_host->GetWebContents())); | |
66 } | |
67 return agent_hosts; | |
68 } | |
69 | |
70 } // namespace android_webview | 65 } // namespace android_webview |
OLD | NEW |