From 3b401a2c03ad31c0b6b508410b4bc0bf8116ea9f Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@bk.ru> Date: Mon, 8 Jun 2015 15:12:44 +0300 Subject: [PATCH] Network: fixed front-end fix non-ascii preview: - Backported `String.prototype.toBase64` from 2426 branch - Backported `NetworkRequest.asDataURL` Removed useless controls --- front-end-node/network/NetworkPanel.js | 5 +++- front-end/platform/utilities.js | 36 ++++++++++++++++++++++++++ front-end/sdk/NetworkRequest.js | 9 ++++--- front-end/sdk/Resource.js | 5 ++-- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/front-end-node/network/NetworkPanel.js b/front-end-node/network/NetworkPanel.js index 51492c9e..7cc3bd43 100644 --- a/front-end-node/network/NetworkPanel.js +++ b/front-end-node/network/NetworkPanel.js @@ -14,4 +14,7 @@ WebInspector.NetworkPanel._instance()._networkLogView.addEventListener( WebInspector.NetworkLogView.EventTypes.ViewCleared, function() { NetworkAgent._clearCapturedData(); - }); \ No newline at end of file + }); + +WebInspector.NetworkPanel._instance()._networkLogView._preserveLogCheckbox.setVisible(false); +WebInspector.NetworkPanel._instance()._networkLogView._disableCacheCheckbox.setVisible(false); diff --git a/front-end/platform/utilities.js b/front-end/platform/utilities.js index 7c9301cf..7ff4ef17 100644 --- a/front-end/platform/utilities.js +++ b/front-end/platform/utilities.js @@ -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 diff --git a/front-end/sdk/NetworkRequest.js b/front-end/sdk/NetworkRequest.js index fcfca1c3..723a1ec5 100644 --- a/front-end/sdk/NetworkRequest.js +++ b/front-end/sdk/NetworkRequest.js @@ -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() diff --git a/front-end/sdk/Resource.js b/front-end/sdk/Resource.js index 422ff18a..943a9533 100644 --- a/front-end/sdk/Resource.js +++ b/front-end/sdk/Resource.js @@ -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; } /**