diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc index b035e7f19410c..d8636d9106033 100644 --- a/chrome/browser/devtools/devtools_ui_bindings.cc +++ b/chrome/browser/devtools/devtools_ui_bindings.cc @@ -7,6 +7,7 @@ #include #include +#include "base/base64.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/json/string_escape.h" @@ -267,17 +268,21 @@ int ResponseWriter::Write(net::IOBuffer* buffer, int num_bytes, const net::CompletionCallback& callback) { std::string chunk = std::string(buffer->data(), num_bytes); - if (!base::IsStringUTF8(chunk)) - return num_bytes; + bool encoded = false; + if (!base::IsStringUTF8(chunk)) { + encoded = true; + base::Base64Encode(chunk, &chunk); + } base::FundamentalValue* id = new base::FundamentalValue(stream_id_); base::StringValue* chunkValue = new base::StringValue(chunk); + base::FundamentalValue* encodedValue = new base::FundamentalValue(encoded); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, - base::Bind(&DevToolsUIBindings::CallClientFunction, - bindings_, "DevToolsAPI.streamWrite", - base::Owned(id), base::Owned(chunkValue), nullptr)); + base::Bind(&DevToolsUIBindings::CallClientFunction, bindings_, + "DevToolsAPI.streamWrite", base::Owned(id), + base::Owned(chunkValue), base::Owned(encodedValue))); return num_bytes; } diff --git a/third_party/WebKit/Source/devtools/front_end/devtools.js b/third_party/WebKit/Source/devtools/front_end/devtools.js index f9c05b2c74478..1e8c833e8a0ae 100644 --- a/third_party/WebKit/Source/devtools/front_end/devtools.js +++ b/third_party/WebKit/Source/devtools/front_end/devtools.js @@ -302,10 +302,28 @@ DevToolsAPIImpl.prototype = { /** * @param {number} id * @param {string} chunk + * @param {boolean} encoded */ - streamWrite: function(id, chunk) + streamWrite: function(id, chunk, encoded) { - this._dispatchOnInspectorFrontendAPI("streamWrite", [id, chunk]); + this._dispatchOnInspectorFrontendAPI("streamWrite", [id, encoded ? this._decodeBase64(chunk) : chunk]); + }, + + /** + * @param {string} chunk + * @return {string} + */ + _decodeBase64: function(chunk) + { + var request = new XMLHttpRequest(); + request.open("GET", "data:text/plain;base64," + chunk, false); + request.send(null); + if (request.status === 200) { + return request.responseText; + } else { + console.error("Error while decoding chunk in streamWrite"); + return ""; + } } }