Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / content / browser / devtools / protocol / devtools_protocol_client.cc
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.
4
5 #include "content/browser/devtools/protocol/devtools_protocol_client.h"
6
7 namespace content {
8
9 DevToolsProtocolClient::DevToolsProtocolClient(
10     const RawMessageCallback& raw_message_callback)
11     : raw_message_callback_(raw_message_callback) {
12 }
13
14 DevToolsProtocolClient::~DevToolsProtocolClient() {
15 }
16
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());
22 }
23
24 void DevToolsProtocolClient::SendAsyncResponse(
25     scoped_refptr<DevToolsProtocol::Response> response) {
26   SendRawMessage(response->Serialize());
27 }
28
29 void DevToolsProtocolClient::SendRawMessage(const std::string& message) {
30   raw_message_callback_.Run(message);
31 }
32
33 void DevToolsProtocolClient::SendInvalidParamsResponse(
34     scoped_refptr<DevToolsProtocol::Command> command,
35     const std::string& message) {
36   SendAsyncResponse(command->InvalidParamResponse(message));
37 }
38
39 void DevToolsProtocolClient::SendInternalErrorResponse(
40     scoped_refptr<DevToolsProtocol::Command> command,
41     const std::string& message) {
42   SendAsyncResponse(command->InternalErrorResponse(message));
43 }
44
45 void DevToolsProtocolClient::SendServerErrorResponse(
46     scoped_refptr<DevToolsProtocol::Command> command,
47     const std::string& message) {
48   SendAsyncResponse(command->ServerErrorResponse(message));
49 }
50
51 typedef DevToolsProtocolClient::Response Response;
52
53 Response Response::FallThrough() {
54   Response response;
55   response.status_ = ResponseStatus::RESPONSE_STATUS_FALLTHROUGH;
56   return response;
57 }
58
59 Response Response::OK() {
60   Response response;
61   response.status_ = ResponseStatus::RESPONSE_STATUS_OK;
62   return response;
63 }
64
65 Response Response::InvalidParams(const std::string& message) {
66   Response response;
67   response.status_ = ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS;
68   response.message_ = message;
69   return response;
70 }
71
72 Response Response::InternalError(const std::string& message) {
73   Response response;
74   response.status_ = ResponseStatus::RESPONSE_STATUS_INTERNAL_ERROR;
75   response.message_ = message;
76   return response;
77 }
78
79 Response Response::ServerError(const std::string& message) {
80   Response response;
81   response.status_ = ResponseStatus::RESPONSE_STATUS_SERVER_ERROR;
82   response.message_ = message;
83   return response;
84 }
85
86 DevToolsProtocolClient::ResponseStatus Response::status() const {
87   return status_;
88 }
89
90 const std::string& Response::message() const {
91   return message_;
92 }
93
94 Response::Response() {
95 }
96
97 }  // namespace content