OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/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_number_conversions.h" | 15 #include "base/string_number_conversions.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/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
23 #include "chrome/common/devtools_messages.h" | 23 #include "chrome/common/devtools_messages.h" |
24 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/extensions/extension_messages.h" |
25 #include "chrome/common/render_messages_params.h" | 25 #include "chrome/common/render_messages_params.h" |
26 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // Protocol is as follows: | 30 // Protocol is as follows: |
31 // | 31 // |
32 // From external client: | 32 // From external client: |
33 // {"command": "connect", | 33 // {"command": "connect", |
34 // "data": { | 34 // "data": { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 scoped_ptr<DevToolsRemoteMessage> response_message( | 219 scoped_ptr<DevToolsRemoteMessage> response_message( |
220 DevToolsRemoteMessageBuilder::instance().Create( | 220 DevToolsRemoteMessageBuilder::instance().Create( |
221 tool, destination, response_content)); | 221 tool, destination, response_content)); |
222 delegate_->Send(*response_message.get()); | 222 delegate_->Send(*response_message.get()); |
223 } | 223 } |
224 | 224 |
225 bool ExtensionPortsRemoteService::Send(IPC::Message *message) { | 225 bool ExtensionPortsRemoteService::Send(IPC::Message *message) { |
226 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 226 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
227 | 227 |
228 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) | 228 IPC_BEGIN_MESSAGE_MAP(ExtensionPortsRemoteService, *message) |
229 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, | 229 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
230 OnExtensionMessageInvoke) | |
231 IPC_MESSAGE_UNHANDLED_ERROR() | 230 IPC_MESSAGE_UNHANDLED_ERROR() |
232 IPC_END_MESSAGE_MAP() | 231 IPC_END_MESSAGE_MAP() |
233 | 232 |
234 delete message; | 233 delete message; |
235 return true; | 234 return true; |
236 } | 235 } |
237 | 236 |
238 void ExtensionPortsRemoteService::OnExtensionMessageInvoke( | 237 void ExtensionPortsRemoteService::OnExtensionMessageInvoke( |
239 const std::string& extension_id, | 238 const std::string& extension_id, |
240 const std::string& function_name, | 239 const std::string& function_name, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 VLOG(1) << "unknown port: " << port_id; | 378 VLOG(1) << "unknown port: " << port_id; |
380 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); | 379 response->SetInteger(kResultKey, RESULT_UNKNOWN_PORT); |
381 return; | 380 return; |
382 } | 381 } |
383 // Post the message through the ExtensionMessageService. | 382 // Post the message through the ExtensionMessageService. |
384 DCHECK(service_); | 383 DCHECK(service_); |
385 service_->PostMessageFromRenderer(port_id, message); | 384 service_->PostMessageFromRenderer(port_id, message); |
386 // Confirm to the external client that we sent its message. | 385 // Confirm to the external client that we sent its message. |
387 response->SetInteger(kResultKey, RESULT_OK); | 386 response->SetInteger(kResultKey, RESULT_OK); |
388 } | 387 } |
OLD | NEW |