зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1135933 - Make nsContextMenu.setDesktopBackground() use a message to get the image as a dataURL and make a new element with it to pass to the setDesktopBackground dialog. r=gabor
Also perform the disableSetDesktopBackground() check in content --HG-- extra : commitid : KxHNPz0K0D3 extra : rebase_source : d5f8876a2f3bc58fd4ce133c2eca9b18ce70f282
This commit is contained in:
Родитель
f30c3c8091
Коммит
7e004684e2
|
@ -102,12 +102,15 @@ let handleContentContextMenu = function (event) {
|
|||
.getInterface(Ci.nsIDOMWindowUtils)
|
||||
.outerWindowID;
|
||||
|
||||
let disableSetDesktopBg = null;
|
||||
// Media related cache info parent needs for saving
|
||||
let contentType = null;
|
||||
let contentDisposition = null;
|
||||
if (event.target.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
event.target instanceof Ci.nsIImageLoadingContent &&
|
||||
event.target.currentURI) {
|
||||
disableSetDesktopBg = disableSetDesktopBackground(event.target);
|
||||
|
||||
try {
|
||||
let imageCache =
|
||||
Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
||||
|
@ -148,7 +151,7 @@ let handleContentContextMenu = function (event) {
|
|||
{ editFlags, spellInfo, customMenuItems, addonInfo,
|
||||
principal, docLocation, charSet, baseURI, referrer,
|
||||
referrerPolicy, contentType, contentDisposition,
|
||||
frameOuterWindowID, selectionInfo },
|
||||
frameOuterWindowID, selectionInfo, disableSetDesktopBg },
|
||||
{ event, popupNode: event.target });
|
||||
}
|
||||
else {
|
||||
|
@ -169,6 +172,7 @@ let handleContentContextMenu = function (event) {
|
|||
contentType: contentType,
|
||||
contentDisposition: contentDisposition,
|
||||
selectionInfo: selectionInfo,
|
||||
disableSetDesktopBackground: disableSetDesktopBg,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -753,3 +757,52 @@ addMessageListener("ContextMenu:SearchFieldBookmarkData", (message) => {
|
|||
sendAsyncMessage("ContextMenu:SearchFieldBookmarkData:Result",
|
||||
{ spec, title, description, postData, charset });
|
||||
});
|
||||
|
||||
function disableSetDesktopBackground(aTarget) {
|
||||
// Disable the Set as Desktop Background menu item if we're still trying
|
||||
// to load the image or the load failed.
|
||||
if (!(aTarget instanceof Ci.nsIImageLoadingContent))
|
||||
return true;
|
||||
|
||||
if (("complete" in aTarget) && !aTarget.complete)
|
||||
return true;
|
||||
|
||||
if (aTarget.currentURI.schemeIs("javascript"))
|
||||
return true;
|
||||
|
||||
let request = aTarget.QueryInterface(Ci.nsIImageLoadingContent)
|
||||
.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
if (!request)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
addMessageListener("ContextMenu:SetAsDesktopBackground", (message) => {
|
||||
let target = message.objects.target;
|
||||
|
||||
// Paranoia: check disableSetDesktopBackground again, in case the
|
||||
// image changed since the context menu was initiated.
|
||||
let disable = disableSetDesktopBackground(target);
|
||||
|
||||
if (!disable) {
|
||||
try {
|
||||
BrowserUtils.urlSecurityCheck(target.currentURI.spec, target.ownerDocument.nodePrincipal);
|
||||
let canvas = content.document.createElement("canvas");
|
||||
canvas.width = target.naturalWidth;
|
||||
canvas.height = target.naturalHeight;
|
||||
let ctx = canvas.getContext("2d");
|
||||
ctx.drawImage(target, 0, 0);
|
||||
let dataUrl = canvas.toDataURL();
|
||||
sendAsyncMessage("ContextMenu:SetAsDesktopBackground:Result",
|
||||
{ dataUrl });
|
||||
}
|
||||
catch (e) {
|
||||
Cu.reportError(e);
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (disable)
|
||||
sendAsyncMessage("ContextMenu:SetAsDesktopBackground:Result", { disable });
|
||||
});
|
||||
|
|
|
@ -241,7 +241,7 @@ nsContextMenu.prototype = {
|
|||
|
||||
if (haveSetDesktopBackground && this.onLoadedImage) {
|
||||
document.getElementById("context-setDesktopBackground")
|
||||
.disabled = this.disableSetDesktopBackground();
|
||||
.disabled = gContextMenuContentData.disableSetDesktopBackground;
|
||||
}
|
||||
|
||||
// Reload image depends on an image that's not fully loaded
|
||||
|
@ -1134,60 +1134,49 @@ nsContextMenu.prototype = {
|
|||
referrerURI: gContextMenuContentData.documentURIObject });
|
||||
},
|
||||
|
||||
disableSetDesktopBackground: function() {
|
||||
// Disable the Set as Desktop Background menu item if we're still trying
|
||||
// to load the image or the load failed.
|
||||
if (!(this.target instanceof Ci.nsIImageLoadingContent))
|
||||
return true;
|
||||
|
||||
if (("complete" in this.target) && !this.target.complete)
|
||||
return true;
|
||||
|
||||
if (this.target.currentURI.schemeIs("javascript"))
|
||||
return true;
|
||||
|
||||
var request = this.target
|
||||
.QueryInterface(Ci.nsIImageLoadingContent)
|
||||
.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
if (!request)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
setDesktopBackground: function() {
|
||||
// Paranoia: check disableSetDesktopBackground again, in case the
|
||||
// image changed since the context menu was initiated.
|
||||
if (this.disableSetDesktopBackground())
|
||||
return;
|
||||
let mm = this.browser.messageManager;
|
||||
|
||||
var doc = this.target.ownerDocument;
|
||||
urlSecurityCheck(this.target.currentURI.spec, this.principal);
|
||||
mm.sendAsyncMessage("ContextMenu:SetAsDesktopBackground", null,
|
||||
{ target: this.target });
|
||||
|
||||
// Confirm since it's annoying if you hit this accidentally.
|
||||
const kDesktopBackgroundURL =
|
||||
"chrome://browser/content/setDesktopBackground.xul";
|
||||
let onMessage = (message) => {
|
||||
mm.removeMessageListener("ContextMenu:SetAsDesktopBackground:Result",
|
||||
onMessage);
|
||||
|
||||
if (message.data.disable)
|
||||
return;
|
||||
|
||||
let image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
|
||||
image.src = message.data.dataUrl;
|
||||
|
||||
// Confirm since it's annoying if you hit this accidentally.
|
||||
const kDesktopBackgroundURL =
|
||||
"chrome://browser/content/setDesktopBackground.xul";
|
||||
#ifdef XP_MACOSX
|
||||
// On Mac, the Set Desktop Background window is not modal.
|
||||
// Don't open more than one Set Desktop Background window.
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var dbWin = wm.getMostRecentWindow("Shell:SetDesktopBackground");
|
||||
if (dbWin) {
|
||||
dbWin.gSetBackground.init(this.target);
|
||||
dbWin.focus();
|
||||
}
|
||||
else {
|
||||
openDialog(kDesktopBackgroundURL, "",
|
||||
"centerscreen,chrome,dialog=no,dependent,resizable=no",
|
||||
this.target);
|
||||
}
|
||||
// On Mac, the Set Desktop Background window is not modal.
|
||||
// Don't open more than one Set Desktop Background window.
|
||||
const wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
let dbWin = wm.getMostRecentWindow("Shell:SetDesktopBackground");
|
||||
if (dbWin) {
|
||||
dbWin.gSetBackground.init(image);
|
||||
dbWin.focus();
|
||||
}
|
||||
else {
|
||||
openDialog(kDesktopBackgroundURL, "",
|
||||
"centerscreen,chrome,dialog=no,dependent,resizable=no",
|
||||
image);
|
||||
}
|
||||
#else
|
||||
// On non-Mac platforms, the Set Wallpaper dialog is modal.
|
||||
openDialog(kDesktopBackgroundURL, "",
|
||||
"centerscreen,chrome,dialog,modal,dependent",
|
||||
this.target);
|
||||
// On non-Mac platforms, the Set Wallpaper dialog is modal.
|
||||
openDialog(kDesktopBackgroundURL, "",
|
||||
"centerscreen,chrome,dialog,modal,dependent",
|
||||
image);
|
||||
#endif
|
||||
};
|
||||
|
||||
mm.addMessageListener("ContextMenu:SetAsDesktopBackground:Result", onMessage);
|
||||
},
|
||||
|
||||
// Save URL of clicked-on frame.
|
||||
|
|
|
@ -3890,6 +3890,7 @@
|
|||
contentDisposition: aMessage.data.contentDisposition,
|
||||
frameOuterWindowID: aMessage.data.frameOuterWindowID,
|
||||
selectionInfo: aMessage.data.selectionInfo,
|
||||
disableSetDesktopBackground: aMessage.data.disableSetDesktopBg,
|
||||
};
|
||||
let popup = browser.ownerDocument.getElementById("contentAreaContextMenu");
|
||||
let event = gContextMenuContentData.event;
|
||||
|
|
Загрузка…
Ссылка в новой задаче