| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" | 5 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
| 11 #include "content/public/browser/devtools_target.h" | 11 #include "content/public/browser/devtools_target.h" |
| 12 #include "content/public/browser/favicon_status.h" | 12 #include "content/public/browser/favicon_status.h" |
| 13 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_delegate.h" | 16 #include "content/public/browser/web_contents_delegate.h" |
| 17 #include "grit/shell_resources.h" | 17 #include "grit/shell_resources.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 | 19 |
| 20 namespace chromecast { | 20 namespace chromecast { |
| 21 namespace shell { | 21 namespace shell { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kTargetTypePage[] = "page"; | 25 const char kTargetTypePage[] = "page"; |
| 26 const char kTargetTypeServiceWorker[] = "service_worker"; |
| 27 const char kTargetTypeOther[] = "other"; |
| 26 | 28 |
| 27 class Target : public content::DevToolsTarget { | 29 class Target : public content::DevToolsTarget { |
| 28 public: | 30 public: |
| 29 explicit Target(content::WebContents* web_contents); | 31 explicit Target(scoped_refptr<content::DevToolsAgentHost> agent_host); |
| 30 | 32 |
| 31 virtual std::string GetId() const OVERRIDE { return id_; } | 33 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } |
| 32 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 34 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
| 33 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 35 virtual std::string GetType() const OVERRIDE { |
| 34 virtual std::string GetTitle() const OVERRIDE { return title_; } | 36 switch (agent_host_->GetType()) { |
| 37 case content::DevToolsAgentHost::TYPE_WEB_CONTENTS: |
| 38 return kTargetTypePage; |
| 39 case content::DevToolsAgentHost::TYPE_SERVICE_WORKER: |
| 40 return kTargetTypeServiceWorker; |
| 41 default: |
| 42 break; |
| 43 } |
| 44 return kTargetTypeOther; |
| 45 } |
| 46 virtual std::string GetTitle() const OVERRIDE { |
| 47 return agent_host_->GetTitle(); |
| 48 } |
| 35 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 49 virtual std::string GetDescription() const OVERRIDE { return std::string(); } |
| 36 virtual GURL GetURL() const OVERRIDE { return url_; } | 50 virtual GURL GetURL() const OVERRIDE { return url_; } |
| 37 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 51 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } |
| 38 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 52 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
| 39 return last_activity_time_; | 53 return last_activity_time_; |
| 40 } | 54 } |
| 41 virtual bool IsAttached() const OVERRIDE { | 55 virtual bool IsAttached() const OVERRIDE { |
| 42 return agent_host_->IsAttached(); | 56 return agent_host_->IsAttached(); |
| 43 } | 57 } |
| 44 virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() | 58 virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() |
| 45 const OVERRIDE { | 59 const OVERRIDE { |
| 46 return agent_host_; | 60 return agent_host_; |
| 47 } | 61 } |
| 48 virtual bool Activate() const OVERRIDE; | 62 virtual bool Activate() const OVERRIDE; |
| 49 virtual bool Close() const OVERRIDE; | 63 virtual bool Close() const OVERRIDE; |
| 50 | 64 |
| 51 private: | 65 private: |
| 52 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 66 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
| 53 std::string id_; | 67 std::string id_; |
| 54 std::string title_; | 68 std::string title_; |
| 55 GURL url_; | 69 GURL url_; |
| 56 GURL favicon_url_; | 70 GURL favicon_url_; |
| 57 base::TimeTicks last_activity_time_; | 71 base::TimeTicks last_activity_time_; |
| 58 | 72 |
| 59 DISALLOW_COPY_AND_ASSIGN(Target); | 73 DISALLOW_COPY_AND_ASSIGN(Target); |
| 60 }; | 74 }; |
| 61 | 75 |
| 62 Target::Target(content::WebContents* web_contents) { | 76 Target::Target(scoped_refptr<content::DevToolsAgentHost> agent_host) |
| 63 agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents); | 77 : agent_host_(agent_host) { |
| 64 id_ = agent_host_->GetId(); | 78 if (content::WebContents* web_contents = agent_host_->GetWebContents()) { |
| 65 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 79 content::NavigationController& controller = web_contents->GetController(); |
| 66 url_ = web_contents->GetURL(); | 80 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 67 content::NavigationController& controller = web_contents->GetController(); | 81 if (entry != NULL && entry->GetURL().is_valid()) |
| 68 content::NavigationEntry* entry = controller.GetActiveEntry(); | 82 favicon_url_ = entry->GetFavicon().url; |
| 69 if (entry != NULL && entry->GetURL().is_valid()) | 83 last_activity_time_ = web_contents->GetLastActiveTime(); |
| 70 favicon_url_ = entry->GetFavicon().url; | 84 } |
| 71 last_activity_time_ = web_contents->GetLastActiveTime(); | |
| 72 } | 85 } |
| 73 | 86 |
| 74 bool Target::Activate() const { | 87 bool Target::Activate() const { |
| 75 content::WebContents* web_contents = agent_host_->GetWebContents(); | 88 content::WebContents* web_contents = agent_host_->GetWebContents(); |
| 76 if (!web_contents) | 89 if (!web_contents) |
| 77 return false; | 90 return false; |
| 78 web_contents->GetDelegate()->ActivateContents(web_contents); | 91 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 79 return true; | 92 return true; |
| 80 } | 93 } |
| 81 | 94 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return ""; | 135 return ""; |
| 123 } | 136 } |
| 124 | 137 |
| 125 scoped_ptr<content::DevToolsTarget> CastDevToolsDelegate::CreateNewTarget( | 138 scoped_ptr<content::DevToolsTarget> CastDevToolsDelegate::CreateNewTarget( |
| 126 const GURL& url) { | 139 const GURL& url) { |
| 127 return scoped_ptr<content::DevToolsTarget>(); | 140 return scoped_ptr<content::DevToolsTarget>(); |
| 128 } | 141 } |
| 129 | 142 |
| 130 void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | 143 void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) { |
| 131 TargetList targets; | 144 TargetList targets; |
| 132 std::vector<content::WebContents*> wc_list = | 145 content::DevToolsAgentHost::List agents = |
| 133 content::DevToolsAgentHost::GetInspectableWebContents(); | 146 content::DevToolsAgentHost::GetOrCreateAll(); |
| 134 for (std::vector<content::WebContents*>::iterator it = wc_list.begin(); | 147 for (content::DevToolsAgentHost::List::iterator it = agents.begin(); |
| 135 it != wc_list.end(); | 148 it != agents.end(); ++it) { |
| 136 ++it) { | |
| 137 targets.push_back(new Target(*it)); | 149 targets.push_back(new Target(*it)); |
| 138 } | 150 } |
| 139 callback.Run(targets); | 151 callback.Run(targets); |
| 140 } | 152 } |
| 141 | 153 |
| 142 scoped_ptr<net::StreamListenSocket> | 154 scoped_ptr<net::StreamListenSocket> |
| 143 CastDevToolsDelegate::CreateSocketForTethering( | 155 CastDevToolsDelegate::CreateSocketForTethering( |
| 144 net::StreamListenSocket::Delegate* delegate, | 156 net::StreamListenSocket::Delegate* delegate, |
| 145 std::string* name) { | 157 std::string* name) { |
| 146 return scoped_ptr<net::StreamListenSocket>(); | 158 return scoped_ptr<net::StreamListenSocket>(); |
| 147 } | 159 } |
| 148 | 160 |
| 149 } // namespace shell | 161 } // namespace shell |
| 150 } // namespace chromecast | 162 } // namespace chromecast |
| OLD | NEW |