Bug 601695 - Paste & Go should only appear when clipboard is URL; r=dao a=blocking2.0-final+

This commit is contained in:
Frank Yan 2010-10-26 15:34:52 -07:00
parent 878becc3e3
commit 8e7f9d5b9b

View File

@ -130,11 +130,24 @@
if (!pasteAndGo)
return;
var controller = document.commandDispatcher.getControllerForCommand("cmd_paste");
var enabled = controller.isCommandEnabled("cmd_paste");
if (enabled)
pasteAndGo.removeAttribute("disabled");
else
pasteAndGo.setAttribute("disabled", "true");
var couldBeURL = controller.isCommandEnabled("cmd_paste");
if (couldBeURL) {
let cbSvc = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
let xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
xferable.addDataFlavor("text/unicode");
cbSvc.getData(xferable, cbSvc.kGlobalClipboard);
let data = {};
xferable.getTransferData("text/unicode", data, {});
data = data.value.QueryInterface(Ci.nsISupportsString).data;
try {
makeURI(data);
} catch (ex) { // clipboard data is not a URL
couldBeURL = false;
}
}
pasteAndGo.hidden = !couldBeURL;
}, false);
var insertLocation = cxmenu.firstChild;