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

Side by Side Diff: content/shell/browser/shell_devtools_frontend.cc

Issue 2022673002: DevTools: Fix Maximum call stack size exceeded error while retrieving CPU profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use EscapeJSONString Created 4 years, 6 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
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 264 }
264 265
265 if (request_id) 266 if (request_id)
266 SendMessageAck(request_id, nullptr); 267 SendMessageAck(request_id, nullptr);
267 } 268 }
268 269
269 void ShellDevToolsFrontend::DispatchProtocolMessage( 270 void ShellDevToolsFrontend::DispatchProtocolMessage(
270 DevToolsAgentHost* agent_host, const std::string& message) { 271 DevToolsAgentHost* agent_host, const std::string& message) {
271 272
272 if (message.length() < kMaxMessageChunkSize) { 273 if (message.length() < kMaxMessageChunkSize) {
273 base::string16 javascript = base::UTF8ToUTF16( 274 std::string param;
274 "DevToolsAPI.dispatchMessage(" + message + ");"); 275 base::EscapeJSONString(message, true, &param);
276 std::string code = "DevToolsAPI.dispatchMessage(" + param + ");";
277 base::string16 javascript = base::UTF8ToUTF16(code);
275 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); 278 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
276 return; 279 return;
277 } 280 }
278 281
279 base::FundamentalValue total_size(static_cast<int>(message.length())); 282 size_t total_size = message.length();
280 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { 283 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
281 std::string param; 284 std::string param;
282 base::JSONWriter::Write( 285 base::EscapeJSONString(message.substr(pos, kMaxMessageChunkSize), true,
283 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), &param); 286 &param);
284 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; 287 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + "," +
288 std::to_string(pos ? 0 : total_size) + ");";
285 base::string16 javascript = base::UTF8ToUTF16(code); 289 base::string16 javascript = base::UTF8ToUTF16(code);
286 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); 290 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
287 } 291 }
288 } 292 }
289 293
290 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { 294 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) {
291 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. 295 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc.
292 // We should handle some of the commands including this one in content. 296 // We should handle some of the commands including this one in content.
293 DCHECK(source); 297 DCHECK(source);
294 PendingRequestsMap::iterator it = pending_requests_.find(source); 298 PendingRequestsMap::iterator it = pending_requests_.find(source);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 CallClientFunction("DevToolsAPI.embedderMessageAck", 345 CallClientFunction("DevToolsAPI.embedderMessageAck",
342 &id_value, arg, nullptr); 346 &id_value, arg, nullptr);
343 } 347 }
344 348
345 void ShellDevToolsFrontend::AgentHostClosed( 349 void ShellDevToolsFrontend::AgentHostClosed(
346 DevToolsAgentHost* agent_host, bool replaced) { 350 DevToolsAgentHost* agent_host, bool replaced) {
347 frontend_shell_->Close(); 351 frontend_shell_->Close();
348 } 352 }
349 353
350 } // namespace content 354 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698