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

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

Issue 3117017: Remove deprecated wstring Get(As)String() methods from Value, etc. (Closed)
Patch Set: fix win Created 10 years, 4 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
OLDNEW
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 // 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/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/debugger/devtools_manager.h" 15 #include "chrome/browser/debugger/devtools_manager.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/renderer_host/render_view_host.h" 19 #include "chrome/browser/renderer_host/render_view_host.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/common/devtools_messages.h" 21 #include "chrome/common/devtools_messages.h"
22 #include "chrome/common/render_messages.h" 22 #include "chrome/common/render_messages.h"
23 23
24 namespace { 24 namespace {
25 25
26 // A constant for the "data" JSON message field. 26 // Constants for the "data", "result", and "command" JSON message fields.
27 // The type is wstring because the constant is used to get a 27 const char kDataKey[] = "data";
28 // DictionaryValue field (which requires a wide string). 28 const char kResultKey[] = "result";
29 static const std::wstring kDataWide = L"data"; 29 const char kCommandKey[] = "command";
30
31 // A constant for the "result" JSON message field.
32 // The type is wstring because the constant is used to get a
33 // DictionaryValue field (which requires a wide string).
34 static const std::wstring kResultWide = L"result";
35
36 // A constant for the "command" JSON message field.
37 // The type is wstring because the constant is used to get a
38 // DictionaryValue field (which requires a wide string).
39 static const std::wstring kCommandWide = L"command";
40 30
41 } // namespace 31 } // namespace
42 32
43 const std::string DebuggerRemoteServiceCommand::kAttach = "attach"; 33 const std::string DebuggerRemoteServiceCommand::kAttach = "attach";
44 const std::string DebuggerRemoteServiceCommand::kDetach = "detach"; 34 const std::string DebuggerRemoteServiceCommand::kDetach = "detach";
45 const std::string DebuggerRemoteServiceCommand::kDebuggerCommand = 35 const std::string DebuggerRemoteServiceCommand::kDebuggerCommand =
46 "debugger_command"; 36 "debugger_command";
47 const std::string DebuggerRemoteServiceCommand::kEvaluateJavascript = 37 const std::string DebuggerRemoteServiceCommand::kEvaluateJavascript =
48 "evaluate_javascript"; 38 "evaluate_javascript";
49 const std::string DebuggerRemoteServiceCommand::kFrameNavigate = 39 const std::string DebuggerRemoteServiceCommand::kFrameNavigate =
(...skipping 21 matching lines...) Expand all
71 // Bad JSON 61 // Bad JSON
72 NOTREACHED(); 62 NOTREACHED();
73 return; 63 return;
74 } 64 }
75 DictionaryValue* content; 65 DictionaryValue* content;
76 if (!request->IsType(Value::TYPE_DICTIONARY)) { 66 if (!request->IsType(Value::TYPE_DICTIONARY)) {
77 NOTREACHED(); // Broken protocol :( 67 NOTREACHED(); // Broken protocol :(
78 return; 68 return;
79 } 69 }
80 content = static_cast<DictionaryValue*>(request.get()); 70 content = static_cast<DictionaryValue*>(request.get());
81 if (!content->HasKey(kCommandWide)) { 71 if (!content->HasKey(kCommandKey)) {
82 NOTREACHED(); // Broken protocol :( 72 NOTREACHED(); // Broken protocol :(
83 return; 73 return;
84 } 74 }
85 std::string command; 75 std::string command;
86 DictionaryValue response; 76 DictionaryValue response;
87 77
88 content->GetString(kCommandWide, &command); 78 content->GetString(kCommandKey, &command);
89 response.SetString(kCommandWide, command); 79 response.SetString(kCommandKey, command);
90 bool send_response = true; 80 bool send_response = true;
91 if (destination.size() == 0) { 81 if (destination.size() == 0) {
92 // Unknown command (bad format?) 82 // Unknown command (bad format?)
93 NOTREACHED(); 83 NOTREACHED();
94 response.SetInteger(kResultWide, RESULT_UNKNOWN_COMMAND); 84 response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND);
95 SendResponse(response, message.tool(), message.destination()); 85 SendResponse(response, message.tool(), message.destination());
96 return; 86 return;
97 } 87 }
98 int32 tab_uid = -1; 88 int32 tab_uid = -1;
99 base::StringToInt(destination, &tab_uid); 89 base::StringToInt(destination, &tab_uid);
100 90
101 if (command == DebuggerRemoteServiceCommand::kAttach) { 91 if (command == DebuggerRemoteServiceCommand::kAttach) {
102 // TODO(apavlov): handle 0 for a new tab 92 // TODO(apavlov): handle 0 for a new tab
103 response.SetString(kCommandWide, DebuggerRemoteServiceCommand::kAttach); 93 response.SetString(kCommandKey, DebuggerRemoteServiceCommand::kAttach);
104 AttachToTab(destination, &response); 94 AttachToTab(destination, &response);
105 } else if (command == DebuggerRemoteServiceCommand::kDetach) { 95 } else if (command == DebuggerRemoteServiceCommand::kDetach) {
106 response.SetString(kCommandWide, DebuggerRemoteServiceCommand::kDetach); 96 response.SetString(kCommandKey, DebuggerRemoteServiceCommand::kDetach);
107 DetachFromTab(destination, &response); 97 DetachFromTab(destination, &response);
108 } else if (command == DebuggerRemoteServiceCommand::kDebuggerCommand) { 98 } else if (command == DebuggerRemoteServiceCommand::kDebuggerCommand) {
109 send_response = DispatchDebuggerCommand(tab_uid, content, &response); 99 send_response = DispatchDebuggerCommand(tab_uid, content, &response);
110 } else if (command == DebuggerRemoteServiceCommand::kEvaluateJavascript) { 100 } else if (command == DebuggerRemoteServiceCommand::kEvaluateJavascript) {
111 send_response = DispatchEvaluateJavascript(tab_uid, content, &response); 101 send_response = DispatchEvaluateJavascript(tab_uid, content, &response);
112 } else { 102 } else {
113 // Unknown command 103 // Unknown command
114 NOTREACHED(); 104 NOTREACHED();
115 response.SetInteger(kResultWide, RESULT_UNKNOWN_COMMAND); 105 response.SetInteger(kResultKey, RESULT_UNKNOWN_COMMAND);
116 } 106 }
117 107
118 if (send_response) { 108 if (send_response) {
119 SendResponse(response, message.tool(), message.destination()); 109 SendResponse(response, message.tool(), message.destination());
120 } 110 }
121 } 111 }
122 112
123 void DebuggerRemoteService::OnConnectionLost() { 113 void DebuggerRemoteService::OnConnectionLost() {
124 delegate_->inspectable_tab_proxy()->OnRemoteDebuggerDetached(); 114 delegate_->inspectable_tab_proxy()->OnRemoteDebuggerDetached();
125 } 115 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 delegate_->Send(*(response_message.get())); 166 delegate_->Send(*(response_message.get()));
177 } 167 }
178 168
179 // Gets invoked from a DevToolsClientHost callback whenever 169 // Gets invoked from a DevToolsClientHost callback whenever
180 // a tab corresponding to |tab_id| changes its URL. |url| is the new 170 // a tab corresponding to |tab_id| changes its URL. |url| is the new
181 // URL of the tab (may be the same as the previous one if the tab is reloaded). 171 // URL of the tab (may be the same as the previous one if the tab is reloaded).
182 // Sends the corresponding message to the remote debugger. 172 // Sends the corresponding message to the remote debugger.
183 void DebuggerRemoteService::FrameNavigate(int32 tab_uid, 173 void DebuggerRemoteService::FrameNavigate(int32 tab_uid,
184 const std::string& url) { 174 const std::string& url) {
185 DictionaryValue value; 175 DictionaryValue value;
186 value.SetString(kCommandWide, DebuggerRemoteServiceCommand::kFrameNavigate); 176 value.SetString(kCommandKey, DebuggerRemoteServiceCommand::kFrameNavigate);
187 value.SetInteger(kResultWide, RESULT_OK); 177 value.SetInteger(kResultKey, RESULT_OK);
188 value.SetString(kDataWide, url); 178 value.SetString(kDataKey, url);
189 SendResponse(value, kToolName, base::IntToString(tab_uid)); 179 SendResponse(value, kToolName, base::IntToString(tab_uid));
190 } 180 }
191 181
192 // Gets invoked from a DevToolsClientHost callback whenever 182 // Gets invoked from a DevToolsClientHost callback whenever
193 // a tab corresponding to |tab_id| gets closed. 183 // a tab corresponding to |tab_id| gets closed.
194 // Sends the corresponding message to the remote debugger. 184 // Sends the corresponding message to the remote debugger.
195 void DebuggerRemoteService::TabClosed(int32 tab_id) { 185 void DebuggerRemoteService::TabClosed(int32 tab_id) {
196 DictionaryValue value; 186 DictionaryValue value;
197 value.SetString(kCommandWide, DebuggerRemoteServiceCommand::kTabClosed); 187 value.SetString(kCommandKey, DebuggerRemoteServiceCommand::kTabClosed);
198 value.SetInteger(kResultWide, RESULT_OK); 188 value.SetInteger(kResultKey, RESULT_OK);
199 SendResponse(value, kToolName, base::IntToString(tab_id)); 189 SendResponse(value, kToolName, base::IntToString(tab_id));
200 } 190 }
201 191
202 // Attaches a remote debugger to the target tab specified by |destination| 192 // Attaches a remote debugger to the target tab specified by |destination|
203 // by posting the DevToolsAgentMsg_Attach message and sends a response 193 // by posting the DevToolsAgentMsg_Attach message and sends a response
204 // to the remote debugger immediately. 194 // to the remote debugger immediately.
205 void DebuggerRemoteService::AttachToTab(const std::string& destination, 195 void DebuggerRemoteService::AttachToTab(const std::string& destination,
206 DictionaryValue* response) { 196 DictionaryValue* response) {
207 int32 tab_uid = -1; 197 int32 tab_uid = -1;
208 base::StringToInt(destination, &tab_uid); 198 base::StringToInt(destination, &tab_uid);
209 if (tab_uid < 0) { 199 if (tab_uid < 0) {
210 // Bad tab_uid received from remote debugger (perhaps NaN) 200 // Bad tab_uid received from remote debugger (perhaps NaN)
211 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 201 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
212 return; 202 return;
213 } 203 }
214 if (tab_uid == 0) { // single tab_uid 204 if (tab_uid == 0) { // single tab_uid
215 // We've been asked to open a new tab with URL 205 // We've been asked to open a new tab with URL
216 // TODO(apavlov): implement 206 // TODO(apavlov): implement
217 NOTIMPLEMENTED(); 207 NOTIMPLEMENTED();
218 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 208 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
219 return; 209 return;
220 } 210 }
221 TabContents* tab_contents = ToTabContents(tab_uid); 211 TabContents* tab_contents = ToTabContents(tab_uid);
222 if (tab_contents == NULL) { 212 if (tab_contents == NULL) {
223 // No active tab contents with tab_uid 213 // No active tab contents with tab_uid
224 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 214 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
225 return; 215 return;
226 } 216 }
227 RenderViewHost* target_host = tab_contents->render_view_host(); 217 RenderViewHost* target_host = tab_contents->render_view_host();
228 DevToolsClientHost* client_host = 218 DevToolsClientHost* client_host =
229 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); 219 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid);
230 if (client_host == NULL) { 220 if (client_host == NULL) {
231 client_host = 221 client_host =
232 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this); 222 delegate_->inspectable_tab_proxy()->NewClientHost(tab_uid, this);
233 DevToolsManager* manager = DevToolsManager::GetInstance(); 223 DevToolsManager* manager = DevToolsManager::GetInstance();
234 if (manager != NULL) { 224 if (manager != NULL) {
235 manager->RegisterDevToolsClientHostFor(target_host, client_host); 225 manager->RegisterDevToolsClientHostFor(target_host, client_host);
236 response->SetInteger(kResultWide, RESULT_OK); 226 response->SetInteger(kResultKey, RESULT_OK);
237 } else { 227 } else {
238 response->SetInteger(kResultWide, RESULT_DEBUGGER_ERROR); 228 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR);
239 } 229 }
240 } else { 230 } else {
241 // DevToolsClientHost for this tab is already registered 231 // DevToolsClientHost for this tab is already registered
242 response->SetInteger(kResultWide, RESULT_ILLEGAL_TAB_STATE); 232 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE);
243 } 233 }
244 } 234 }
245 235
246 // Detaches a remote debugger from the target tab specified by |destination| 236 // Detaches a remote debugger from the target tab specified by |destination|
247 // by posting the DevToolsAgentMsg_Detach message and sends a response 237 // by posting the DevToolsAgentMsg_Detach message and sends a response
248 // to the remote debugger immediately. 238 // to the remote debugger immediately.
249 void DebuggerRemoteService::DetachFromTab(const std::string& destination, 239 void DebuggerRemoteService::DetachFromTab(const std::string& destination,
250 DictionaryValue* response) { 240 DictionaryValue* response) {
251 int32 tab_uid = -1; 241 int32 tab_uid = -1;
252 base::StringToInt(destination, &tab_uid); 242 base::StringToInt(destination, &tab_uid);
253 if (tab_uid == -1) { 243 if (tab_uid == -1) {
254 // Bad tab_uid received from remote debugger (NaN) 244 // Bad tab_uid received from remote debugger (NaN)
255 if (response != NULL) { 245 if (response != NULL) {
256 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 246 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
257 } 247 }
258 return; 248 return;
259 } 249 }
260 int result_code; 250 int result_code;
261 DevToolsClientHostImpl* client_host = 251 DevToolsClientHostImpl* client_host =
262 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid); 252 delegate_->inspectable_tab_proxy()->ClientHostForTabId(tab_uid);
263 if (client_host != NULL) { 253 if (client_host != NULL) {
264 client_host->Close(); 254 client_host->Close();
265 result_code = RESULT_OK; 255 result_code = RESULT_OK;
266 } else { 256 } else {
267 // No client host registered for |tab_uid|. 257 // No client host registered for |tab_uid|.
268 result_code = RESULT_UNKNOWN_TAB; 258 result_code = RESULT_UNKNOWN_TAB;
269 } 259 }
270 if (response != NULL) { 260 if (response != NULL) {
271 response->SetInteger(kResultWide, result_code); 261 response->SetInteger(kResultKey, result_code);
272 } 262 }
273 } 263 }
274 264
275 // Sends a V8 debugger command to the target tab V8 debugger. 265 // Sends a V8 debugger command to the target tab V8 debugger.
276 // Does not send back a response (which is received asynchronously 266 // Does not send back a response (which is received asynchronously
277 // through IPC) unless an error occurs before the command has actually 267 // through IPC) unless an error occurs before the command has actually
278 // been sent. 268 // been sent.
279 bool DebuggerRemoteService::DispatchDebuggerCommand(int tab_uid, 269 bool DebuggerRemoteService::DispatchDebuggerCommand(int tab_uid,
280 DictionaryValue* content, 270 DictionaryValue* content,
281 DictionaryValue* response) { 271 DictionaryValue* response) {
282 if (tab_uid == -1) { 272 if (tab_uid == -1) {
283 // Invalid tab_uid from remote debugger (perhaps NaN) 273 // Invalid tab_uid from remote debugger (perhaps NaN)
284 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 274 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
285 return true; 275 return true;
286 } 276 }
287 DevToolsManager* manager = DevToolsManager::GetInstance(); 277 DevToolsManager* manager = DevToolsManager::GetInstance();
288 if (manager == NULL) { 278 if (manager == NULL) {
289 response->SetInteger(kResultWide, RESULT_DEBUGGER_ERROR); 279 response->SetInteger(kResultKey, RESULT_DEBUGGER_ERROR);
290 return true; 280 return true;
291 } 281 }
292 TabContents* tab_contents = ToTabContents(tab_uid); 282 TabContents* tab_contents = ToTabContents(tab_uid);
293 if (tab_contents == NULL) { 283 if (tab_contents == NULL) {
294 // Unknown tab_uid from remote debugger 284 // Unknown tab_uid from remote debugger
295 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 285 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
296 return true; 286 return true;
297 } 287 }
298 DevToolsClientHost* client_host = 288 DevToolsClientHost* client_host =
299 manager->GetDevToolsClientHostFor(tab_contents->render_view_host()); 289 manager->GetDevToolsClientHostFor(tab_contents->render_view_host());
300 if (client_host == NULL) { 290 if (client_host == NULL) {
301 // tab_uid is not being debugged (Attach has not been invoked) 291 // tab_uid is not being debugged (Attach has not been invoked)
302 response->SetInteger(kResultWide, RESULT_ILLEGAL_TAB_STATE); 292 response->SetInteger(kResultKey, RESULT_ILLEGAL_TAB_STATE);
303 return true; 293 return true;
304 } 294 }
305 std::string v8_command; 295 std::string v8_command;
306 DictionaryValue* v8_command_value; 296 DictionaryValue* v8_command_value;
307 content->GetDictionary(kDataWide, &v8_command_value); 297 content->GetDictionary(kDataKey, &v8_command_value);
308 base::JSONWriter::Write(v8_command_value, false, &v8_command); 298 base::JSONWriter::Write(v8_command_value, false, &v8_command);
309 manager->ForwardToDevToolsAgent( 299 manager->ForwardToDevToolsAgent(
310 client_host, DevToolsAgentMsg_DebuggerCommand(v8_command)); 300 client_host, DevToolsAgentMsg_DebuggerCommand(v8_command));
311 // Do not send the response right now, as the JSON will be received from 301 // Do not send the response right now, as the JSON will be received from
312 // the V8 debugger asynchronously. 302 // the V8 debugger asynchronously.
313 return false; 303 return false;
314 } 304 }
315 305
316 // Sends the immediate "evaluate Javascript" command to the V8 debugger. 306 // Sends the immediate "evaluate Javascript" command to the V8 debugger.
317 // The evaluation result is not sent back to the client as this command 307 // The evaluation result is not sent back to the client as this command
318 // is in fact needed to invoke processing of queued debugger commands. 308 // is in fact needed to invoke processing of queued debugger commands.
319 bool DebuggerRemoteService::DispatchEvaluateJavascript( 309 bool DebuggerRemoteService::DispatchEvaluateJavascript(
320 int tab_uid, 310 int tab_uid,
321 DictionaryValue* content, 311 DictionaryValue* content,
322 DictionaryValue* response) { 312 DictionaryValue* response) {
323 if (tab_uid == -1) { 313 if (tab_uid == -1) {
324 // Invalid tab_uid from remote debugger (perhaps NaN) 314 // Invalid tab_uid from remote debugger (perhaps NaN)
325 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 315 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
326 return true; 316 return true;
327 } 317 }
328 TabContents* tab_contents = ToTabContents(tab_uid); 318 TabContents* tab_contents = ToTabContents(tab_uid);
329 if (tab_contents == NULL) { 319 if (tab_contents == NULL) {
330 // Unknown tab_uid from remote debugger 320 // Unknown tab_uid from remote debugger
331 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 321 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
332 return true; 322 return true;
333 } 323 }
334 RenderViewHost* render_view_host = tab_contents->render_view_host(); 324 RenderViewHost* render_view_host = tab_contents->render_view_host();
335 if (render_view_host == NULL) { 325 if (render_view_host == NULL) {
336 // No RenderViewHost 326 // No RenderViewHost
337 response->SetInteger(kResultWide, RESULT_UNKNOWN_TAB); 327 response->SetInteger(kResultKey, RESULT_UNKNOWN_TAB);
338 return true; 328 return true;
339 } 329 }
340 std::wstring javascript; 330 std::string javascript;
341 content->GetString(kDataWide, &javascript); 331 content->GetString(kDataKey, &javascript);
342 render_view_host->Send( 332 render_view_host->Send(
343 new ViewMsg_ScriptEvalRequest(render_view_host->routing_id(), 333 new ViewMsg_ScriptEvalRequest(render_view_host->routing_id(),
344 L"", 334 L"",
345 javascript)); 335 UTF8ToWide(javascript)));
346 return false; 336 return false;
347 } 337 }
OLDNEW
« no previous file with comments | « chrome/browser/command_line_pref_store_unittest.cc ('k') | chrome/browser/debugger/devtools_remote_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698