mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
Bug 363512 - remove base-64 encoding functions in favor of built-ins. r=gavin.
This commit is contained in:
parent
1e18f4d51c
commit
444eb436ac
@ -999,8 +999,7 @@ iconDataURIGenerator.prototype = {
|
||||
if (!requestFailed && this._countRead != 0) {
|
||||
var str = String.fromCharCode.apply(null, this._bytes);
|
||||
try {
|
||||
var dataURI = ICON_DATAURL_PREFIX +
|
||||
this._element.ownerDocument.defaultView.btoa(str);
|
||||
var dataURI = ICON_DATAURL_PREFIX + btoa(str);
|
||||
this._element.setAttribute("image", dataURI);
|
||||
}
|
||||
catch(ex) {}
|
||||
|
@ -266,58 +266,6 @@ function ENSURE_ARG(assertion, message) {
|
||||
ENSURE(assertion, message, Cr.NS_ERROR_INVALID_ARG);
|
||||
}
|
||||
|
||||
// FIXME: Bug 326854: no btoa for components, use our own
|
||||
/**
|
||||
* Encodes an array of bytes into a string using the base 64 encoding scheme.
|
||||
* @param aBytes
|
||||
* An array of bytes to encode.
|
||||
*/
|
||||
function b64(aBytes) {
|
||||
const B64_CHARS =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
var index = 0;
|
||||
function get3Bytes() {
|
||||
if (aBytes.length - index < 3)
|
||||
return null; // Less than three bytes remaining
|
||||
|
||||
// Return the next three bytes in the array, and increment index for our
|
||||
// next invocation
|
||||
return aBytes.slice(index, index += 3);
|
||||
}
|
||||
|
||||
var out = "";
|
||||
var bytes = null;
|
||||
while ((bytes = get3Bytes())) {
|
||||
var bits = 0;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
bits <<= 8;
|
||||
bits |= bytes[i];
|
||||
}
|
||||
for (var j = 18; j >= 0; j -= 6)
|
||||
out += B64_CHARS[(bits>>j) & 0x3F];
|
||||
}
|
||||
|
||||
// Get the remaining bytes
|
||||
bytes = aBytes.slice(index);
|
||||
|
||||
switch (bytes.length) {
|
||||
case 2:
|
||||
out += B64_CHARS[(bytes[0]>>2) & 0x3F] +
|
||||
B64_CHARS[((bytes[0] & 0x03) << 4) | ((bytes[1] >> 4) & 0x0F)] +
|
||||
B64_CHARS[((bytes[1] & 0x0F) << 2)] +
|
||||
"=";
|
||||
break;
|
||||
case 1:
|
||||
out += B64_CHARS[(bytes[0]>>2) & 0x3F] +
|
||||
B64_CHARS[(bytes[0] & 0x03) << 4] +
|
||||
"==";
|
||||
break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
function loadListener(aChannel, aEngine, aCallback) {
|
||||
this._channel = aChannel;
|
||||
this._bytes = [];
|
||||
@ -1347,7 +1295,7 @@ Engine.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
var str = b64(aByteArray);
|
||||
var str = btoa(String.fromCharCode.apply(null, aByteArray));
|
||||
aEngine._iconURI = makeURI(ICON_DATAURL_PREFIX + str);
|
||||
|
||||
// The engine might not have a file yet, if it's being downloaded,
|
||||
|
Loading…
x
Reference in New Issue
Block a user