| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DevToolsRemoteMessageBuilder::instance().Create( | 219 DevToolsRemoteMessageBuilder::instance().Create( |
| 220 tool, destination, response_content)); | 220 tool, destination, response_content)); |
| 221 delegate_->Send(*response_message.get()); | 221 delegate_->Send(*response_message.get()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool ExtensionPortsRemoteService::Send(IPC::Message *message) { | 224 bool ExtensionPortsRemoteService::Send(IPC::Message *message) { |
| 225 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 225 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
| 226 | 226 |
| 227 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) | 227 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) |
| 228 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) | 228 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
| 229 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 229 IPC_MESSAGE_UNHANDLED_ERROR() | 230 IPC_MESSAGE_UNHANDLED_ERROR() |
| 230 IPC_END_MESSAGE_MAP() | 231 IPC_END_MESSAGE_MAP() |
| 231 | 232 |
| 232 delete message; | 233 delete message; |
| 233 return true; | 234 return true; |
| 234 } | 235 } |
| 235 | 236 |
| 236 void ExtensionPortsRemoteService::OnExtensionMessageInvoke( | 237 void ExtensionPortsRemoteService::OnExtensionMessageInvoke( |
| 237 const std::string& extension_id, | 238 const std::string& extension_id, |
| 238 const std::string& function_name, | 239 const std::string& function_name, |
| 239 const ListValue& args, | 240 const ListValue& args, |
| 240 const GURL& event_url) { | 241 const GURL& event_url) { |
| 241 if (function_name == ExtensionMessageService::kDispatchOnMessage) { | 242 if (function_name == ExtensionMessageService::kDispatchOnDisconnect) { |
| 242 DCHECK_EQ(args.GetSize(), 2u); | |
| 243 std::string message; | |
| 244 int port_id; | |
| 245 if (args.GetString(0, &message) && args.GetInteger(1, &port_id)) | |
| 246 OnExtensionMessage(message, port_id); | |
| 247 } else if (function_name == ExtensionMessageService::kDispatchOnDisconnect) { | |
| 248 DCHECK_EQ(args.GetSize(), 1u); | 243 DCHECK_EQ(args.GetSize(), 1u); |
| 249 int port_id; | 244 int port_id; |
| 250 if (args.GetInteger(0, &port_id)) | 245 if (args.GetInteger(0, &port_id)) |
| 251 OnExtensionPortDisconnected(port_id); | 246 OnExtensionPortDisconnected(port_id); |
| 252 } else if (function_name == ExtensionMessageService::kDispatchOnConnect) { | 247 } else if (function_name == ExtensionMessageService::kDispatchOnConnect) { |
| 253 // There is no way for this service to be addressed and receive | 248 // There is no way for this service to be addressed and receive |
| 254 // connections. | 249 // connections. |
| 255 NOTREACHED() << function_name << " shouldn't be called."; | 250 NOTREACHED() << function_name << " shouldn't be called."; |
| 256 } else { | 251 } else { |
| 257 NOTREACHED() << function_name << " shouldn't be called."; | 252 NOTREACHED() << function_name << " shouldn't be called."; |
| 258 } | 253 } |
| 259 } | 254 } |
| 260 | 255 |
| 261 void ExtensionPortsRemoteService::OnExtensionMessage( | 256 void ExtensionPortsRemoteService::OnDeliverMessage( |
| 262 const std::string& message, int port_id) { | 257 int port_id, const std::string& message) { |
| 263 VLOG(1) << "Message event: from port " << port_id << ", < " << message << ">"; | 258 VLOG(1) << "Message event: from port " << port_id << ", < " << message << ">"; |
| 264 // Transpose the information into a JSON message for the external client. | 259 // Transpose the information into a JSON message for the external client. |
| 265 DictionaryValue content; | 260 DictionaryValue content; |
| 266 content.SetString(kCommandKey, kOnMessage); | 261 content.SetString(kCommandKey, kOnMessage); |
| 267 content.SetInteger(kResultKey, RESULT_OK); | 262 content.SetInteger(kResultKey, RESULT_OK); |
| 268 // Turn the stringified message body back into JSON. | 263 // Turn the stringified message body back into JSON. |
| 269 Value* data = base::JSONReader::Read(message, false); | 264 Value* data = base::JSONReader::Read(message, false); |
| 270 if (!data) { | 265 if (!data) { |
| 271 NOTREACHED(); | 266 NOTREACHED(); |
| 272 return; | 267 return; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 VLOG(1) << "unknown port: " << port_id; | 371 VLOG(1) << "unknown port: " << port_id; |
| 377 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); | 372 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); |
| 378 return; | 373 return; |
| 379 } | 374 } |
| 380 // Post the message through the ExtensionMessageService. | 375 // Post the message through the ExtensionMessageService. |
| 381 DCHECK(service_); | 376 DCHECK(service_); |
| 382 service_->PostMessageFromRenderer(port_id, message); | 377 service_->PostMessageFromRenderer(port_id, message); |
| 383 // Confirm to the external client that we sent its message. | 378 // Confirm to the external client that we sent its message. |
| 384 response->SetInteger(kResultKey, RESULT_OK); | 379 response->SetInteger(kResultKey, RESULT_OK); |
| 385 } | 380 } |
| OLD | NEW |