Use the new devtools API
This commit is contained in:
parent
dc01ba5a72
commit
c874219101
9 changed files with 189 additions and 124 deletions
|
@ -43,10 +43,10 @@
|
|||
'browser/default_web_contents_delegate_mac.mm',
|
||||
'browser/devtools_contents_resizing_strategy.cc',
|
||||
'browser/devtools_contents_resizing_strategy.h',
|
||||
'browser/devtools_delegate.cc',
|
||||
'browser/devtools_delegate.h',
|
||||
'browser/devtools_embedder_message_dispatcher.cc',
|
||||
'browser/devtools_embedder_message_dispatcher.h',
|
||||
'browser/devtools_manager_delegate.cc',
|
||||
'browser/devtools_manager_delegate.h',
|
||||
'browser/devtools_ui.cc',
|
||||
'browser/devtools_ui.h',
|
||||
'browser/inspectable_web_contents.cc',
|
||||
|
@ -73,6 +73,8 @@
|
|||
'browser/notification_presenter_mac.mm',
|
||||
'browser/linux/notification_presenter_linux.h',
|
||||
'browser/linux/notification_presenter_linux.cc',
|
||||
'browser/remote_debugging_server.cc',
|
||||
'browser/remote_debugging_server.h',
|
||||
'browser/url_request_context_getter.cc',
|
||||
'browser/url_request_context_getter.h',
|
||||
'browser/views/inspectable_web_contents_view_views.h',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "browser/browser_context.h"
|
||||
#include "browser/browser_main_parts.h"
|
||||
#include "browser/devtools_delegate.h"
|
||||
#include "browser/devtools_manager_delegate.h"
|
||||
#include "browser/media/media_capture_devices_dispatcher.h"
|
||||
#include "browser/notification_presenter.h"
|
||||
|
||||
|
@ -98,7 +98,7 @@ base::FilePath BrowserClient::GetDefaultDownloadDirectory() {
|
|||
}
|
||||
|
||||
content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() {
|
||||
return new DevToolsManagerDelegate(browser_context());
|
||||
return new DevToolsManagerDelegate;
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
|
||||
#include "browser/browser_main_parts.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "browser/browser_context.h"
|
||||
#include "browser/devtools_delegate.h"
|
||||
#include "browser/remote_debugging_server.h"
|
||||
#include "browser/web_ui_controller_factory.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "net/proxy/proxy_resolver_v8.h"
|
||||
|
||||
|
@ -121,10 +123,17 @@ void BrowserMainParts::PreMainMessageLoopRun() {
|
|||
new WebUIControllerFactory(browser_context_.get()));
|
||||
content::WebUIControllerFactory::RegisterFactory(
|
||||
web_ui_controller_factory_.get());
|
||||
if (CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kRemoteDebuggingPort)) {
|
||||
devtools_delegate_.reset(new brightray::DevToolsDelegate(
|
||||
browser_context()));
|
||||
|
||||
// --remote-debugging-port
|
||||
base::CommandLine* command_line = CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) {
|
||||
std::string port_str = command_line->GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
||||
int port;
|
||||
if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535)
|
||||
remote_debugging_server_.reset(
|
||||
new RemoteDebuggingServer("127.0.0.1", static_cast<uint16>(port)));
|
||||
else
|
||||
DLOG(WARNING) << "Invalid http debugger port number " << port;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace brightray {
|
|||
|
||||
class BrowserContext;
|
||||
class WebUIControllerFactory;
|
||||
class DevToolsDelegate;
|
||||
class RemoteDebuggingServer;
|
||||
|
||||
class BrowserMainParts : public content::BrowserMainParts {
|
||||
public:
|
||||
|
@ -58,7 +58,7 @@ class BrowserMainParts : public content::BrowserMainParts {
|
|||
|
||||
scoped_ptr<BrowserContext> browser_context_;
|
||||
scoped_ptr<WebUIControllerFactory> web_ui_controller_factory_;
|
||||
scoped_ptr<DevToolsDelegate> devtools_delegate_;
|
||||
scoped_ptr<RemoteDebuggingServer> remote_debugging_server_;
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
scoped_ptr<ViewsDelegate> views_delegate_;
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
// Copyright (c) 2014 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-CHROMIUM file.
|
||||
|
||||
#ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
||||
#define BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/browser/devtools_http_handler_delegate.h"
|
||||
#include "content/public/browser/devtools_manager_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
class DevToolsHttpHandler;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
|
||||
public:
|
||||
explicit DevToolsDelegate(content::BrowserContext* browser_context);
|
||||
virtual ~DevToolsDelegate();
|
||||
|
||||
// Stops http server.
|
||||
void Stop();
|
||||
|
||||
// DevToolsHttpProtocolHandler::Delegate overrides.
|
||||
std::string GetDiscoveryPageHTML() override;
|
||||
bool BundlesFrontendResources() override;
|
||||
base::FilePath GetDebugFrontendDir() override;
|
||||
scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
|
||||
net::StreamListenSocket::Delegate* delegate,
|
||||
std::string* name) override;
|
||||
|
||||
content::DevToolsHttpHandler* devtools_http_handler() {
|
||||
return devtools_http_handler_;
|
||||
}
|
||||
|
||||
private:
|
||||
content::BrowserContext* browser_context_;
|
||||
content::DevToolsHttpHandler* devtools_http_handler_;
|
||||
|
||||
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
|
||||
|
||||
#endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_
|
|
@ -2,12 +2,13 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#include "browser/devtools_delegate.h"
|
||||
#include "browser/devtools_manager_delegate.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
@ -32,6 +33,8 @@ using content::BrowserContext;
|
|||
using content::DevToolsTarget;
|
||||
using content::DevToolsHttpHandler;
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
// A hack here:
|
||||
|
@ -85,9 +88,9 @@ class Target : public content::DevToolsTarget {
|
|||
public:
|
||||
explicit Target(scoped_refptr<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 {
|
||||
std::string GetId() const override { return agent_host_->GetId(); }
|
||||
std::string GetParentId() const override { return std::string(); }
|
||||
std::string GetType() const override {
|
||||
switch (agent_host_->GetType()) {
|
||||
case DevToolsAgentHost::TYPE_WEB_CONTENTS:
|
||||
return kTargetTypePage;
|
||||
|
@ -98,23 +101,19 @@ class Target : public content::DevToolsTarget {
|
|||
}
|
||||
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 {
|
||||
std::string GetTitle() const override { return agent_host_->GetTitle(); }
|
||||
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 {
|
||||
return last_activity_time_;
|
||||
}
|
||||
virtual bool IsAttached() const OVERRIDE {
|
||||
return agent_host_->IsAttached();
|
||||
}
|
||||
virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
|
||||
bool IsAttached() const override { return agent_host_->IsAttached(); }
|
||||
scoped_refptr<DevToolsAgentHost> GetAgentHost() const override {
|
||||
return agent_host_;
|
||||
}
|
||||
virtual bool Activate() const OVERRIDE;
|
||||
virtual bool Close() const OVERRIDE;
|
||||
bool Activate() const override;
|
||||
bool Close() const override;
|
||||
|
||||
private:
|
||||
scoped_refptr<DevToolsAgentHost> agent_host_;
|
||||
|
@ -141,27 +140,31 @@ bool Target::Close() const {
|
|||
return agent_host_->Close();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace brightray {
|
||||
|
||||
// DevToolsDelegate --------------------------------------------------------
|
||||
|
||||
DevToolsDelegate::DevToolsDelegate(content::BrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
std::string frontend_url;
|
||||
devtools_http_handler_ = DevToolsHttpHandler::Start(
|
||||
CreateSocketFactory(), frontend_url, this, base::FilePath());
|
||||
class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
|
||||
public:
|
||||
DevToolsDelegate();
|
||||
virtual ~DevToolsDelegate();
|
||||
|
||||
// content::DevToolsHttpHandlerDelegate.
|
||||
std::string GetDiscoveryPageHTML() override;
|
||||
bool BundlesFrontendResources() override;
|
||||
base::FilePath GetDebugFrontendDir() override;
|
||||
scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
|
||||
net::StreamListenSocket::Delegate* delegate,
|
||||
std::string* name) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate);
|
||||
};
|
||||
|
||||
DevToolsDelegate::DevToolsDelegate() {
|
||||
}
|
||||
|
||||
DevToolsDelegate::~DevToolsDelegate() {
|
||||
}
|
||||
|
||||
void DevToolsDelegate::Stop() {
|
||||
// The call below destroys this.
|
||||
devtools_http_handler_->Stop();
|
||||
}
|
||||
|
||||
std::string DevToolsDelegate::GetDiscoveryPageHTML() {
|
||||
return ResourceBundle::GetSharedInstance().GetRawDataResource(
|
||||
kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string();
|
||||
|
@ -182,11 +185,20 @@ DevToolsDelegate::CreateSocketForTethering(
|
|||
return scoped_ptr<net::StreamListenSocket>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// DevToolsManagerDelegate ---------------------------------------------------
|
||||
|
||||
DevToolsManagerDelegate::DevToolsManagerDelegate(
|
||||
content::BrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {
|
||||
// static
|
||||
content::DevToolsHttpHandler*
|
||||
DevToolsManagerDelegate::CreateHttpHandler() {
|
||||
return DevToolsHttpHandler::Start(CreateSocketFactory(),
|
||||
std::string(),
|
||||
new DevToolsDelegate,
|
||||
base::FilePath());
|
||||
}
|
||||
|
||||
DevToolsManagerDelegate::DevToolsManagerDelegate() {
|
||||
}
|
||||
|
||||
DevToolsManagerDelegate::~DevToolsManagerDelegate() {
|
||||
|
@ -210,11 +222,8 @@ DevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
|
|||
|
||||
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));
|
||||
for (const auto& agent_host : DevToolsAgentHost::GetOrCreateAll()) {
|
||||
targets.push_back(new Target(agent_host));
|
||||
}
|
||||
callback.Run(targets);
|
||||
}
|
43
brightray/browser/devtools_manager_delegate.h
Normal file
43
brightray/browser/devtools_manager_delegate.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (c) 2014 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-CHROMIUM file.
|
||||
|
||||
#ifndef BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_
|
||||
#define BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/browser/devtools_http_handler_delegate.h"
|
||||
#include "content/public/browser/devtools_manager_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class DevToolsHttpHandler;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class DevToolsManagerDelegate : public content::DevToolsManagerDelegate {
|
||||
public:
|
||||
static content::DevToolsHttpHandler* CreateHttpHandler();
|
||||
|
||||
DevToolsManagerDelegate();
|
||||
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:
|
||||
DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_
|
44
brightray/browser/remote_debugging_server.cc
Normal file
44
brightray/browser/remote_debugging_server.cc
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2015 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-CHROMIUM file.
|
||||
|
||||
#include "browser/remote_debugging_server.h"
|
||||
|
||||
#include "browser/devtools_manager_delegate.h"
|
||||
|
||||
#include "base/files/file_util.h"
|
||||
#include "content/public/browser/devtools_http_handler.h"
|
||||
#include "net/socket/tcp_server_socket.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
class TCPServerSocketFactory
|
||||
: public content::DevToolsHttpHandler::ServerSocketFactory {
|
||||
public:
|
||||
TCPServerSocketFactory(const std::string& address, uint16 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);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, uint16 port) {
|
||||
scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory(
|
||||
new TCPServerSocketFactory(ip, port, 1));
|
||||
devtools_http_handler_ = DevToolsManagerDelegate::CreateHttpHandler();
|
||||
}
|
||||
|
||||
RemoteDebuggingServer::~RemoteDebuggingServer() {
|
||||
devtools_http_handler_->Stop();
|
||||
}
|
||||
|
||||
} // namespace brightray
|
31
brightray/browser/remote_debugging_server.h
Normal file
31
brightray/browser/remote_debugging_server.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2015 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-CHROMIUM file.
|
||||
|
||||
#ifndef BROWSER_REMOTE_DEBUGGING_SERVER_H_
|
||||
#define BROWSER_REMOTE_DEBUGGING_SERVER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
namespace content {
|
||||
class DevToolsHttpHandler;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class RemoteDebuggingServer {
|
||||
public:
|
||||
RemoteDebuggingServer(const std::string& ip, uint16 port);
|
||||
virtual ~RemoteDebuggingServer();
|
||||
|
||||
private:
|
||||
content::DevToolsHttpHandler* devtools_http_handler_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BROWSER_REMOTE_DEBUGGING_SERVER_H_
|
Loading…
Reference in a new issue