| 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 |
| 43 } // namespace | 62 } // namespace |
| 44 | 63 |
| 45 namespace android_webview { | 64 namespace android_webview { |
| 46 | 65 |
| 47 // static | 66 // static |
| 48 void AwDevToolsDiscoveryProvider::Install() { | 67 void AwDevToolsDiscoveryProvider::Install() { |
| 49 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 68 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = |
| 50 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 69 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); |
| 51 discovery_manager->AddProvider( | 70 discovery_manager->AddProvider( |
| 52 base::WrapUnique(new AwDevToolsDiscoveryProvider())); | 71 base::WrapUnique(new AwDevToolsDiscoveryProvider())); |
| 53 } | 72 } |
| 54 | 73 |
| 55 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { | 74 AwDevToolsDiscoveryProvider::AwDevToolsDiscoveryProvider() { |
| 56 } | 75 } |
| 57 | 76 |
| 58 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { | 77 AwDevToolsDiscoveryProvider::~AwDevToolsDiscoveryProvider() { |
| 59 } | 78 } |
| 60 | 79 |
| 61 devtools_discovery::DevToolsTargetDescriptor::List | 80 devtools_discovery::DevToolsTargetDescriptor::List |
| 62 AwDevToolsDiscoveryProvider::GetDescriptors() { | 81 AwDevToolsDiscoveryProvider::GetDescriptors() { |
| 63 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); | 82 DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll(); |
| 64 devtools_discovery::DevToolsTargetDescriptor::List result; | 83 devtools_discovery::DevToolsTargetDescriptor::List result; |
| 65 result.reserve(agent_hosts.size()); | 84 result.reserve(agent_hosts.size()); |
| 66 for (auto& agent_host : agent_hosts) { | 85 for (const auto& agent_host : agent_hosts) |
| 67 agent_host->SetDescriptionOverride( | 86 result.push_back(new TargetDescriptor(agent_host)); |
| 68 GetViewDescription(agent_host->GetWebContents())); | |
| 69 result.push_back(new devtools_discovery::BasicTargetDescriptor(agent_host)); | |
| 70 } | |
| 71 return result; | 87 return result; |
| 72 } | 88 } |
| 73 | 89 |
| 74 } // namespace android_webview | 90 } // namespace android_webview |
| OLD | NEW |