Skip to content

Commit

Permalink
[DevTools] Fix problem with loading source maps
Browse files Browse the repository at this point in the history
Encode not utf8 chunk as base 64 and then decode it on frontend side.

BUG=611328
[email protected]

Review-Url: https://codereview.chromium.org/2032013003
Cr-Commit-Position: refs/heads/master@{#397618}
(cherry picked from commit 72c3019)

Review URL: https://codereview.chromium.org/2039013002 .

Cr-Commit-Position: refs/branch-heads/2743@{crosswalk-project#227}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
alexkozy committed Jun 4, 2016
1 parent bb87ede commit ef323f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
15 changes: 10 additions & 5 deletions chrome/browser/devtools/devtools_ui_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stddef.h>
#include <utility>

#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
Expand Down Expand Up @@ -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;
}

Expand Down
22 changes: 20 additions & 2 deletions third_party/WebKit/Source/devtools/front_end/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
}
}

Expand Down

0 comments on commit ef323f0

Please sign in to comment.