Index: content/browser/debugger/devtools_browser_target.cc |
diff --git a/content/browser/debugger/devtools_browser_target.cc b/content/browser/debugger/devtools_browser_target.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7aecc3c753c95eff9fb9559d97d905d33c9d578f |
--- /dev/null |
+++ b/content/browser/debugger/devtools_browser_target.cc |
@@ -0,0 +1,54 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/debugger/devtools_browser_target.h" |
+ |
+#include "base/json/json_reader.h" |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/values.h" |
+ |
+ |
+namespace content { |
+ |
+DevToolsBrowserTarget::DevToolsBrowserTarget(int connection_id) |
+ : connection_id_(connection_id) { |
+} |
+ |
+DevToolsBrowserTarget::~DevToolsBrowserTarget() { |
+} |
+ |
+void DevToolsBrowserTarget::RegisterHandler(const std::string& domain, |
+ Handler* handler) { |
+ handlers_[domain] = handler; |
+} |
+ |
+base::Value* DevToolsBrowserTarget::OnWebSocketMessage( |
+ int connection_id, const std::string& data) { |
+ scoped_ptr<base::Value> command(base::JSONReader::Read(data)); |
+ int request_id; |
+ std::string domain; |
+ std::string method; |
+ base::DictionaryValue* params = NULL; |
+ if (command && command->IsType(base::Value::TYPE_DICTIONARY)) { |
pfeldman
2012/12/14 10:39:33
Fast return otherwise.
bulach
2012/12/14 16:03:52
Done.
|
+ base::DictionaryValue* command_dict; |
+ command->GetAsDictionary(&command_dict); |
+ command_dict->GetInteger("id", &request_id); |
+ command_dict->GetString("method", &method); |
+ command_dict->GetDictionary("params", ¶ms); |
+ } |
+ size_t pos = method.find("."); |
+ if (pos != std::string::npos) |
pfeldman
2012/12/14 10:39:33
Return "error" response that has request id and er
bulach
2012/12/14 16:03:52
Done.
|
+ domain = method.substr(0, pos); |
+ if (domain.empty() || handlers_.find(domain) == handlers_.end()) |
+ return NULL; |
+ base::Value* domain_response = handlers_[domain]->OnProtocolCommand( |
+ connection_id, request_id, method, params); |
+ base::DictionaryValue* response = new base::DictionaryValue(); |
+ response->SetInteger("id", request_id); |
+ response->Set("response", domain_response); |
+ return response; |
+} |
+ |
+} // namespace content |