1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/devtools/protocol/devtools_protocol_client.h"
9 DevToolsProtocolClient::DevToolsProtocolClient(
10 const RawMessageCallback& raw_message_callback)
11 : raw_message_callback_(raw_message_callback) {
14 DevToolsProtocolClient::~DevToolsProtocolClient() {
17 void DevToolsProtocolClient::SendNotification(const std::string& method,
18 base::DictionaryValue* params) {
19 scoped_refptr<DevToolsProtocol::Notification> notification =
20 new DevToolsProtocol::Notification(method, params);
21 SendRawMessage(notification->Serialize());
24 void DevToolsProtocolClient::SendAsyncResponse(
25 scoped_refptr<DevToolsProtocol::Response> response) {
26 SendRawMessage(response->Serialize());
29 void DevToolsProtocolClient::SendRawMessage(const std::string& message) {
30 raw_message_callback_.Run(message);
33 void DevToolsProtocolClient::SendInvalidParamsResponse(
34 scoped_refptr<DevToolsProtocol::Command> command,
35 const std::string& message) {
36 SendAsyncResponse(command->InvalidParamResponse(message));
39 void DevToolsProtocolClient::SendInternalErrorResponse(
40 scoped_refptr<DevToolsProtocol::Command> command,
41 const std::string& message) {
42 SendAsyncResponse(command->InternalErrorResponse(message));
45 void DevToolsProtocolClient::SendServerErrorResponse(
46 scoped_refptr<DevToolsProtocol::Command> command,
47 const std::string& message) {
48 SendAsyncResponse(command->ServerErrorResponse(message));
51 typedef DevToolsProtocolClient::Response Response;
53 Response Response::FallThrough() {
55 response.status_ = ResponseStatus::RESPONSE_STATUS_FALLTHROUGH;
59 Response Response::OK() {
61 response.status_ = ResponseStatus::RESPONSE_STATUS_OK;
65 Response Response::InvalidParams(const std::string& message) {
67 response.status_ = ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS;
68 response.message_ = message;
72 Response Response::InternalError(const std::string& message) {
74 response.status_ = ResponseStatus::RESPONSE_STATUS_INTERNAL_ERROR;
75 response.message_ = message;
79 Response Response::ServerError(const std::string& message) {
81 response.status_ = ResponseStatus::RESPONSE_STATUS_SERVER_ERROR;
82 response.message_ = message;
86 DevToolsProtocolClient::ResponseStatus Response::status() const {
90 const std::string& Response::message() const {
94 Response::Response() {
97 } // namespace content