2013-11-08 17:06:06 +01: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 03:34:16 +02:00
|
|
|
|
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
2012-05-18 17:04:56 +02:00
|
|
|
#include "libcef/browser/devtools_scheme_handler.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
2012-04-27 00:20:18 +02:00
|
|
|
#include <string>
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-27 00:20:18 +02:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/md5.h"
|
|
|
|
#include "base/rand_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
2013-10-17 01:09:07 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "content/public/browser/devtools_agent_host.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "base/time/time.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/devtools_http_handler.h"
|
2013-10-17 01:09:07 +02:00
|
|
|
#include "content/public/browser/devtools_target.h"
|
|
|
|
#include "content/public/browser/favicon_status.h"
|
|
|
|
#include "content/public/browser/navigation_entry.h"
|
2012-04-27 00:20:18 +02:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2013-10-16 02:25:38 +02:00
|
|
|
#include "content/public/browser/render_widget_host_iterator.h"
|
2013-10-17 01:09:07 +02:00
|
|
|
#include "content/public/browser/web_contents.h"
|
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
2012-04-27 00:20:18 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "grit/cef_resources.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "net/socket/tcp_listen_socket.h"
|
2012-05-31 17:19:33 +02:00
|
|
|
#include "ui/base/layout.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
namespace {
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
const char kTargetTypePage[] = "page";
|
2013-01-15 20:12:28 +01:00
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
class Target : public content::DevToolsTarget {
|
|
|
|
public:
|
|
|
|
explicit Target(content::WebContents* web_contents);
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
virtual std::string GetId() const OVERRIDE { return id_; }
|
|
|
|
virtual std::string GetType() const OVERRIDE { return kTargetTypePage; }
|
|
|
|
virtual std::string GetTitle() const OVERRIDE { return title_; }
|
|
|
|
virtual std::string GetDescription() const OVERRIDE { return std::string(); }
|
2014-05-29 19:15:34 +02:00
|
|
|
virtual GURL GetURL() const OVERRIDE { return url_; }
|
|
|
|
virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; }
|
2013-10-17 01:09:07 +02:00
|
|
|
virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
|
|
|
return last_activity_time_;
|
2013-01-15 20:12:28 +01:00
|
|
|
}
|
2013-10-17 01:09:07 +02:00
|
|
|
virtual bool IsAttached() const OVERRIDE {
|
|
|
|
return agent_host_->IsAttached();
|
2012-04-27 00:20:18 +02:00
|
|
|
}
|
2013-10-17 01:09:07 +02:00
|
|
|
virtual scoped_refptr<content::DevToolsAgentHost> GetAgentHost() const
|
|
|
|
OVERRIDE {
|
|
|
|
return agent_host_;
|
|
|
|
}
|
|
|
|
virtual bool Activate() const OVERRIDE;
|
|
|
|
virtual bool Close() const OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
|
|
|
std::string id_;
|
|
|
|
std::string title_;
|
|
|
|
GURL url_;
|
|
|
|
GURL favicon_url_;
|
|
|
|
base::TimeTicks last_activity_time_;
|
|
|
|
};
|
|
|
|
|
|
|
|
Target::Target(content::WebContents* web_contents) {
|
|
|
|
agent_host_ =
|
|
|
|
content::DevToolsAgentHost::GetOrCreateFor(
|
|
|
|
web_contents->GetRenderViewHost());
|
|
|
|
id_ = agent_host_->GetId();
|
2014-01-02 23:41:11 +01:00
|
|
|
title_ = base::UTF16ToUTF8(web_contents->GetTitle());
|
2013-10-17 01:09:07 +02:00
|
|
|
url_ = web_contents->GetURL();
|
|
|
|
content::NavigationController& controller = web_contents->GetController();
|
|
|
|
content::NavigationEntry* entry = controller.GetActiveEntry();
|
|
|
|
if (entry != NULL && entry->GetURL().is_valid())
|
|
|
|
favicon_url_ = entry->GetFavicon().url;
|
2014-02-19 17:27:54 +01:00
|
|
|
last_activity_time_ = web_contents->GetLastActiveTime();
|
2013-10-17 01:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Target::Activate() const {
|
|
|
|
content::RenderViewHost* rvh = agent_host_->GetRenderViewHost();
|
|
|
|
if (!rvh)
|
|
|
|
return false;
|
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderViewHost(rvh);
|
|
|
|
if (!web_contents)
|
|
|
|
return false;
|
|
|
|
web_contents->GetDelegate()->ActivateContents(web_contents);
|
|
|
|
return true;
|
2013-01-15 20:12:28 +01:00
|
|
|
}
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
bool Target::Close() const {
|
|
|
|
content::RenderViewHost* rvh = agent_host_->GetRenderViewHost();
|
|
|
|
if (!rvh)
|
|
|
|
return false;
|
|
|
|
rvh->ClosePage();
|
|
|
|
return true;
|
2013-01-15 20:12:28 +01:00
|
|
|
}
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
} // namespace
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-01-15 20:12:28 +01:00
|
|
|
// CefDevToolsDelegate
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2012-10-04 21:17:13 +02:00
|
|
|
CefDevToolsDelegate::CefDevToolsDelegate(int port) {
|
2012-04-03 03:34:16 +02:00
|
|
|
devtools_http_handler_ = content::DevToolsHttpHandler::Start(
|
2012-05-31 17:19:33 +02:00
|
|
|
new net::TCPListenSocketFactory("127.0.0.1", port),
|
2012-04-03 03:34:16 +02:00
|
|
|
"",
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefDevToolsDelegate::~CefDevToolsDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDevToolsDelegate::Stop() {
|
|
|
|
// The call below destroys this.
|
|
|
|
devtools_http_handler_->Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CefDevToolsDelegate::GetDiscoveryPageHTML() {
|
2013-04-16 00:16:01 +02:00
|
|
|
return CefContentClient::Get()->GetDataResource(
|
2012-05-31 17:19:33 +02:00
|
|
|
IDR_CEF_DEVTOOLS_DISCOVERY_PAGE, ui::SCALE_FACTOR_NONE).as_string();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDevToolsDelegate::BundlesFrontendResources() {
|
2012-10-04 21:17:13 +02:00
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath CefDevToolsDelegate::GetDebugFrontendDir() {
|
|
|
|
return base::FilePath();
|
2012-10-04 21:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CefDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
|
|
|
|
return std::string();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-04-27 00:20:18 +02:00
|
|
|
|
2013-10-29 18:53:18 +01:00
|
|
|
scoped_ptr<content::DevToolsTarget> CefDevToolsDelegate::CreateNewTarget(
|
|
|
|
const GURL& url) {
|
2013-10-17 01:09:07 +02:00
|
|
|
return scoped_ptr<content::DevToolsTarget>();
|
2012-11-05 21:18:20 +01:00
|
|
|
}
|
|
|
|
|
2013-10-17 01:09:07 +02:00
|
|
|
void CefDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
|
|
|
|
TargetList targets;
|
|
|
|
std::vector<content::RenderViewHost*> rvh_list =
|
|
|
|
content::DevToolsAgentHost::GetValidRenderViewHosts();
|
|
|
|
for (std::vector<content::RenderViewHost*>::iterator it = rvh_list.begin();
|
|
|
|
it != rvh_list.end(); ++it) {
|
|
|
|
content::WebContents* web_contents =
|
|
|
|
content::WebContents::FromRenderViewHost(*it);
|
|
|
|
if (web_contents)
|
|
|
|
targets.push_back(new Target(web_contents));
|
|
|
|
}
|
|
|
|
callback.Run(targets);
|
2013-04-02 19:21:37 +02:00
|
|
|
}
|
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
scoped_ptr<net::StreamListenSocket>
|
2013-05-07 23:48:34 +02:00
|
|
|
CefDevToolsDelegate::CreateSocketForTethering(
|
|
|
|
net::StreamListenSocket::Delegate* delegate,
|
|
|
|
std::string* name) {
|
2013-10-16 02:25:38 +02:00
|
|
|
return scoped_ptr<net::StreamListenSocket>();
|
2013-05-07 23:48:34 +02:00
|
|
|
}
|
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
std::string CefDevToolsDelegate::GetChromeDevToolsURL() {
|
|
|
|
return base::StringPrintf("%s://%s/devtools.html",
|
2014-02-19 17:27:54 +01:00
|
|
|
content::kChromeDevToolsScheme, scheme::kChromeDevToolsHost);
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|