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

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

Issue 8103003: Revert 103263 - Merge 101221 - Reland 101111 - Only deliver extension messages to contexts that c... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/874/src/
Patch Set: Created 9 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
OLDNEW
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
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)
230 IPC_MESSAGE_UNHANDLED_ERROR() 229 IPC_MESSAGE_UNHANDLED_ERROR()
231 IPC_END_MESSAGE_MAP() 230 IPC_END_MESSAGE_MAP()
232 231
233 delete message; 232 delete message;
234 return true; 233 return true;
235 } 234 }
236 235
237 void ExtensionPortsRemoteService::OnExtensionMessageInvoke( 236 void ExtensionPortsRemoteService::OnExtensionMessageInvoke(
238 const std::string& extension_id, 237 const std::string& extension_id,
239 const std::string& function_name, 238 const std::string& function_name,
240 const ListValue& args, 239 const ListValue& args,
241 const GURL& event_url) { 240 const GURL& event_url) {
242 if (function_name == ExtensionMessageService::kDispatchOnDisconnect) { 241 if (function_name == ExtensionMessageService::kDispatchOnMessage) {
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) {
243 DCHECK_EQ(args.GetSize(), 1u); 248 DCHECK_EQ(args.GetSize(), 1u);
244 int port_id; 249 int port_id;
245 if (args.GetInteger(0, &port_id)) 250 if (args.GetInteger(0, &port_id))
246 OnExtensionPortDisconnected(port_id); 251 OnExtensionPortDisconnected(port_id);
247 } else if (function_name == ExtensionMessageService::kDispatchOnConnect) { 252 } else if (function_name == ExtensionMessageService::kDispatchOnConnect) {
248 // There is no way for this service to be addressed and receive 253 // There is no way for this service to be addressed and receive
249 // connections. 254 // connections.
250 NOTREACHED() << function_name << " shouldn't be called."; 255 NOTREACHED() << function_name << " shouldn't be called.";
251 } else { 256 } else {
252 NOTREACHED() << function_name << " shouldn't be called."; 257 NOTREACHED() << function_name << " shouldn't be called.";
253 } 258 }
254 } 259 }
255 260
256 void ExtensionPortsRemoteService::OnDeliverMessage( 261 void ExtensionPortsRemoteService::OnExtensionMessage(
257 int port_id, const std::string& message) { 262 const std::string& message, int port_id) {
258 VLOG(1) << "Message event: from port " << port_id << ", < " << message << ">"; 263 VLOG(1) << "Message event: from port " << port_id << ", < " << message << ">";
259 // Transpose the information into a JSON message for the external client. 264 // Transpose the information into a JSON message for the external client.
260 DictionaryValue content; 265 DictionaryValue content;
261 content.SetString(kCommandKey, kOnMessage); 266 content.SetString(kCommandKey, kOnMessage);
262 content.SetInteger(kResultKey, RESULT_OK); 267 content.SetInteger(kResultKey, RESULT_OK);
263 // Turn the stringified message body back into JSON. 268 // Turn the stringified message body back into JSON.
264 Value* data = base::JSONReader::Read(message, false); 269 Value* data = base::JSONReader::Read(message, false);
265 if (!data) { 270 if (!data) {
266 NOTREACHED(); 271 NOTREACHED();
267 return; 272 return;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 VLOG(1) << "unknown port: " << port_id; 376 VLOG(1) << "unknown port: " << port_id;
372 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); 377 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT);
373 return; 378 return;
374 } 379 }
375 // Post the message through the ExtensionMessageService. 380 // Post the message through the ExtensionMessageService.
376 DCHECK(service_); 381 DCHECK(service_);
377 service_->PostMessageFromRenderer(port_id, message); 382 service_->PostMessageFromRenderer(port_id, message);
378 // Confirm to the external client that we sent its message. 383 // Confirm to the external client that we sent its message.
379 response->SetInteger(kResultKey, RESULT_OK); 384 response->SetInteger(kResultKey, RESULT_OK);
380 } 385 }
OLDNEW
« no previous file with comments | « chrome/browser/debugger/extension_ports_remote_service.h ('k') | chrome/browser/extensions/extension_message_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698