Add insertText to WebContents
This commit is contained in:
parent
5567baf335
commit
5b7d1a9890
6 changed files with 44 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var EventEmitter, Menu, NavigationController, PDFPageSize, binding, deprecate, getNextId, ipcMain, nextId, ref, session, wrapWebContents,
|
var EventEmitter, Menu, NavigationController, PDFPageSize, binding, deprecate, getNextId, ipcMain, nextId, ref, session, wrapWebContents,
|
||||||
slice = [].slice;
|
slice = [].slice;
|
||||||
|
|
||||||
|
@ -53,6 +55,11 @@ PDFPageSize = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Following methods are mapped to webFrame.
|
||||||
|
const webFrameMethods = [
|
||||||
|
'insertText',
|
||||||
|
];
|
||||||
|
|
||||||
wrapWebContents = function(webContents) {
|
wrapWebContents = function(webContents) {
|
||||||
|
|
||||||
/* webContents is an EventEmitter. */
|
/* webContents is an EventEmitter. */
|
||||||
|
@ -95,6 +102,14 @@ wrapWebContents = function(webContents) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mapping webFrame methods.
|
||||||
|
for (let method of webFrameMethods) {
|
||||||
|
webContents[method] = function() {
|
||||||
|
let args = Array.prototype.slice.call(arguments);
|
||||||
|
this.send('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* Dispatch IPC messages to the ipc module. */
|
/* Dispatch IPC messages to the ipc module. */
|
||||||
webContents.on('ipc-message', function(event, packed) {
|
webContents.on('ipc-message', function(event, packed) {
|
||||||
var args, channel;
|
var args, channel;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'user strict';
|
||||||
|
|
||||||
var Module, arg, error, error1, events, globalPaths, i, len, nodeIntegration, path, pathname, preloadScript, ref, url, v8Util;
|
var Module, arg, error, error1, events, globalPaths, i, len, nodeIntegration, path, pathname, preloadScript, ref, url, v8Util;
|
||||||
|
|
||||||
events = require('events');
|
events = require('events');
|
||||||
|
@ -44,6 +46,13 @@ v8Util = process.atomBinding('v8_util');
|
||||||
|
|
||||||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter);
|
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter);
|
||||||
|
|
||||||
|
// Use electron module after everything is ready.
|
||||||
|
const electron = require('electron');
|
||||||
|
|
||||||
|
// Call webFrame method.
|
||||||
|
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, method, args) => {
|
||||||
|
electron.webFrame[method].apply(electron.webFrame, args);
|
||||||
|
});
|
||||||
|
|
||||||
/* Process command line arguments. */
|
/* Process command line arguments. */
|
||||||
|
|
||||||
|
|
|
@ -376,7 +376,13 @@ registerWebViewElement = function() {
|
||||||
|
|
||||||
/* Public-facing API methods. */
|
/* Public-facing API methods. */
|
||||||
methods = ['getURL', 'getTitle', 'isLoading', 'isWaitingForResponse', 'stop', 'reload', 'reloadIgnoringCache', 'canGoBack', 'canGoForward', 'canGoToOffset', 'clearHistory', 'goBack', 'goForward', 'goToIndex', 'goToOffset', 'isCrashed', 'setUserAgent', 'getUserAgent', 'openDevTools', 'closeDevTools', 'isDevToolsOpened', 'isDevToolsFocused', 'inspectElement', 'setAudioMuted', 'isAudioMuted', 'undo', 'redo', 'cut', 'copy', 'paste', 'pasteAndMatchStyle', 'delete', 'selectAll', 'unselect', 'replace', 'replaceMisspelling', 'findInPage', 'stopFindInPage', 'getId', 'downloadURL', 'inspectServiceWorker', 'print', 'printToPDF'];
|
methods = ['getURL', 'getTitle', 'isLoading', 'isWaitingForResponse', 'stop', 'reload', 'reloadIgnoringCache', 'canGoBack', 'canGoForward', 'canGoToOffset', 'clearHistory', 'goBack', 'goForward', 'goToIndex', 'goToOffset', 'isCrashed', 'setUserAgent', 'getUserAgent', 'openDevTools', 'closeDevTools', 'isDevToolsOpened', 'isDevToolsFocused', 'inspectElement', 'setAudioMuted', 'isAudioMuted', 'undo', 'redo', 'cut', 'copy', 'paste', 'pasteAndMatchStyle', 'delete', 'selectAll', 'unselect', 'replace', 'replaceMisspelling', 'findInPage', 'stopFindInPage', 'getId', 'downloadURL', 'inspectServiceWorker', 'print', 'printToPDF'];
|
||||||
nonblockMethods = ['send', 'sendInputEvent', 'executeJavaScript', 'insertCSS'];
|
nonblockMethods = [
|
||||||
|
'executeJavaScript',
|
||||||
|
'insertCSS',
|
||||||
|
'insertText',
|
||||||
|
'send',
|
||||||
|
'sendInputEvent',
|
||||||
|
];
|
||||||
|
|
||||||
/* Forward proto.foo* method calls to WebViewImpl.foo*. */
|
/* Forward proto.foo* method calls to WebViewImpl.foo*. */
|
||||||
createBlockHandler = function(m) {
|
createBlockHandler = function(m) {
|
||||||
|
|
|
@ -472,6 +472,12 @@ Executes the editing command `replace` in web page.
|
||||||
|
|
||||||
Executes the editing command `replaceMisspelling` in web page.
|
Executes the editing command `replaceMisspelling` in web page.
|
||||||
|
|
||||||
|
### `webContents.insertText(text)`
|
||||||
|
|
||||||
|
* `text` String
|
||||||
|
|
||||||
|
Inserts `text` to the focused element.
|
||||||
|
|
||||||
### `webContents.findInPage(text[, options])`
|
### `webContents.findInPage(text[, options])`
|
||||||
|
|
||||||
* `text` String - Content to be searched, must not be empty.
|
* `text` String - Content to be searched, must not be empty.
|
||||||
|
|
|
@ -94,6 +94,6 @@ allows registering ServiceWorker and supports fetch API.
|
||||||
|
|
||||||
* `text` String
|
* `text` String
|
||||||
|
|
||||||
* Inserts `text` to the focused element.
|
Inserts `text` to the focused element.
|
||||||
|
|
||||||
[spellchecker]: https://github.com/atom/node-spellchecker
|
[spellchecker]: https://github.com/atom/node-spellchecker
|
||||||
|
|
|
@ -352,6 +352,12 @@ Executes editing command `replace` in page.
|
||||||
|
|
||||||
Executes editing command `replaceMisspelling` in page.
|
Executes editing command `replaceMisspelling` in page.
|
||||||
|
|
||||||
|
### `<webview>.insertText(text)`
|
||||||
|
|
||||||
|
* `text` String
|
||||||
|
|
||||||
|
Inserts `text` to the focused element.
|
||||||
|
|
||||||
### `<webview>.findInPage(text[, options])`
|
### `<webview>.findInPage(text[, options])`
|
||||||
|
|
||||||
* `text` String - Content to be searched, must not be empty.
|
* `text` String - Content to be searched, must not be empty.
|
||||||
|
|
Loading…
Add table
Reference in a new issue