Skip to content

Commit

Permalink
Network: fixed front-end
Browse files Browse the repository at this point in the history
fix non-ascii preview:
- Backported `String.prototype.toBase64` from 2426 branch
- Backported `NetworkRequest.asDataURL`

Removed useless controls
  • Loading branch information
3y3 committed Jun 28, 2015
1 parent d46f68c commit 3b401a2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
5 changes: 4 additions & 1 deletion front-end-node/network/NetworkPanel.js
Expand Up @@ -14,4 +14,7 @@ WebInspector.NetworkPanel._instance()._networkLogView.addEventListener(
WebInspector.NetworkLogView.EventTypes.ViewCleared,
function() {
NetworkAgent._clearCapturedData();
});
});

WebInspector.NetworkPanel._instance()._networkLogView._preserveLogCheckbox.setVisible(false);
WebInspector.NetworkPanel._instance()._networkLogView._disableCacheCheckbox.setVisible(false);
36 changes: 36 additions & 0 deletions front-end/platform/utilities.js
Expand Up @@ -313,6 +313,42 @@ String.prototype.isDigitAt = function(index)
return 48 <= c && c <= 57;
}

/**
* @return {string}
*/
String.prototype.toBase64 = function()
{
/**
* @param {number} b
* @return {number}
*/
function encodeBits(b)
{
return b < 26 ? b + 65 : b < 52 ? b + 71 : b < 62 ? b - 4 : b === 62 ? 43 : b === 63 ? 47 : 65;
}
var encoder = new TextEncoder();
var data = encoder.encode(this.toString());
var n = data.length;
var encoded = "";
if (n === 0)
return encoded;
var shift;
var v = 0;
for (var i = 0; i < n; i++) {
shift = i % 3;
v |= data[i] << (16 >>> shift & 24);
if (shift === 2) {
encoded += String.fromCharCode(encodeBits(v >>> 18 & 63), encodeBits(v >>> 12 & 63), encodeBits(v >>> 6 & 63), encodeBits(v & 63));
v = 0;
}
}
if (shift === 0)
encoded += String.fromCharCode(encodeBits(v >>> 18 & 63), encodeBits(v >>> 12 & 63), 61, 61);
else if (shift === 1)
encoded += String.fromCharCode(encodeBits(v >>> 18 & 63), encodeBits(v >>> 12 & 63), encodeBits(v >>> 6 & 63), 61);
return encoded;
}

/**
* @param {string} a
* @param {string} b
Expand Down
9 changes: 6 additions & 3 deletions front-end/sdk/NetworkRequest.js
Expand Up @@ -899,9 +899,12 @@ WebInspector.NetworkRequest.prototype = {
asDataURL: function()
{
var content = this._content;
if (!this._contentEncoded)
content = window.btoa(content);
return WebInspector.Resource.contentAsDataURL(content, this.mimeType, true);
var charset = null;
if (!this._contentEncoded) {
content = content.toBase64();
charset = "utf-8";
}
return WebInspector.Resource.contentAsDataURL(content, this.mimeType, true, charset);
},

_innerRequestContent: function()
Expand Down
5 changes: 3 additions & 2 deletions front-end/sdk/Resource.js
Expand Up @@ -68,15 +68,16 @@ WebInspector.Resource.Events = {
* @param {?string} content
* @param {string} mimeType
* @param {boolean} contentEncoded
* @param {?string=} charset
* @return {?string}
*/
WebInspector.Resource.contentAsDataURL = function(content, mimeType, contentEncoded)
WebInspector.Resource.contentAsDataURL = function(content, mimeType, contentEncoded, charset)
{
const maxDataUrlSize = 1024 * 1024;
if (content === null || content.length > maxDataUrlSize)
return null;

return "data:" + mimeType + (contentEncoded ? ";base64," : ",") + content;
return "data:" + mimeType + (charset ? ";charset=" + charset : "") + (contentEncoded ? ";base64" : "") + "," + content;
}

/**
Expand Down

0 comments on commit 3b401a2

Please sign in to comment.