<p>I have a XULRunner application that needs to copy image data to the clipboard. I have figured out how to handle copying text to the clipboard, and I can paste PNG data from the clipboard. What I can't figure out is how to get data from a data URL into the clipboard so that it can be pasted into other applications.</p>

<p>This is the code I use to copy text (well, XUL):</p>

<pre><code>var transferObject=Components.classes["@mozilla.org/widget/transferable;1"].
    createInstance(Components.interfaces.nsITransferable);

var stringWrapper=Components.classes["@mozilla.org/supports-string;1"].
    createInstance(Components.interfaces.nsISupportsString);

var systemClipboard=Components.classes["@mozilla.org/widget/clipboard;1"].
    createInstance(Components.interfaces.nsIClipboard);

var objToSerialize=aDOMNode;

transferObject.addDataFlavor("text/xul");

var xmls=new XMLSerializer();
var serializedObj=xmls.serializeToString(objToSerialize);

stringWrapper.data=serializedObj;

transferObject.setTransferData("text/xul",stringWrapper,serializedObj.length*2);
</code></pre>

<p>And, as I said, the data I'm trying to transfer is a PNG as a data URL. So I'm looking for the equivalent to the above that will allow, e.g. Paint.NET to paste my app's data.</p>

[{'answer_id': 69119, 'author': 'pc1oad1etter', 'author_id': 525, 'author_profile': 'https://Stackoverflow.com/users/525', 'pm_score': 2, 'selected': False, 'text': '<p>Neal Deakin has an <a href="http://developer.mozilla.org/en/Using_the_Clipboard" rel="nofollow noreferrer">article on manipulating the clipboard</a> in xulrunner.  I\'m not sure if it answers your question specifically, but it\'s definitely worth checking out.</p>\n'}, {'answer_id': 130880, 'author': 'Joel Anair', 'author_id': 7441, 'author_profile': 'https://Stackoverflow.com/users/7441', 'pm_score': 3, 'selected': True, 'text': "<p>Here's a workaround that I ended up using that solves the problem pretty well. The variable <code>dataURL</code> is the image I was trying to get to the clipboard in the first place.</p>\n\n<pre><code>var newImg=document.createElement('img');\nnewImg.src=dataURL;\n\ndocument.popupNode=newImg;\n\nvar command='cmd_copyImageContents'\n\nvar controller=document.commandDispatcher.getControllerForCommand(command);\n\nif(controller &amp;&amp; controller.isCommandEnabled(command)){\n    controller.doCommand(command);\n}\n</code></pre>\n\n<p>That copies the image to the clipboard as an 'image/jpg'.</p>\n"}]
['https://Stackoverflow.com/questions/68103', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7441/']