| 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 struct DevToolsCommandId { | 13 using DevToolsCommandId = int; |
| 14 static const int kNoId; | 14 class DevToolsProtocolHandler; |
| 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; | 15 class DevToolsProtocolDispatcher; |
| 25 class DevToolsProtocolHandler; | |
| 26 | 16 |
| 27 class DevToolsProtocolClient { | 17 class DevToolsProtocolClient { |
| 28 public: | 18 public: |
| 19 typedef base::Callback<void(const std::string& message)> |
| 20 RawMessageCallback; |
| 21 static const DevToolsCommandId kNoId; |
| 22 |
| 29 struct Response { | 23 struct Response { |
| 30 public: | 24 public: |
| 31 static Response FallThrough(); | 25 static Response FallThrough(); |
| 32 static Response OK(); | 26 static Response OK(); |
| 33 static Response InvalidParams(const std::string& param); | 27 static Response InvalidParams(const std::string& param); |
| 34 static Response InternalError(const std::string& message); | 28 static Response InternalError(const std::string& message); |
| 35 static Response ServerError(const std::string& message); | 29 static Response ServerError(const std::string& message); |
| 36 | 30 |
| 37 int status() const; | 31 int status() const; |
| 38 const std::string& message() const; | 32 const std::string& message() const; |
| 39 | 33 |
| 40 bool IsFallThrough() const; | 34 bool IsFallThrough() const; |
| 41 | 35 |
| 42 private: | 36 private: |
| 43 friend class DevToolsProtocolHandler; | 37 friend class DevToolsProtocolHandler; |
| 44 | 38 |
| 45 explicit Response(int status); | 39 explicit Response(int status); |
| 46 Response(int status, const std::string& message); | 40 Response(int status, const std::string& message); |
| 47 | 41 |
| 48 int status_; | 42 int status_; |
| 49 std::string message_; | 43 std::string message_; |
| 50 }; | 44 }; |
| 51 | 45 |
| 52 bool SendError(DevToolsCommandId command_id, | 46 bool SendError(DevToolsCommandId command_id, |
| 53 const Response& response); | 47 const Response& response); |
| 54 | 48 |
| 55 // Sends notification to client, the caller is presumed to properly | 49 // Sends message to client, the caller is presumed to properly |
| 56 // format the message. Do not use unless you must. | 50 // format the message. Do not use unless you must. |
| 57 void SendRawNotification(const std::string& message); | 51 void SendRawMessage(const std::string& message); |
| 58 | 52 |
| 59 void SendMessage(int session_id, const base::DictionaryValue& message); | 53 explicit DevToolsProtocolClient( |
| 60 | 54 const RawMessageCallback& raw_message_callback); |
| 61 explicit DevToolsProtocolClient(DevToolsProtocolDelegate* notifier); | |
| 62 virtual ~DevToolsProtocolClient(); | 55 virtual ~DevToolsProtocolClient(); |
| 63 | 56 |
| 64 protected: | 57 protected: |
| 65 void SendSuccess(DevToolsCommandId command_id, | 58 void SendSuccess(DevToolsCommandId command_id, |
| 66 scoped_ptr<base::DictionaryValue> params); | 59 scoped_ptr<base::DictionaryValue> params); |
| 67 void SendNotification(const std::string& method, | 60 void SendNotification(const std::string& method, |
| 68 scoped_ptr<base::DictionaryValue> params); | 61 scoped_ptr<base::DictionaryValue> params); |
| 69 | 62 |
| 70 private: | 63 private: |
| 71 friend class DevToolsProtocolDispatcher; | 64 friend class DevToolsProtocolDispatcher; |
| 72 | 65 |
| 73 DevToolsProtocolDelegate* notifier_; | 66 void SendMessage(const base::DictionaryValue& message); |
| 67 |
| 68 RawMessageCallback raw_message_callback_; |
| 74 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); | 69 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient); |
| 75 }; | 70 }; |
| 76 | 71 |
| 77 } // namespace content | 72 } // namespace content |
| 78 | 73 |
| 79 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ | 74 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_ |
| OLD | NEW |