mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-07 23:58:49 +01:00
0b78461f5b
- Building Chromium using SVN is no longer supported. - Remove CefDOMEvent and CefDOMEventListener (issue #933). - Remove CefRenderHandler::OnScrollOffsetChanged (http://crbug.com/404656). - Remove UR_FLAG_REPORT_LOAD_TIMING (https://codereview.chromium.org/451623002/). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1816 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
189 lines
6.1 KiB
C++
189 lines
6.1 KiB
C++
// 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.
|
|
|
|
#include "libcef/browser/devtools_delegate.h"
|
|
#include "libcef/browser/devtools_scheme_handler.h"
|
|
#include "libcef/common/content_client.h"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/md5.h"
|
|
#include "base/rand_util.h"
|
|
#include "base/strings/stringprintf.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "content/public/browser/devtools_agent_host.h"
|
|
#include "base/time/time.h"
|
|
#include "content/public/browser/devtools_http_handler.h"
|
|
#include "content/public/browser/devtools_target.h"
|
|
#include "content/public/browser/favicon_status.h"
|
|
#include "content/public/browser/navigation_entry.h"
|
|
#include "content/public/browser/render_view_host.h"
|
|
#include "content/public/browser/render_widget_host_iterator.h"
|
|
#include "content/public/browser/web_contents.h"
|
|
#include "content/public/browser/web_contents_delegate.h"
|
|
#include "content/public/common/content_switches.h"
|
|
#include "content/public/common/url_constants.h"
|
|
#include "grit/cef_resources.h"
|
|
#include "net/socket/tcp_server_socket.h"
|
|
#include "ui/base/layout.h"
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
namespace {
|
|
|
|
const char kTargetTypePage[] = "page";
|
|
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.
|
|
virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE {
|
|
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));
|
|
}
|
|
|
|
class Target : public content::DevToolsTarget {
|
|
public:
|
|
explicit Target(scoped_refptr<content::DevToolsAgentHost> agent_host);
|
|
|
|
virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
|
|
virtual std::string GetParentId() const OVERRIDE { return std::string(); }
|
|
virtual std::string GetType() const OVERRIDE {
|
|
switch (agent_host_->GetType()) {
|
|
case content::DevToolsAgentHost::TYPE_WEB_CONTENTS:
|
|
return kTargetTypePage;
|
|
case content::DevToolsAgentHost::TYPE_SERVICE_WORKER:
|
|
return kTargetTypeServiceWorker;
|
|
default:
|
|
break;
|
|
}
|
|
return kTargetTypeOther;
|
|
}
|
|
virtual std::string GetTitle() const OVERRIDE {
|
|
return agent_host_->GetTitle();
|
|
}
|
|
virtual std::string GetDescription() const OVERRIDE { return std::string(); }
|
|
virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); }
|
|
virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; }
|
|
virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
|
return last_activity_time_;
|
|
}
|
|
virtual bool IsAttached() const OVERRIDE {
|
|
return agent_host_->IsAttached();
|
|
}
|
|
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_;
|
|
GURL favicon_url_;
|
|
base::TimeTicks last_activity_time_;
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
bool Target::Activate() const {
|
|
return agent_host_->Activate();
|
|
}
|
|
|
|
bool Target::Close() const {
|
|
return agent_host_->Close();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// CefDevToolsDelegate
|
|
|
|
CefDevToolsDelegate::CefDevToolsDelegate(int port) {
|
|
devtools_http_handler_ = content::DevToolsHttpHandler::Start(
|
|
CreateSocketFactory(port),
|
|
std::string(),
|
|
this,
|
|
base::FilePath());
|
|
}
|
|
|
|
CefDevToolsDelegate::~CefDevToolsDelegate() {
|
|
}
|
|
|
|
void CefDevToolsDelegate::Stop() {
|
|
// The call below destroys this.
|
|
devtools_http_handler_->Stop();
|
|
}
|
|
|
|
std::string CefDevToolsDelegate::GetDiscoveryPageHTML() {
|
|
return CefContentClient::Get()->GetDataResource(
|
|
IDR_CEF_DEVTOOLS_DISCOVERY_PAGE, ui::SCALE_FACTOR_NONE).as_string();
|
|
}
|
|
|
|
bool CefDevToolsDelegate::BundlesFrontendResources() {
|
|
return true;
|
|
}
|
|
|
|
base::FilePath CefDevToolsDelegate::GetDebugFrontendDir() {
|
|
return base::FilePath();
|
|
}
|
|
|
|
std::string CefDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
|
|
return std::string();
|
|
}
|
|
|
|
scoped_ptr<content::DevToolsTarget> CefDevToolsDelegate::CreateNewTarget(
|
|
const GURL& url) {
|
|
return scoped_ptr<content::DevToolsTarget>();
|
|
}
|
|
|
|
void CefDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
|
|
TargetList targets;
|
|
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));
|
|
}
|
|
callback.Run(targets);
|
|
}
|
|
|
|
scoped_ptr<net::StreamListenSocket>
|
|
CefDevToolsDelegate::CreateSocketForTethering(
|
|
net::StreamListenSocket::Delegate* delegate,
|
|
std::string* name) {
|
|
return scoped_ptr<net::StreamListenSocket>();
|
|
}
|
|
|
|
std::string CefDevToolsDelegate::GetChromeDevToolsURL() {
|
|
return base::StringPrintf("%s://%s/devtools.html",
|
|
content::kChromeDevToolsScheme, scheme::kChromeDevToolsHost);
|
|
}
|