diff --git a/atom/common/api/atom_api_clipboard.cc b/atom/common/api/atom_api_clipboard.cc index 13cf3651824..d54fc457309 100644 --- a/atom/common/api/atom_api_clipboard.cc +++ b/atom/common/api/atom_api_clipboard.cc @@ -66,6 +66,7 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardType(args)); base::string16 text, html, bookmark; gfx::Image image; + std::map> customBuffers; if (data.Get("text", &text)) { writer.WriteText(text); @@ -84,6 +85,14 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) { if (data.Get("image", &image)) writer.WriteImage(image.AsBitmap()); + + if (data.Get("buffer", &customBuffers)) { + for (auto i = customBuffers.begin(); i != customBuffers.end(); ++i) { + writer.WriteData(node::Buffer::Data(i->second), + node::Buffer::Length(i->second), + ui::Clipboard::GetFormatType(i->first)); + } + } } base::string16 Clipboard::ReadText(mate::Arguments* args) { diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index b1a1b732552..c73f0fd6e64 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -1,5 +1,6 @@ const assert = require('assert') const path = require('path') +const fs = require('fs') const {Buffer} = require('buffer') const {clipboard, nativeImage} = require('electron') @@ -67,17 +68,23 @@ describe('clipboard module', function () { var i = nativeImage.createFromPath(p) var markup = process.platform === 'darwin' ? "Hi" : process.platform === 'linux' ? 'Hi' : 'Hi' var bookmark = {title: 'a title', url: 'test'} + const pdfType = process.platform === 'darwin' ? 'com.adobe.pdf' : 'application/pdf' + const pdf = fs.readFileSync(path.join(fixtures, 'assets', 'cat.pdf')) clipboard.write({ text: 'test', html: 'Hi', rtf: '{\\rtf1\\utf8 text}', bookmark: 'a title', - image: p + image: p, + buffer: { + [pdfType]: pdf + } }) assert.equal(clipboard.readText(), text) assert.equal(clipboard.readHTML(), markup) assert.equal(clipboard.readRTF(), rtf) assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()) + assert.deepEqual(clipboard.readBuffer(pdfType), pdf) if (process.platform !== 'linux') { assert.deepEqual(clipboard.readBookmark(), bookmark)