-
Notifications
You must be signed in to change notification settings - Fork 15k
/
devtools_manager_delegate.cc
118 lines (96 loc) · 3.78 KB
/
devtools_manager_delegate.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// 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.
#include "atom/browser/ui/devtools_manager_delegate.h"
#include <memory>
#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"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/devtools_socket_factory.h"
#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"
#include "content/shell/grit/shell_resources.h"
#include "net/base/net_errors.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
#include "ui/base/resource/resource_bundle.h"
namespace atom {
namespace {
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
public:
TCPServerSocketFactory(const std::string& address, int port)
: address_(address), port_(port) {}
private:
// content::ServerSocketFactory.
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
std::unique_ptr<net::ServerSocket> socket(
new net::TCPServerSocket(nullptr, net::NetLogSource()));
if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK)
return std::unique_ptr<net::ServerSocket>();
return socket;
}
std::unique_ptr<net::ServerSocket> CreateForTethering(
std::string* name) override {
return std::unique_ptr<net::ServerSocket>();
}
std::string address_;
uint16_t port_;
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
};
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
auto& command_line = *base::CommandLine::ForCurrentProcess();
// 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);
if (base::StringToInt(port_str, &temp_port) && temp_port > 0 &&
temp_port < 65535) {
port = temp_port;
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
return std::unique_ptr<content::DevToolsSocketFactory>(
new TCPServerSocketFactory("127.0.0.1", port));
}
} // namespace
// DevToolsManagerDelegate ---------------------------------------------------
// static
void DevToolsManagerDelegate::StartHttpHandler() {
content::DevToolsAgentHost::StartRemoteDebuggingServer(
CreateSocketFactory(), base::FilePath(), base::FilePath());
}
DevToolsManagerDelegate::DevToolsManagerDelegate() {}
DevToolsManagerDelegate::~DevToolsManagerDelegate() {}
void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) {}
bool DevToolsManagerDelegate::HandleCommand(
content::DevToolsAgentHost* agent_host,
content::DevToolsAgentHostClient* client,
base::DictionaryValue* command) {
return false;
}
scoped_refptr<content::DevToolsAgentHost>
DevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
return nullptr;
}
std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
return ui::ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE)
.as_string();
}
bool DevToolsManagerDelegate::HasBundledFrontendResources() {
return true;
}
} // namespace atom