From abd119db8febdd1979bf61e8c93792bae22d9c5e Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Mon, 7 Oct 2019 10:24:40 -0400 Subject: [PATCH 1/6] exposed findInPage for windows --- src/browser/api/webcontents.ts | 14 ++++++++++++++ src/browser/api/window.js | 5 +++++ .../api_protocol/api_handlers/webcontents.ts | 14 +++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/browser/api/webcontents.ts b/src/browser/api/webcontents.ts index b6e290449..ec0b39442 100644 --- a/src/browser/api/webcontents.ts +++ b/src/browser/api/webcontents.ts @@ -7,6 +7,12 @@ import { InjectableContext, EntityType } from '../../shapes'; import { prepareConsoleMessageForRVM } from '../rvm/utils'; export function hookWebContentsEvents(webContents: Electron.WebContents, { uuid, name }: Identity, topic: string, routeFunc: WindowRoute) { + webContents.on('found-in-page', (e, result) => { + const type = 'found-in-page'; + const payload = { uuid, name, topic, type, result }; + ofEvents.emit(routeFunc(type, uuid, name), payload); + }); + webContents.on('did-get-response-details', (e, status, newUrl, @@ -205,3 +211,11 @@ export function setIframeHandlers (webContents: Electron.WebContents, contextObj ofEvents.emit(route.window('frame-disconnected', uuid, name), payload); }; } + +export function findInPage(webContents: Electron.WebContents, searchTerm: string, options: any) { + return webContents.findInPage(searchTerm, options); +} + +export function stopFindInPage(webContents: Electron.WebContents, action: 'clearSelection' | 'keepSelection' | 'activateSelection') { + webContents.stopFindInPage(action); +} diff --git a/src/browser/api/window.js b/src/browser/api/window.js index a238ffa97..1eca4edca 100644 --- a/src/browser/api/window.js +++ b/src/browser/api/window.js @@ -1110,6 +1110,11 @@ Window.executeJavascript = function(identity, code, callback = () => {}) { WebContents.executeJavascript(browserWindow.webContents, code, callback); }; +Window.findInPage = function(identity, searchTerm, options) { + let browserWindow = getElectronBrowserWindow(identity); + WebContents.findInPage(browserWindow.webContents, searchTerm, options); +}; + Window.flash = function(identity) { const browserWindow = getElectronBrowserWindow(identity); if (!browserWindow) { diff --git a/src/browser/api_protocol/api_handlers/webcontents.ts b/src/browser/api_protocol/api_handlers/webcontents.ts index cadb25057..22bac30d0 100644 --- a/src/browser/api_protocol/api_handlers/webcontents.ts +++ b/src/browser/api_protocol/api_handlers/webcontents.ts @@ -10,6 +10,7 @@ const successAck: APIPayloadAck = { success: true }; export const webContentsApiMap = { 'execute-javascript-in-window': { apiFunc: executeJavascript, apiPath: '.executeJavaScript' }, + 'find-in-page': findInPage, 'get-zoom-level': getZoomLevel, 'navigate-window': navigateWindow, 'navigate-window-back': navigateWindowBack, @@ -49,6 +50,17 @@ function executeJavascript(identity: Identity, message: APIMessage, ack: Acker, return nack(new Error('Rejected, target window is not owned by requesting identity')); } + +function findInPage(identity: Identity, message: APIMessage, ack: Acker): void { + const { payload } = message; + const { searchTerm, options } = payload; + const windowIdentity = getTargetWindowIdentity(payload); + const webContents = getElectronWebContents(windowIdentity); + + WebContents.findInPage(webContents, searchTerm, options); + ack(successAck); +} + function navigateWindow(identity: Identity, message: APIMessage, ack: Acker, nack: (error: Error) => void): void { const { payload } = message; const { url } = payload; @@ -137,4 +149,4 @@ export function getElectronWebContents({uuid, name}: Identity, errDesc?: string) } return webContents; -} \ No newline at end of file +} From 1b9405e09008b0b4a5373bd19d8532ceb48ba7b5 Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Mon, 7 Oct 2019 10:43:42 -0400 Subject: [PATCH 2/6] exposed stopFindInPage for windows --- src/browser/api/window.js | 5 +++++ src/browser/api_protocol/api_handlers/webcontents.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/browser/api/window.js b/src/browser/api/window.js index 1eca4edca..1c5f6ecd1 100644 --- a/src/browser/api/window.js +++ b/src/browser/api/window.js @@ -1131,6 +1131,11 @@ Window.stopFlashing = function(identity) { NativeWindow.stopFlashing(browserWindow); }; +Window.stopFindInPage = function(identity, action) { + let browserWindow = getElectronBrowserWindow(identity); + WebContents.findInPage(browserWindow.webContents, action); +}; + Window.focus = function(identity) { const browserWindow = getElectronBrowserWindow(identity); if (!browserWindow) { diff --git a/src/browser/api_protocol/api_handlers/webcontents.ts b/src/browser/api_protocol/api_handlers/webcontents.ts index 22bac30d0..50b43a8bb 100644 --- a/src/browser/api_protocol/api_handlers/webcontents.ts +++ b/src/browser/api_protocol/api_handlers/webcontents.ts @@ -16,6 +16,7 @@ export const webContentsApiMap = { 'navigate-window-back': navigateWindowBack, 'navigate-window-forward': navigateWindowForward, 'stop-window-navigation': stopWindowNavigation, + 'stop-find-in-page': stopFindInPage, 'reload-window': reloadWindow, 'set-zoom-level': setZoomLevel, 'set-window-preload-state': setWindowPreloadState @@ -61,6 +62,16 @@ function findInPage(identity: Identity, message: APIMessage, ack: Acker): void { ack(successAck); } +function stopFindInPage(identity: Identity, message: APIMessage, ack: Acker): void { + const { payload } = message; + const { action } = payload; + const windowIdentity = getTargetWindowIdentity(payload); + const webContents = getElectronWebContents(windowIdentity); + + WebContents.stopFindInPage(webContents, action); + ack(successAck); +} + function navigateWindow(identity: Identity, message: APIMessage, ack: Acker, nack: (error: Error) => void): void { const { payload } = message; const { url } = payload; From a15ac8a8f92177ae34bb0102899b597037920335 Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Tue, 8 Oct 2019 13:26:33 -0400 Subject: [PATCH 3/6] removed findInPage funcs --- src/browser/api/window.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/browser/api/window.js b/src/browser/api/window.js index 1c5f6ecd1..a238ffa97 100644 --- a/src/browser/api/window.js +++ b/src/browser/api/window.js @@ -1110,11 +1110,6 @@ Window.executeJavascript = function(identity, code, callback = () => {}) { WebContents.executeJavascript(browserWindow.webContents, code, callback); }; -Window.findInPage = function(identity, searchTerm, options) { - let browserWindow = getElectronBrowserWindow(identity); - WebContents.findInPage(browserWindow.webContents, searchTerm, options); -}; - Window.flash = function(identity) { const browserWindow = getElectronBrowserWindow(identity); if (!browserWindow) { @@ -1131,11 +1126,6 @@ Window.stopFlashing = function(identity) { NativeWindow.stopFlashing(browserWindow); }; -Window.stopFindInPage = function(identity, action) { - let browserWindow = getElectronBrowserWindow(identity); - WebContents.findInPage(browserWindow.webContents, action); -}; - Window.focus = function(identity) { const browserWindow = getElectronBrowserWindow(identity); if (!browserWindow) { From 5c818c809a3722df3dc56efaad501d6fcecf8469 Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Tue, 8 Oct 2019 15:51:44 -0400 Subject: [PATCH 4/6] fixed typing --- src/browser/api/webcontents.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/api/webcontents.ts b/src/browser/api/webcontents.ts index ec0b39442..0021266cf 100644 --- a/src/browser/api/webcontents.ts +++ b/src/browser/api/webcontents.ts @@ -212,7 +212,7 @@ export function setIframeHandlers (webContents: Electron.WebContents, contextObj }; } -export function findInPage(webContents: Electron.WebContents, searchTerm: string, options: any) { +export function findInPage(webContents: Electron.WebContents, searchTerm: string, options?: Electron.FindInPageOptions) { return webContents.findInPage(searchTerm, options); } From c41ef029663aef685c809f72b7518fd5e13d6707 Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Tue, 8 Oct 2019 15:52:06 -0400 Subject: [PATCH 5/6] find in page returns id number --- src/browser/api_protocol/api_handlers/webcontents.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/browser/api_protocol/api_handlers/webcontents.ts b/src/browser/api_protocol/api_handlers/webcontents.ts index 50b43a8bb..0adb300dd 100644 --- a/src/browser/api_protocol/api_handlers/webcontents.ts +++ b/src/browser/api_protocol/api_handlers/webcontents.ts @@ -55,11 +55,12 @@ function executeJavascript(identity: Identity, message: APIMessage, ack: Acker, function findInPage(identity: Identity, message: APIMessage, ack: Acker): void { const { payload } = message; const { searchTerm, options } = payload; + const dataAck = Object.assign({}, successAck); const windowIdentity = getTargetWindowIdentity(payload); const webContents = getElectronWebContents(windowIdentity); - WebContents.findInPage(webContents, searchTerm, options); - ack(successAck); + dataAck.data = WebContents.findInPage(webContents, searchTerm, options); + ack(dataAck); } function stopFindInPage(identity: Identity, message: APIMessage, ack: Acker): void { From 780d8606caae76e2cceca9309e1317023af2982a Mon Sep 17 00:00:00 2001 From: Luis Espinola Date: Wed, 16 Oct 2019 14:27:15 -0400 Subject: [PATCH 6/6] findInPage returns request results --- js-adapter | 2 +- src/browser/api/webcontents.ts | 9 ++++++++- src/browser/api_protocol/api_handlers/webcontents.ts | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/js-adapter b/js-adapter index 354bbb098..01acf07b8 160000 --- a/js-adapter +++ b/js-adapter @@ -1 +1 @@ -Subproject commit 354bbb098fa48d9851e694a68a780b1103afda00 +Subproject commit 01acf07b8034493122b347d6d7ac4c15abe49313 diff --git a/src/browser/api/webcontents.ts b/src/browser/api/webcontents.ts index 0021266cf..4be612c60 100644 --- a/src/browser/api/webcontents.ts +++ b/src/browser/api/webcontents.ts @@ -213,7 +213,14 @@ export function setIframeHandlers (webContents: Electron.WebContents, contextObj } export function findInPage(webContents: Electron.WebContents, searchTerm: string, options?: Electron.FindInPageOptions) { - return webContents.findInPage(searchTerm, options); + return new Promise((resolve) => { + const getResults = (event: Electron.Event, result: any) => { + resolve(result); + }; + + webContents.once('found-in-page', getResults); + webContents.findInPage(searchTerm, options); + }); } export function stopFindInPage(webContents: Electron.WebContents, action: 'clearSelection' | 'keepSelection' | 'activateSelection') { diff --git a/src/browser/api_protocol/api_handlers/webcontents.ts b/src/browser/api_protocol/api_handlers/webcontents.ts index 0adb300dd..0a8a70884 100644 --- a/src/browser/api_protocol/api_handlers/webcontents.ts +++ b/src/browser/api_protocol/api_handlers/webcontents.ts @@ -59,8 +59,10 @@ function findInPage(identity: Identity, message: APIMessage, ack: Acker): void { const windowIdentity = getTargetWindowIdentity(payload); const webContents = getElectronWebContents(windowIdentity); - dataAck.data = WebContents.findInPage(webContents, searchTerm, options); - ack(dataAck); + WebContents.findInPage(webContents, searchTerm, options).then((data) => { + dataAck.data = data; + ack(dataAck); + }); } function stopFindInPage(identity: Identity, message: APIMessage, ack: Acker): void {