summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools
diff options
context:
space:
mode:
authorvkuzkokov <vkuzkokov@chromium.org>2014-11-11 04:55:54 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-11 12:56:15 +0000
commit5323241303055424caca721c48306aae8d10df35 (patch)
tree1950d5735c6e50a9e647cd7d38020ad7fa64d23c /content/browser/devtools
parentc48f7c3c2037f98037533971a459f56a16c40ceb (diff)
downloadchromium_src-5323241303055424caca721c48306aae8d10df35.zip
chromium_src-5323241303055424caca721c48306aae8d10df35.tar.gz
chromium_src-5323241303055424caca721c48306aae8d10df35.tar.bz2
[DevTools] Added browser protocol to handler generator
BUG=405566 Review URL: https://codereview.chromium.org/658163003 Cr-Commit-Position: refs/heads/master@{#303632}
Diffstat (limited to 'content/browser/devtools')
-rw-r--r--content/browser/devtools/BUILD.gn8
-rw-r--r--content/browser/devtools/browser_protocol.json8
-rw-r--r--content/browser/devtools/devtools.gyp5
-rw-r--r--content/browser/devtools/devtools_http_handler_impl.cc11
-rwxr-xr-xcontent/browser/devtools/protocol/devtools_protocol_handler_generator.py22
-rw-r--r--content/browser/devtools/protocol/system_info_handler.cc25
-rw-r--r--content/browser/devtools/protocol/system_info_handler.h31
-rw-r--r--content/browser/devtools/protocol/tethering_handler.cc (renamed from content/browser/devtools/tethering_handler.cc)68
-rw-r--r--content/browser/devtools/protocol/tethering_handler.h (renamed from content/browser/devtools/tethering_handler.h)36
9 files changed, 130 insertions, 84 deletions
diff --git a/content/browser/devtools/BUILD.gn b/content/browser/devtools/BUILD.gn
index 75777316..19a4003 100644
--- a/content/browser/devtools/BUILD.gn
+++ b/content/browser/devtools/BUILD.gn
@@ -64,16 +64,16 @@ action("gen_devtools_protocol_handler") {
"devtools_protocol_handler_generator.py"
blink_protocol = "//third_party/WebKit/Source/devtools/protocol.json"
- inputs = [ blink_protocol ]
+ browser_protocol = "browser_protocol.json"
+ inputs = [ blink_protocol, browser_protocol ]
outputs = [
"$target_gen_dir/protocol/devtools_protocol_handler_impl.cc",
"$target_gen_dir/protocol/devtools_protocol_handler_impl.h",
]
- args = [
- rebase_path(blink_protocol, root_build_dir),
- ] + rebase_path(outputs, root_build_dir)
+ args = rebase_path(inputs, root_build_dir) +
+ rebase_path(outputs, root_build_dir)
}
source_set("devtools_protocol_constants") {
diff --git a/content/browser/devtools/browser_protocol.json b/content/browser/devtools/browser_protocol.json
index f4b6740..53ad99c 100644
--- a/content/browser/devtools/browser_protocol.json
+++ b/content/browser/devtools/browser_protocol.json
@@ -55,17 +55,19 @@
"commands": [
{
"name": "bind",
+ "async": true,
"description": "Request browser port binding.",
"parameters": [
- { "name": "port", "type": "number", "description": "Port number to bind." }
+ { "name": "port", "type": "integer", "description": "Port number to bind." }
],
"handlers": ["browser"]
},
{
"name": "unbind",
+ "async": true,
"description": "Request browser port unbinding.",
"parameters": [
- { "name": "port", "type": "number", "description": "Port number to unbind." }
+ { "name": "port", "type": "integer", "description": "Port number to unbind." }
],
"handlers": ["browser"]
}
@@ -75,7 +77,7 @@
"name": "accepted",
"description": "Informs that port was successfully bound and got a specified connection id.",
"parameters": [
- {"name": "port", "type": "number", "description": "Port number that was successfully bound." },
+ {"name": "port", "type": "integer", "description": "Port number that was successfully bound." },
{"name": "connectionId", "type": "string", "description": "Connection id to be used." }
],
"handlers": ["browser"]
diff --git a/content/browser/devtools/devtools.gyp b/content/browser/devtools/devtools.gyp
index a67eca8..8957d72 100644
--- a/content/browser/devtools/devtools.gyp
+++ b/content/browser/devtools/devtools.gyp
@@ -12,12 +12,14 @@
'action_name': 'devtools_protocol_handler',
'variables': {
'blink_protocol': '../../../third_party/WebKit/Source/devtools/protocol.json',
+ 'browser_protocol': 'browser_protocol.json',
'generator': 'protocol/devtools_protocol_handler_generator.py',
'output_cc': '<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/protocol/devtools_protocol_handler_impl.cc',
'output_h': '<(SHARED_INTERMEDIATE_DIR)/content/browser/devtools/protocol/devtools_protocol_handler_impl.h',
},
'inputs': [
'<(blink_protocol)',
+ '<(browser_protocol)',
'<(generator)',
],
'outputs': [
@@ -28,10 +30,11 @@
'python',
'<(generator)',
'<(blink_protocol)',
+ '<(browser_protocol)',
'<(output_cc)',
'<(output_h)',
],
- 'message': 'Generating DevTools protocol browser-side handlers from <(blink_protocol)'
+ 'message': 'Generating DevTools protocol browser-side handlers from <(blink_protocol) and <(browser_protocol)'
},
],
'direct_dependent_settings': {
diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc
index e7b7fb9..6ee6eaa 100644
--- a/content/browser/devtools/devtools_http_handler_impl.cc
+++ b/content/browser/devtools/devtools_http_handler_impl.cc
@@ -22,8 +22,8 @@
#include "content/browser/devtools/devtools_protocol_constants.h"
#include "content/browser/devtools/devtools_system_info_handler.h"
#include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
+#include "content/browser/devtools/protocol/tethering_handler.h"
#include "content/browser/devtools/protocol/tracing_handler.h"
-#include "content/browser/devtools/tethering_handler.h"
#include "content/common/devtools_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
@@ -156,15 +156,19 @@ class DevToolsHttpHandlerImpl::BrowserTarget {
public:
BrowserTarget(base::MessageLoop* message_loop,
net::HttpServer* server,
+ DevToolsHttpHandlerDelegate* delegate,
int connection_id)
: message_loop_(message_loop),
server_(server),
connection_id_(connection_id),
+ tethering_handler_(new devtools::tethering::TetheringHandler(
+ delegate, message_loop->message_loop_proxy())),
tracing_handler_(new devtools::tracing::TracingHandler(
devtools::tracing::TracingHandler::Browser)),
protocol_handler_(new DevToolsProtocolHandlerImpl()) {
protocol_handler_->SetNotifier(
base::Bind(&BrowserTarget::Respond, base::Unretained(this)));
+ protocol_handler_->SetTetheringHandler(tethering_handler_.get());
protocol_handler_->SetTracingHandler(tracing_handler_.get());
}
@@ -220,6 +224,7 @@ class DevToolsHttpHandlerImpl::BrowserTarget {
base::MessageLoop* const message_loop_;
net::HttpServer* const server_;
const int connection_id_;
+ scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_;
scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_;
scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_;
std::vector<DevToolsProtocol::Handler*> handlers_;
@@ -701,9 +706,7 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
size_t browser_pos = request.path.find(browser_prefix);
if (browser_pos == 0) {
BrowserTarget* browser_target = new BrowserTarget(
- thread_->message_loop(), server_.get(), connection_id);
- browser_target->RegisterHandler(
- new TetheringHandler(delegate_.get(), thread_->message_loop_proxy()));
+ thread_->message_loop(), server_.get(), delegate_.get(), connection_id);
browser_target->RegisterHandler(
new DevToolsSystemInfoHandler());
browser_targets_[connection_id] = browser_target;
diff --git a/content/browser/devtools/protocol/devtools_protocol_handler_generator.py b/content/browser/devtools/protocol/devtools_protocol_handler_generator.py
index 3d3393f..9138e26 100755
--- a/content/browser/devtools/protocol/devtools_protocol_handler_generator.py
+++ b/content/browser/devtools/protocol/devtools_protocol_handler_generator.py
@@ -7,9 +7,10 @@ import sys
import string
import json
-input_json_path = sys.argv[1]
-output_cc_path = sys.argv[2]
-output_h_path = sys.argv[3]
+blink_protocol_path = sys.argv[1]
+browser_protocol_path = sys.argv[2]
+output_cc_path = sys.argv[3]
+output_h_path = sys.argv[4]
header = """\
// Copyright 2014 The Chromium Authors. All rights reserved.
@@ -19,7 +20,8 @@ header = """\
// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
// Generated by
// content/public/browser/devtools_protocol_handler_generator.py from
-// third_party/WebKit/Source/devtools/protocol.json
+// third_party/WebKit/Source/devtools/protocol.json and
+// content/browser/devtools/browser_protocol.json
"""
template_h = string.Template(header + """\
@@ -427,13 +429,16 @@ def Uncamelcase(s):
return result
types = {}
-json_api = json.loads(open(input_json_path, "r").read())
+blink_protocol = json.loads(open(blink_protocol_path, "r").read())
+browser_protocol = json.loads(open(browser_protocol_path, "r").read())
type_decls = []
type_impls = []
handler_methods = []
handler_method_impls = []
-for json_domain in json_api["domains"]:
+all_domains = blink_protocol["domains"] + browser_protocol["domains"]
+
+for json_domain in all_domains:
if "types" in json_domain:
for json_type in json_domain["types"]:
types["%s.%s" % (json_domain["domain"], json_type["id"])] = json_type
@@ -589,7 +594,7 @@ fields = []
includes = []
fields_init = []
-for json_domain in json_api["domains"]:
+for json_domain in all_domains:
domain_map = {}
domain_map["Domain"] = json_domain["domain"]
domain_map["domain"] = Uncamelcase(json_domain["domain"])
@@ -619,7 +624,6 @@ for json_domain in json_api["domains"]:
param_map = command_map.copy()
param_map["proto_param"] = json_param["name"]
param_map["param"] = Uncamelcase(json_param["name"])
-
ResolveType(json_param, param_map)
if len(prep) == 0:
prep.append(params_prep)
@@ -659,7 +663,6 @@ for json_domain in json_api["domains"]:
param_map = command_map.copy()
param_map["proto_param"] = json_param["name"]
param_map["param"] = Uncamelcase(json_param["name"])
-
if json_param.get("optional"):
# TODO(vkuzkokov) Implement Optional<T> for value types.
raise Exception("Optional return values are not implemented")
@@ -667,7 +670,6 @@ for json_domain in json_api["domains"]:
prep.append(tmpl_prep_output.substitute(param_map))
args.append(param_map["arg_out"])
wrap.append(tmpl_wrap.substitute(param_map))
-
args_str = ""
if len(args) > 0:
args_str = "\n " + ",\n ".join(args)
diff --git a/content/browser/devtools/protocol/system_info_handler.cc b/content/browser/devtools/protocol/system_info_handler.cc
new file mode 100644
index 0000000..2a0366e
--- /dev/null
+++ b/content/browser/devtools/protocol/system_info_handler.cc
@@ -0,0 +1,25 @@
+// Copyright 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 file.
+
+#include "content/browser/devtools/protocol/system_info_handler.h"
+
+namespace content {
+namespace devtools {
+namespace system_info {
+
+typedef DevToolsProtocolClient::Response Response;
+
+SystemInfoHandler::SystemInfoHandler() {
+}
+
+SystemInfoHandler::~SystemInfoHandler() {
+}
+
+Response SystemInfoHandler::GetInfo(scoped_refptr<SystemInfo>* info) {
+ return Response::FallThrough();
+}
+
+} // namespace system_info
+} // namespace devtools
+} // namespace content
diff --git a/content/browser/devtools/protocol/system_info_handler.h b/content/browser/devtools/protocol/system_info_handler.h
new file mode 100644
index 0000000..5781275
--- /dev/null
+++ b/content/browser/devtools/protocol/system_info_handler.h
@@ -0,0 +1,31 @@
+// Copyright 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 file.
+
+#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_
+#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_
+
+#include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
+
+namespace content {
+namespace devtools {
+namespace system_info {
+
+class SystemInfoHandler {
+ public:
+ typedef DevToolsProtocolClient::Response Response;
+
+ SystemInfoHandler();
+ virtual ~SystemInfoHandler();
+
+ Response GetInfo(scoped_refptr<SystemInfo>* info);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler);
+};
+
+} // namespace system_info
+} // namespace devtools
+} // namespace content
+
+#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SYSTEM_INFO_HANDLER_H_
diff --git a/content/browser/devtools/tethering_handler.cc b/content/browser/devtools/protocol/tethering_handler.cc
index 5f03911..3706a2d6 100644
--- a/content/browser/devtools/tethering_handler.cc
+++ b/content/browser/devtools/protocol/tethering_handler.cc
@@ -1,26 +1,20 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 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 file.
-#include "content/browser/devtools/tethering_handler.h"
+#include "content/browser/devtools/protocol/tethering_handler.h"
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/stl_util.h"
-#include "base/values.h"
-#include "content/browser/devtools/devtools_http_handler_impl.h"
-#include "content/browser/devtools/devtools_protocol_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "net/base/io_buffer.h"
-#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
-#include "net/base/net_log.h"
#include "net/socket/server_socket.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
namespace content {
+namespace devtools {
+namespace tethering {
namespace {
@@ -159,17 +153,6 @@ class SocketPump {
bool pending_destruction_;
};
-static int GetPort(scoped_refptr<DevToolsProtocol::Command> command,
- const std::string& paramName) {
- base::DictionaryValue* params = command->params();
- int port = 0;
- if (!params ||
- !params->GetInteger(paramName, &port) ||
- port < kMinTetheringPort || port > kMaxTetheringPort)
- return 0;
- return port;
-}
-
class BoundSocket {
public:
typedef base::Callback<void(int, const std::string&)> AcceptedCallback;
@@ -351,12 +334,6 @@ TetheringHandler::TetheringHandler(
message_loop_proxy_(message_loop_proxy),
is_active_(false),
weak_factory_(this) {
- RegisterCommandHandler(devtools::Tethering::bind::kName,
- base::Bind(&TetheringHandler::OnBind,
- base::Unretained(this)));
- RegisterCommandHandler(devtools::Tethering::unbind::kName,
- base::Bind(&TetheringHandler::OnUnbind,
- base::Unretained(this)));
}
TetheringHandler::~TetheringHandler() {
@@ -366,11 +343,13 @@ TetheringHandler::~TetheringHandler() {
}
}
+void TetheringHandler::SetClient(scoped_ptr<Client> client) {
+ client_.swap(client);
+}
+
void TetheringHandler::Accepted(int port, const std::string& name) {
- base::DictionaryValue* params = new base::DictionaryValue();
- params->SetInteger(devtools::Tethering::accepted::kParamPort, port);
- params->SetString(devtools::Tethering::accepted::kParamConnectionId, name);
- SendNotification(devtools::Tethering::accepted::kName, params);
+ client_->Accepted(AcceptedParams::Create()->set_port(port)
+ ->set_connection_id(name));
}
bool TetheringHandler::Activate() {
@@ -383,12 +362,10 @@ bool TetheringHandler::Activate() {
return true;
}
-scoped_refptr<DevToolsProtocol::Response>
-TetheringHandler::OnBind(scoped_refptr<DevToolsProtocol::Command> command) {
- const std::string& portParamName = devtools::Tethering::bind::kParamPort;
- int port = GetPort(command, portParamName);
- if (port == 0)
- return command->InvalidParamResponse(portParamName);
+scoped_refptr<DevToolsProtocol::Response> TetheringHandler::Bind(
+ int port, scoped_refptr<DevToolsProtocol::Command> command) {
+ if (port < kMinTetheringPort || port > kMaxTetheringPort)
+ return command->InvalidParamResponse("port");
if (!Activate()) {
return command->ServerErrorResponse(
@@ -402,13 +379,8 @@ TetheringHandler::OnBind(scoped_refptr<DevToolsProtocol::Command> command) {
return command->AsyncResponsePromise();
}
-scoped_refptr<DevToolsProtocol::Response>
-TetheringHandler::OnUnbind(scoped_refptr<DevToolsProtocol::Command> command) {
- const std::string& portParamName = devtools::Tethering::unbind::kParamPort;
- int port = GetPort(command, portParamName);
- if (port == 0)
- return command->InvalidParamResponse(portParamName);
-
+scoped_refptr<DevToolsProtocol::Response> TetheringHandler::Unbind(
+ int port, scoped_refptr<DevToolsProtocol::Command> command) {
if (!Activate()) {
return command->ServerErrorResponse(
"Tethering is used by another connection");
@@ -423,18 +395,20 @@ TetheringHandler::OnUnbind(scoped_refptr<DevToolsProtocol::Command> command) {
void TetheringHandler::SendBindSuccess(
scoped_refptr<DevToolsProtocol::Command> command) {
- SendAsyncResponse(command->SuccessResponse(nullptr));
+ client_->SendBindResponse(command, BindResponse::Create());
}
void TetheringHandler::SendUnbindSuccess(
scoped_refptr<DevToolsProtocol::Command> command) {
- SendAsyncResponse(command->SuccessResponse(nullptr));
+ client_->SendUnbindResponse(command, UnbindResponse::Create());
}
void TetheringHandler::SendInternalError(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message) {
- SendAsyncResponse(command->InternalErrorResponse(message));
+ client_->SendInternalErrorResponse(command, message);
}
+} // namespace tethering
+} // namespace devtools
} // namespace content
diff --git a/content/browser/devtools/tethering_handler.h b/content/browser/devtools/protocol/tethering_handler.h
index d6e56b5..a1b8082 100644
--- a/content/browser/devtools/tethering_handler.h
+++ b/content/browser/devtools/protocol/tethering_handler.h
@@ -1,26 +1,34 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 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 file.
-#ifndef CONTENT_BROWSER_DEVTOOLS_TETHERING_HANDLER_H_
-#define CONTENT_BROWSER_DEVTOOLS_TETHERING_HANDLER_H_
+#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_
+#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_
-#include <map>
-
-#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "content/browser/devtools/devtools_protocol.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
namespace content {
class DevToolsHttpHandlerDelegate;
+namespace devtools {
+namespace tethering {
+
// This class implements reversed tethering handler.
-class TetheringHandler : public DevToolsProtocol::Handler {
+class TetheringHandler {
public:
TetheringHandler(DevToolsHttpHandlerDelegate* delegate,
scoped_refptr<base::MessageLoopProxy> message_loop_proxy);
- ~TetheringHandler() override;
+ ~TetheringHandler();
+
+ void SetClient(scoped_ptr<Client> client);
+
+ scoped_refptr<DevToolsProtocol::Response> Bind(
+ int port, scoped_refptr<DevToolsProtocol::Command> command);
+ scoped_refptr<DevToolsProtocol::Response> Unbind(
+ int port, scoped_refptr<DevToolsProtocol::Command> command);
private:
class TetheringImpl;
@@ -28,16 +36,12 @@ class TetheringHandler : public DevToolsProtocol::Handler {
void Accepted(int port, const std::string& name);
bool Activate();
- scoped_refptr<DevToolsProtocol::Response> OnBind(
- scoped_refptr<DevToolsProtocol::Command> command);
- scoped_refptr<DevToolsProtocol::Response> OnUnbind(
- scoped_refptr<DevToolsProtocol::Command> command);
-
void SendBindSuccess(scoped_refptr<DevToolsProtocol::Command> command);
void SendUnbindSuccess(scoped_refptr<DevToolsProtocol::Command> command);
void SendInternalError(scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message);
+ scoped_ptr<Client> client_;
DevToolsHttpHandlerDelegate* delegate_;
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
bool is_active_;
@@ -48,6 +52,8 @@ class TetheringHandler : public DevToolsProtocol::Handler {
DISALLOW_COPY_AND_ASSIGN(TetheringHandler);
};
+} // namespace tethering
+} // namespace devtools
} // namespace content
-#endif // CONTENT_BROWSER_DEVTOOLS_TETHERING_HANDLER_H_
+#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_