OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell_devtools_frontend.h" | 5 #include "content/shell/browser/shell_devtools_frontend.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 if (message.length() < kMaxMessageChunkSize) { | 261 if (message.length() < kMaxMessageChunkSize) { |
262 base::string16 javascript = base::UTF8ToUTF16( | 262 base::string16 javascript = base::UTF8ToUTF16( |
263 "DevToolsAPI.dispatchMessage(" + message + ");"); | 263 "DevToolsAPI.dispatchMessage(" + message + ");"); |
264 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 264 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); |
265 return; | 265 return; |
266 } | 266 } |
267 | 267 |
268 base::FundamentalValue total_size(static_cast<int>(message.length())); | 268 base::FundamentalValue total_size(static_cast<int>(message.length())); |
269 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 269 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
270 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); | |
271 std::string param; | 270 std::string param; |
272 base::JSONWriter::Write(&message_value, ¶m); | 271 base::JSONWriter::Write( |
| 272 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m); |
273 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; | 273 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; |
274 base::string16 javascript = base::UTF8ToUTF16(code); | 274 base::string16 javascript = base::UTF8ToUTF16(code); |
275 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 275 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { | 279 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { |
280 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. | 280 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. |
281 // We should handle some of the commands including this one in content. | 281 // We should handle some of the commands including this one in content. |
282 DCHECK(source); | 282 DCHECK(source); |
(...skipping 18 matching lines...) Expand all Loading... |
301 } | 301 } |
302 | 302 |
303 void ShellDevToolsFrontend::CallClientFunction( | 303 void ShellDevToolsFrontend::CallClientFunction( |
304 const std::string& function_name, | 304 const std::string& function_name, |
305 const base::Value* arg1, | 305 const base::Value* arg1, |
306 const base::Value* arg2, | 306 const base::Value* arg2, |
307 const base::Value* arg3) { | 307 const base::Value* arg3) { |
308 std::string javascript = function_name + "("; | 308 std::string javascript = function_name + "("; |
309 if (arg1) { | 309 if (arg1) { |
310 std::string json; | 310 std::string json; |
311 base::JSONWriter::Write(arg1, &json); | 311 base::JSONWriter::Write(*arg1, &json); |
312 javascript.append(json); | 312 javascript.append(json); |
313 if (arg2) { | 313 if (arg2) { |
314 base::JSONWriter::Write(arg2, &json); | 314 base::JSONWriter::Write(*arg2, &json); |
315 javascript.append(", ").append(json); | 315 javascript.append(", ").append(json); |
316 if (arg3) { | 316 if (arg3) { |
317 base::JSONWriter::Write(arg3, &json); | 317 base::JSONWriter::Write(*arg3, &json); |
318 javascript.append(", ").append(json); | 318 javascript.append(", ").append(json); |
319 } | 319 } |
320 } | 320 } |
321 } | 321 } |
322 javascript.append(");"); | 322 javascript.append(");"); |
323 web_contents()->GetMainFrame()->ExecuteJavaScript( | 323 web_contents()->GetMainFrame()->ExecuteJavaScript( |
324 base::UTF8ToUTF16(javascript)); | 324 base::UTF8ToUTF16(javascript)); |
325 } | 325 } |
326 | 326 |
327 void ShellDevToolsFrontend::SendMessageAck(int request_id, | 327 void ShellDevToolsFrontend::SendMessageAck(int request_id, |
328 const base::Value* arg) { | 328 const base::Value* arg) { |
329 base::FundamentalValue id_value(request_id); | 329 base::FundamentalValue id_value(request_id); |
330 CallClientFunction("DevToolsAPI.embedderMessageAck", | 330 CallClientFunction("DevToolsAPI.embedderMessageAck", |
331 &id_value, arg, nullptr); | 331 &id_value, arg, nullptr); |
332 } | 332 } |
333 | 333 |
334 void ShellDevToolsFrontend::AgentHostClosed( | 334 void ShellDevToolsFrontend::AgentHostClosed( |
335 DevToolsAgentHost* agent_host, bool replaced) { | 335 DevToolsAgentHost* agent_host, bool replaced) { |
336 frontend_shell_->Close(); | 336 frontend_shell_->Close(); |
337 } | 337 } |
338 | 338 |
339 } // namespace content | 339 } // namespace content |
OLD | NEW |