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

Side by Side Diff: chrome/browser/debugger/extension_ports_remote_service.cc

Issue 316016: Move the json-related files into a separate json directory. This hopefully al... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome/browser/debugger/devtools_remote_service.cc ('k') | chrome/browser/dom_ui/dom_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // Implementation of the ExtensionPortsRemoteService. 5 // Implementation of the ExtensionPortsRemoteService.
6 6
7 // Inspired significantly from debugger_remote_service 7 // Inspired significantly from debugger_remote_service
8 // and ../automation/extension_port_container. 8 // and ../automation/extension_port_container.
9 9
10 #include "chrome/browser/debugger/extension_ports_remote_service.h" 10 #include "chrome/browser/debugger/extension_ports_remote_service.h"
11 11
12 #include "base/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/debugger/devtools_manager.h" 18 #include "chrome/browser/debugger/devtools_manager.h"
19 #include "chrome/browser/debugger/devtools_protocol_handler.h" 19 #include "chrome/browser/debugger/devtools_protocol_handler.h"
20 #include "chrome/browser/debugger/devtools_remote_message.h" 20 #include "chrome/browser/debugger/devtools_remote_message.h"
21 #include "chrome/browser/debugger/inspectable_tab_proxy.h" 21 #include "chrome/browser/debugger/inspectable_tab_proxy.h"
22 #include "chrome/browser/profile.h" 22 #include "chrome/browser/profile.h"
23 #include "chrome/browser/profile_manager.h" 23 #include "chrome/browser/profile_manager.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 NotificationService::current()->Notify( 140 NotificationService::current()->Notify(
141 NotificationType::EXTENSION_PORT_DELETED_DEBUG, 141 NotificationType::EXTENSION_PORT_DELETED_DEBUG,
142 Source<IPC::Message::Sender>(this), 142 Source<IPC::Message::Sender>(this),
143 NotificationService::NoDetails()); 143 NotificationService::NoDetails());
144 } 144 }
145 145
146 void ExtensionPortsRemoteService::HandleMessage( 146 void ExtensionPortsRemoteService::HandleMessage(
147 const DevToolsRemoteMessage& message) { 147 const DevToolsRemoteMessage& message) {
148 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 148 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
149 const std::string destinationString = message.destination(); 149 const std::string destinationString = message.destination();
150 scoped_ptr<Value> request(JSONReader::Read(message.content(), true)); 150 scoped_ptr<Value> request(base::JSONReader::Read(message.content(), true));
151 if (request.get() == NULL) { 151 if (request.get() == NULL) {
152 // Bad JSON 152 // Bad JSON
153 NOTREACHED(); 153 NOTREACHED();
154 return; 154 return;
155 } 155 }
156 DictionaryValue* content; 156 DictionaryValue* content;
157 if (!request->IsType(Value::TYPE_DICTIONARY)) { 157 if (!request->IsType(Value::TYPE_DICTIONARY)) {
158 NOTREACHED(); // Broken protocol :( 158 NOTREACHED(); // Broken protocol :(
159 return; 159 return;
160 } 160 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 it != openPortIds_.end(); 213 it != openPortIds_.end();
214 ++it) 214 ++it)
215 service_->CloseChannel(*it); 215 service_->CloseChannel(*it);
216 openPortIds_.clear(); 216 openPortIds_.clear();
217 } 217 }
218 218
219 void ExtensionPortsRemoteService::SendResponse( 219 void ExtensionPortsRemoteService::SendResponse(
220 const Value& response, const std::string& tool, 220 const Value& response, const std::string& tool,
221 const std::string& destination) { 221 const std::string& destination) {
222 std::string response_content; 222 std::string response_content;
223 JSONWriter::Write(&response, false, &response_content); 223 base::JSONWriter::Write(&response, false, &response_content);
224 scoped_ptr<DevToolsRemoteMessage> response_message( 224 scoped_ptr<DevToolsRemoteMessage> response_message(
225 DevToolsRemoteMessageBuilder::instance().Create( 225 DevToolsRemoteMessageBuilder::instance().Create(
226 tool, destination, response_content)); 226 tool, destination, response_content));
227 delegate_->Send(*response_message.get()); 227 delegate_->Send(*response_message.get());
228 } 228 }
229 229
230 bool ExtensionPortsRemoteService::Send(IPC::Message *message) { 230 bool ExtensionPortsRemoteService::Send(IPC::Message *message) {
231 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 231 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
232 232
233 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) 233 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message)
(...skipping 30 matching lines...) Expand all
264 264
265 void ExtensionPortsRemoteService::OnExtensionMessage( 265 void ExtensionPortsRemoteService::OnExtensionMessage(
266 const std::string& message, int port_id) { 266 const std::string& message, int port_id) {
267 LOG(INFO) << "Message event: from port " << port_id 267 LOG(INFO) << "Message event: from port " << port_id
268 << ", < " << message << ">"; 268 << ", < " << message << ">";
269 // Transpose the information into a JSON message for the external client. 269 // Transpose the information into a JSON message for the external client.
270 DictionaryValue content; 270 DictionaryValue content;
271 content.SetString(kCommandWide, kOnMessage); 271 content.SetString(kCommandWide, kOnMessage);
272 content.SetInteger(kResultWide, RESULT_OK); 272 content.SetInteger(kResultWide, RESULT_OK);
273 // Turn the stringified message body back into JSON. 273 // Turn the stringified message body back into JSON.
274 Value* data = JSONReader::Read(message, false); 274 Value* data = base::JSONReader::Read(message, false);
275 if (!data) { 275 if (!data) {
276 NOTREACHED(); 276 NOTREACHED();
277 return; 277 return;
278 } 278 }
279 content.Set(kDataWide, data); 279 content.Set(kDataWide, data);
280 SendResponse(content, kToolName, IntToString(port_id)); 280 SendResponse(content, kToolName, IntToString(port_id));
281 } 281 }
282 282
283 void ExtensionPortsRemoteService::OnExtensionPortDisconnected(int port_id) { 283 void ExtensionPortsRemoteService::OnExtensionPortDisconnected(int port_id) {
284 LOG(INFO) << "Disconnect event for port " << port_id; 284 LOG(INFO) << "Disconnect event for port " << port_id;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 void ExtensionPortsRemoteService::PostMessageCommand( 368 void ExtensionPortsRemoteService::PostMessageCommand(
369 int port_id, DictionaryValue* content, DictionaryValue* response) { 369 int port_id, DictionaryValue* content, DictionaryValue* response) {
370 Value* data; 370 Value* data;
371 if (!content->Get(kDataWide, &data)) { 371 if (!content->Get(kDataWide, &data)) {
372 response->SetInteger(kResultWide, RESULT_PARAMETER_ERROR); 372 response->SetInteger(kResultWide, RESULT_PARAMETER_ERROR);
373 return; 373 return;
374 } 374 }
375 std::string message; 375 std::string message;
376 // Stringified the JSON message body. 376 // Stringified the JSON message body.
377 JSONWriter::Write(data, false, &message); 377 base::JSONWriter::Write(data, false, &message);
378 LOG(INFO) << "postMessage: port " << port_id 378 LOG(INFO) << "postMessage: port " << port_id
379 << ", message: <" << message << ">"; 379 << ", message: <" << message << ">";
380 PortIdSet::iterator portEntry = openPortIds_.find(port_id); 380 PortIdSet::iterator portEntry = openPortIds_.find(port_id);
381 if (portEntry == openPortIds_.end()) { // Unknown port ID. 381 if (portEntry == openPortIds_.end()) { // Unknown port ID.
382 LOG(INFO) << "unknown port: " << port_id; 382 LOG(INFO) << "unknown port: " << port_id;
383 response->SetInteger(kResultWide, RESULT_UNKNOWN_PORT); 383 response->SetInteger(kResultWide, RESULT_UNKNOWN_PORT);
384 return; 384 return;
385 } 385 }
386 // Post the message through the ExtensionMessageService. 386 // Post the message through the ExtensionMessageService.
387 DCHECK(service_); 387 DCHECK(service_);
388 service_->PostMessageFromRenderer(port_id, message); 388 service_->PostMessageFromRenderer(port_id, message);
389 // Confirm to the external client that we sent its message. 389 // Confirm to the external client that we sent its message.
390 response->SetInteger(kResultWide, RESULT_OK); 390 response->SetInteger(kResultWide, RESULT_OK);
391 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/debugger/devtools_remote_service.cc ('k') | chrome/browser/dom_ui/dom_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698