Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: chrome/browser/devtools/devtools_protocol.cc

Issue 290873002: DevTools: allow embedder handling remote debugger commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary include Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/devtools/devtools_protocol.h ('k') | content/browser/devtools/devtools_manager_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/devtools_protocol.cc
diff --git a/chrome/browser/devtools/devtools_protocol.cc b/chrome/browser/devtools/devtools_protocol.cc
index f14864ccf7645253bb4a729af3678a4009bf5fd0..ef7cb6ae63a950f11404acbc7175e81cd1143925 100644
--- a/chrome/browser/devtools/devtools_protocol.cc
+++ b/chrome/browser/devtools/devtools_protocol.cc
@@ -6,13 +6,23 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/strings/stringprintf.h"
namespace {
+
+const char kErrorCodeParam[] = "code";
+const char kErrorParam[] = "error";
+const char kErrorMessageParam[] = "message";
const char kIdParam[] = "id";
const char kMethodParam[] = "method";
const char kParamsParam[] = "params";
-const char kErrorParam[] = "error";
-const char kErrorCodeParam[] = "code";
+const char kResultParam[] = "result";
+
+// JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object
+enum Error {
+ kErrorInvalidParams = -32602
+};
+
} // namespace
DevToolsProtocol::Message::~Message() {
@@ -46,6 +56,20 @@ std::string DevToolsProtocol::Command::Serialize() {
return json_command;
}
+scoped_ptr<DevToolsProtocol::Response>
+DevToolsProtocol::Command::SuccessResponse(base::DictionaryValue* result) {
+ return scoped_ptr<DevToolsProtocol::Response>(
+ new DevToolsProtocol::Response(id_, result));
+}
+
+scoped_ptr<DevToolsProtocol::Response>
+DevToolsProtocol::Command::InvalidParamResponse(const std::string& param) {
+ std::string message =
+ base::StringPrintf("Missing or invalid '%s' parameter", param.c_str());
+ return scoped_ptr<DevToolsProtocol::Response>(
+ new DevToolsProtocol::Response(id_, kErrorInvalidParams, message));
+}
+
DevToolsProtocol::Notification::~Notification() {
}
@@ -57,9 +81,55 @@ DevToolsProtocol::Notification::Notification(const std::string& method,
DevToolsProtocol::Response::~Response() {
}
-DevToolsProtocol::Response::Response(int id, int error_code)
+DevToolsProtocol::Response::Response(int id,
+ int error_code,
+ const std::string error_message)
+ : id_(id),
+ error_code_(error_code),
+ error_message_(error_message) {
+}
+
+DevToolsProtocol::Response::Response(int id, base::DictionaryValue* result)
: id_(id),
- error_code_(error_code) {
+ error_code_(0),
+ result_(result) {
+}
+
+base::DictionaryValue* DevToolsProtocol::Response::Serialize() {
+ base::DictionaryValue* response = new base::DictionaryValue();
+
+ response->SetInteger(kIdParam, id_);
+
+ if (error_code_) {
+ base::DictionaryValue* error_object = new base::DictionaryValue();
+ response->Set(kErrorParam, error_object);
+ error_object->SetInteger(kErrorCodeParam, error_code_);
+ if (!error_message_.empty())
+ error_object->SetString(kErrorMessageParam, error_message_);
+ } else if (result_) {
+ response->Set(kResultParam, result_->DeepCopy());
+ }
+
+ return response;
+}
+
+// static
+DevToolsProtocol::Command* DevToolsProtocol::ParseCommand(
+ base::DictionaryValue* command_dict) {
+ if (!command_dict)
+ return NULL;
+
+ int id;
+ if (!command_dict->GetInteger(kIdParam, &id) || id < 0)
+ return NULL;
+
+ std::string method;
+ if (!command_dict->GetString(kMethodParam, &method))
+ return NULL;
+
+ base::DictionaryValue* params = NULL;
+ command_dict->GetDictionary(kParamsParam, &params);
+ return new Command(id, method, params ? params->DeepCopy() : NULL);
}
// static
@@ -98,5 +168,5 @@ DevToolsProtocol::Response* DevToolsProtocol::ParseResponse(
base::DictionaryValue* error_dict = NULL;
if (dict->GetDictionary(kErrorParam, &error_dict))
error_dict->GetInteger(kErrorCodeParam, &error_code);
- return new Response(id, error_code);
+ return new Response(id, error_code, std::string());
}
« no previous file with comments | « chrome/browser/devtools/devtools_protocol.h ('k') | content/browser/devtools/devtools_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698