| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 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/json/string_escape.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "components/devtools_http_handler/devtools_http_handler.h" | 18 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 263 } |
| 263 | 264 |
| 264 if (request_id) | 265 if (request_id) |
| 265 SendMessageAck(request_id, nullptr); | 266 SendMessageAck(request_id, nullptr); |
| 266 } | 267 } |
| 267 | 268 |
| 268 void ShellDevToolsFrontend::DispatchProtocolMessage( | 269 void ShellDevToolsFrontend::DispatchProtocolMessage( |
| 269 DevToolsAgentHost* agent_host, const std::string& message) { | 270 DevToolsAgentHost* agent_host, const std::string& message) { |
| 270 | 271 |
| 271 if (message.length() < kMaxMessageChunkSize) { | 272 if (message.length() < kMaxMessageChunkSize) { |
| 272 base::string16 javascript = base::UTF8ToUTF16( | 273 std::string param; |
| 273 "DevToolsAPI.dispatchMessage(" + message + ");"); | 274 base::EscapeJSONString(message, true, ¶m); |
| 275 std::string code = "DevToolsAPI.dispatchMessage(" + param + ");"; |
| 276 base::string16 javascript = base::UTF8ToUTF16(code); |
| 274 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); | 277 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); |
| 275 return; | 278 return; |
| 276 } | 279 } |
| 277 | 280 |
| 278 base::FundamentalValue total_size(static_cast<int>(message.length())); | 281 size_t total_size = message.length(); |
| 279 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 282 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 280 std::string param; | 283 std::string param; |
| 281 base::JSONWriter::Write( | 284 base::EscapeJSONString(message.substr(pos, kMaxMessageChunkSize), true, |
| 282 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m); | 285 ¶m); |
| 283 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; | 286 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + "," + |
| 287 std::to_string(pos ? 0 : total_size) + ");"; |
| 284 base::string16 javascript = base::UTF8ToUTF16(code); | 288 base::string16 javascript = base::UTF8ToUTF16(code); |
| 285 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); | 289 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); |
| 286 } | 290 } |
| 287 } | 291 } |
| 288 | 292 |
| 289 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { | 293 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { |
| 290 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. | 294 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. |
| 291 // We should handle some of the commands including this one in content. | 295 // We should handle some of the commands including this one in content. |
| 292 DCHECK(source); | 296 DCHECK(source); |
| 293 PendingRequestsMap::iterator it = pending_requests_.find(source); | 297 PendingRequestsMap::iterator it = pending_requests_.find(source); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 CallClientFunction("DevToolsAPI.embedderMessageAck", | 344 CallClientFunction("DevToolsAPI.embedderMessageAck", |
| 341 &id_value, arg, nullptr); | 345 &id_value, arg, nullptr); |
| 342 } | 346 } |
| 343 | 347 |
| 344 void ShellDevToolsFrontend::AgentHostClosed( | 348 void ShellDevToolsFrontend::AgentHostClosed( |
| 345 DevToolsAgentHost* agent_host, bool replaced) { | 349 DevToolsAgentHost* agent_host, bool replaced) { |
| 346 frontend_shell_->Close(); | 350 frontend_shell_->Close(); |
| 347 } | 351 } |
| 348 | 352 |
| 349 } // namespace content | 353 } // namespace content |
| OLD | NEW |