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/base64.h" |
10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
12 #include "base/json/string_escape.h" | 13 #include "base/json/string_escape.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 261 } |
261 | 262 |
262 int ResponseWriter::Initialize(const net::CompletionCallback& callback) { | 263 int ResponseWriter::Initialize(const net::CompletionCallback& callback) { |
263 return net::OK; | 264 return net::OK; |
264 } | 265 } |
265 | 266 |
266 int ResponseWriter::Write(net::IOBuffer* buffer, | 267 int ResponseWriter::Write(net::IOBuffer* buffer, |
267 int num_bytes, | 268 int num_bytes, |
268 const net::CompletionCallback& callback) { | 269 const net::CompletionCallback& callback) { |
269 std::string chunk = std::string(buffer->data(), num_bytes); | 270 std::string chunk = std::string(buffer->data(), num_bytes); |
270 if (!base::IsStringUTF8(chunk)) | 271 bool encoded = false; |
271 return num_bytes; | 272 if (!base::IsStringUTF8(chunk)) { |
| 273 encoded = true; |
| 274 base::Base64Encode(chunk, &chunk); |
| 275 } |
272 | 276 |
273 base::FundamentalValue* id = new base::FundamentalValue(stream_id_); | 277 base::FundamentalValue* id = new base::FundamentalValue(stream_id_); |
274 base::StringValue* chunkValue = new base::StringValue(chunk); | 278 base::StringValue* chunkValue = new base::StringValue(chunk); |
| 279 base::FundamentalValue* encodedValue = new base::FundamentalValue(encoded); |
275 | 280 |
276 content::BrowserThread::PostTask( | 281 content::BrowserThread::PostTask( |
277 content::BrowserThread::UI, FROM_HERE, | 282 content::BrowserThread::UI, FROM_HERE, |
278 base::Bind(&DevToolsUIBindings::CallClientFunction, | 283 base::Bind(&DevToolsUIBindings::CallClientFunction, bindings_, |
279 bindings_, "DevToolsAPI.streamWrite", | 284 "DevToolsAPI.streamWrite", base::Owned(id), |
280 base::Owned(id), base::Owned(chunkValue), nullptr)); | 285 base::Owned(chunkValue), base::Owned(encodedValue))); |
281 return num_bytes; | 286 return num_bytes; |
282 } | 287 } |
283 | 288 |
284 int ResponseWriter::Finish(const net::CompletionCallback& callback) { | 289 int ResponseWriter::Finish(const net::CompletionCallback& callback) { |
285 return net::OK; | 290 return net::OK; |
286 } | 291 } |
287 | 292 |
288 } // namespace | 293 } // namespace |
289 | 294 |
290 // DevToolsUIBindings::FrontendWebContentsObserver ---------------------------- | 295 // DevToolsUIBindings::FrontendWebContentsObserver ---------------------------- |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 void DevToolsUIBindings::FrontendLoaded() { | 1097 void DevToolsUIBindings::FrontendLoaded() { |
1093 if (frontend_loaded_) | 1098 if (frontend_loaded_) |
1094 return; | 1099 return; |
1095 frontend_loaded_ = true; | 1100 frontend_loaded_ = true; |
1096 | 1101 |
1097 // Call delegate first - it seeds importants bit of information. | 1102 // Call delegate first - it seeds importants bit of information. |
1098 delegate_->OnLoadCompleted(); | 1103 delegate_->OnLoadCompleted(); |
1099 | 1104 |
1100 AddDevToolsExtensionsToClient(); | 1105 AddDevToolsExtensionsToClient(); |
1101 } | 1106 } |
OLD | NEW |