Add DevToolsManagerDelegateA
This commit is contained in:
parent
8ec5b5ad20
commit
289d3b54f3
2 changed files with 129 additions and 80 deletions
|
@ -12,9 +12,6 @@
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "browser/browser_context.h"
|
#include "browser/browser_context.h"
|
||||||
#include "browser/inspectable_web_contents.h"
|
|
||||||
#include "browser/default_web_contents_delegate.h"
|
|
||||||
#include "browser/inspectable_web_contents_delegate.h"
|
|
||||||
#include "content/public/browser/devtools_agent_host.h"
|
#include "content/public/browser/devtools_agent_host.h"
|
||||||
#include "content/public/browser/devtools_http_handler.h"
|
#include "content/public/browser/devtools_http_handler.h"
|
||||||
#include "content/public/browser/devtools_target.h"
|
#include "content/public/browser/devtools_target.h"
|
||||||
|
@ -25,7 +22,7 @@
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
#include "content/public/common/url_constants.h"
|
#include "content/public/common/url_constants.h"
|
||||||
#include "content/public/common/user_agent.h"
|
#include "content/public/common/user_agent.h"
|
||||||
#include "net/socket/tcp_listen_socket.h"
|
#include "net/socket/tcp_server_socket.h"
|
||||||
#include "ui/base/resource/resource_bundle.h"
|
#include "ui/base/resource/resource_bundle.h"
|
||||||
|
|
||||||
using content::DevToolsAgentHost;
|
using content::DevToolsAgentHost;
|
||||||
|
@ -43,8 +40,28 @@ namespace {
|
||||||
const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500;
|
const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500;
|
||||||
|
|
||||||
const char kTargetTypePage[] = "page";
|
const char kTargetTypePage[] = "page";
|
||||||
|
const char kTargetTypeServiceWorker[] = "service_worker";
|
||||||
|
const char kTargetTypeOther[] = "other";
|
||||||
|
|
||||||
net::StreamListenSocketFactory* CreateSocketFactory() {
|
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.
|
||||||
|
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() {
|
||||||
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
||||||
// See if the user specified a port on the command line (useful for
|
// See if the user specified a port on the command line (useful for
|
||||||
// automation). If not, use an ephemeral port by specifying 0.
|
// automation). If not, use an ephemeral port by specifying 0.
|
||||||
|
@ -60,75 +77,77 @@ net::StreamListenSocketFactory* CreateSocketFactory() {
|
||||||
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new net::TCPListenSocketFactory("127.0.0.1", port);
|
return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>(
|
||||||
|
new TCPServerSocketFactory("127.0.0.1", port, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Target : public content::DevToolsTarget {
|
class Target : public content::DevToolsTarget {
|
||||||
public:
|
public:
|
||||||
explicit Target(WebContents* web_contents);
|
explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
|
||||||
|
|
||||||
virtual std::string GetId() const override { return id_; }
|
virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
|
||||||
virtual std::string GetParentId() const { return std::string(); }
|
virtual std::string GetParentId() const OVERRIDE { return std::string(); }
|
||||||
virtual std::string GetType() const override { return kTargetTypePage; }
|
virtual std::string GetType() const OVERRIDE {
|
||||||
virtual std::string GetTitle() const override { return title_; }
|
switch (agent_host_->GetType()) {
|
||||||
virtual std::string GetDescription() const override { return std::string(); }
|
case DevToolsAgentHost::TYPE_WEB_CONTENTS:
|
||||||
virtual GURL GetURL() const override { return url_; }
|
return kTargetTypePage;
|
||||||
virtual GURL GetFaviconURL() const override { return favicon_url_; }
|
case DevToolsAgentHost::TYPE_SERVICE_WORKER:
|
||||||
virtual base::TimeTicks GetLastActivityTime() const override {
|
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_;
|
return last_activity_time_;
|
||||||
}
|
}
|
||||||
virtual bool IsAttached() const override {
|
virtual bool IsAttached() const OVERRIDE {
|
||||||
return agent_host_->IsAttached();
|
return agent_host_->IsAttached();
|
||||||
}
|
}
|
||||||
virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const override {
|
virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
|
||||||
return agent_host_;
|
return agent_host_;
|
||||||
}
|
}
|
||||||
virtual bool Activate() const override;
|
virtual bool Activate() const OVERRIDE;
|
||||||
virtual bool Close() const override;
|
virtual bool Close() const OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scoped_refptr<DevToolsAgentHost> agent_host_;
|
scoped_refptr<DevToolsAgentHost> agent_host_;
|
||||||
std::string id_;
|
|
||||||
std::string title_;
|
|
||||||
GURL url_;
|
|
||||||
GURL favicon_url_;
|
GURL favicon_url_;
|
||||||
base::TimeTicks last_activity_time_;
|
base::TimeTicks last_activity_time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Target::Target(WebContents* web_contents) {
|
Target::Target(scoped_refptr<DevToolsAgentHost> agent_host)
|
||||||
agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents);
|
: agent_host_(agent_host) {
|
||||||
id_ = agent_host_->GetId();
|
if (WebContents* web_contents = agent_host_->GetWebContents()) {
|
||||||
title_ = base::UTF16ToUTF8(web_contents->GetTitle());
|
content::NavigationController& controller = web_contents->GetController();
|
||||||
url_ = web_contents->GetURL();
|
content::NavigationEntry* entry = controller.GetActiveEntry();
|
||||||
content::NavigationController& controller = web_contents->GetController();
|
if (entry != NULL && entry->GetURL().is_valid())
|
||||||
content::NavigationEntry* entry = controller.GetActiveEntry();
|
favicon_url_ = entry->GetFavicon().url;
|
||||||
if (entry != NULL && entry->GetURL().is_valid())
|
last_activity_time_ = web_contents->GetLastActiveTime();
|
||||||
favicon_url_ = entry->GetFavicon().url;
|
}
|
||||||
last_activity_time_ = web_contents->GetLastActiveTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Target::Activate() const {
|
bool Target::Activate() const {
|
||||||
WebContents* web_contents = agent_host_->GetWebContents();
|
return agent_host_->Activate();
|
||||||
if (!web_contents)
|
|
||||||
return false;
|
|
||||||
web_contents->GetDelegate()->ActivateContents(web_contents);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Target::Close() const {
|
bool Target::Close() const {
|
||||||
WebContents* web_contents = agent_host_->GetWebContents();
|
return agent_host_->Close();
|
||||||
if (!web_contents)
|
|
||||||
return false;
|
|
||||||
web_contents->GetRenderViewHost()->ClosePage();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
DevToolsDelegate::DevToolsDelegate(
|
// DevToolsDelegate --------------------------------------------------------
|
||||||
content::BrowserContext* browser_context)
|
|
||||||
|
DevToolsDelegate::DevToolsDelegate(content::BrowserContext* browser_context)
|
||||||
: browser_context_(browser_context) {
|
: browser_context_(browser_context) {
|
||||||
std::string frontend_url;
|
std::string frontend_url;
|
||||||
devtools_http_handler_ = DevToolsHttpHandler::Start(
|
devtools_http_handler_ = DevToolsHttpHandler::Start(
|
||||||
|
@ -156,32 +175,6 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() {
|
||||||
return base::FilePath();
|
return base::FilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_ptr<DevToolsTarget>
|
|
||||||
DevToolsDelegate::CreateNewTarget(const GURL& url) {
|
|
||||||
content::WebContents::CreateParams create_params(
|
|
||||||
new brightray::BrowserContext());
|
|
||||||
brightray::InspectableWebContents* web_contents =
|
|
||||||
brightray::InspectableWebContents::Create(create_params);
|
|
||||||
web_contents->SetDelegate(new brightray::InspectableWebContentsDelegate());
|
|
||||||
return scoped_ptr<DevToolsTarget>(new Target(web_contents->GetWebContents()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DevToolsDelegate::EnumerateTargets(TargetCallback callback) {
|
|
||||||
TargetList targets;
|
|
||||||
std::vector<WebContents*> wc_list =
|
|
||||||
content::DevToolsAgentHost::GetInspectableWebContents();
|
|
||||||
for (std::vector<WebContents*>::iterator it = wc_list.begin();
|
|
||||||
it != wc_list.end();
|
|
||||||
++it) {
|
|
||||||
targets.push_back(new Target(*it));
|
|
||||||
}
|
|
||||||
callback.Run(targets);
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_ptr<net::StreamListenSocket>
|
scoped_ptr<net::StreamListenSocket>
|
||||||
DevToolsDelegate::CreateSocketForTethering(
|
DevToolsDelegate::CreateSocketForTethering(
|
||||||
net::StreamListenSocket::Delegate* delegate,
|
net::StreamListenSocket::Delegate* delegate,
|
||||||
|
@ -189,4 +182,41 @@ DevToolsDelegate::CreateSocketForTethering(
|
||||||
return scoped_ptr<net::StreamListenSocket>();
|
return scoped_ptr<net::StreamListenSocket>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DevToolsManagerDelegate ---------------------------------------------------
|
||||||
|
|
||||||
|
DevToolsManagerDelegate::DevToolsManagerDelegate(
|
||||||
|
content::BrowserContext* browser_context)
|
||||||
|
: browser_context_(browser_context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
DevToolsManagerDelegate::~DevToolsManagerDelegate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
base::DictionaryValue* DevToolsManagerDelegate::HandleCommand(
|
||||||
|
content::DevToolsAgentHost* agent_host,
|
||||||
|
base::DictionaryValue* command) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DevToolsManagerDelegate::GetPageThumbnailData(
|
||||||
|
const GURL& url) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
scoped_ptr<content::DevToolsTarget>
|
||||||
|
DevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
|
||||||
|
return scoped_ptr<content::DevToolsTarget>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevToolsManagerDelegate::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);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
#ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
#ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
||||||
#define BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
#define BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "content/public/browser/devtools_http_handler_delegate.h"
|
#include "content/public/browser/devtools_http_handler_delegate.h"
|
||||||
|
#include "content/public/browser/devtools_manager_delegate.h"
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class BrowserContext;
|
class BrowserContext;
|
||||||
|
@ -27,14 +26,10 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
// DevToolsHttpProtocolHandler::Delegate overrides.
|
// DevToolsHttpProtocolHandler::Delegate overrides.
|
||||||
virtual std::string GetDiscoveryPageHTML() override;
|
std::string GetDiscoveryPageHTML() override;
|
||||||
virtual bool BundlesFrontendResources() override;
|
bool BundlesFrontendResources() override;
|
||||||
virtual base::FilePath GetDebugFrontendDir() override;
|
base::FilePath GetDebugFrontendDir() override;
|
||||||
virtual std::string GetPageThumbnailData(const GURL& url) override;
|
scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
|
||||||
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
|
|
||||||
const GURL& url) override;
|
|
||||||
virtual void EnumerateTargets(TargetCallback callback) override;
|
|
||||||
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
|
|
||||||
net::StreamListenSocket::Delegate* delegate,
|
net::StreamListenSocket::Delegate* delegate,
|
||||||
std::string* name) override;
|
std::string* name) override;
|
||||||
|
|
||||||
|
@ -49,6 +44,30 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
|
||||||
DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate);
|
DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DevToolsManagerDelegate : public content::DevToolsManagerDelegate {
|
||||||
|
public:
|
||||||
|
explicit DevToolsManagerDelegate(content::BrowserContext* browser_context);
|
||||||
|
virtual ~DevToolsManagerDelegate();
|
||||||
|
|
||||||
|
// DevToolsManagerDelegate implementation.
|
||||||
|
void Inspect(content::BrowserContext* browser_context,
|
||||||
|
content::DevToolsAgentHost* agent_host) override {}
|
||||||
|
void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host,
|
||||||
|
bool attached) override {}
|
||||||
|
base::DictionaryValue* HandleCommand(
|
||||||
|
content::DevToolsAgentHost* agent_host,
|
||||||
|
base::DictionaryValue* command) override;
|
||||||
|
scoped_ptr<content::DevToolsTarget> CreateNewTarget(
|
||||||
|
const GURL& url) override;
|
||||||
|
void EnumerateTargets(TargetCallback callback) override;
|
||||||
|
std::string GetPageThumbnailData(const GURL& url) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
content::BrowserContext* browser_context_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
||||||
#endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
#endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
||||||
|
|
Loading…
Reference in a new issue