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

Side by Side Diff: content/browser/devtools/devtools_protocol.cc

Issue 12218134: Introduce intercepting and handling devtools messages in the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "content/browser/devtools/devtools_protocol.h" 5 #include "content/browser/devtools/devtools_protocol.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::DictionaryValue notification; 111 base::DictionaryValue notification;
112 notification.SetString("method", method_); 112 notification.SetString("method", method_);
113 if (params_.get()) 113 if (params_.get())
114 notification.Set("params", params_->DeepCopy()); 114 notification.Set("params", params_->DeepCopy());
115 115
116 std::string json_notification; 116 std::string json_notification;
117 base::JSONWriter::Write(&notification, &json_notification); 117 base::JSONWriter::Write(&notification, &json_notification);
118 return json_notification; 118 return json_notification;
119 } 119 }
120 120
121 DevToolsProtocol::Handler::~Handler() {
122 }
123
124 DevToolsProtocol::Handler::Handler(const Notifier& notifier)
pfeldman 2013/02/13 17:38:24 Method definition order should match the declarati
kkania 2013/02/13 19:17:19 Done.
125 : notifier_(notifier) {
126 }
127
128 scoped_ptr<DevToolsProtocol::Response>
129 DevToolsProtocol::Handler::HandleCommand(
130 DevToolsProtocol::Command* command) {
131 CommandHandlers::iterator it = command_handlers_.find(command->method());
132 if (it == command_handlers_.end())
133 return scoped_ptr<DevToolsProtocol::Response>();
134 return (it->second).Run(command);
135 }
136
137 void DevToolsProtocol::Handler::RegisterCommandHandler(
138 const std::string& command,
139 const CommandHandler& handler) {
140 command_handlers_[command] = handler;
141 }
142
143 void DevToolsProtocol::Handler::SendNotification(
144 const std::string& method,
145 base::DictionaryValue* params) {
146 DevToolsProtocol::Notification notification(method, params);
147 notifier_.Run(notification.Serialize());
148 }
149
121 // static 150 // static
122 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand( 151 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand(
123 const std::string& json, 152 const std::string& json,
124 std::string* error_response) { 153 std::string* error_response) {
125 int parse_error_code; 154 int parse_error_code;
126 std::string error_message; 155 std::string error_message;
127 scoped_ptr<base::Value> command( 156 scoped_ptr<base::Value> command(
128 base::JSONReader::ReadAndReturnError( 157 base::JSONReader::ReadAndReturnError(
129 json, 0, &parse_error_code, &error_message)); 158 json, 0, &parse_error_code, &error_message));
130 159
(...skipping 26 matching lines...) Expand all
157 } 186 }
158 187
159 std::string domain = method.substr(0, pos); 188 std::string domain = method.substr(0, pos);
160 189
161 base::DictionaryValue* params = NULL; 190 base::DictionaryValue* params = NULL;
162 command_dict->GetDictionary("params", &params); 191 command_dict->GetDictionary("params", &params);
163 return new Command(id, domain, method, params ? params->DeepCopy() : NULL); 192 return new Command(id, domain, method, params ? params->DeepCopy() : NULL);
164 } 193 }
165 194
166 } // namespace content 195 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698