| 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 // This file contains implementations of the DebuggerRemoteService methods, | 5 // This file contains implementations of the DebuggerRemoteService methods, |
| 6 // defines DebuggerRemoteService and DebuggerRemoteServiceCommand constants. | 6 // defines DebuggerRemoteService and DebuggerRemoteServiceCommand constants. |
| 7 | 7 |
| 8 #include "chrome/browser/debugger/debugger_remote_service.h" | 8 #include "chrome/browser/debugger/debugger_remote_service.h" |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/debugger/devtools_protocol_handler.h" | 16 #include "chrome/browser/debugger/devtools_protocol_handler.h" |
| 17 #include "chrome/browser/debugger/devtools_remote_message.h" | 17 #include "chrome/browser/debugger/devtools_remote_message.h" |
| 18 #include "chrome/browser/debugger/inspectable_tab_proxy.h" | 18 #include "chrome/browser/debugger/inspectable_tab_proxy.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
| 21 #include "content/browser/debugger/devtools_manager.h" | |
| 22 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/common/devtools_messages.h" | 23 #include "content/common/devtools_messages.h" |
| 24 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 25 #include "content/public/browser/devtools/devtools_manager.h" |
| 26 |
| 27 using content::DevToolsAgentHost; |
| 28 using content::DevToolsAgentHostRegistry; |
| 29 using content::DevToolsClientHost; |
| 30 using content::DevToolsManager; |
| 25 | 31 |
| 26 namespace { | 32 namespace { |
| 27 | 33 |
| 28 // Constants for the "data", "result", and "command" JSON message fields. | 34 // Constants for the "data", "result", and "command" JSON message fields. |
| 29 const char kDataKey[] = "data"; | 35 const char kDataKey[] = "data"; |
| 30 const char kResultKey[] = "result"; | 36 const char kResultKey[] = "result"; |
| 31 const char kCommandKey[] = "command"; | 37 const char kCommandKey[] = "command"; |
| 32 | 38 |
| 33 } // namespace | 39 } // namespace |
| 34 | 40 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return; | 220 return; |
| 215 } | 221 } |
| 216 RenderViewHost* target_host = tab_contents->render_view_host(); | 222 RenderViewHost* target_host = tab_contents->render_view_host(); |
| 217 DevToolsClientHost* client_host = | 223 DevToolsClientHost* client_host = |
| 218 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); | 224 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); |
| 219 if (client_host == NULL) { | 225 if (client_host == NULL) { |
| 220 client_host = | 226 client_host = |
| 221 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); | 227 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); |
| 222 DevToolsManager* manager = DevToolsManager::GetInstance(); | 228 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 223 if (manager != NULL) { | 229 if (manager != NULL) { |
| 224 manager->RegisterDevToolsClientHostFor(target_host, client_host); | 230 DevToolsAgentHost* agent = |
| 231 DevToolsAgentHostRegistry::GetDevToolsAgentHost(target_host); |
| 232 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 225 response->SetInteger(kResultKey, RESULT_OK); | 233 response->SetInteger(kResultKey, RESULT_OK); |
| 226 } else { | 234 } else { |
| 227 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); | 235 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); |
| 228 } | 236 } |
| 229 } else { | 237 } else { |
| 230 // DevToolsClientHost for this tab is already registered | 238 // DevToolsClientHost for this tab is already registered |
| 231 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); | 239 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); |
| 232 } | 240 } |
| 233 } | 241 } |
| 234 | 242 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (manager == NULL) { | 285 if (manager == NULL) { |
| 278 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); | 286 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); |
| 279 return true; | 287 return true; |
| 280 } | 288 } |
| 281 TabContents* tab_contents = ToTabContents(tab_uid); | 289 TabContents* tab_contents = ToTabContents(tab_uid); |
| 282 if (tab_contents == NULL) { | 290 if (tab_contents == NULL) { |
| 283 // Unknown tab_uid from remote debugger | 291 // Unknown tab_uid from remote debugger |
| 284 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); | 292 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); |
| 285 return true; | 293 return true; |
| 286 } | 294 } |
| 287 DevToolsClientHost* client_host = | 295 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 288 manager->GetDevToolsClientHostFor(tab_contents->render_view_host()); | 296 tab_contents->render_view_host()); |
| 297 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); |
| 289 if (client_host == NULL) { | 298 if (client_host == NULL) { |
| 290 // tab_uid is not being debugged (Attach has not been invoked) | 299 // tab_uid is not being debugged (Attach has not been invoked) |
| 291 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); | 300 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); |
| 292 return true; | 301 return true; |
| 293 } | 302 } |
| 294 std::string v8_command; | 303 std::string v8_command; |
| 295 DictionaryValue* v8_command_value; | 304 DictionaryValue* v8_command_value; |
| 296 content->GetDictionary(kDataKey, &v8_command_value); | 305 content->GetDictionary(kDataKey, &v8_command_value); |
| 297 base::JSONWriter::Write(v8_command_value, false, &v8_command); | 306 base::JSONWriter::Write(v8_command_value, false, &v8_command); |
| 298 manager->ForwardToDevToolsAgent( | 307 manager->ForwardToDevToolsAgent( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 326 // No RenderViewHost | 335 // No RenderViewHost |
| 327 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); | 336 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); |
| 328 return true; | 337 return true; |
| 329 } | 338 } |
| 330 std::string javascript; | 339 std::string javascript; |
| 331 content->GetString(kDataKey, &javascript); | 340 content->GetString(kDataKey, &javascript); |
| 332 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 341 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
| 333 UTF8ToUTF16(javascript)); | 342 UTF8ToUTF16(javascript)); |
| 334 return false; | 343 return false; |
| 335 } | 344 } |
| OLD | NEW |