| 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::DevToolsAgentHostRegistry; |
| 28 using content::DevToolsManager; |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 // Constants for the "data", "result", and "command" JSON message fields. | 32 // Constants for the "data", "result", and "command" JSON message fields. |
| 29 const char kDataKey[] = "data"; | 33 const char kDataKey[] = "data"; |
| 30 const char kResultKey[] = "result"; | 34 const char kResultKey[] = "result"; |
| 31 const char kCommandKey[] = "command"; | 35 const char kCommandKey[] = "command"; |
| 32 | 36 |
| 33 } // namespace | 37 } // namespace |
| 34 | 38 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return; | 218 return; |
| 215 } | 219 } |
| 216 RenderViewHost* target_host = tab_contents->render_view_host(); | 220 RenderViewHost* target_host = tab_contents->render_view_host(); |
| 217 DevToolsClientHost* client_host = | 221 DevToolsClientHost* client_host = |
| 218 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); | 222 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); |
| 219 if (client_host == NULL) { | 223 if (client_host == NULL) { |
| 220 client_host = | 224 client_host = |
| 221 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); | 225 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); |
| 222 DevToolsManager* manager = DevToolsManager::GetInstance(); | 226 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 223 if (manager != NULL) { | 227 if (manager != NULL) { |
| 224 manager->RegisterDevToolsClientHostFor(target_host, client_host); | 228 DevToolsAgentHost* agent = |
| 229 DevToolsAgentHostRegistry::GetDevToolsAgentHost(target_host); |
| 230 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 225 response->SetInteger(kResultKey, RESULT_OK); | 231 response->SetInteger(kResultKey, RESULT_OK); |
| 226 } else { | 232 } else { |
| 227 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); | 233 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); |
| 228 } | 234 } |
| 229 } else { | 235 } else { |
| 230 // DevToolsClientHost for this tab is already registered | 236 // DevToolsClientHost for this tab is already registered |
| 231 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); | 237 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); |
| 232 } | 238 } |
| 233 } | 239 } |
| 234 | 240 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (manager == NULL) { | 283 if (manager == NULL) { |
| 278 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); | 284 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR); |
| 279 return true; | 285 return true; |
| 280 } | 286 } |
| 281 TabContents* tab_contents = ToTabContents(tab_uid); | 287 TabContents* tab_contents = ToTabContents(tab_uid); |
| 282 if (tab_contents == NULL) { | 288 if (tab_contents == NULL) { |
| 283 // Unknown tab_uid from remote debugger | 289 // Unknown tab_uid from remote debugger |
| 284 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); | 290 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); |
| 285 return true; | 291 return true; |
| 286 } | 292 } |
| 287 DevToolsClientHost* client_host = | 293 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 288 manager->GetDevToolsClientHostFor(tab_contents->render_view_host()); | 294 tab_contents->render_view_host()); |
| 295 DevToolsClientHost* client_host = manager->GetDevToolsClientHostFor(agent); |
| 289 if (client_host == NULL) { | 296 if (client_host == NULL) { |
| 290 // tab_uid is not being debugged (Attach has not been invoked) | 297 // tab_uid is not being debugged (Attach has not been invoked) |
| 291 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); | 298 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE); |
| 292 return true; | 299 return true; |
| 293 } | 300 } |
| 294 std::string v8_command; | 301 std::string v8_command; |
| 295 DictionaryValue* v8_command_value; | 302 DictionaryValue* v8_command_value; |
| 296 content->GetDictionary(kDataKey, &v8_command_value); | 303 content->GetDictionary(kDataKey, &v8_command_value); |
| 297 base::JSONWriter::Write(v8_command_value, false, &v8_command); | 304 base::JSONWriter::Write(v8_command_value, false, &v8_command); |
| 298 manager->ForwardToDevToolsAgent( | 305 manager->ForwardToDevToolsAgent( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 326 // No RenderViewHost | 333 // No RenderViewHost |
| 327 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); | 334 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB); |
| 328 return true; | 335 return true; |
| 329 } | 336 } |
| 330 std::string javascript; | 337 std::string javascript; |
| 331 content->GetString(kDataKey, &javascript); | 338 content->GetString(kDataKey, &javascript); |
| 332 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 339 render_view_host->ExecuteJavascriptInWebFrame(string16(), |
| 333 UTF8ToUTF16(javascript)); | 340 UTF8ToUTF16(javascript)); |
| 334 return false; | 341 return false; |
| 335 } | 342 } |
| OLD | NEW |