forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevTools: Protocol handler generator for content
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
Showing
27 changed files
with
1,843 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
93
content/browser/devtools/protocol/devtools_protocol_client.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
content/browser/devtools/protocol/devtools_protocol_client.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.