2013-11-08 16:06:06 +00:00
|
|
|
// Copyright 2013 the Chromium Embedded Framework Authors. Portions Copyright
|
|
|
|
// 2012 The Chromium Authors. All rights reserved. Use of this source code is
|
|
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
2012-04-03 01:34:16 +00:00
|
|
|
|
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
2012-05-18 15:04:56 +00:00
|
|
|
#include "libcef/browser/devtools_scheme_handler.h"
|
2013-04-15 22:16:01 +00:00
|
|
|
#include "libcef/common/content_client.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2012-04-26 22:20:18 +00:00
|
|
|
#include <string>
|
2012-04-03 01:34:16 +00:00
|
|
|
|
2012-04-26 22:20:18 +00:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/md5.h"
|
|
|
|
#include "base/rand_util.h"
|
2013-06-22 02:06:32 +00:00
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
2013-10-16 23:09:07 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "content/public/browser/devtools_agent_host.h"
|
2013-07-24 20:15:18 +00:00
|
|
|
#include "base/time/time.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "content/public/browser/devtools_http_handler.h"
|
2013-10-16 23:09:07 +00:00
|
|
|
#include "content/public/browser/devtools_target.h"
|
|
|
|
#include "content/public/browser/favicon_status.h"
|
|
|
|
#include "content/public/browser/navigation_entry.h"
|
2012-04-26 22:20:18 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2013-10-16 00:25:38 +00:00
|
|
|
#include "content/public/browser/render_widget_host_iterator.h"
|
2013-10-16 23:09:07 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2012-04-26 22:20:18 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "grit/cef_resources.h"
|
2014-09-04 17:53:40 +00:00
|
|
|
#include "net/socket/tcp_server_socket.h"
|
2012-05-31 15:19:33 +00:00
|
|
|
#include "ui/base/layout.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2013-10-16 23:09:07 +00:00
|
|
|
namespace {
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2013-10-16 23:09:07 +00:00
|
|
|
const char kTargetTypePage[] = "page";
|
2014-09-04 17:53:40 +00:00
|
|
|
const char kTargetTypeServiceWorker[] = "service_worker";
|
|
|
|
const char kTargetTypeOther[] = "other";
|
|
|
|
|
|
|
|
class TCPServerSocketFactory
|
|
|
|
: public content::DevToolsHttpHandler::ServerSocketFactory {
|
|
|
|
public:
|
|
|
|
TCPServerSocketFactory(const std::string& address, int port, int backlog)
|
|
|
|
: content::DevToolsHttpHandler::ServerSocketFactory(
|
|
|
|
address, port, backlog) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// content::DevToolsHttpHandler::ServerSocketFactory.
|
2014-11-12 19:25:15 +00:00
|
|
|
scoped_ptr<net::ServerSocket> Create() const override {
|
2014-09-04 17:53:40 +00:00
|
|
|
return scoped_ptr<net::ServerSocket>(
|
|
|
|
new net::TCPServerSocket(NULL, net::NetLog::Source()));
|
|
|
|
}
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
|
|
|
|
};
|
|
|
|
|
|
|
|
scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>
|
|
|
|
CreateSocketFactory(int port) {
|
|
|
|
return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>(
|
|
|
|
new TCPServerSocketFactory("127.0.0.1", port, 1));
|
|
|
|
}
|
2013-01-15 19:12:28 +00:00
|
|
|
|
2013-10-16 23:09:07 +00:00
|
|
|
class Target : public content::DevToolsTarget {
|
|
|
|
public:
|
2014-09-04 17:53:40 +00:00
|
|
|
explicit Target(scoped_refptr<content::DevToolsAgentHost> agent_host);
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2014-11-12 19:25:15 +00:00
|
|
|
std::string GetId() const override { return agent_host_->GetId(); }
|
|
|
|
std::string GetParentId() const override { return std::string(); }
|
|
|
|
std::string GetType() const override {
|
2014-09-04 17:53:40 +00:00
|
|
|
switch (agent_host_->GetType()) {
|
|
|
|
case content::DevToolsAgentHost::TYPE_WEB_CONTENTS:
|
|
|
|
return kTargetTypePage;
|
|
|
|
case content::DevToolsAgentHost::TYPE_SERVICE_WORKER:
|
|
|
|
return kTargetTypeServiceWorker;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return kTargetTypeOther;
|
|
|
|
}
|
2014-11-12 19:25:15 +00:00
|
|
|
std::string GetTitle() const override {
|
2014-09-04 17:53:40 +00:00
|
|
|
return agent_host_->GetTitle();
|
|
|
|
}
|
2014-11-12 19:25:15 +00:00
|
|
|
std::string GetDescription() const override { return std::string(); }
|
|
|
|
GURL GetURL() const override { return agent_host_->GetURL(); }
|
|
|
|
GURL GetFaviconURL() const override { return favicon_url_; }
|
|
|
|
base::TimeTicks GetLastActivityTime() const override {
|
2013-10-16 23:09:07 +00:00
|
|
|
return last_activity_time_;
|
2013-01-15 19:12:28 +00:00
|
|
|
}
|
2014-11-12 19:25:15 +00:00
|
|
|
bool IsAttached() const override {
|
2013-10-16 23:09:07 +00:00
|
|
|
return agent_host_->IsAttached();
|
2012-04-26 22:20:18 +00:00
|
|
|
}
|
2014-11-12 19:25:15 +00:00
|
|
|
scoped_refptr<content::DevToolsAgentHost> GetAgentHost() const
|
|
|
|
override {
|
2013-10-16 23:09:07 +00:00
|
|
|
return agent_host_;
|
|
|
|
}
|
2014-11-12 19:25:15 +00:00
|
|
|
bool Activate() const override;
|
|
|
|
bool Close() const override;
|
2013-10-16 23:09:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
|
|
|
GURL favicon_url_;
|
|
|
|
base::TimeTicks last_activity_time_;
|
|
|
|
};
|
|
|
|
|
2014-09-04 17:53:40 +00:00
|
|
|
Target::Target(scoped_refptr<content::DevToolsAgentHost> agent_host)
|
|
|
|
: agent_host_(agent_host) {
|
|
|
|
if (content::WebContents* web_contents = agent_host_->GetWebContents()) {
|
|
|
|
content::NavigationController& controller = web_contents->GetController();
|
|
|
|
content::NavigationEntry* entry = controller.GetActiveEntry();
|
|
|
|
if (entry != NULL && entry->GetURL().is_valid())
|
|
|
|
favicon_url_ = entry->GetFavicon().url;
|
|
|
|
last_activity_time_ = web_contents->GetLastActiveTime();
|
|
|
|
}
|
2013-10-16 23:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Target::Activate() const {
|
2014-09-04 17:53:40 +00:00
|
|
|
return agent_host_->Activate();
|
2013-01-15 19:12:28 +00:00
|
|
|
}
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2013-10-16 23:09:07 +00:00
|
|
|
bool Target::Close() const {
|
2014-09-04 17:53:40 +00:00
|
|
|
return agent_host_->Close();
|
2013-01-15 19:12:28 +00:00
|
|
|
}
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2013-10-16 23:09:07 +00:00
|
|
|
} // namespace
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2013-01-15 19:12:28 +00:00
|
|
|
// CefDevToolsDelegate
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2012-10-04 19:17:13 +00:00
|
|
|
CefDevToolsDelegate::CefDevToolsDelegate(int port) {
|
2012-04-03 01:34:16 +00:00
|
|
|
devtools_http_handler_ = content::DevToolsHttpHandler::Start(
|
2014-09-04 17:53:40 +00:00
|
|
|
CreateSocketFactory(port),
|
|
|
|
std::string(),
|
2014-06-12 20:28:58 +00:00
|
|
|
this,
|
|
|
|
base::FilePath());
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CefDevToolsDelegate::~CefDevToolsDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsDelegate::Stop() {
|
|
|
|
// The call below destroys this.
|
|
|
|
devtools_http_handler_->Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CefDevToolsDelegate::GetDiscoveryPageHTML() {
|
2013-04-15 22:16:01 +00:00
|
|
|
return CefContentClient::Get()->GetDataResource(
|
2012-05-31 15:19:33 +00:00
|
|
|
IDR_CEF_DEVTOOLS_DISCOVERY_PAGE, ui::SCALE_FACTOR_NONE).as_string();
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDevToolsDelegate::BundlesFrontendResources() {
|
2012-10-04 19:17:13 +00:00
|
|
|
return true;
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
2013-02-23 00:43:28 +00:00
|
|
|
base::FilePath CefDevToolsDelegate::GetDebugFrontendDir() {
|
|
|
|
return base::FilePath();
|
2012-10-04 19:17:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:48:19 +00:00
|
|
|
scoped_ptr<net::StreamListenSocket>
|
|
|
|
CefDevToolsDelegate::CreateSocketForTethering(
|
|
|
|
net::StreamListenSocket::Delegate* delegate,
|
|
|
|
std::string* name) {
|
|
|
|
return scoped_ptr<net::StreamListenSocket>();
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
2012-04-26 22:20:18 +00:00
|
|
|
|
2014-09-26 23:48:19 +00:00
|
|
|
std::string CefDevToolsDelegate::GetChromeDevToolsURL() {
|
|
|
|
return base::StringPrintf("%s://%s/devtools.html",
|
|
|
|
content::kChromeDevToolsScheme, scheme::kChromeDevToolsHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CefDevToolsManagerDelegate
|
|
|
|
|
|
|
|
CefDevToolsManagerDelegate::CefDevToolsManagerDelegate(
|
|
|
|
content::BrowserContext* browser_context)
|
|
|
|
: browser_context_(browser_context) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefDevToolsManagerDelegate::~CefDevToolsManagerDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
base::DictionaryValue* CefDevToolsManagerDelegate::HandleCommand(
|
|
|
|
content::DevToolsAgentHost* agent_host,
|
|
|
|
base::DictionaryValue* command) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CefDevToolsManagerDelegate::GetPageThumbnailData(
|
2013-10-29 17:53:18 +00:00
|
|
|
const GURL& url) {
|
2014-09-26 23:48:19 +00:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_ptr<content::DevToolsTarget>
|
|
|
|
CefDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
|
|
|
|
return scoped_ptr<content::DevToolsTarget>();
|
2012-11-05 20:18:20 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:48:19 +00:00
|
|
|
void CefDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
|
2013-10-16 23:09:07 +00:00
|
|
|
TargetList targets;
|
2014-09-04 17:53:40 +00:00
|
|
|
content::DevToolsAgentHost::List agents =
|
|
|
|
content::DevToolsAgentHost::GetOrCreateAll();
|
|
|
|
for (content::DevToolsAgentHost::List::iterator it = agents.begin();
|
|
|
|
it != agents.end(); ++it) {
|
|
|
|
targets.push_back(new Target(*it));
|
2013-10-16 23:09:07 +00:00
|
|
|
}
|
|
|
|
callback.Run(targets);
|
2013-04-02 17:21:37 +00:00
|
|
|
}
|