diff options
22 files changed, 0 insertions, 1219 deletions
diff --git a/components/devtools_service/BUILD.gn b/components/devtools_service/BUILD.gn deleted file mode 100644 index 1c524fb..0000000 --- a/components/devtools_service/BUILD.gn +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 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 file. - -import("//mojo/public/mojo_application.gni") - -source_set("lib") { - sources = [ - "devtools_agent_host.cc", - "devtools_agent_host.h", - "devtools_http_server.cc", - "devtools_http_server.h", - "devtools_registry_impl.cc", - "devtools_registry_impl.h", - "devtools_service.cc", - "devtools_service.h", - "devtools_service_delegate.cc", - "devtools_service_delegate.h", - ] - - deps = [ - "//base", - "//components/devtools_service/public/interfaces", - "//mojo/common", - "//mojo/public/cpp/bindings", - "//mojo/public/cpp/bindings:callback", - "//mojo/public/cpp/system", - "//mojo/services/network/public/cpp", - "//mojo/services/network/public/interfaces", - "//mojo/shell/public/cpp", - "//url", - ] -} - -mojo_native_application("devtools_service") { - sources = [ - "main.cc", - ] - - avoid_runner_cycle = true - - deps = [ - ":lib", - "//mojo/shell/public/cpp", - ] -} diff --git a/components/devtools_service/DEPS b/components/devtools_service/DEPS deleted file mode 100644 index d5bdd60..0000000 --- a/components/devtools_service/DEPS +++ /dev/null @@ -1,6 +0,0 @@ -include_rules = [ - "+mojo/shell", - "+mojo/common", - "+mojo/public", - "+mojo/services/network/public", -] diff --git a/components/devtools_service/OWNERS b/components/devtools_service/OWNERS deleted file mode 100644 index 557fed8..0000000 --- a/components/devtools_service/OWNERS +++ /dev/null @@ -1 +0,0 @@ -yzshen@chromium.org diff --git a/components/devtools_service/devtools_agent_host.cc b/components/devtools_service/devtools_agent_host.cc deleted file mode 100644 index 1f68e93..0000000 --- a/components/devtools_service/devtools_agent_host.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_agent_host.h" - -#include <utility> - -namespace devtools_service { - -DevToolsAgentHost::DevToolsAgentHost(const std::string& id, - DevToolsAgentPtr agent) - : id_(id), agent_(std::move(agent)), binding_(this), delegate_(nullptr) {} - -DevToolsAgentHost::~DevToolsAgentHost() { - if (delegate_) - delegate_->OnAgentHostClosed(this); -} - -void DevToolsAgentHost::SetDelegate(Delegate* delegate) { - delegate_ = delegate; - if (delegate_) { - if (binding_.is_bound()) - return; - - agent_->SetClient(binding_.CreateInterfacePtrAndBind()); - } else { - if (!binding_.is_bound()) - return; - - binding_.Close(); - } -} - -void DevToolsAgentHost::SendProtocolMessageToAgent(const std::string& message) { - agent_->DispatchProtocolMessage(message); -} - -void DevToolsAgentHost::DispatchProtocolMessage(int32_t call_id, - const mojo::String& message, - const mojo::String& state) { - delegate_->DispatchProtocolMessage(this, message); -} - -} // namespace devtools_service diff --git a/components/devtools_service/devtools_agent_host.h b/components/devtools_service/devtools_agent_host.h deleted file mode 100644 index 21fce2e..0000000 --- a/components/devtools_service/devtools_agent_host.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ - -#include <stdint.h> - -#include <string> - -#include "base/macros.h" -#include "components/devtools_service/public/interfaces/devtools_service.mojom.h" -#include "mojo/public/cpp/bindings/binding.h" -#include "mojo/public/cpp/bindings/callback.h" - -namespace devtools_service { - -// DevToolsAgentHost represents a DevTools agent at the service side. -class DevToolsAgentHost : public DevToolsAgentClient { - public: - class Delegate { - public: - virtual ~Delegate() {} - - virtual void DispatchProtocolMessage(DevToolsAgentHost* agent_host, - const std::string& message) = 0; - - // Notifies the delegate that |agent_host| is going away. - virtual void OnAgentHostClosed(DevToolsAgentHost* agent_host) = 0; - }; - - DevToolsAgentHost(const std::string& id, DevToolsAgentPtr agent); - - ~DevToolsAgentHost() override; - - void set_agent_connection_error_handler(const mojo::Closure& handler) { - agent_.set_connection_error_handler(handler); - } - - std::string id() const { return id_; } - - // Doesn't take ownership of |delegate|. If |delegate| dies before this - // object, a new delegate or nullptr must be set so that this object doesn't - // hold an invalid pointer. - void SetDelegate(Delegate* delegate); - - bool IsAttached() const { return !!delegate_; } - - void SendProtocolMessageToAgent(const std::string& message); - - private: - // DevToolsAgentClient implementation. - void DispatchProtocolMessage(int32_t call_id, - const mojo::String& message, - const mojo::String& state) override; - - const std::string id_; - - DevToolsAgentPtr agent_; - - mojo::Binding<DevToolsAgentClient> binding_; - - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHost); -}; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ diff --git a/components/devtools_service/devtools_http_server.cc b/components/devtools_service/devtools_http_server.cc deleted file mode 100644 index 38b166f1..0000000 --- a/components/devtools_service/devtools_http_server.cc +++ /dev/null @@ -1,502 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_http_server.h" - -#include <stddef.h> -#include <string.h> -#include <string> -#include <utility> - -#include "base/bind.h" -#include "base/json/json_writer.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/stl_util.h" -#include "base/strings/stringprintf.h" -#include "base/values.h" -#include "components/devtools_service/devtools_agent_host.h" -#include "components/devtools_service/devtools_registry_impl.h" -#include "components/devtools_service/devtools_service.h" -#include "mojo/public/cpp/system/data_pipe.h" -#include "mojo/services/network/public/cpp/web_socket_read_queue.h" -#include "mojo/services/network/public/cpp/web_socket_write_queue.h" -#include "mojo/services/network/public/interfaces/net_address.mojom.h" -#include "mojo/services/network/public/interfaces/network_service.mojom.h" -#include "mojo/services/network/public/interfaces/web_socket.mojom.h" -#include "mojo/shell/public/cpp/shell.h" - -namespace devtools_service { - -namespace { - -const char kPageUrlPrefix[] = "/devtools/page/"; -const char kBrowserUrlPrefix[] = "/devtools/browser"; -const char kJsonRequestUrlPrefix[] = "/json"; - -const char kActivateCommand[] = "activate"; -const char kCloseCommand[] = "close"; -const char kListCommand[] = "list"; -const char kNewCommand[] = "new"; -const char kVersionCommand[] = "version"; - -const char kTargetIdField[] = "id"; -const char kTargetTypeField[] = "type"; -const char kTargetTitleField[] = "title"; -const char kTargetDescriptionField[] = "description"; -const char kTargetUrlField[] = "url"; -const char kTargetWebSocketDebuggerUrlField[] = "webSocketDebuggerUrl"; -const char kTargetDevtoolsFrontendUrlField[] = "devtoolsFrontendUrl"; - -std::string GetHeaderValue(const mojo::HttpRequest& request, - const std::string& name) { - for (size_t i = 0; i < request.headers.size(); ++i) { - if (name == request.headers[i]->name) - return request.headers[i]->value; - } - - return std::string(); -} - -bool ParseJsonPath(const std::string& path, - std::string* command, - std::string* target_id) { - // Fall back to list in case of empty query. - if (path.empty()) { - *command = kListCommand; - return true; - } - - if (path.find("/") != 0) { - // Malformed command. - return false; - } - *command = path.substr(1); - - size_t separator_pos = command->find("/"); - if (separator_pos != std::string::npos) { - *target_id = command->substr(separator_pos + 1); - *command = command->substr(0, separator_pos); - } - return true; -} - -mojo::HttpResponsePtr MakeResponse(uint32_t status_code, - const std::string& content_type, - const std::string& body) { - mojo::HttpResponsePtr response(mojo::HttpResponse::New()); - response->headers.resize(2); - response->headers[0] = mojo::HttpHeader::New(); - response->headers[0]->name = "Content-Length"; - response->headers[0]->value = - base::StringPrintf("%lu", static_cast<unsigned long>(body.size())); - response->headers[1] = mojo::HttpHeader::New(); - response->headers[1]->name = "Content-Type"; - response->headers[1]->value = content_type; - - if (!body.empty()) { - uint32_t num_bytes = static_cast<uint32_t>(body.size()); - MojoCreateDataPipeOptions options; - options.struct_size = sizeof(MojoCreateDataPipeOptions); - options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; - options.element_num_bytes = 1; - options.capacity_num_bytes = num_bytes; - mojo::DataPipe data_pipe(options); - response->body = std::move(data_pipe.consumer_handle); - MojoResult result = - WriteDataRaw(data_pipe.producer_handle.get(), body.data(), &num_bytes, - MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); - CHECK_EQ(MOJO_RESULT_OK, result); - } - return response; -} - -mojo::HttpResponsePtr MakeJsonResponse(uint32_t status_code, - base::Value* value, - const std::string& message) { - // Serialize value and message. - std::string json_value; - if (value) { - base::JSONWriter::WriteWithOptions( - *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json_value); - } - - return MakeResponse(status_code, "application/json; charset=UTF-8", - json_value + message); -} - -class WebSocketRelayer : public DevToolsAgentHost::Delegate, - public mojo::WebSocketClient { - public: - // Creates a WebSocketRelayer instance and sets it as the delegate of - // |agent_host|. - // - // The object destroys itself when either of the following happens: - // - |agent_host| is dead and the object finishes all pending sends (if any) - // to the Web socket; or - // - the underlying pipe of |web_socket| is closed and the object finishes all - // pending receives (if any) from the Web socket. - static mojo::WebSocketClientPtr SetUp( - DevToolsAgentHost* agent_host, - mojo::WebSocketPtr web_socket, - mojo::ScopedDataPipeProducerHandle send_stream) { - DCHECK(agent_host); - DCHECK(web_socket); - DCHECK(send_stream.is_valid()); - - mojo::WebSocketClientPtr web_socket_client; - new WebSocketRelayer(agent_host, std::move(web_socket), - std::move(send_stream), &web_socket_client); - return web_socket_client; - } - - private: - WebSocketRelayer(DevToolsAgentHost* agent_host, - mojo::WebSocketPtr web_socket, - mojo::ScopedDataPipeProducerHandle send_stream, - mojo::WebSocketClientPtr* web_socket_client) - : agent_host_(agent_host), - binding_(this, web_socket_client), - web_socket_(std::move(web_socket)), - send_stream_(std::move(send_stream)), - write_send_stream_(new mojo::WebSocketWriteQueue(send_stream_.get())), - pending_send_count_(0), - pending_receive_count_(0) { - web_socket_.set_connection_error_handler([this]() { OnConnectionError(); }); - agent_host->SetDelegate(this); - } - - ~WebSocketRelayer() override { - if (agent_host_) - agent_host_->SetDelegate(nullptr); - } - - // DevToolsAgentHost::Delegate implementation. - void DispatchProtocolMessage(DevToolsAgentHost* agent_host, - const std::string& message) override { - if (!web_socket_) - return; - - // TODO(yzshen): It shouldn't be an issue to pass an empty message. However, - // WebSocket{Read,Write}Queue doesn't handle that correctly. - if (message.empty()) - return; - - pending_send_count_++; - uint32_t size = static_cast<uint32_t>(message.size()); - write_send_stream_->Write( - &message[0], size, - base::Bind(&WebSocketRelayer::OnFinishedWritingSendStream, - base::Unretained(this), size)); - } - - void OnAgentHostClosed(DevToolsAgentHost* agent_host) override { - DispatchProtocolMessage(agent_host_, - "{ \"method\": \"Inspector.detached\", " - "\"params\": { \"reason\": \"target_closed\" } }"); - - // No need to call SetDelegate(nullptr) on |agent_host_| because it is going - // away. - agent_host_ = nullptr; - - if (ShouldSelfDestruct()) - delete this; - } - - // WebSocketClient implementation. - void DidConnect(const mojo::String& selected_subprotocol, - const mojo::String& extensions, - mojo::ScopedDataPipeConsumerHandle receive_stream) override { - receive_stream_ = std::move(receive_stream); - read_receive_stream_.reset( - new mojo::WebSocketReadQueue(receive_stream_.get())); - } - - void DidReceiveData(bool fin, - mojo::WebSocket::MessageType type, - uint32_t num_bytes) override { - if (!agent_host_) - return; - - // TODO(yzshen): It shouldn't be an issue to pass an empty message. However, - // WebSocket{Read,Write}Queue doesn't handle that correctly. - if (num_bytes == 0) - return; - - pending_receive_count_++; - read_receive_stream_->Read( - num_bytes, base::Bind(&WebSocketRelayer::OnFinishedReadingReceiveStream, - base::Unretained(this), num_bytes)); - } - - void DidReceiveFlowControl(int64_t quota) override {} - - void DidFail(const mojo::String& message) override {} - - void DidClose(bool was_clean, - uint16_t code, - const mojo::String& reason) override {} - - void OnConnectionError() { - web_socket_ = nullptr; - binding_.Close(); - - if (ShouldSelfDestruct()) - delete this; - } - - void OnFinishedWritingSendStream(uint32_t num_bytes, const char* buffer) { - DCHECK_GT(pending_send_count_, 0u); - pending_send_count_--; - - if (web_socket_ && buffer) - web_socket_->Send(true, mojo::WebSocket::MessageType::TEXT, num_bytes); - - if (ShouldSelfDestruct()) - delete this; - } - - void OnFinishedReadingReceiveStream(uint32_t num_bytes, const char* data) { - DCHECK_GT(pending_receive_count_, 0u); - pending_receive_count_--; - - if (agent_host_ && data) - agent_host_->SendProtocolMessageToAgent(std::string(data, num_bytes)); - - if (ShouldSelfDestruct()) - delete this; - } - - bool ShouldSelfDestruct() const { - return (!agent_host_ && pending_send_count_ == 0) || - (!web_socket_ && pending_receive_count_ == 0); - } - - DevToolsAgentHost* agent_host_; - mojo::Binding<WebSocketClient> binding_; - mojo::WebSocketPtr web_socket_; - - mojo::ScopedDataPipeProducerHandle send_stream_; - scoped_ptr<mojo::WebSocketWriteQueue> write_send_stream_; - size_t pending_send_count_; - - mojo::ScopedDataPipeConsumerHandle receive_stream_; - scoped_ptr<mojo::WebSocketReadQueue> read_receive_stream_; - size_t pending_receive_count_; - - DISALLOW_COPY_AND_ASSIGN(WebSocketRelayer); -}; - -} // namespace - -class DevToolsHttpServer::HttpConnectionDelegateImpl - : public mojo::HttpConnectionDelegate { - public: - HttpConnectionDelegateImpl( - DevToolsHttpServer* owner, - mojo::HttpConnectionPtr connection, - mojo::InterfaceRequest<HttpConnectionDelegate> delegate_request) - : owner_(owner), - connection_(std::move(connection)), - binding_(this, std::move(delegate_request)) { - DCHECK(owner_); - DCHECK(connection_); - DCHECK(binding_.is_bound()); - - auto error_handler = [this]() { owner_->OnConnectionClosed(this); }; - connection_.set_connection_error_handler(error_handler); - binding_.set_connection_error_handler(error_handler); - } - - mojo::HttpConnection* connection() { return connection_.get(); } - - private: - // mojo::HttpConnectionDelegate implementation: - void OnReceivedRequest(mojo::HttpRequestPtr request, - const OnReceivedRequestCallback& callback) override { - owner_->OnReceivedRequest(this, std::move(request), callback); - } - - void OnReceivedWebSocketRequest( - mojo::HttpRequestPtr request, - const OnReceivedWebSocketRequestCallback& callback) override { - owner_->OnReceivedWebSocketRequest(this, std::move(request), callback); - } - - DevToolsHttpServer* const owner_; - mojo::HttpConnectionPtr connection_; - mojo::Binding<HttpConnectionDelegate> binding_; - - DISALLOW_COPY_AND_ASSIGN(HttpConnectionDelegateImpl); -}; - -DevToolsHttpServer::DevToolsHttpServer(DevToolsService* service, - uint16_t remote_debugging_port) - : service_(service), remote_debugging_port_(remote_debugging_port) { - VLOG(1) << "Remote debugging HTTP server is started on port " - << remote_debugging_port << "."; - mojo::NetworkServicePtr network_service; - service_->shell()->ConnectToService("mojo:network_service", &network_service); - - mojo::NetAddressPtr local_address(mojo::NetAddress::New()); - local_address->family = mojo::NetAddressFamily::IPV4; - local_address->ipv4 = mojo::NetAddressIPv4::New(); - local_address->ipv4->port = remote_debugging_port; - local_address->ipv4->addr.resize(4); - local_address->ipv4->addr[0] = 127; - local_address->ipv4->addr[1] = 0; - local_address->ipv4->addr[2] = 0; - local_address->ipv4->addr[3] = 1; - - mojo::HttpServerDelegatePtr http_server_delegate; - http_server_delegate_binding_.reset( - new mojo::Binding<mojo::HttpServerDelegate>(this, &http_server_delegate)); - network_service->CreateHttpServer( - std::move(local_address), std::move(http_server_delegate), - mojo::NetworkService::CreateHttpServerCallback()); -} - -DevToolsHttpServer::~DevToolsHttpServer() { - STLDeleteElements(&connections_); -} - -void DevToolsHttpServer::OnConnected( - mojo::HttpConnectionPtr connection, - mojo::InterfaceRequest<mojo::HttpConnectionDelegate> delegate) { - connections_.insert(new HttpConnectionDelegateImpl( - this, std::move(connection), std::move(delegate))); -} - -void DevToolsHttpServer::OnReceivedRequest( - HttpConnectionDelegateImpl* connection, - mojo::HttpRequestPtr request, - const OnReceivedRequestCallback& callback) { - DCHECK(connections_.find(connection) != connections_.end()); - - if (request->url.get().find(kJsonRequestUrlPrefix) == 0) { - mojo::HttpResponsePtr response = ProcessJsonRequest(std::move(request)); - if (response) - callback.Run(std::move(response)); - else - OnConnectionClosed(connection); - } else { - // TODO(yzshen): Implement it. - NOTIMPLEMENTED(); - callback.Run(MakeResponse(404, "text/html", "Not implemented yet!")); - } -} - -void DevToolsHttpServer::OnReceivedWebSocketRequest( - HttpConnectionDelegateImpl* connection, - mojo::HttpRequestPtr request, - const OnReceivedWebSocketRequestCallback& callback) { - DCHECK(connections_.find(connection) != connections_.end()); - - std::string path = request->url; - size_t browser_pos = path.find(kBrowserUrlPrefix); - if (browser_pos == 0) { - // TODO(yzshen): Implement it. - NOTIMPLEMENTED(); - callback.Run(nullptr, mojo::ScopedDataPipeConsumerHandle(), nullptr); - return; - } - - size_t pos = path.find(kPageUrlPrefix); - if (pos != 0) { - callback.Run(nullptr, mojo::ScopedDataPipeConsumerHandle(), nullptr); - return; - } - - std::string target_id = path.substr(strlen(kPageUrlPrefix)); - DevToolsAgentHost* agent = service_->registry()->GetAgentById(target_id); - if (!agent || agent->IsAttached()) { - callback.Run(nullptr, mojo::ScopedDataPipeConsumerHandle(), nullptr); - return; - } - - mojo::WebSocketPtr web_socket; - mojo::InterfaceRequest<mojo::WebSocket> web_socket_request = - mojo::GetProxy(&web_socket); - mojo::DataPipe data_pipe; - mojo::WebSocketClientPtr web_socket_client = WebSocketRelayer::SetUp( - agent, std::move(web_socket), std::move(data_pipe.producer_handle)); - callback.Run(std::move(web_socket_request), - std::move(data_pipe.consumer_handle), - std::move(web_socket_client)); -} - -void DevToolsHttpServer::OnConnectionClosed( - HttpConnectionDelegateImpl* connection) { - DCHECK(connections_.find(connection) != connections_.end()); - - delete connection; - connections_.erase(connection); -} - -mojo::HttpResponsePtr DevToolsHttpServer::ProcessJsonRequest( - mojo::HttpRequestPtr request) { - // Trim "/json". - std::string path = request->url.get().substr(strlen(kJsonRequestUrlPrefix)); - - // Trim query. - size_t query_pos = path.find("?"); - if (query_pos != std::string::npos) - path = path.substr(0, query_pos); - - // Trim fragment. - size_t fragment_pos = path.find("#"); - if (fragment_pos != std::string::npos) - path = path.substr(0, fragment_pos); - - std::string command; - std::string target_id; - if (!ParseJsonPath(path, &command, &target_id)) - return MakeJsonResponse(404, nullptr, - "Malformed query: " + request->url.get()); - - if (command == kVersionCommand || command == kNewCommand || - command == kActivateCommand || command == kCloseCommand) { - NOTIMPLEMENTED(); - return MakeJsonResponse(404, nullptr, - "Not implemented yet: " + request->url.get()); - } - - if (command == kListCommand) { - DevToolsRegistryImpl::Iterator iter(service_->registry()); - if (iter.IsAtEnd()) { - // If no agent is available, return a nullptr to indicate that the - // connection should be closed. - return nullptr; - } - - std::string host = GetHeaderValue(*request, "host"); - if (host.empty()) { - host = base::StringPrintf("127.0.0.1:%u", - static_cast<unsigned>(remote_debugging_port_)); - } - - base::ListValue list_value; - for (; !iter.IsAtEnd(); iter.Advance()) { - scoped_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue()); - - // TODO(yzshen): Add more information. - dict_value->SetString(kTargetDescriptionField, std::string()); - dict_value->SetString(kTargetDevtoolsFrontendUrlField, std::string()); - dict_value->SetString(kTargetIdField, iter.value()->id()); - dict_value->SetString(kTargetTitleField, std::string()); - dict_value->SetString(kTargetTypeField, "page"); - dict_value->SetString(kTargetUrlField, std::string()); - dict_value->SetString( - kTargetWebSocketDebuggerUrlField, - base::StringPrintf("ws://%s%s%s", host.c_str(), kPageUrlPrefix, - iter.value()->id().c_str())); - list_value.Append(std::move(dict_value)); - } - return MakeJsonResponse(200, &list_value, std::string()); - } - - return MakeJsonResponse(404, nullptr, "Unknown command: " + command); -} - -} // namespace devtools_service diff --git a/components/devtools_service/devtools_http_server.h b/components/devtools_service/devtools_http_server.h deleted file mode 100644 index f6ed06c..0000000 --- a/components/devtools_service/devtools_http_server.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_HTTP_SERVER_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_HTTP_SERVER_H_ - -#include <stdint.h> - -#include <set> - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "mojo/public/cpp/bindings/binding.h" -#include "mojo/services/network/public/interfaces/http_connection.mojom.h" -#include "mojo/services/network/public/interfaces/http_message.mojom.h" -#include "mojo/services/network/public/interfaces/http_server.mojom.h" - -namespace devtools_service { - -class DevToolsService; - -class DevToolsHttpServer : public mojo::HttpServerDelegate { - public: - // |service| must outlive this object. - DevToolsHttpServer(DevToolsService* service, uint16_t remote_debugging_port); - ~DevToolsHttpServer() override; - - private: - class HttpConnectionDelegateImpl; - - // mojo::HttpServerDelegate implementation. - void OnConnected( - mojo::HttpConnectionPtr connection, - mojo::InterfaceRequest<mojo::HttpConnectionDelegate> delegate) override; - - // The following three methods are called by HttpConnectionDelegateImpl. - using OnReceivedRequestCallback = - mojo::HttpConnectionDelegate::OnReceivedRequestCallback; - void OnReceivedRequest(HttpConnectionDelegateImpl* connection, - mojo::HttpRequestPtr request, - const OnReceivedRequestCallback& callback); - using OnReceivedWebSocketRequestCallback = - mojo::HttpConnectionDelegate::OnReceivedWebSocketRequestCallback; - void OnReceivedWebSocketRequest( - HttpConnectionDelegateImpl* connection, - mojo::HttpRequestPtr request, - const OnReceivedWebSocketRequestCallback& callback); - void OnConnectionClosed(HttpConnectionDelegateImpl* connection); - - mojo::HttpResponsePtr ProcessJsonRequest(mojo::HttpRequestPtr request); - - // Not owned by this object. - DevToolsService* const service_; - - const uint16_t remote_debugging_port_; - - scoped_ptr<mojo::Binding<mojo::HttpServerDelegate>> - http_server_delegate_binding_; - - // Owns the elements. - std::set<HttpConnectionDelegateImpl*> connections_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsHttpServer); -}; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_HTTP_SERVER_H_ diff --git a/components/devtools_service/devtools_registry_impl.cc b/components/devtools_service/devtools_registry_impl.cc deleted file mode 100644 index 6dfe242..0000000 --- a/components/devtools_service/devtools_registry_impl.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_registry_impl.h" - -#include <utility> - -#include "base/logging.h" -#include "components/devtools_service/devtools_agent_host.h" - -namespace devtools_service { - -DevToolsRegistryImpl::Iterator::Iterator(DevToolsRegistryImpl* registry) - : registry_(registry), iter_(registry->agents_.begin()) { -} - -DevToolsRegistryImpl::Iterator::~Iterator() { -} - -DevToolsRegistryImpl::DevToolsRegistryImpl(DevToolsService* service) - : service_(service) { -} - -DevToolsRegistryImpl::~DevToolsRegistryImpl() { -} - -void DevToolsRegistryImpl::BindToRegistryRequest( - mojo::InterfaceRequest<DevToolsRegistry> request) { - bindings_.AddBinding(this, std::move(request)); -} - -DevToolsAgentHost* DevToolsRegistryImpl::GetAgentById(const std::string& id) { - auto iter = agents_.find(id); - if (iter == agents_.end()) - return nullptr; - - return iter->second.get(); -} - -void DevToolsRegistryImpl::RegisterAgent(const mojo::String& id, - DevToolsAgentPtr agent) { - linked_ptr<DevToolsAgentHost> agent_host( - new DevToolsAgentHost(id, std::move(agent))); - agent_host->set_agent_connection_error_handler( - [this, id]() { OnAgentConnectionError(id); }); - - agents_[id] = agent_host; -} - -void DevToolsRegistryImpl::OnAgentConnectionError(const std::string& id) { - DCHECK(agents_.find(id) != agents_.end()); - agents_.erase(id); -} - -} // namespace devtools_service diff --git a/components/devtools_service/devtools_registry_impl.h b/components/devtools_service/devtools_registry_impl.h deleted file mode 100644 index 64974f5..0000000 --- a/components/devtools_service/devtools_registry_impl.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_ - -#include <map> -#include <string> - -#include "base/macros.h" -#include "base/memory/linked_ptr.h" -#include "components/devtools_service/public/interfaces/devtools_service.mojom.h" -#include "mojo/common/weak_binding_set.h" - -namespace devtools_service { - -class DevToolsAgentHost; -class DevToolsService; - -class DevToolsRegistryImpl : public DevToolsRegistry { - public: - class Iterator { - public: - // |registry| must outlive this object. - explicit Iterator(DevToolsRegistryImpl* registry); - ~Iterator(); - - bool IsAtEnd() const { return iter_ == registry_->agents_.end(); } - void Advance() { ++iter_; } - - DevToolsAgentHost* value() { return iter_->second.get(); } - - private: - DevToolsRegistryImpl* const registry_; - std::map<std::string, linked_ptr<DevToolsAgentHost>>::const_iterator iter_; - }; - - // |service| must outlive this object. - explicit DevToolsRegistryImpl(DevToolsService* service); - ~DevToolsRegistryImpl() override; - - void BindToRegistryRequest(mojo::InterfaceRequest<DevToolsRegistry> request); - - DevToolsAgentHost* GetAgentById(const std::string& id); - - private: - // DevToolsRegistry implementation. - void RegisterAgent(const mojo::String& id, DevToolsAgentPtr agent) override; - - void OnAgentConnectionError(const std::string& id); - - DevToolsService* const service_; - - mojo::WeakBindingSet<DevToolsRegistry> bindings_; - - std::map<std::string, linked_ptr<DevToolsAgentHost>> agents_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsRegistryImpl); -}; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_ diff --git a/components/devtools_service/devtools_service.cc b/components/devtools_service/devtools_service.cc deleted file mode 100644 index cf265f8..0000000 --- a/components/devtools_service/devtools_service.cc +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_service.h" - -#include <utility> - -#include "base/logging.h" -#include "components/devtools_service/devtools_http_server.h" -#include "mojo/shell/public/cpp/shell.h" - -namespace devtools_service { - -DevToolsService::DevToolsService(mojo::Shell* shell) - : shell_(shell), registry_(this) { - DCHECK(shell_); -} - -DevToolsService::~DevToolsService() { -} - -void DevToolsService::BindToCoordinatorRequest( - mojo::InterfaceRequest<DevToolsCoordinator> request) { - coordinator_bindings_.AddBinding(this, std::move(request)); -} - -void DevToolsService::Initialize(uint16_t remote_debugging_port) { - if (http_server_) { - LOG(WARNING) << "DevTools service receives a " - << "DevToolsCoordinator.Initialize() call while it has " - << "already been initialized."; - return; - } - - http_server_.reset(new DevToolsHttpServer(this, remote_debugging_port)); -} - -} // namespace devtools_service diff --git a/components/devtools_service/devtools_service.h b/components/devtools_service/devtools_service.h deleted file mode 100644 index 974e938..0000000 --- a/components/devtools_service/devtools_service.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_H_ - -#include <stdint.h> - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "components/devtools_service/devtools_registry_impl.h" -#include "components/devtools_service/public/interfaces/devtools_service.mojom.h" -#include "mojo/common/weak_binding_set.h" - -namespace mojo { -class Shell; -} - -namespace devtools_service { - -class DevToolsHttpServer; - -// DevToolsService is the central control. It manages the communication with -// DevTools agents (e.g., Web page renderers). It also starts an HTTP server to -// speak the Chrome remote debugging protocol. -class DevToolsService : public DevToolsCoordinator { - public: - // Doesn't take ownership of |application|, which must outlive this object. - explicit DevToolsService(mojo::Shell* shell); - ~DevToolsService() override; - - void BindToCoordinatorRequest( - mojo::InterfaceRequest<DevToolsCoordinator> request); - - mojo::Shell* shell() { return shell_; } - - DevToolsRegistryImpl* registry() { return ®istry_; } - - private: - // DevToolsCoordinator implementation. - void Initialize(uint16_t remote_debugging_port) override; - - // Not owned by this object. - mojo::Shell* const shell_; - - mojo::WeakBindingSet<DevToolsCoordinator> coordinator_bindings_; - - scoped_ptr<DevToolsHttpServer> http_server_; - DevToolsRegistryImpl registry_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsService); -}; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_H_ diff --git a/components/devtools_service/devtools_service_delegate.cc b/components/devtools_service/devtools_service_delegate.cc deleted file mode 100644 index 9e3dc5f..0000000 --- a/components/devtools_service/devtools_service_delegate.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_service_delegate.h" - -#include <utility> - -#include "base/logging.h" -#include "components/devtools_service/devtools_registry_impl.h" -#include "components/devtools_service/devtools_service.h" -#include "mojo/common/url_type_converters.h" -#include "mojo/shell/public/cpp/connection.h" -#include "mojo/shell/public/cpp/shell.h" -#include "url/gurl.h" - -namespace devtools_service { - -namespace { - -bool IsShell(const GURL& requestor_url) { - // TODO(yzshen): http://crbug.com/491656 "mojo://shell/" has to be used - // instead of "mojo:shell" because "mojo" is not treated as a standard scheme. - return requestor_url == GURL("mojo://shell/"); -} - -} // namespace - -DevToolsServiceDelegate::DevToolsServiceDelegate() { -} - -DevToolsServiceDelegate::~DevToolsServiceDelegate() { -} - -void DevToolsServiceDelegate::Initialize(mojo::Shell* shell, - const std::string& url, - uint32_t id) { - service_.reset(new DevToolsService(shell)); -} - -bool DevToolsServiceDelegate::AcceptConnection(mojo::Connection* connection) { - connection->AddInterface<DevToolsRegistry>(this); - - // DevToolsCoordinator is a privileged interface and only allowed for the - // shell. - if (IsShell(GURL(connection->GetRemoteApplicationURL()))) - connection->AddInterface<DevToolsCoordinator>(this); - return true; -} - -void DevToolsServiceDelegate::Quit() { - service_.reset(); -} - -void DevToolsServiceDelegate::Create( - mojo::Connection* connection, - mojo::InterfaceRequest<DevToolsRegistry> request) { - service_->registry()->BindToRegistryRequest(std::move(request)); -} - -void DevToolsServiceDelegate::Create( - mojo::Connection* connection, - mojo::InterfaceRequest<DevToolsCoordinator> request) { - service_->BindToCoordinatorRequest(std::move(request)); -} - -} // namespace devtools_service diff --git a/components/devtools_service/devtools_service_delegate.h b/components/devtools_service/devtools_service_delegate.h deleted file mode 100644 index 5ae52f9..0000000 --- a/components/devtools_service/devtools_service_delegate.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_DELEGATE_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_DELEGATE_H_ - -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "components/devtools_service/public/interfaces/devtools_service.mojom.h" -#include "mojo/shell/public/cpp/interface_factory.h" -#include "mojo/shell/public/cpp/shell_client.h" - -namespace devtools_service { - -class DevToolsService; - -class DevToolsServiceDelegate - : public mojo::ShellClient, - public mojo::InterfaceFactory<DevToolsRegistry>, - public mojo::InterfaceFactory<DevToolsCoordinator> { - public: - DevToolsServiceDelegate(); - ~DevToolsServiceDelegate() override; - - private: - // mojo::Connection implementation. - void Initialize(mojo::Shell* shell, const std::string& url, - uint32_t id) override; - bool AcceptConnection(mojo::Connection* connection) override; - void Quit() override; - - // mojo::InterfaceFactory<DevToolsRegistry> implementation. - void Create(mojo::Connection* connection, - mojo::InterfaceRequest<DevToolsRegistry> request) override; - - // mojo::InterfaceFactory<DevToolsCoordinator> implementation. - void Create(mojo::Connection* connection, - mojo::InterfaceRequest<DevToolsCoordinator> request) override; - - scoped_ptr<DevToolsService> service_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsServiceDelegate); -}; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_DELEGATE_H_ diff --git a/components/devtools_service/main.cc b/components/devtools_service/main.cc deleted file mode 100644 index 169ba7b..0000000 --- a/components/devtools_service/main.cc +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/devtools_service_delegate.h" -#include "mojo/public/c/system/main.h" -#include "mojo/shell/public/cpp/application_runner.h" - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunner runner(new devtools_service::DevToolsServiceDelegate); - return runner.Run(shell_handle); -} diff --git a/components/devtools_service/public/cpp/BUILD.gn b/components/devtools_service/public/cpp/BUILD.gn deleted file mode 100644 index 2f8933b..0000000 --- a/components/devtools_service/public/cpp/BUILD.gn +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 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 file. - -source_set("cpp") { - sources = [ - "switches.cc", - "switches.h", - ] -} diff --git a/components/devtools_service/public/cpp/switches.cc b/components/devtools_service/public/cpp/switches.cc deleted file mode 100644 index 0a1d8ea..0000000 --- a/components/devtools_service/public/cpp/switches.cc +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 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 file. - -#include "components/devtools_service/public/cpp/switches.h" - -namespace devtools_service { - -// Enables remote debug over HTTP on the specified port. -const char kRemoteDebuggingPort[] = "remote-debugging-port"; - -} // namespace devtools_service diff --git a/components/devtools_service/public/cpp/switches.h b/components/devtools_service/public/cpp/switches.h deleted file mode 100644 index 65c48e9..0000000 --- a/components/devtools_service/public/cpp/switches.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 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 file. - -#ifndef COMPONENTS_DEVTOOLS_SERVICE_PUBLIC_CPP_SWITCHES_H_ -#define COMPONENTS_DEVTOOLS_SERVICE_PUBLIC_CPP_SWITCHES_H_ - -namespace devtools_service { - -// All switches in alphabetical order. The switches should be documented -// alongside the definition of their values in the .cc file. -extern const char kRemoteDebuggingPort[]; - -} // namespace devtools_service - -#endif // COMPONENTS_DEVTOOLS_SERVICE_PUBLIC_CPP_SWITCHES_H_ diff --git a/components/devtools_service/public/interfaces/BUILD.gn b/components/devtools_service/public/interfaces/BUILD.gn deleted file mode 100644 index f3dd804..0000000 --- a/components/devtools_service/public/interfaces/BUILD.gn +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 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 file. - -import("//mojo/public/tools/bindings/mojom.gni") - -mojom("interfaces") { - sources = [ - "devtools_service.mojom", - ] -} diff --git a/components/devtools_service/public/interfaces/devtools_service.mojom b/components/devtools_service/public/interfaces/devtools_service.mojom deleted file mode 100644 index 83d4750..0000000 --- a/components/devtools_service/public/interfaces/devtools_service.mojom +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 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 file. - -module devtools_service; - -// The DevTools service exposes two interfaces: -// - DevToolsCoordinator: Privileged interface used by the shell to setup the -// service and perform other control operations. Other applications are not -// able to request this interface. -// - DevToolsRegistry: Interface that DevTools agents (e.g., Web page renderers) -// use to register themselves. -// -// DevTools agents need to implement the DevToolsAgent interface and register -// themselves in order to receive DevTools commands from the DevTools service. - -interface DevToolsCoordinator { - // Initializes the DevTools service. An HTTP server will be run on the - // specified port and speak the Chrome remote debugging protocol. - Initialize(uint16 remote_debugging_port); -}; - -interface DevToolsRegistry { - // Registers a DevTools agent. |id| is the agent ID, which is used to identify - // the agent when the service and its clients communicate using the Chrome - // remote debugging protocol. - RegisterAgent(string id, DevToolsAgent agent); -}; - -interface DevToolsAgent { - // Sets/resets a client to receive event notifications and responses for - // DispatchProtocolMessage() calls. If a client doesn't want to receive - // messages anymore, it could simply close the underlying message pipe of - // |client|. - SetClient(DevToolsAgentClient client); - - // Sends a command (in remote debugging protocol JSON format) to the agent. - DispatchProtocolMessage(string message); -}; - -interface DevToolsAgentClient { - // Sends a notification or response message to the client. |message| is in - // remote debugging protocol JSON format. |call_id| is the "id" field of the - // message or 0 if such a field doesn't exist. If not empty or null, |state| - // is the state of the DevTools agent at the point when generating this - // message. - DispatchProtocolMessage(int32 call_id, string message, string? state); -}; diff --git a/mojo/shell/standalone/BUILD.gn b/mojo/shell/standalone/BUILD.gn index 6dcfdf3..b84fb32 100644 --- a/mojo/shell/standalone/BUILD.gn +++ b/mojo/shell/standalone/BUILD.gn @@ -105,8 +105,6 @@ source_set("lib") { "//base", "//base:base_static", "//base/third_party/dynamic_annotations", - "//components/devtools_service/public/cpp", - "//components/devtools_service/public/interfaces", "//components/tracing:startup_tracing", "//mojo/message_pump", "//mojo/services/network/public/interfaces", @@ -132,7 +130,6 @@ source_set("lib") { if (!is_component_build) { data_deps = [ - "//components/devtools_service", "//mojo/services/tracing", ] } diff --git a/mojo/shell/standalone/DEPS b/mojo/shell/standalone/DEPS index 09e0750..473cdf7 100644 --- a/mojo/shell/standalone/DEPS +++ b/mojo/shell/standalone/DEPS @@ -1,5 +1,4 @@ include_rules = [ - "+components/devtools_service/public", "+components/mus", "+components/mus/gles2", "+components/mus/native_viewport", diff --git a/mojo/shell/standalone/context.cc b/mojo/shell/standalone/context.cc index ed2c364..6f0ae06 100644 --- a/mojo/shell/standalone/context.cc +++ b/mojo/shell/standalone/context.cc @@ -24,8 +24,6 @@ #include "base/strings/string_util.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" -#include "components/devtools_service/public/cpp/switches.h" -#include "components/devtools_service/public/interfaces/devtools_service.mojom.h" #include "components/tracing/tracing_switches.h" #include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/services/tracing/public/cpp/switches.h" @@ -117,37 +115,6 @@ void InitContentHandlers(PackageManagerImpl* manager, } } -void InitDevToolsServiceIfNeeded(ApplicationManager* manager, - const base::CommandLine& command_line) { - if (!command_line.HasSwitch(devtools_service::kRemoteDebuggingPort)) - return; - - std::string port_str = - command_line.GetSwitchValueASCII(devtools_service::kRemoteDebuggingPort); - unsigned port; - if (!base::StringToUint(port_str, &port) || port > 65535) { - LOG(ERROR) << "Invalid value for switch " - << devtools_service::kRemoteDebuggingPort << ": '" << port_str - << "' is not a valid port number."; - return; - } - - ServiceProviderPtr devtools_service_provider; - scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); - params->set_source(Identity(GURL("mojo:shell"), std::string(), - GetPermissiveCapabilityFilter())); - params->SetTarget(Identity(GURL("mojo:devtools_service"), std::string(), - GetPermissiveCapabilityFilter())); - params->set_services(GetProxy(&devtools_service_provider)); - manager->ConnectToApplication(std::move(params)); - - devtools_service::DevToolsCoordinatorPtr devtools_coordinator; - devtools_service_provider->ConnectToService( - devtools_service::DevToolsCoordinator::Name_, - GetProxy(&devtools_coordinator).PassMessagePipe()); - devtools_coordinator->Initialize(static_cast<uint16_t>(port)); -} - class TracingServiceProvider : public ServiceProvider { public: TracingServiceProvider(Tracer* tracer, @@ -265,8 +232,6 @@ void Context::Init(const base::FilePath& shell_file_root) { #endif collector->SetShellMainEntryPointTime(main_entry_time_.ToInternalValue()); } - - InitDevToolsServiceIfNeeded(application_manager_.get(), command_line); } void Context::Shutdown() { |