| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 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/json/string_escape.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/devtools/devtools_file_watcher.h" | 22 #include "chrome/browser/devtools/devtools_file_watcher.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 method, | 460 method, |
| 460 params); | 461 params); |
| 461 } | 462 } |
| 462 | 463 |
| 463 // content::DevToolsAgentHostClient implementation -------------------------- | 464 // content::DevToolsAgentHostClient implementation -------------------------- |
| 464 void DevToolsUIBindings::DispatchProtocolMessage( | 465 void DevToolsUIBindings::DispatchProtocolMessage( |
| 465 content::DevToolsAgentHost* agent_host, const std::string& message) { | 466 content::DevToolsAgentHost* agent_host, const std::string& message) { |
| 466 DCHECK(agent_host == agent_host_.get()); | 467 DCHECK(agent_host == agent_host_.get()); |
| 467 | 468 |
| 468 if (message.length() < kMaxMessageChunkSize) { | 469 if (message.length() < kMaxMessageChunkSize) { |
| 469 base::string16 javascript = base::UTF8ToUTF16( | 470 std::string param; |
| 470 "DevToolsAPI.dispatchMessage(" + message + ");"); | 471 base::EscapeJSONString(message, true, ¶m); |
| 472 base::string16 javascript = |
| 473 base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + param + ");"); |
| 471 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); | 474 web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); |
| 472 return; | 475 return; |
| 473 } | 476 } |
| 474 | 477 |
| 475 base::FundamentalValue total_size(static_cast<int>(message.length())); | 478 base::FundamentalValue total_size(static_cast<int>(message.length())); |
| 476 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 479 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 477 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); | 480 base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); |
| 478 CallClientFunction("DevToolsAPI.dispatchMessageChunk", | 481 CallClientFunction("DevToolsAPI.dispatchMessageChunk", |
| 479 &message_value, pos ? NULL : &total_size, NULL); | 482 &message_value, pos ? NULL : &total_size, NULL); |
| 480 } | 483 } |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 void DevToolsUIBindings::FrontendLoaded() { | 1092 void DevToolsUIBindings::FrontendLoaded() { |
| 1090 if (frontend_loaded_) | 1093 if (frontend_loaded_) |
| 1091 return; | 1094 return; |
| 1092 frontend_loaded_ = true; | 1095 frontend_loaded_ = true; |
| 1093 | 1096 |
| 1094 // Call delegate first - it seeds importants bit of information. | 1097 // Call delegate first - it seeds importants bit of information. |
| 1095 delegate_->OnLoadCompleted(); | 1098 delegate_->OnLoadCompleted(); |
| 1096 | 1099 |
| 1097 AddDevToolsExtensionsToClient(); | 1100 AddDevToolsExtensionsToClient(); |
| 1098 } | 1101 } |
| OLD | NEW |