From: Cheng Zhao Date: Wed, 13 Jan 2016 03:55:49 +0000 (+0800) Subject: Add insertText to WebContents X-Git-Tag: v0.36.4~12^2~6 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=5b7d1a9890d386f32713eda8646a896905c4790d;p=electron.git Add insertText to WebContents --- diff --git a/atom/browser/api/lib/web-contents.js b/atom/browser/api/lib/web-contents.js index 0d1b8b24..d0abae7e 100644 --- a/atom/browser/api/lib/web-contents.js +++ b/atom/browser/api/lib/web-contents.js @@ -1,3 +1,5 @@ +'use strict'; + var EventEmitter, Menu, NavigationController, PDFPageSize, binding, deprecate, getNextId, ipcMain, nextId, ref, session, wrapWebContents, slice = [].slice; @@ -53,6 +55,11 @@ PDFPageSize = { } }; +// Following methods are mapped to webFrame. +const webFrameMethods = [ + 'insertText', +]; + wrapWebContents = function(webContents) { /* 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. */ webContents.on('ipc-message', function(event, packed) { var args, channel; diff --git a/atom/renderer/lib/init.js b/atom/renderer/lib/init.js index 3d3026b5..344c7f2b 100644 --- a/atom/renderer/lib/init.js +++ b/atom/renderer/lib/init.js @@ -1,3 +1,5 @@ +'user strict'; + var Module, arg, error, error1, events, globalPaths, i, len, nodeIntegration, path, pathname, preloadScript, ref, url, v8Util; events = require('events'); @@ -44,6 +46,13 @@ v8Util = process.atomBinding('v8_util'); 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. */ diff --git a/atom/renderer/lib/web-view/web-view.js b/atom/renderer/lib/web-view/web-view.js index fcdfad18..7f3c000d 100644 --- a/atom/renderer/lib/web-view/web-view.js +++ b/atom/renderer/lib/web-view/web-view.js @@ -376,7 +376,13 @@ registerWebViewElement = function() { /* 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']; - nonblockMethods = ['send', 'sendInputEvent', 'executeJavaScript', 'insertCSS']; + nonblockMethods = [ + 'executeJavaScript', + 'insertCSS', + 'insertText', + 'send', + 'sendInputEvent', + ]; /* Forward proto.foo* method calls to WebViewImpl.foo*. */ createBlockHandler = function(m) { diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index b399e143..48658a29 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -472,6 +472,12 @@ Executes the editing command `replace` 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])` * `text` String - Content to be searched, must not be empty. diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 6c4c9d86..e5dfa0b4 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -94,6 +94,6 @@ allows registering ServiceWorker and supports fetch API. * `text` String -* Inserts `text` to the focused element. +Inserts `text` to the focused element. [spellchecker]: https://github.com/atom/node-spellchecker diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 8b8f5ffd..b3d94b85 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -352,6 +352,12 @@ Executes editing command `replace` in page. Executes editing command `replaceMisspelling` in page. +### `.insertText(text)` + +* `text` String + +Inserts `text` to the focused element. + ### `.findInPage(text[, options])` * `text` String - Content to be searched, must not be empty.