Skip to content

Commit

Permalink
DevTools: Protocol handler generator for content
Browse files Browse the repository at this point in the history
BUG=405566

Review URL: https://codereview.chromium.org/508973003

Cr-Commit-Position: refs/heads/master@{#296694}
  • Loading branch information
vkuzkokov authored and Commit bot committed Sep 25, 2014
1 parent 84a24d2 commit fa9990e
Show file tree
Hide file tree
Showing 27 changed files with 1,843 additions and 186 deletions.
2 changes: 2 additions & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ source_set("browser") {
"$root_gen_dir/ui/resources/grit/webui_resources_map.cc",
"$root_gen_dir/content/browser/devtools/devtools_protocol_constants.cc",
"$root_gen_dir/content/browser/devtools/devtools_protocol_constants.h",
"$root_gen_dir/content/browser/devtools/protocol/devtools_protocol_handler_impl.cc",
"$root_gen_dir/content/browser/devtools/protocol/devtools_protocol_handler_impl.h",
], ".")

# Non-iOS deps.
Expand Down
25 changes: 25 additions & 0 deletions content/browser/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ group("resources") {
deps = [
":devtools_resources",
":devtools_protocol_constants",
":devtools_protocol_handler",
]
}

Expand Down Expand Up @@ -56,7 +57,31 @@ action("gen_devtools_protocol_constants") {
]
}

action("gen_devtools_protocol_handler") {
visibility = [ ":devtools_protocol_handler" ]

script = "//content/browser/devtools/protocol/" +
"devtools_protocol_handler_generator.py"

blink_protocol = "//third_party/WebKit/Source/devtools/protocol.json"
inputs = [ blink_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)
}

source_set("devtools_protocol_constants") {
visibility = [ ":resources" ]
sources = get_target_outputs(":gen_devtools_protocol_constants")
}

source_set("devtools_protocol_handler") {
visibility = [ ":resources" ]
sources = get_target_outputs(":gen_devtools_protocol_handler")
}
44 changes: 44 additions & 0 deletions content/browser/devtools/devtools.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

{
'targets': [
{
'target_name': 'devtools_protocol_handler',
'type': 'none',
'actions': [
{
'action_name': 'devtools_protocol_handler',
'variables': {
'blink_protocol': '../../../third_party/WebKit/Source/devtools/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)',
'<(generator)',
],
'outputs': [
'<(output_cc)',
'<(output_h)',
],
'action':[
'python',
'<(generator)',
'<(blink_protocol)',
'<(output_cc)',
'<(output_h)',
],
'message': 'Generating DevTools protocol browser-side handlers from <(blink_protocol)'
},
],
'direct_dependent_settings': {
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)',
]
},
},
],
}
93 changes: 93 additions & 0 deletions content/browser/devtools/protocol/devtools_protocol_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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/devtools_protocol_client.h"

namespace content {

DevToolsProtocolClient::DevToolsProtocolClient(
const EventCallback& event_callback,
const ResponseCallback& response_callback)
: event_callback_(event_callback),
response_callback_(response_callback) {
}

DevToolsProtocolClient::~DevToolsProtocolClient() {
}

void DevToolsProtocolClient::SendNotification(const std::string& method,
base::DictionaryValue* params) {
event_callback_.Run(method, params);
}

void DevToolsProtocolClient::SendAsyncResponse(
scoped_refptr<DevToolsProtocol::Response> response) {
response_callback_.Run(response);
}

void DevToolsProtocolClient::SendInvalidParamsResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message) {
SendAsyncResponse(command->InvalidParamResponse(message));
}

void DevToolsProtocolClient::SendInternalErrorResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message) {
SendAsyncResponse(command->InternalErrorResponse(message));
}

void DevToolsProtocolClient::SendServerErrorResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message) {
SendAsyncResponse(command->ServerErrorResponse(message));
}

typedef DevToolsProtocolClient::Response Response;

Response Response::FallThrough() {
Response response;
response.status_ = ResponseStatus::RESPONSE_STATUS_FALLTHROUGH;
return response;
}

Response Response::OK() {
Response response;
response.status_ = ResponseStatus::RESPONSE_STATUS_OK;
return response;
}

Response Response::InvalidParams(const std::string& message) {
Response response;
response.status_ = ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS;
response.message_ = message;
return response;
}

Response Response::InternalError(const std::string& message) {
Response response;
response.status_ = ResponseStatus::RESPONSE_STATUS_INTERNAL_ERROR;
response.message_ = message;
return response;
}

Response Response::ServerError(const std::string& message) {
Response response;
response.status_ = ResponseStatus::RESPONSE_STATUS_SERVER_ERROR;
response.message_ = message;
return response;
}

DevToolsProtocolClient::ResponseStatus Response::status() const {
return status_;
}

const std::string& Response::message() const {
return message_;
}

Response::Response() {
}

} // namespace content
76 changes: 76 additions & 0 deletions content/browser/devtools/protocol/devtools_protocol_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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_DEVTOOLS_PROTOCOL_CLIENT_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_

#include "content/browser/devtools/devtools_protocol.h"

namespace content {

class DevToolsProtocolClient {
public:
typedef base::Callback<void(const std::string& event,
base::DictionaryValue* params)> EventCallback;

typedef base::Callback<void(scoped_refptr<DevToolsProtocol::Response>)>
ResponseCallback;

enum ResponseStatus {
RESPONSE_STATUS_FALLTHROUGH,
RESPONSE_STATUS_OK,
RESPONSE_STATUS_INVALID_PARAMS,
RESPONSE_STATUS_INTERNAL_ERROR,
RESPONSE_STATUS_SERVER_ERROR,
};

struct Response {
public:
static Response FallThrough();
static Response OK();
static Response InvalidParams(const std::string& message);
static Response InternalError(const std::string& message);
static Response ServerError(const std::string& message);

ResponseStatus status() const;
const std::string& message() const;

private:
Response();

ResponseStatus status_;
std::string message_;
};

void SendInvalidParamsResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message);
void SendInternalErrorResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message);
void SendServerErrorResponse(
scoped_refptr<DevToolsProtocol::Command> command,
const std::string& message);

protected:
DevToolsProtocolClient(const EventCallback& event_callback,
const ResponseCallback& response_callback);

virtual ~DevToolsProtocolClient();

void SendNotification(const std::string& method,
base::DictionaryValue* params);

void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response);

private:
EventCallback event_callback_;
ResponseCallback response_callback_;

DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient);
};

} // namespace content

#endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
Loading

0 comments on commit fa9990e

Please sign in to comment.