OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_DEVTOOLS_PROTOCOL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 Notification(const std::string& method, | 120 Notification(const std::string& method, |
121 base::DictionaryValue* params); | 121 base::DictionaryValue* params); |
122 | 122 |
123 DISALLOW_COPY_AND_ASSIGN(Notification); | 123 DISALLOW_COPY_AND_ASSIGN(Notification); |
124 }; | 124 }; |
125 | 125 |
126 class CONTENT_EXPORT Handler { | 126 class CONTENT_EXPORT Handler { |
127 public: | 127 public: |
128 typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>( | 128 typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>( |
129 scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler; | 129 scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler; |
| 130 typedef base::Callback<void( |
| 131 scoped_refptr<DevToolsProtocol::Notification> notification)> |
| 132 NotificationHandler; |
130 | 133 |
131 virtual ~Handler(); | 134 virtual ~Handler(); |
132 | 135 |
133 virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand( | 136 virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand( |
134 scoped_refptr<DevToolsProtocol::Command> command); | 137 scoped_refptr<DevToolsProtocol::Command> command); |
135 | 138 |
| 139 virtual void HandleNotification( |
| 140 scoped_refptr<DevToolsProtocol::Notification> notification); |
| 141 |
136 void SetNotifier(const Notifier& notifier); | 142 void SetNotifier(const Notifier& notifier); |
137 | 143 |
138 protected: | 144 protected: |
139 Handler(); | 145 Handler(); |
140 | 146 |
141 void RegisterCommandHandler(const std::string& command, | 147 void RegisterCommandHandler(const std::string& command, |
142 const CommandHandler& handler); | 148 const CommandHandler& handler); |
143 | 149 |
| 150 void RegisterNotificationHandler(const std::string& notification, |
| 151 const NotificationHandler& handler); |
| 152 |
144 // Sends notification to the client. Takes ownership of |params|. | 153 // Sends notification to the client. Takes ownership of |params|. |
145 void SendNotification(const std::string& method, | 154 void SendNotification(const std::string& method, |
146 base::DictionaryValue* params); | 155 base::DictionaryValue* params); |
147 | 156 |
148 void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response); | 157 void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response); |
149 | 158 |
150 // Sends message to client, the caller is presumed to properly | 159 // Sends message to client, the caller is presumed to properly |
151 // format the message. | 160 // format the message. |
152 void SendRawMessage(const std::string& message); | 161 void SendRawMessage(const std::string& message); |
153 | 162 |
154 private: | 163 private: |
155 typedef std::map<std::string, CommandHandler> CommandHandlers; | 164 typedef std::map<std::string, CommandHandler> CommandHandlers; |
| 165 typedef std::map<std::string, NotificationHandler> NotificationHandlers; |
156 | 166 |
157 Notifier notifier_; | 167 Notifier notifier_; |
158 CommandHandlers command_handlers_; | 168 CommandHandlers command_handlers_; |
| 169 NotificationHandlers notification_handlers_; |
159 | 170 |
160 DISALLOW_COPY_AND_ASSIGN(Handler); | 171 DISALLOW_COPY_AND_ASSIGN(Handler); |
161 }; | 172 }; |
162 | 173 |
163 CONTENT_EXPORT static base::DictionaryValue* ParseMessage( | 174 CONTENT_EXPORT static base::DictionaryValue* ParseMessage( |
164 const std::string& json, | 175 const std::string& json, |
165 std::string* error_response); | 176 std::string* error_response); |
166 | 177 |
167 CONTENT_EXPORT static scoped_refptr<Command> ParseCommand( | 178 CONTENT_EXPORT static scoped_refptr<Command> ParseCommand( |
168 const std::string& json, | 179 const std::string& json, |
(...skipping 17 matching lines...) Expand all Loading... |
186 static scoped_refptr<Notification> CreateNotification( | 197 static scoped_refptr<Notification> CreateNotification( |
187 const std::string& method, base::DictionaryValue* params); | 198 const std::string& method, base::DictionaryValue* params); |
188 | 199 |
189 DevToolsProtocol() {} | 200 DevToolsProtocol() {} |
190 ~DevToolsProtocol() {} | 201 ~DevToolsProtocol() {} |
191 }; | 202 }; |
192 | 203 |
193 } // namespace content | 204 } // namespace content |
194 | 205 |
195 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 206 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
OLD | NEW |