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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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 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
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, &param); 271 base::JSONWriter::Write(
272 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), &param);
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
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
OLDNEW
« no previous file with comments | « content/renderer/stats_collection_controller.cc ('k') | content/shell/renderer/layout_test/leak_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698