Skip to content

Commit

Permalink
Slightly refactor setTabAttributeProxy() for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Aug 25, 2016
1 parent 1148b32 commit fa63385
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,18 +1225,19 @@ var privateTab = {
}
_log((applyPatch ? "Override" : "Restore") + " tab.setAttribute()");
},
setTabAttributeProxy: function(attr, val) {
setTabAttributeProxy: function(attr, src) {
var args = arguments;
var tab = this;
var window = tab.ownerDocument.defaultView;
function done() {
args[1] = src;
var window = tab.ownerDocument.defaultView;
return window.Element.prototype.setAttribute.apply(tab, args);
}
if(attr != "image" || !val)
if(attr != "image" || !src)
return done();
val += ""; // Convert to string
src += ""; // Convert to string
if(
val.startsWith("moz-anno:favicon:")
src.startsWith("moz-anno:favicon:")
|| !privateTabInternal.isPrivateTab(tab)
)
return done();
Expand All @@ -1246,10 +1247,10 @@ var privateTab = {
var mm = browser.messageManager;
var receiveMessage = function(msg) {
mm.removeMessageListener("PrivateTab:ImageDocumentDataURL", receiveMessage);
args[1] = msg.data.isImageDocument
src = msg.data.isImageDocument
? msg.data.dataURL
: val.replace(/^moz-anno:favicon:/, "");
_log("setTabAttributeProxy(): received response from remote tab, set image to\n" + _str(args[1]));
: origSrc || src;
_log("setTabAttributeProxy(): received response from remote tab, set image to\n" + _str(src));
done();
};
mm.addMessageListener("PrivateTab:ImageDocumentDataURL", receiveMessage);
Expand All @@ -1258,7 +1259,8 @@ var privateTab = {
});

// Actually this doesn't work (if icon isn't cached yet), but we should return something in sync mode
args[1] = "moz-anno:favicon:" + val.replace(/[&#]-moz-resolution=\d+,\d+$/, "");
var origSrc = src;
src = "moz-anno:favicon:" + src.replace(/[&#]-moz-resolution=\d+,\d+$/, "");
return done();
}

Expand All @@ -1277,7 +1279,7 @@ var privateTab = {
canvas.height = image.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
args[1] = canvas.toDataURL();
src = canvas.toDataURL();
_log("setTabAttributeProxy() => data:");
}
else {
Expand All @@ -1288,7 +1290,7 @@ var privateTab = {
catch(e) {
Components.utils.reportError(e);
// Something went wrong, will use cached icon
args[1] = "moz-anno:favicon:" + val.replace(/[&#]-moz-resolution=\d+,\d+$/, "");
src = "moz-anno:favicon:" + src.replace(/[&#]-moz-resolution=\d+,\d+$/, "");
_log("setTabAttributeProxy() => moz-anno:favicon:");
}
return done();
Expand Down

0 comments on commit fa63385

Please sign in to comment.