|
@@ -4,8 +4,10 @@ const electron = require('electron')
|
|
|
const { EventEmitter } = require('events')
|
|
|
const fs = require('fs')
|
|
|
const util = require('util')
|
|
|
+
|
|
|
const v8Util = process.atomBinding('v8_util')
|
|
|
const eventBinding = process.atomBinding('event')
|
|
|
+const clipboard = process.atomBinding('clipboard')
|
|
|
|
|
|
const { isPromise } = electron
|
|
|
|
|
@@ -16,6 +18,7 @@ const objectsRegistry = require('@electron/internal/browser/objects-registry')
|
|
|
const guestViewManager = require('@electron/internal/browser/guest-view-manager')
|
|
|
const bufferUtils = require('@electron/internal/common/buffer-utils')
|
|
|
const errorUtils = require('@electron/internal/common/error-utils')
|
|
|
+const clipboardUtils = require('@electron/internal/common/clipboard-utils')
|
|
|
|
|
|
const hasProp = {}.hasOwnProperty
|
|
|
|
|
@@ -488,12 +491,24 @@ ipcMainUtils.handle('ELECTRON_BROWSER_GET_LAST_WEB_PREFERENCES', function (event
|
|
|
return event.sender.getLastWebPreferences()
|
|
|
})
|
|
|
|
|
|
-ipcMainUtils.handle('ELECTRON_BROWSER_CLIPBOARD_READ_FIND_TEXT', function (event) {
|
|
|
- return electron.clipboard.readFindText()
|
|
|
-})
|
|
|
+// Methods not listed in this set are called directly in the renderer process.
|
|
|
+const allowedClipboardMethods = (() => {
|
|
|
+ switch (process.platform) {
|
|
|
+ case 'darwin':
|
|
|
+ return new Set(['readFindText', 'writeFindText'])
|
|
|
+ case 'linux':
|
|
|
+ return new Set(Object.keys(clipboard))
|
|
|
+ default:
|
|
|
+ return new Set()
|
|
|
+ }
|
|
|
+})()
|
|
|
+
|
|
|
+ipcMainUtils.handle('ELECTRON_BROWSER_CLIPBOARD', function (event, method, ...args) {
|
|
|
+ if (!allowedClipboardMethods.has(method)) {
|
|
|
+ throw new Error(`Invalid method: ${method}`)
|
|
|
+ }
|
|
|
|
|
|
-ipcMainUtils.handle('ELECTRON_BROWSER_CLIPBOARD_WRITE_FIND_TEXT', function (event, text) {
|
|
|
- return electron.clipboard.writeFindText(text)
|
|
|
+ return clipboardUtils.serialize(electron.clipboard[method](...clipboardUtils.deserialize(args)))
|
|
|
})
|
|
|
|
|
|
const readFile = util.promisify(fs.readFile)
|