16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 26e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 36e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// found in the LICENSE file. 46e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" 66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 76e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/files/file_path.h" 86e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/macros.h" 96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/devtools_agent_host.h" 116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/devtools_target.h" 126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/favicon_status.h" 136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/navigation_entry.h" 146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/render_view_host.h" 156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/web_contents.h" 166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h" 176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "grit/shell_resources.h" 186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace chromecast { 216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace shell { 226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)namespace { 246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)const char kTargetTypePage[] = "page"; 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst char kTargetTypeServiceWorker[] = "service_worker"; 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst char kTargetTypeSharedWorker[] = "worker"; 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst char kTargetTypeOther[] = "other"; 296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class Target : public content::DevToolsTarget { 316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) public: 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci explicit Target(scoped_refptr<content::DevToolsAgentHost> agent_host); 336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } 356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual std::string GetParentId() const OVERRIDE { return std::string(); } 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual std::string GetType() const OVERRIDE { 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci switch (agent_host_->GetType()) { 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci case content::DevToolsAgentHost::TYPE_WEB_CONTENTS: 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return kTargetTypePage; 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci case content::DevToolsAgentHost::TYPE_SERVICE_WORKER: 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return kTargetTypeServiceWorker; 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci case content::DevToolsAgentHost::TYPE_SHARED_WORKER: 431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return kTargetTypeSharedWorker; 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci default: 451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci break; 461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return kTargetTypeOther; 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual std::string GetTitle() const OVERRIDE { 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return agent_host_->GetTitle(); 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual std::string GetDescription() const OVERRIDE { return std::string(); } 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual GURL GetURL() const OVERRIDE { 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return agent_host_->GetURL(); 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } 576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { 586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return last_activity_time_; 596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual bool IsAttached() const OVERRIDE { 616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return agent_host_->IsAttached(); 626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() 646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const OVERRIDE { 656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return agent_host_; 666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool Activate() const OVERRIDE { 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return agent_host_->Activate(); 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool Close() const OVERRIDE { 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return agent_host_->Close(); 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) private: 756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) scoped_refptr<content::DevToolsAgentHost> agent_host_; 766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) GURL favicon_url_; 776e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) base::TimeTicks last_activity_time_; 786e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(Target); 806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)}; 816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTarget::Target(scoped_refptr<content::DevToolsAgentHost> agent_host) 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci : agent_host_(agent_host) { 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (content::WebContents* web_contents = agent_host_->GetWebContents()) { 851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::NavigationController& controller = web_contents->GetController(); 861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::NavigationEntry* entry = controller.GetActiveEntry(); 871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (entry != NULL && entry->GetURL().is_valid()) 881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci favicon_url_ = entry->GetFavicon().url; 891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci last_activity_time_ = web_contents->GetLastActiveTime(); 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} // namespace 946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// CastDevToolsDelegate ----------------------------------------------------- 961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)CastDevToolsDelegate::CastDevToolsDelegate() { 986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)CastDevToolsDelegate::~CastDevToolsDelegate() { 1016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)std::string CastDevToolsDelegate::GetDiscoveryPageHTML() { 1046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return ResourceBundle::GetSharedInstance().GetRawDataResource( 1056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) IDR_CAST_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); 1066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)bool CastDevToolsDelegate::BundlesFrontendResources() { 1096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return true; 1106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)base::FilePath CastDevToolsDelegate::GetDebugFrontendDir() { 1136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return base::FilePath(); 1146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciscoped_ptr<net::StreamListenSocket> 1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCastDevToolsDelegate::CreateSocketForTethering( 1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci net::StreamListenSocket::Delegate* delegate, 1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci std::string* name) { 1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return scoped_ptr<net::StreamListenSocket>(); 1216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// CastDevToolsManagerDelegate ----------------------------------------------- 1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCastDevToolsManagerDelegate::CastDevToolsManagerDelegate() { 1261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCastDevToolsManagerDelegate::~CastDevToolsManagerDelegate() { 1291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibase::DictionaryValue* CastDevToolsManagerDelegate::HandleCommand( 1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::DevToolsAgentHost* agent_host, 1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::DictionaryValue* command) { 1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return NULL; 1351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistd::string CastDevToolsManagerDelegate::GetPageThumbnailData( 1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const GURL& url) { 1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return ""; 1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciscoped_ptr<content::DevToolsTarget> 1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCastDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { 1446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return scoped_ptr<content::DevToolsTarget>(); 1456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid CastDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { 1486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) TargetList targets; 1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::DevToolsAgentHost::List agents = 1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::DevToolsAgentHost::GetOrCreateAll(); 1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci for (content::DevToolsAgentHost::List::iterator it = agents.begin(); 1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci it != agents.end(); ++it) { 1536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) targets.push_back(new Target(*it)); 1546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 1556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) callback.Run(targets); 1566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} 1576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} // namespace shell 1596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)} // namespace chromecast 160