Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: components/ui_devtools/devtools_server.cc

Issue 2502863002: Add UI DevTools under chrome://inspect/#other (Closed)
Patch Set: feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ui_devtools/devtools_server.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ui_devtools/devtools_server.cc
diff --git a/components/ui_devtools/devtools_server.cc b/components/ui_devtools/devtools_server.cc
index ff0616d52c916cb8df69229b0189a6cb6f65fe22..a7428e4b4c82427f69ae1b7bcc4ebdd00f8238ee 100644
--- a/components/ui_devtools/devtools_server.cc
+++ b/components/ui_devtools/devtools_server.cc
@@ -25,11 +25,32 @@ namespace devtools {
namespace {
const char kChromeDeveloperToolsPrefix[] =
"chrome-devtools://devtools/bundled/inspector.html?ws=";
+
+bool IsUiDevToolsEnabled() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableUiDevTools);
+}
+
+int GetUiDevToolsPort() {
+ DCHECK(IsUiDevToolsEnabled());
+ constexpr int kDefaultPort = 9223;
+ int port;
+ if (!base::StringToInt(
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ kEnableUiDevTools),
+ &port))
+ port = kDefaultPort;
+ return port;
+}
+
} // namespace
+UiDevToolsServer* UiDevToolsServer::devtools_server_ = nullptr;
+
UiDevToolsServer::UiDevToolsServer(
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: task_runner_(task_runner) {
+ DCHECK(!devtools_server_);
+ devtools_server_ = this;
if (task_runner_)
return;
// If task_runner not passed in, create an I/O thread the server can run on
@@ -40,25 +61,40 @@ UiDevToolsServer::UiDevToolsServer(
task_runner_ = thread_->task_runner();
}
-UiDevToolsServer::~UiDevToolsServer() {}
+UiDevToolsServer::~UiDevToolsServer() {
+ devtools_server_ = nullptr;
+}
// static
std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
std::unique_ptr<UiDevToolsServer> server;
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableUiDevTools)) {
+ if (IsUiDevToolsEnabled() && !devtools_server_) {
// TODO(mhashmi): Change port if more than one inspectable clients
- int port = 9223; // Default port is 9223
- base::StringToInt(
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- kEnableUiDevTools),
- &port);
server.reset(new UiDevToolsServer(task_runner));
- server->Start("127.0.0.1", port);
+ server->Start("127.0.0.1", GetUiDevToolsPort());
}
return server;
}
+// static
+std::vector<UiDevToolsServer::NameUrlPair>
+UiDevToolsServer::GetClientNamesAndUrls() {
+ std::vector<NameUrlPair> pairs;
+ if (!devtools_server_)
+ return pairs;
+
+ for (ClientsList::size_type i = 0; i != devtools_server_->clients_.size();
+ i++) {
+ pairs.push_back(std::pair<std::string, std::string>(
+ devtools_server_->clients_[i]->name(),
+ base::StringPrintf("%slocalhost:%d/%" PRIuS,
+ kChromeDeveloperToolsPrefix, GetUiDevToolsPort(),
+ i)));
+ }
+ return pairs;
+}
+
void UiDevToolsServer::AttachClient(std::unique_ptr<UiDevToolsClient> client) {
clients_.push_back(std::move(client));
}
@@ -96,32 +132,7 @@ void UiDevToolsServer::OnConnect(int connection_id) {
void UiDevToolsServer::OnHttpRequest(int connection_id,
const net::HttpServerRequestInfo& info) {
- // Display a simple html page with all the clients and the corresponding
- // devtools links
- // TODO(mhashmi): Remove and display all clients under chrome://inspect/#other
- if (info.path.empty() || info.path == "/") {
- std::string clientHTML = "<html>";
- clientHTML +=
- "<h3>Copy paste the corresponding links in your browser to inspect "
- "them:</h3>";
- net::IPEndPoint ip;
- server_->GetLocalAddress(&ip);
- for (ClientsList::size_type i = 0; i != clients_.size(); i++) {
- clientHTML += base::StringPrintf(
- "<p><strong>%s</strong> (%s%s/%" PRIuS ")</p>",
- clients_[i]->name().c_str(), kChromeDeveloperToolsPrefix,
- ip.ToString().c_str(), i);
- }
- clientHTML += "</html>";
- task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&net::HttpServer::Send200, base::Unretained(server_.get()),
- connection_id, clientHTML, "text/html"));
- return;
- }
- task_runner_->PostTask(
- FROM_HERE, base::Bind(&net::HttpServer::Send404,
- base::Unretained(server_.get()), connection_id));
+ NOTIMPLEMENTED();
}
void UiDevToolsServer::OnWebSocketRequest(
« no previous file with comments | « components/ui_devtools/devtools_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698