2014-07-30 03:40:17 +00:00
|
|
|
// 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.
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
#include "atom/browser/ui/devtools_manager_delegate.h"
|
2014-07-30 03:40:17 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2014-07-30 03:40:17 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/command_line.h"
|
2015-01-10 01:14:52 +00:00
|
|
|
#include "base/files/file_path.h"
|
2014-07-30 03:40:17 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
|
|
|
#include "base/strings/stringprintf.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "content/public/browser/devtools_agent_host.h"
|
2015-07-23 10:18:03 +00:00
|
|
|
#include "content/public/browser/devtools_frontend_host.h"
|
2017-01-23 05:48:23 +00:00
|
|
|
#include "content/public/browser/devtools_socket_factory.h"
|
2014-07-30 03:40:17 +00:00
|
|
|
#include "content/public/browser/favicon_status.h"
|
|
|
|
#include "content/public/browser/navigation_entry.h"
|
|
|
|
#include "content/public/common/content_switches.h"
|
|
|
|
#include "content/public/common/url_constants.h"
|
|
|
|
#include "content/public/common/user_agent.h"
|
2017-01-13 08:52:45 +00:00
|
|
|
#include "content/shell/grit/shell_resources.h"
|
2015-07-23 10:18:03 +00:00
|
|
|
#include "net/base/net_errors.h"
|
2015-03-09 02:07:53 +00:00
|
|
|
#include "net/socket/stream_socket.h"
|
2017-05-18 22:29:22 +00:00
|
|
|
#include "net/socket/tcp_server_socket.h"
|
2014-07-30 03:40:17 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
namespace atom {
|
2015-01-10 01:14:52 +00:00
|
|
|
|
2014-07-30 03:40:17 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-01-23 05:48:23 +00:00
|
|
|
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
2014-12-05 23:37:11 +00:00
|
|
|
public:
|
2015-04-21 10:54:57 +00:00
|
|
|
TCPServerSocketFactory(const std::string& address, int port)
|
2018-04-18 01:56:12 +00:00
|
|
|
: address_(address), port_(port) {}
|
2014-12-05 23:37:11 +00:00
|
|
|
|
|
|
|
private:
|
2017-01-23 05:48:23 +00:00
|
|
|
// content::ServerSocketFactory.
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
|
|
|
|
std::unique_ptr<net::ServerSocket> socket(
|
2017-01-23 06:07:18 +00:00
|
|
|
new net::TCPServerSocket(nullptr, net::NetLogSource()));
|
2015-04-21 10:54:57 +00:00
|
|
|
if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK)
|
2016-05-23 01:59:07 +00:00
|
|
|
return std::unique_ptr<net::ServerSocket>();
|
2015-04-21 10:54:57 +00:00
|
|
|
|
|
|
|
return socket;
|
2014-12-05 23:37:11 +00:00
|
|
|
}
|
2017-01-23 06:07:18 +00:00
|
|
|
std::unique_ptr<net::ServerSocket> CreateForTethering(
|
|
|
|
std::string* name) override {
|
|
|
|
return std::unique_ptr<net::ServerSocket>();
|
|
|
|
}
|
2014-12-05 23:37:11 +00:00
|
|
|
|
2015-04-21 10:54:57 +00:00
|
|
|
std::string address_;
|
2016-03-08 06:38:48 +00:00
|
|
|
uint16_t port_;
|
2015-04-21 10:54:57 +00:00
|
|
|
|
2014-12-05 23:37:11 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
|
|
|
|
};
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
|
2015-03-09 02:07:53 +00:00
|
|
|
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
2014-07-30 03:40:17 +00:00
|
|
|
// See if the user specified a port on the command line (useful for
|
|
|
|
// automation). If not, use an ephemeral port by specifying 0.
|
|
|
|
int port = 0;
|
|
|
|
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
|
|
|
|
int temp_port;
|
|
|
|
std::string port_str =
|
|
|
|
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
2018-04-18 01:56:12 +00:00
|
|
|
if (base::StringToInt(port_str, &temp_port) && temp_port > 0 &&
|
|
|
|
temp_port < 65535) {
|
2014-07-30 03:40:17 +00:00
|
|
|
port = temp_port;
|
|
|
|
} else {
|
|
|
|
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
|
|
|
}
|
|
|
|
}
|
2017-01-23 06:07:18 +00:00
|
|
|
return std::unique_ptr<content::DevToolsSocketFactory>(
|
|
|
|
new TCPServerSocketFactory("127.0.0.1", port));
|
2015-12-07 11:55:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 01:14:52 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-12-05 23:37:11 +00:00
|
|
|
// DevToolsManagerDelegate ---------------------------------------------------
|
|
|
|
|
2015-01-10 01:14:52 +00:00
|
|
|
// static
|
2017-01-23 06:07:18 +00:00
|
|
|
void DevToolsManagerDelegate::StartHttpHandler() {
|
|
|
|
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
2018-04-04 13:15:04 +00:00
|
|
|
CreateSocketFactory(), base::FilePath(), base::FilePath());
|
2015-01-10 01:14:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 18:17:48 +00:00
|
|
|
DevToolsManagerDelegate::DevToolsManagerDelegate() {}
|
2014-12-05 23:37:11 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
DevToolsManagerDelegate::~DevToolsManagerDelegate() {}
|
2014-12-05 23:37:11 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) {}
|
2016-03-13 21:05:22 +00:00
|
|
|
|
2018-10-25 17:18:21 +00:00
|
|
|
void DevToolsManagerDelegate::HandleCommand(
|
2017-01-23 06:07:18 +00:00
|
|
|
content::DevToolsAgentHost* agent_host,
|
2018-04-08 16:02:06 +00:00
|
|
|
content::DevToolsAgentHostClient* client,
|
2018-10-25 17:18:21 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> command,
|
|
|
|
const std::string& message,
|
|
|
|
NotHandledCallback callback) {
|
|
|
|
std::move(callback).Run(std::move(command), message);
|
2014-12-05 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 05:48:23 +00:00
|
|
|
scoped_refptr<content::DevToolsAgentHost>
|
2017-01-23 06:07:18 +00:00
|
|
|
DevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
|
2017-01-23 05:48:23 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-23 06:07:18 +00:00
|
|
|
std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
|
2018-04-04 13:08:44 +00:00
|
|
|
return ui::ResourceBundle::GetSharedInstance()
|
2018-04-18 01:56:12 +00:00
|
|
|
.GetRawDataResource(IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE)
|
|
|
|
.as_string();
|
2017-01-23 06:07:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 13:15:04 +00:00
|
|
|
bool DevToolsManagerDelegate::HasBundledFrontendResources() {
|
|
|
|
return true;
|
2017-01-23 06:07:18 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
} // namespace atom
|