| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "content/public/browser/devtools_agent_host.h" | |
| 11 #include "content/public/browser/devtools_target.h" | |
| 12 #include "content/public/browser/favicon_status.h" | |
| 13 #include "content/public/browser/navigation_entry.h" | |
| 14 #include "content/public/browser/render_view_host.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/browser/web_contents_delegate.h" | |
| 17 #include "grit/shell_resources.h" | |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 | |
| 20 namespace chromecast { | |
| 21 namespace shell { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 const char kTargetTypePage[] = "page"; | |
| 26 const char kTargetTypeServiceWorker[] = "service_worker"; | |
| 27 const char kTargetTypeSharedWorker[] = "worker"; | |
| 28 const char kTargetTypeOther[] = "other"; | |
| 29 | |
| 30 class Target : public content::DevToolsTarget { | |
| 31 public: | |
| 32 explicit Target(scoped_refptr<content::DevToolsAgentHost> agent_host); | |
| 33 | |
| 34 virtual std::string GetId() const override { return agent_host_->GetId(); } | |
| 35 virtual std::string GetParentId() const override { return std::string(); } | |
| 36 virtual std::string GetType() const override { | |
| 37 switch (agent_host_->GetType()) { | |
| 38 case content::DevToolsAgentHost::TYPE_WEB_CONTENTS: | |
| 39 return kTargetTypePage; | |
| 40 case content::DevToolsAgentHost::TYPE_SERVICE_WORKER: | |
| 41 return kTargetTypeServiceWorker; | |
| 42 case content::DevToolsAgentHost::TYPE_SHARED_WORKER: | |
| 43 return kTargetTypeSharedWorker; | |
| 44 default: | |
| 45 break; | |
| 46 } | |
| 47 return kTargetTypeOther; | |
| 48 } | |
| 49 virtual std::string GetTitle() const override { | |
| 50 return agent_host_->GetTitle(); | |
| 51 } | |
| 52 virtual std::string GetDescription() const override { return std::string(); } | |
| 53 virtual GURL GetURL() const override { | |
| 54 return agent_host_->GetURL(); | |
| 55 } | |
| 56 virtual GURL GetFaviconURL() const override { return favicon_url_; } | |
| 57 virtual base::TimeTicks GetLastActivityTime() const override { | |
| 58 return last_activity_time_; | |
| 59 } | |
| 60 virtual bool IsAttached() const override { | |
| 61 return agent_host_->IsAttached(); | |
| 62 } | |
| 63 virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() | |
| 64 const override { | |
| 65 return agent_host_; | |
| 66 } | |
| 67 virtual bool Activate() const override { | |
| 68 return agent_host_->Activate(); | |
| 69 } | |
| 70 virtual bool Close() const override { | |
| 71 return agent_host_->Close(); | |
| 72 } | |
| 73 | |
| 74 private: | |
| 75 scoped_refptr<content::DevToolsAgentHost> agent_host_; | |
| 76 GURL favicon_url_; | |
| 77 base::TimeTicks last_activity_time_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(Target); | |
| 80 }; | |
| 81 | |
| 82 Target::Target(scoped_refptr<content::DevToolsAgentHost> agent_host) | |
| 83 : agent_host_(agent_host) { | |
| 84 if (content::WebContents* web_contents = agent_host_->GetWebContents()) { | |
| 85 content::NavigationController& controller = web_contents->GetController(); | |
| 86 content::NavigationEntry* entry = controller.GetActiveEntry(); | |
| 87 if (entry != NULL && entry->GetURL().is_valid()) | |
| 88 favicon_url_ = entry->GetFavicon().url; | |
| 89 last_activity_time_ = web_contents->GetLastActiveTime(); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 } // namespace | |
| 94 | |
| 95 // CastDevToolsDelegate ----------------------------------------------------- | |
| 96 | |
| 97 CastDevToolsDelegate::CastDevToolsDelegate() { | |
| 98 } | |
| 99 | |
| 100 CastDevToolsDelegate::~CastDevToolsDelegate() { | |
| 101 } | |
| 102 | |
| 103 std::string CastDevToolsDelegate::GetDiscoveryPageHTML() { | |
| 104 #if defined(OS_ANDROID) | |
| 105 return std::string(); | |
| 106 #else | |
| 107 return ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 108 IDR_CAST_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); | |
| 109 #endif // defined(OS_ANDROID) | |
| 110 } | |
| 111 | |
| 112 bool CastDevToolsDelegate::BundlesFrontendResources() { | |
| 113 #if defined(OS_ANDROID) | |
| 114 return false; | |
| 115 #else | |
| 116 return true; | |
| 117 #endif // defined(OS_ANDROID) | |
| 118 } | |
| 119 | |
| 120 base::FilePath CastDevToolsDelegate::GetDebugFrontendDir() { | |
| 121 return base::FilePath(); | |
| 122 } | |
| 123 | |
| 124 scoped_ptr<net::StreamListenSocket> | |
| 125 CastDevToolsDelegate::CreateSocketForTethering( | |
| 126 net::StreamListenSocket::Delegate* delegate, | |
| 127 std::string* name) { | |
| 128 return scoped_ptr<net::StreamListenSocket>(); | |
| 129 } | |
| 130 | |
| 131 // CastDevToolsManagerDelegate ----------------------------------------------- | |
| 132 | |
| 133 CastDevToolsManagerDelegate::CastDevToolsManagerDelegate() { | |
| 134 } | |
| 135 | |
| 136 CastDevToolsManagerDelegate::~CastDevToolsManagerDelegate() { | |
| 137 } | |
| 138 | |
| 139 base::DictionaryValue* CastDevToolsManagerDelegate::HandleCommand( | |
| 140 content::DevToolsAgentHost* agent_host, | |
| 141 base::DictionaryValue* command) { | |
| 142 return NULL; | |
| 143 } | |
| 144 | |
| 145 std::string CastDevToolsManagerDelegate::GetPageThumbnailData( | |
| 146 const GURL& url) { | |
| 147 return ""; | |
| 148 } | |
| 149 | |
| 150 scoped_ptr<content::DevToolsTarget> | |
| 151 CastDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { | |
| 152 return scoped_ptr<content::DevToolsTarget>(); | |
| 153 } | |
| 154 | |
| 155 void CastDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { | |
| 156 TargetList targets; | |
| 157 content::DevToolsAgentHost::List agents = | |
| 158 content::DevToolsAgentHost::GetOrCreateAll(); | |
| 159 for (content::DevToolsAgentHost::List::iterator it = agents.begin(); | |
| 160 it != agents.end(); ++it) { | |
| 161 targets.push_back(new Target(*it)); | |
| 162 } | |
| 163 callback.Run(targets); | |
| 164 } | |
| 165 | |
| 166 } // namespace shell | |
| 167 } // namespace chromecast | |
| OLD | NEW |