]> khamidou — GitHub mirrors - electron.git/commitdiff
Add insertText to WebContents
authorCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 03:55:49 +0000 (11:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 03:55:49 +0000 (11:55 +0800)
atom/browser/api/lib/web-contents.js
atom/renderer/lib/init.js
atom/renderer/lib/web-view/web-view.js
docs/api/web-contents.md
docs/api/web-frame.md
docs/api/web-view-tag.md

index 0d1b8b24bdd0a64ad4ecb26f9082a718d6d47387..d0abae7e65c46e786c23654128f4ae0ba2e67075 100644 (file)
@@ -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;
index 3d3026b595ef52db4b77c1e97b9da72cc6b0f911..344c7f2b1d26b1b2b8c5f598ed3d0709f0c50106 100644 (file)
@@ -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. */
 
index fcdfad1877ed6ceb59814b705585a6d47e5615ee..7f3c000dd7f086e1b91794494f83830e23a57e24 100644 (file)
@@ -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) {
index b399e143aaccb4395dd9bf501380aef9061de6ff..48658a29459565f4f1ab39195d92b11f2dda8271 100644 (file)
@@ -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.
index 6c4c9d8640781887ad68857643c2b493080f1d2f..e5dfa0b4eb95e6e05f091178afe9185a5744badf 100644 (file)
@@ -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
index 8b8f5ffd49adf8d59fb6aee629e4dba243051935..b3d94b85f7157d2faf425ada486ec4a858b42e63 100644 (file)
@@ -352,6 +352,12 @@ Executes editing command `replace` in page.
 
 Executes editing command `replaceMisspelling` in page.
 
+### `<webview>.insertText(text)`
+
+* `text` String
+
+Inserts `text` to the focused element.
+
 ### `<webview>.findInPage(text[, options])`
 
 * `text` String - Content to be searched, must not be empty.