diff options
author | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-08-14 14:52:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-14 20:22:24 +0530 |
commit | 8a37b92bc83db229a788008c5a6a68cf51216ed2 (patch) | |
tree | 1929798a3aa4089203668bd2b93dba497363eb5a /src/webview/contextMenuBuilder.js | |
parent | New Crowdin updates (#1786) (diff) | |
download | ferdium-app-8a37b92bc83db229a788008c5a6a68cf51216ed2.tar.gz ferdium-app-8a37b92bc83db229a788008c5a6a68cf51216ed2.tar.zst ferdium-app-8a37b92bc83db229a788008c5a6a68cf51216ed2.zip |
Refactoring: Url helpers (#1789)
These changes are mainly to ensure that 'shell.open*' invocations are only in a single file.
* Moved 'openPath' into the 'url-helpers' file.
* Extract 'openExternalUrl' into a common location in 'url-helpers'
This is done so that we can then apply vetting rules to ensure that there is no security concern as described in https://benjamin-altpeter.de/shell-openexternal-dangers/
Diffstat (limited to 'src/webview/contextMenuBuilder.js')
-rw-r--r-- | src/webview/contextMenuBuilder.js | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js index 602ce06f5..126fa4086 100644 --- a/src/webview/contextMenuBuilder.js +++ b/src/webview/contextMenuBuilder.js | |||
@@ -6,13 +6,12 @@ | |||
6 | * | 6 | * |
7 | * Source: https://github.com/electron-userland/electron-spellchecker/blob/master/src/context-menu-builder.js | 7 | * Source: https://github.com/electron-userland/electron-spellchecker/blob/master/src/context-menu-builder.js |
8 | */ | 8 | */ |
9 | import { | 9 | import { clipboard, ipcRenderer, nativeImage } from 'electron'; |
10 | clipboard, ipcRenderer, nativeImage, shell, | ||
11 | } from 'electron'; | ||
12 | import { Menu, MenuItem } from '@electron/remote'; | 10 | import { Menu, MenuItem } from '@electron/remote'; |
13 | import { shortcutKey, isMac } from '../environment'; | 11 | import { shortcutKey, isMac } from '../environment'; |
14 | 12 | ||
15 | import { SEARCH_ENGINE_NAMES, SEARCH_ENGINE_URLS } from '../config'; | 13 | import { SEARCH_ENGINE_NAMES, SEARCH_ENGINE_URLS } from '../config'; |
14 | import { openExternalUrl } from '../helpers/url-helpers'; | ||
16 | 15 | ||
17 | const { URL } = require('url'); | 16 | const { URL } = require('url'); |
18 | 17 | ||
@@ -170,7 +169,7 @@ module.exports = class ContextMenuBuilder { | |||
170 | const openLink = new MenuItem({ | 169 | const openLink = new MenuItem({ |
171 | label: this.stringTable.openLinkUrl(), | 170 | label: this.stringTable.openLinkUrl(), |
172 | click: () => { | 171 | click: () => { |
173 | shell.openExternal(menuInfo.linkURL); | 172 | openExternalUrl(menuInfo.linkURL, true); |
174 | }, | 173 | }, |
175 | }); | 174 | }); |
176 | 175 | ||
@@ -299,7 +298,7 @@ module.exports = class ContextMenuBuilder { | |||
299 | label: this.stringTable.searchWith({ searchEngine: SEARCH_ENGINE_NAMES[menuInfo.searchEngine] }), | 298 | label: this.stringTable.searchWith({ searchEngine: SEARCH_ENGINE_NAMES[menuInfo.searchEngine] }), |
300 | click: () => { | 299 | click: () => { |
301 | const url = SEARCH_ENGINE_URLS[menuInfo.searchEngine]({ searchTerm: encodeURIComponent(menuInfo.selectionText) }); | 300 | const url = SEARCH_ENGINE_URLS[menuInfo.searchEngine]({ searchTerm: encodeURIComponent(menuInfo.selectionText) }); |
302 | shell.openExternal(url); | 301 | openExternalUrl(url, true); |
303 | }, | 302 | }, |
304 | }); | 303 | }); |
305 | 304 | ||
@@ -555,7 +554,7 @@ module.exports = class ContextMenuBuilder { | |||
555 | label: this.stringTable.openInBrowser(), | 554 | label: this.stringTable.openInBrowser(), |
556 | enabled: true, | 555 | enabled: true, |
557 | click: () => { | 556 | click: () => { |
558 | shell.openExternal(menuInfo.pageURL); | 557 | openExternalUrl(menuInfo.pageURL, true); |
559 | }, | 558 | }, |
560 | })); | 559 | })); |
561 | 560 | ||