application/x-moz-nativeimage
try { var cb = Components.classes['@mozilla.org/widget/clipboard;1'].getService(Components.interfaces.nsIClipboard); var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); //var flavor = 'text/unicode'; //var flavor = 'text/unicode'; var flavor = "application/x-moz-nativeimage"; trans.addDataFlavor(flavor); try { cb.getData(trans, cb.kSelectionClipboard); } catch(ex) { cb.getData(trans, cb.kGlobalClipboard); } var data = {}, dataLength = {}; trans.getTransferData(flavor, data, dataLength); //data = data.value.QueryInterface( Components.interfaces.nsISupportsWString || Components.interfaces.nsISupportsString ); console.log(data, dataLength); var s = data.data; var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( "c:\\" ); file.append("t.bin"); var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); fos.init(file, 0x04 | 0x08 | 0x20, 0664, 0); // write, create, truncate var bos = Components.classes["@mozilla.org/binaryoutputstream;1"]. createInstance(Components.interfaces.nsIBinaryOutputStream); bos.setOutputStream(fos); bos.writeBytes(s, dataLength); bos.close(); }catch(e) { console.log(e); }
画像を選んで"copy image"をしたときのデータが application/x-moz-nativeimage で取れてるっぽいんだけど、dataLength.valueが6になるのでなんかちがうかも....
ちなみに text/html にすると Firebug console copy as html - ロックスターになりたい とおんなじようなHTML(といってもDOMが得られるとかではなくてHTMLタグを含んだ普通の文字列みたい)で取れます。
clipboardはおもしろいかも。microformatsでcopy&pasteみたいなのとからめて。
ひとつのデータを、クライアント側が受け入れられる形で出力する、みたいな、中小彼イヤー抽象化レイヤーのようなのを作るのが個人的にツボにはまるのもあると思うけど。なんでそういうのがツボにはまるのかがわかんない。
id:brazilさんがどっかでchrome開いとくとfirebugでふつうにComponents触れるっていうのかいてて、それ以来firebug consoleプログラミングが楽しくてしかたない。BASICみたいに、書いて、そこでCtrl+Enter押すだけで結果が出て、上のやつもfirebug consoleでためしてた。インデントが汚くなるのが難。