blob: 68b09f2f25417353e9194fef2d943bc72c90f380 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2013 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 CHROME_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/values.h"
// Utility class for processing DevTools remote debugging messages.
// This is a stripped down clone of content::DevTools which is not accessible
// from chrome component (see content/browser/devtools/devtools_protocol.*).
class DevToolsProtocol {
public:
class Response;
class Message {
public:
virtual ~Message();
std::string method() { return method_; }
base::DictionaryValue* params() { return params_.get(); }
protected:
Message(const std::string& method, base::DictionaryValue* params);
std::string method_;
scoped_ptr<base::DictionaryValue> params_;
private:
DISALLOW_COPY_AND_ASSIGN(Message);
};
class Command : public Message {
public:
Command(int id, const std::string& method, base::DictionaryValue* params);
virtual ~Command();
int id() { return id_; }
std::string Serialize();
// Creates success response. Takes ownership of |result|.
scoped_ptr<Response> SuccessResponse(base::DictionaryValue* result);
// Creates error response.
scoped_ptr<Response> InvalidParamResponse(const std::string& param);
private:
int id_;
DISALLOW_COPY_AND_ASSIGN(Command);
};
class Response {
public:
virtual ~Response();
int id() { return id_; }
int error_code() { return error_code_; }
// Result ownership is passed to the caller.
base::DictionaryValue* Serialize();
private:
friend class DevToolsProtocol;
Response(int id, int error_code, const std::string error_message);
Response(int id, base::DictionaryValue* result);
int id_;
int error_code_;
std::string error_message_;
scoped_ptr<base::DictionaryValue> result_;
DISALLOW_COPY_AND_ASSIGN(Response);
};
class Notification : public Message {
public:
virtual ~Notification();
private:
friend class DevToolsProtocol;
// Takes ownership of |params|.
Notification(const std::string& method,
base::DictionaryValue* params);
DISALLOW_COPY_AND_ASSIGN(Notification);
};
// Result ownership is passed to the caller.
static Command* ParseCommand(base::DictionaryValue* command_dict);
// Result ownership is passed to the caller.
static Notification* ParseNotification(const std::string& json);
// Result ownership is passed to the caller.
static Response* ParseResponse(const std::string& json);
private:
DevToolsProtocol() {}
~DevToolsProtocol() {}
};
#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_
|