MSE: Reduce spurious buffered range discontinuities
[chromium-blink-merge.git] / android_webview / browser / aw_dev_tools_manager_delegate.cc
blob6e9f0ce0fa47cea0646ca71496991ff273932990
1 // Copyright 2014 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.
5 #include "android_webview/browser/aw_dev_tools_manager_delegate.h"
7 #include "android_webview/native/aw_contents.h"
8 #include "base/bind.h"
9 #include "base/json/json_writer.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/devtools_target.h"
15 #include "content/public/browser/web_contents.h"
17 using content::DevToolsAgentHost;
18 using content::RenderViewHost;
19 using content::WebContents;
21 namespace {
23 const char kTargetTypePage[] = "page";
24 const char kTargetTypeServiceWorker[] = "service_worker";
25 const char kTargetTypeOther[] = "other";
27 std::string GetViewDescription(WebContents* web_contents);
29 class Target : public content::DevToolsTarget {
30 public:
31 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
33 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
34 virtual std::string GetParentId() const OVERRIDE { return std::string(); }
35 virtual std::string GetType() const OVERRIDE {
36 switch (agent_host_->GetType()) {
37 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
38 return kTargetTypePage;
39 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
40 return kTargetTypeServiceWorker;
41 default:
42 break;
44 return kTargetTypeOther;
46 virtual std::string GetTitle() const OVERRIDE {
47 return agent_host_->GetTitle();
49 virtual std::string GetDescription() const OVERRIDE { return description_; }
50 virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); }
51 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); }
52 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
53 return last_activity_time_;
55 virtual bool IsAttached() const OVERRIDE {
56 return agent_host_->IsAttached();
58 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
59 return agent_host_;
61 virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); }
62 virtual bool Close() const OVERRIDE { return agent_host_->Close(); }
64 private:
65 scoped_refptr<DevToolsAgentHost> agent_host_;
66 std::string description_;
67 base::TimeTicks last_activity_time_;
70 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host)
71 : agent_host_(agent_host) {
72 if (WebContents* web_contents = agent_host->GetWebContents()) {
73 description_ = GetViewDescription(web_contents);
74 last_activity_time_ = web_contents->GetLastActiveTime();
78 std::string GetViewDescription(WebContents* web_contents) {
79 const android_webview::BrowserViewRenderer* bvr =
80 android_webview::AwContents::FromWebContents(web_contents)
81 ->GetBrowserViewRenderer();
82 if (!bvr) return "";
83 base::DictionaryValue description;
84 description.SetBoolean("attached", bvr->attached_to_window());
85 description.SetBoolean("visible", bvr->IsVisible());
86 gfx::Rect screen_rect = bvr->GetScreenRect();
87 description.SetInteger("screenX", screen_rect.x());
88 description.SetInteger("screenY", screen_rect.y());
89 description.SetBoolean("empty", screen_rect.size().IsEmpty());
90 if (!screen_rect.size().IsEmpty()) {
91 description.SetInteger("width", screen_rect.width());
92 description.SetInteger("height", screen_rect.height());
94 std::string json;
95 base::JSONWriter::Write(&description, &json);
96 return json;
99 } // namespace
101 namespace android_webview {
103 AwDevToolsManagerDelegate::AwDevToolsManagerDelegate() {
106 AwDevToolsManagerDelegate::~AwDevToolsManagerDelegate() {
109 base::DictionaryValue* AwDevToolsManagerDelegate::HandleCommand(
110 content::DevToolsAgentHost* agent_host,
111 base::DictionaryValue* command_dict) {
112 return NULL;
115 void AwDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
116 TargetList targets;
117 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
118 for (DevToolsAgentHost::List::iterator it = agents.begin();
119 it != agents.end(); ++it) {
120 targets.push_back(new Target(*it));
122 callback.Run(targets);
125 std::string AwDevToolsManagerDelegate::GetPageThumbnailData(const GURL&) {
126 return "";
129 scoped_ptr<content::DevToolsTarget> AwDevToolsManagerDelegate::CreateNewTarget(
130 const GURL&) {
131 return scoped_ptr<content::DevToolsTarget>();
134 } // namespace android_webview