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 #include "chrome/browser/debugger/devtools_http_protocol_handler.h" | 5 #include "chrome/browser/debugger/devtools_http_protocol_handler.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 virtual void InspectedTabClosing() { | 40 virtual void InspectedTabClosing() { |
41 ChromeThread::PostTask( | 41 ChromeThread::PostTask( |
42 ChromeThread::IO, | 42 ChromeThread::IO, |
43 FROM_HERE, | 43 FROM_HERE, |
44 NewRunnableMethod(socket_, | 44 NewRunnableMethod(socket_, |
45 &HttpListenSocket::Close)); | 45 &HttpListenSocket::Close)); |
46 } | 46 } |
47 | 47 |
48 virtual void SendMessageToClient(const IPC::Message& msg) { | 48 virtual void SendMessageToClient(const IPC::Message& msg) { |
49 IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) | 49 IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) |
50 IPC_MESSAGE_HANDLER(DevToolsClientMsg_RpcMessage, OnRpcMessage); | 50 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| 51 OnDispatchOnInspectorFrontend); |
51 IPC_MESSAGE_UNHANDLED_ERROR() | 52 IPC_MESSAGE_UNHANDLED_ERROR() |
52 IPC_END_MESSAGE_MAP() | 53 IPC_END_MESSAGE_MAP() |
53 } | 54 } |
54 | 55 |
55 void NotifyCloseListener() { | 56 void NotifyCloseListener() { |
56 DevToolsClientHost::NotifyCloseListener(); | 57 DevToolsClientHost::NotifyCloseListener(); |
57 } | 58 } |
58 private: | 59 private: |
59 // Message handling routines | 60 // Message handling routines |
60 void OnRpcMessage(const DevToolsMessageData& data) { | 61 void OnDispatchOnInspectorFrontend(const std::string& data) { |
61 std::string message; | 62 std::string message; |
62 message += "devtools$$dispatch(\"" + data.class_name + "\", \"" + | 63 message += "devtools$$dispatch(\"" + data + "\")"; |
63 data.method_name + "\""; | |
64 for (std::vector<std::string>::const_iterator it = data.arguments.begin(); | |
65 it != data.arguments.end(); ++it) { | |
66 std::string param = *it; | |
67 if (!param.empty()) | |
68 message += ", " + param; | |
69 } | |
70 message += ")"; | |
71 socket_->SendOverWebSocket(message); | 64 socket_->SendOverWebSocket(message); |
72 } | 65 } |
73 HttpListenSocket* socket_; | 66 HttpListenSocket* socket_; |
74 }; | 67 }; |
75 | 68 |
76 } | 69 } |
77 | 70 |
78 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { | 71 DevToolsHttpProtocolHandler::~DevToolsHttpProtocolHandler() { |
79 // Stop() must be called prior to this being called | 72 // Stop() must be called prior to this being called |
80 DCHECK(server_.get() == NULL); | 73 DCHECK(server_.get() == NULL); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 AcceptWebSocket(socket, request); | 237 AcceptWebSocket(socket, request); |
245 } | 238 } |
246 | 239 |
247 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( | 240 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( |
248 HttpListenSocket* socket, | 241 HttpListenSocket* socket, |
249 const std::string& data) { | 242 const std::string& data) { |
250 SocketToClientHostMap::iterator it = socket_to_client_host_ui_.find(socket); | 243 SocketToClientHostMap::iterator it = socket_to_client_host_ui_.find(socket); |
251 if (it == socket_to_client_host_ui_.end()) | 244 if (it == socket_to_client_host_ui_.end()) |
252 return; | 245 return; |
253 | 246 |
254 // TODO(pfeldman): Replace with proper parsing / dispatching. | |
255 DevToolsMessageData message_data; | |
256 message_data.class_name = "ToolsAgent"; | |
257 message_data.method_name = "dispatchOnInspectorController"; | |
258 message_data.arguments.push_back(data); | |
259 | |
260 DevToolsManager* manager = DevToolsManager::GetInstance(); | 247 DevToolsManager* manager = DevToolsManager::GetInstance(); |
261 manager->ForwardToDevToolsAgent(it->second, | 248 manager->ForwardToDevToolsAgent(it->second, |
262 DevToolsAgentMsg_RpcMessage(DevToolsMessageData(message_data))); | 249 DevToolsAgentMsg_DispatchOnInspectorBackend(data)); |
263 } | 250 } |
264 | 251 |
265 void DevToolsHttpProtocolHandler::OnCloseUI(HttpListenSocket* socket) { | 252 void DevToolsHttpProtocolHandler::OnCloseUI(HttpListenSocket* socket) { |
266 SocketToClientHostMap::iterator it = socket_to_client_host_ui_.find(socket); | 253 SocketToClientHostMap::iterator it = socket_to_client_host_ui_.find(socket); |
267 if (it == socket_to_client_host_ui_.end()) | 254 if (it == socket_to_client_host_ui_.end()) |
268 return; | 255 return; |
269 DevToolsClientHostImpl* client_host = | 256 DevToolsClientHostImpl* client_host = |
270 static_cast<DevToolsClientHostImpl*>(it->second); | 257 static_cast<DevToolsClientHostImpl*>(it->second); |
271 client_host->NotifyCloseListener(); | 258 client_host->NotifyCloseListener(); |
272 delete client_host; | 259 delete client_host; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 TabStripModel* model = (*it)->tabstrip_model(); | 398 TabStripModel* model = (*it)->tabstrip_model(); |
412 for (int i = 0, size = model->count(); i < size; ++i) { | 399 for (int i = 0, size = model->count(); i < size; ++i) { |
413 NavigationController& controller = | 400 NavigationController& controller = |
414 model->GetTabContentsAt(i)->controller(); | 401 model->GetTabContentsAt(i)->controller(); |
415 if (controller.session_id().id() == session_id) | 402 if (controller.session_id().id() == session_id) |
416 return controller.tab_contents(); | 403 return controller.tab_contents(); |
417 } | 404 } |
418 } | 405 } |
419 return NULL; | 406 return NULL; |
420 } | 407 } |
OLD | NEW |