OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 using DevToolsCommandId = int; | 13 struct DevToolsCommandId { |
| 14 static const int kNoId; |
| 15 |
| 16 DevToolsCommandId(int call_id, int session_id) |
| 17 : call_id(call_id), session_id(session_id) {} |
| 18 |
| 19 int call_id; |
| 20 int session_id; |
| 21 }; |
| 22 |
| 23 class DevToolsProtocolDelegate; |
| 24 class DevToolsProtocolDispatcher; |
14 class DevToolsProtocolHandler; | 25 class DevToolsProtocolHandler; |
15 class DevToolsProtocolDispatcher; | |
16 | 26 |
17 class DevToolsProtocolClient { | 27 class DevToolsProtocolClient { |
18 public: | 28 public: |
19 typedef base::Callback<void(const std::string& message)> | |
20 RawMessageCallback; | |
21 static const DevToolsCommandId kNoId; | |
22 | |
23 struct Response { | 29 struct Response { |
24 public: | 30 public: |
25 static Response FallThrough(); | 31 static Response FallThrough(); |
26 static Response OK(); | 32 static Response OK(); |
27 static Response InvalidParams(const std::string& param); | 33 static Response InvalidParams(const std::string& param); |
28 static Response InternalError(const std::string& message); | 34 static Response InternalError(const std::string& message); |
29 static Response ServerError(const std::string& message); | 35 static Response ServerError(const std::string& message); |
30 | 36 |
31 int status() const; | 37 int status() const; |
32 const std::string& message() const; | 38 const std::string& message() const; |
33 | 39 |
34 bool IsFallThrough() const; | 40 bool IsFallThrough() const; |
35 | 41 |
36 private: | 42 private: |
37 friend class DevToolsProtocolHandler; | 43 friend class DevToolsProtocolHandler; |
38 | 44 |
39 explicit Response(int status); | 45 explicit Response(int status); |
40 Response(int status, const std::string& message); | 46 Response(int status, const std::string& message); |
41 | 47 |
42 int status_; | 48 int status_; |
43 std::string message_; | 49 std::string message_; |
44 }; | 50 }; |
45 | 51 |
46 bool SendError(DevToolsCommandId command_id, | 52 bool SendError(DevToolsCommandId command_id, |
47 const Response& response); | 53 const Response& response); |
48 | 54 |
49 // Sends message to client, the caller is presumed to properly | 55 // Sends notification to client, the caller is presumed to properly |
50 // format the message. Do not use unless you must. | 56 // format the message. Do not use unless you must. |
51 void SendRawMessage(const std::string& message); | 57 void SendRawNotification(const std::string& message); |
52 | 58 |
53 explicit DevToolsProtocolClient( | 59 void SendMessage(int session_id, const base::DictionaryValue& message); |
54 const RawMessageCallback& raw_message_callback); | 60 |
| 61 explicit DevToolsProtocolClient(DevToolsProtocolDelegate* notifier); |
55 virtual ~DevToolsProtocolClient(); | 62 virtual ~DevToolsProtocolClient(); |
56 | 63 |
57 protected: | 64 protected: |
58 void SendSuccess(DevToolsCommandId command_id, | 65 void SendSuccess(DevToolsCommandId command_id, |
59 scoped_ptr<base::DictionaryValue> params); | 66 scoped_ptr<base::DictionaryValue> params); |
60 void SendNotification(const std::string& method, | 67 void SendNotification(const std::string& method, |
61 scoped_ptr<base::DictionaryValue> params); | 68 scoped_ptr<base::DictionaryValue> params); |
62 | 69 |
63 private: | 70 private: |
64 friend class DevToolsProtocolDispatcher; | 71 friend class DevToolsProtocolDispatcher; |
65 | 72 |
66 void SendMessage(const base::DictionaryValue& message); | 73 DevToolsProtocolDelegate* notifier_; |
67 | |
68 RawMessageCallback raw_message_callback_; | |
69 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); | 74 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); |
70 }; | 75 }; |
71 | 76 |
72 } // namespace content | 77 } // namespace content |
73 | 78 |
74 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 79 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
OLD | NEW |