OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/browser/aw_dev_tools_discovery_provider.h" | |
6 | |
7 #include "android_webview/browser/browser_view_renderer.h" | |
8 #include "base/json/json_writer.h" | |
9 #include "base/memory/ptr_util.h" | |
10 #include "base/strings/stringprintf.h" | |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "base/values.h" | |
13 #include "content/public/browser/devtools_agent_host.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 | |
16 using content::DevToolsAgentHost; | |
17 using content::WebContents; | |
18 | |
19 namespace { | |
20 | |
21 std::string GetViewDescription(WebContents* web_contents) { | |
22 android_webview::BrowserViewRenderer* bvr = | |
23 android_webview::BrowserViewRenderer::FromWebContents(web_contents); | |
24 if (!bvr) return ""; | |
25 base::DictionaryValue description; | |
26 description.SetBoolean("attached", bvr->attached_to_window()); | |
27 description.SetBoolean("visible", bvr->IsVisible()); | |
28 gfx::Rect screen_rect = bvr->GetScreenRect(); | |
29 description.SetInteger("screenX", screen_rect.x()); | |
30 description.SetInteger("screenY", screen_rect.y()); | |
31 description.SetBoolean("empty", screen_rect.size().IsEmpty()); | |
32 if (!screen_rect.size().IsEmpty()) { | |
33 description.SetInteger("width", screen_rect.width()); | |
34 description.SetInteger("height", screen_rect.height()); | |
35 } | |
36 std::string json; | |
37 base::JSONWriter::Write(description, &json); | |
38 return json; | |
39 } | |
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 | |
50 } // namespace | |
51 | |
52 namespace android_webview { | |
53 | |
54 // static | |
55 void AwDevToolsDiscoveryProvider::Install() { | |
56 content::DevToolsAgentHost::AddDiscoveryProvider(base::Bind(&GetDescriptors)); | |
57 } | |
58 | |
59 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { | |
60 } | |
61 | |
62 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { | |
63 } | |
64 | |
65 } // namespace android_webview | |
OLD | NEW |