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

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 scoped_ptr<DevToolsProtocol::Response>
125 DevToolsProtocol::Handler::HandleCommand(
126 DevToolsProtocol::Command* command) {
127 CommandHandlers::iterator it = command_handlers_.find(command->method());
128 if (it == command_handlers_.end())
129 return scoped_ptr<DevToolsProtocol::Response>();
130 return (it->second).Run(command);
131 }
132
133 void DevToolsProtocol::Handler::SetNotifier(const Notifier& notifier) {
134 notifier_ = notifier;
135 }
136
137 DevToolsProtocol::Handler::Handler() {
138 }
139
140 void DevToolsProtocol::Handler::RegisterCommandHandler(
141 const std::string& command,
142 const CommandHandler& handler) {
143 command_handlers_[command] = handler;
144 }
145
146 void DevToolsProtocol::Handler::SendNotification(
147 const std::string& method,
148 base::DictionaryValue* params) {
149 DevToolsProtocol::Notification notification(method, params);
150 if (!notifier_.is_null())
151 notifier_.Run(notification.Serialize());
152 }
153
121 // static 154 // static
122 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand( 155 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand(
123 const std::string& json, 156 const std::string& json,
124 std::string* error_response) { 157 std::string* error_response) {
125 int parse_error_code; 158 int parse_error_code;
126 std::string error_message; 159 std::string error_message;
127 scoped_ptr<base::Value> command( 160 scoped_ptr<base::Value> command(
128 base::JSONReader::ReadAndReturnError( 161 base::JSONReader::ReadAndReturnError(
129 json, 0, &parse_error_code, &error_message)); 162 json, 0, &parse_error_code, &error_message));
130 163
(...skipping 26 matching lines...) Expand all
157 } 190 }
158 191
159 std::string domain = method.substr(0, pos); 192 std::string domain = method.substr(0, pos);
160 193
161 base::DictionaryValue* params = NULL; 194 base::DictionaryValue* params = NULL;
162 command_dict->GetDictionary("params", &params); 195 command_dict->GetDictionary("params", &params);
163 return new Command(id, domain, method, params ? params->DeepCopy() : NULL); 196 return new Command(id, domain, method, params ? params->DeepCopy() : NULL);
164 } 197 }
165 198
166 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_protocol.h ('k') | content/browser/devtools/devtools_tracing_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698