Skip to content

Commit 3e0f420

Browse files
authored
Switch from OPEN_EXTERNAL_LINK IPC call to window.open() (#7380)
1 parent 5764fd2 commit 3e0f420

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+50
-144
lines changed

src/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const IpcChannels = {
33
ENABLE_PROXY: 'enable-proxy',
44
DISABLE_PROXY: 'disable-proxy',
5-
OPEN_EXTERNAL_LINK: 'open-external-link',
65
GET_SYSTEM_LOCALE: 'get-system-locale',
76
GET_NAVIGATION_HISTORY: 'get-navigation-history',
87
STOP_POWER_SAVE_BLOCKER: 'stop-power-save-blocker',

src/main/index.js

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,21 @@ function runApp() {
664664
}
665665

666666
/**
667-
* @param {string} urlString
667+
* @param {string | URL} url
668668
*/
669-
function isFreeTubeUrl(urlString) {
670-
const { protocol, host, pathname } = new URL(urlString)
669+
function isFreeTubeUrl(url) {
670+
let url_
671+
672+
if (url instanceof URL) {
673+
url_ = url
674+
} else {
675+
url_ = URL.parse(url)
676+
}
671677

672678
if (process.env.NODE_ENV === 'development') {
673-
return protocol === 'http:' && host === 'localhost:9080' && (pathname === '/' || pathname === '/index.html')
679+
return url_ !== null && url_.protocol === 'http:' && url_.host === 'localhost:9080' && (url_.pathname === '/' || url_.pathname === '/index.html')
674680
} else {
675-
return protocol === 'app:' && host === 'bundle' && pathname === '/index.html'
681+
return url_ !== null && url_.protocol === 'app:' && url_.host === 'bundle' && url_.pathname === '/index.html'
676682
}
677683
}
678684

@@ -778,14 +784,33 @@ function runApp() {
778784

779785
// https://github.com/electron/electron/blob/14-x-y/docs/api/window-open.md#native-window-example
780786
newWindow.webContents.setWindowOpenHandler((details) => {
781-
createWindow({
782-
replaceMainWindow: false,
783-
showWindowNow: true,
784-
windowStartupUrl: details.url
785-
})
786-
return {
787-
action: 'deny'
787+
const url = URL.parse(details.url)
788+
789+
// Only handle valid URLs that came from a FreeTube page
790+
if (url !== null && isFreeTubeUrl(details.referrer.url)) {
791+
if (isFreeTubeUrl(url)) {
792+
createWindow({
793+
replaceMainWindow: false,
794+
showWindowNow: true,
795+
windowStartupUrl: details.url
796+
})
797+
} else if (
798+
url.protocol === 'http:' || url.protocol === 'https:' ||
799+
800+
// Email address on the about page and Autolinker detects and links email addresses
801+
url.protocol === 'mailto:' ||
802+
803+
// Autolinker detects and links phone numbers
804+
url.protocol === 'tel:' ||
805+
806+
// Donation links on the about page
807+
(url.protocol === 'bitcoin:' && url.pathname === ABOUT_BITCOIN_ADDRESS)
808+
) {
809+
shell.openExternal(details.url)
810+
}
788811
}
812+
813+
return { action: 'deny' }
789814
})
790815

791816
// endregion Ensure child windows use same options since electron 14
@@ -995,37 +1020,6 @@ function runApp() {
9951020

9961021
// #endregion navigation history
9971022

998-
ipcMain.handle(IpcChannels.OPEN_EXTERNAL_LINK, (_, url) => {
999-
if (typeof url === 'string') {
1000-
let parsedURL
1001-
1002-
try {
1003-
parsedURL = new URL(url)
1004-
} catch {
1005-
// If it's not a valid URL don't open it
1006-
return false
1007-
}
1008-
1009-
if (
1010-
parsedURL.protocol === 'http:' || parsedURL.protocol === 'https:' ||
1011-
1012-
// Email address on the about page and Autolinker detects and links email addresses
1013-
parsedURL.protocol === 'mailto:' ||
1014-
1015-
// Autolinker detects and links phone numbers
1016-
parsedURL.protocol === 'tel:' ||
1017-
1018-
// Donation links on the about page
1019-
(parsedURL.protocol === 'bitcoin:' && parsedURL.pathname === ABOUT_BITCOIN_ADDRESS)
1020-
) {
1021-
shell.openExternal(url)
1022-
return true
1023-
}
1024-
}
1025-
1026-
return false
1027-
})
1028-
10291023
ipcMain.handle(IpcChannels.GET_SYSTEM_LOCALE, () => {
10301024
// we should switch to getPreferredSystemLanguages at some point and iterate through until we find a supported locale
10311025
return app.getSystemLocale()
@@ -1184,11 +1178,6 @@ function runApp() {
11841178
return
11851179
}
11861180

1187-
if (path == null && query == null && searchQueryText == null) {
1188-
createWindow({ replaceMainWindow: false, showWindowNow: true })
1189-
return
1190-
}
1191-
11921181
if (
11931182
typeof path !== 'string' ||
11941183
(query != null && typeof query !== 'object') ||

src/renderer/components/TopNav/TopNav.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ const newWindowText = computed(() => {
244244
})
245245
246246
function createNewWindow() {
247-
if (process.env.IS_ELECTRON) {
248-
const { ipcRenderer } = require('electron')
249-
ipcRenderer.send(IpcChannels.CREATE_NEW_WINDOW)
250-
} else {
251-
const url = new URL(window.location.href)
252-
url.hash = landingPage.value
247+
const url = new URL(window.location.href)
248+
url.hash = landingPage.value
253249
250+
if (process.env.IS_ELECTRON) {
251+
// Don't pass noreferrer in Electron as we use the referrer to check if the call came from a FreeTube app URL.
254252
window.open(url.toString(), '_blank')
253+
} else {
254+
window.open(url.toString(), '_blank', 'noreferrer')
255255
}
256256
}
257257

src/renderer/helpers/utils.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,10 @@ export async function copyToClipboard(content, { messageOnSuccess = null, messag
213213
*/
214214
export async function openExternalLink(url) {
215215
if (process.env.IS_ELECTRON) {
216-
const ipcRenderer = require('electron').ipcRenderer
217-
const success = await ipcRenderer.invoke(IpcChannels.OPEN_EXTERNAL_LINK, url)
218-
219-
if (!success) {
220-
showToast(i18n.t('Blocked opening potentially unsafe URL', { url }))
221-
}
222-
} else {
216+
// Don't pass noreferrer in Electron as we use the referrer to check if the call came from a FreeTube app URL.
223217
window.open(url, '_blank')
218+
} else {
219+
window.open(url, '_blank', 'noreferrer')
224220
}
225221
}
226222

static/locales/af.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,6 @@ Age Restricted:
11641164
This video is age restricted: 'Hierdie video het ’n ouderdomsperk'
11651165
External link opening has been disabled in the general settings: 'Die open van eksterne
11661166
skakels is gedeaktiveer in die algemene instellings'
1167-
'Blocked opening potentially unsafe URL': 'Open van potensiële onveilige URL is versper:
1168-
“{url}”.'
11691167
Downloading has completed: '“{videoTitle}” is afgelaai'
11701168
Starting download: 'Begin aflaai van “{videoTitle}”'
11711169
Downloading failed: 'Daar was ’n probleem by die aflaai van “{videoTitle}”'

static/locales/ar.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,6 @@ Search Listing:
12091209
360 Video: 360°
12101210
New: جديد
12111211
3D: ثلاثي الابعاد
1212-
'Blocked opening potentially unsafe URL': 'تم حظر فتح الرابط الذي يحتمل أن يكون غير
1213-
آمن: "{url}".'
12141212
Right-click or hold to see history: انقر زر الفارة الأيمن أو اضغط مطولا لعرض السجل
12151213
KeyboardShortcutPrompt:
12161214
Force Restart Window: إجبار إعادة تشغيل النافذة

static/locales/awa.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ Age Restricted:
10251025
This channel is age restricted: ''
10261026
This video is age restricted: ''
10271027
External link opening has been disabled in the general settings: ''
1028-
'Blocked opening potentially unsafe URL': ''
10291028
Downloading has completed: ''
10301029
Starting download: ''
10311030
Downloading failed: ''

static/locales/be.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,6 @@ Channel Hidden: '{channel} дададзены ў фільтр каналаў'
12411241
Age Restricted:
12421242
This channel is age restricted: Гэты канал мае ўзроставыя абмежаванні
12431243
This video is age restricted: Гэты відэа мае ўзроставыя абмежаванні
1244-
'Blocked opening potentially unsafe URL': 'Заблакіравана адкрыццё патэнцыйна небяспечнага
1245-
URL: "{url}".'
12461244
Channel Unhidden: '{channel} выдалены з фільтра каналаў'
12471245
KeyboardShortcutPrompt:
12481246
Show Keyboard Shortcuts: Паказаць спалучэнні клавіш

static/locales/bg.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,6 @@ Search Listing:
12461246
8K: 8K
12471247
360 Video: 360°
12481248
New: Нов
1249-
'Blocked opening potentially unsafe URL': 'Блокирано отваряне на потенциално опасен
1250-
URL адрес: "{url}".'
12511249
Description:
12521250
Collapse Description: По-малко
12531251
Expand Description: '...още'

static/locales/br.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,6 @@ Age Restricted:
11671167
This video is age restricted: 'Ur vevenn oad a zo d''ar video-mañ'
11681168
External link opening has been disabled in the general settings: 'Diweredekaet eo
11691169
al liammoù diavaez en arventennoù hollek'
1170-
'Blocked opening potentially unsafe URL': 'Stanket eo an URL a c''hell bezañ arvarus :
1171-
"{url}".'
11721170
Downloading has completed: '"{videoTitle}" a zo bet pellgarget'
11731171
Starting download: 'Kregiñ da bellgargañ "{videoTitle}"'
11741172
Downloading failed: 'C''hoarvezet ez eus ur gudenn en ur bellgargañ "{videoTitle}"'

static/locales/cs.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,6 @@ Search Listing:
12341234
8K: 8K
12351235
VR180: VR180
12361236
3D: 3D
1237-
'Blocked opening potentially unsafe URL': 'Zablokováno otevření potenciálně nebezpečné
1238-
adresy URL: „{url}“.'
12391237
KeyboardShortcutTemplate: '{label} ({shortcut})'
12401238
shortcutJoinOperator: +
12411239
Keys:

static/locales/cy.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,6 @@ Age Restricted:
12581258
Moments Ago: eiliad yn ôl
12591259
checkmark:
12601260
Display Label: '{label}: {value}'
1261-
'Blocked opening potentially unsafe URL': 'Wedi rhwystro URL a allai fod yn anniogel
1262-
wrth agor : "{url}".'
12631261
Trimmed input must be at least N characters long: Rhaid i fewnbwn wedi'i docio fod
12641262
o leiaf 1 nod o hyd | Rhaid i fewnbwn wedi'i docio fod o leiaf {length} nod
12651263
Tag already exists: Mae'r tag "{tagName}" eisoes yn bodoli

static/locales/da.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,4 @@ Cancel: annullere
13031303
Autoplay Interruption Timer: Autoplay afbrudt på grund af {autoplayInterruptionIntervalHours}
13041304
timers inaktivitet
13051305
shortcutLabelSeparator:
1306-
'Blocked opening potentially unsafe URL': 'Blokeret åbning af potentielt usikker URL:
1307-
»{url}«.'
13081306
checkmark:

static/locales/de-DE.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,6 @@ Search Listing:
12731273
360 Video: 360°
12741274
New: Neu
12751275
3D: 3D
1276-
'Blocked opening potentially unsafe URL': 'Das Öffnen einer potenziell unsicheren
1277-
URL wurde blockiert: „{url}“.'
12781276
Keys:
12791277
arrowdown: Pfeil nach unten
12801278
arrowleft: Pfeil nach links

static/locales/el.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,6 @@ Yes, Open Link: Ναι, Άνοιγμα συνδέσμου
13421342
Description:
13431343
Expand Description: '...περισσότερα'
13441344
Collapse Description: Εμφάνιση λιγότερων
1345-
'Blocked opening potentially unsafe URL': 'Αποκλεισμός ανοίγματος δυνητικά μη ασφαλούς
1346-
URL: «{url}».'
13471345
shortcutJoinOperator: +
13481346
KeyboardShortcutTemplate: '{label} ({shortcut})'
13491347
Age Restricted:

static/locales/en-GB.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,6 @@ Trimmed input must be at least N characters long: Trimmed input must be at least
12151215
Yes, Delete: Yes, delete
12161216
Yes, Restart: Yes, restart
12171217
Yes, Open Link: Yes, open link
1218-
'Blocked opening potentially unsafe URL': 'Blocked opening potentially unsafe URL:
1219-
‘{url}’.'
12201218
Search Listing:
12211219
Label:
12221220
4K: 4K

static/locales/en-US.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ Age Restricted:
11261126
This channel is age restricted: This channel is age restricted
11271127
This video is age restricted: This video is age restricted
11281128
External link opening has been disabled in the general settings: 'External link opening has been disabled in the general settings'
1129-
'Blocked opening potentially unsafe URL': 'Blocked opening potentially unsafe URL: "{url}".'
11301129
Downloading has completed: '"{videoTitle}" has finished downloading'
11311130
Starting download: 'Starting download of "{videoTitle}"'
11321131
Downloading failed: 'There was an issue downloading "{videoTitle}"'

static/locales/es.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,6 @@ Search Listing:
12601260
8K: 8K
12611261
VR180: VR180
12621262
3D: 3D
1263-
'Blocked opening potentially unsafe URL': 'Bloqueada la apertura de la URL potencialmente
1264-
insegura: «{url}».'
12651263
KeyboardShortcutTemplate: '{label} ({shortcut})'
12661264
Right-click or hold to see history: Clic con el botón derecho del ratón o mantén presionado
12671265
para ver el historial

static/locales/et.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,6 @@ Search Listing:
12311231
8K: 8K
12321232
VR180: VR180
12331233
360 Video: 360°
1234-
'Blocked opening potentially unsafe URL': 'Blokeerisime võimaliku ohtliku aadressi
1235-
avamise: „{url}“.'
12361234
shortcutJoinOperator: +
12371235
KeyboardShortcutTemplate: '{label} ({shortcut})'
12381236
Keys:

static/locales/eu.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,6 @@ Search Listing:
12611261
360 Video: 360º
12621262
New: Berria
12631263
3D: 3D
1264-
'Blocked opening potentially unsafe URL': 'Insegurua izan daitekeen URLa irekitzea
1265-
blokeatu da: "{url}".'
12661264
Keys:
12671265
arrowleft: Gezia ezkerrera
12681266
arrowright: Gezia eskuinera

static/locales/fa.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,6 @@ Trimmed input must be at least N characters long: ورودی بریده شده
12121212
Tag already exists: برچسب "{tagName}" از قبل وجود دارد
12131213
checkmark:
12141214
Channel Unhidden: '{channel} از فیلتر کانال حذف شد'
1215-
'Blocked opening potentially unsafe URL': 'باز کردن آدرس بالقوه ناامن مسدود شد: "{url}".'
12161215
Channel Hidden: '{channel} به فیلتر کانال اضافه شد'
12171216
Yes, Open Link: بله بازکردن پیوند
12181217
KeyboardShortcutTemplate: '{label} ({shortcut})'

static/locales/fil.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ Search Bar:
9999
Clear Input: Alisin ang Input
100100
External link opening has been disabled in the general settings: Ang pag bukas ng
101101
link sa panlabas ay pinasara sa general settings
102-
'Blocked opening potentially unsafe URL': 'I-Blinock ang URL na possibleng hindi ligtas:
103-
"{url]".'
104102
Age Restricted:
105103
This channel is age restricted: Itong channel ay pinaghihigpitan sa edad
106104
This video is age restricted: Ang video na ito ay pinaghihigpitan sa edad

static/locales/fr-FR.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,6 @@ Search Listing:
12861286
360 Video: 360°
12871287
New: Nouveau
12881288
3D: 3D
1289-
'Blocked opening potentially unsafe URL': "Blocage de l'ouverture d'une URL potentiellement
1290-
dangereuse : « {url} »."
12911289
shortcutJoinOperator: +
12921290
Keys:
12931291
ctrl: Ctrl

static/locales/he.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,6 @@ Yes, Restart: כן, להפעיל מחדש
11251125
Yes, Delete: כן, למחוק
11261126
Yes, Open Link: כן, לפתוח את הקישור
11271127
Cancel: ביטול
1128-
'Blocked opening potentially unsafe URL': 'נחסמה פתיחת כתובת שחשודה כמפוקפקת: „{url}”.'
11291128
checkmark:
11301129
Tag already exists: התגית „{tagName}” כבר קיימת
11311130
Moments Ago: לפני מס׳ רגעים

static/locales/hr.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,6 @@ Search Listing:
12161216
360 Video: 360°
12171217
New: Novi
12181218
3D: 3D
1219-
'Blocked opening potentially unsafe URL': 'Blokirano je otvaranje potencijalno nesigurnog
1220-
URL-a: „{url}”.'
12211219
Right-click or hold to see history: Pritisni desnu tipku miša ili zadrži za prikaz
12221220
povijest
12231221
Description:

static/locales/hu.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,6 @@ Search Listing:
12611261
360 Video: 360°
12621262
New: Új
12631263
3D: 3D
1264-
'Blocked opening potentially unsafe URL': 'Potenciálisan nem biztonságos webcím megnyitása
1265-
letiltva: „{url}”.'
12661264
Keys:
12671265
arrowup: Felfele nyíl
12681266
alt: Alt

static/locales/id.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,6 @@ Age Restricted:
12961296
Trimmed input must be at least N characters long: Input yang dipangkas harus memiliki
12971297
panjang minimal 1 karakter | Input yang dipangkas harus memiliki panjang minimal
12981298
{length} karakter
1299-
'Blocked opening potentially unsafe URL': 'Pembukaan URL yang berpotensi tidak aman
1300-
diblokir: "{url}".'
13011299
KeyboardShortcutTemplate: '{label} ({pintasan})'
13021300
shortcutJoinOperator: +
13031301
Chapters:

static/locales/is.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,6 @@ Search character limit: Leitarstrengurinn er kominn yfir hámarksfjöldann {sear
12361236
Yes, Restart: Já, endurræsa
12371237
Yes, Open Link: Já, opna tengil
12381238
Cancel: Hætta við
1239-
'Blocked opening potentially unsafe URL': 'Lokaði á opnun mögulega óöruggrar slóðar:
1240-
"{url}".'
12411239
Yes, Delete: Já, eyða
12421240
checkmark:
12431241
Trimmed input must be at least N characters long: Stytt úttak verður að minnsta kosti

static/locales/it.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,6 @@ Search Listing:
12601260
360 Video: 360°
12611261
New: Nuovo
12621262
3D: 3D
1263-
'Blocked opening potentially unsafe URL': 'Apertura di URL potenzialmente non sicura
1264-
bloccata: "{url}".'
12651263
shortcutJoinOperator: +
12661264
Keys:
12671265
ctrl: Ctrl

0 commit comments

Comments
 (0)