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