mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 17:31:36 -06:00
Merge pull request #1921 from NguyenTranHoangSym/SDA-4234
SDA-4234: Support Tel Protocol on loading _blank
This commit is contained in:
commit
0754bca41f
@ -18,6 +18,7 @@ import { whitelistHandler } from '../common/whitelist-handler';
|
||||
import { CloudConfigDataTypes, config } from './config-handler';
|
||||
import crashHandler from './crash-handler';
|
||||
import { mainEvents } from './main-event-handler';
|
||||
import { verifyProtocolForNewUrl } from './protocol-handler';
|
||||
import {
|
||||
handlePermissionRequests,
|
||||
monitorWindowActions,
|
||||
@ -44,31 +45,6 @@ const MIN_HEIGHT = 300;
|
||||
|
||||
const CHILD_WINDOW_EVENTS = ['enter-full-screen', 'leave-full-screen'];
|
||||
|
||||
/**
|
||||
* Verifies protocol for a new url to check if it is http or https
|
||||
* @param url URL to be verified
|
||||
*/
|
||||
const verifyProtocolForNewUrl = (url: string): boolean => {
|
||||
const parsedUrl = parse(url);
|
||||
if (!parsedUrl || !parsedUrl.protocol) {
|
||||
logger.info(
|
||||
`child-window-handler: The url ${url} doesn't have a protocol. Returning false for verification!`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const allowedProtocols = ['http:', 'https:', 'mailto:', 'symphony:', 'sms:'];
|
||||
// url parse returns protocol with :
|
||||
if (allowedProtocols.includes(parsedUrl.protocol)) {
|
||||
logger.info(
|
||||
`child-window-handler: Protocol of the url ${url} is whitelisted! Returning true for verification!`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verifies if the url is valid and forcefully appends https if not present
|
||||
* This happens mainly for urls from the same domain
|
||||
@ -133,7 +109,7 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
const mainWinDomainName = `${mainWinUrlData.domain}${mainWinUrlData.tld}`;
|
||||
|
||||
logger.info(
|
||||
`child-window-handler: main window url: ${mainWinUrlData.subdomain}.${mainWinUrlData.domain}.${mainWinUrlData.tld}`,
|
||||
`child-window-handler: main window url: ${mainWinUrlData.subdomain}.${mainWinUrlData.domain}${mainWinUrlData.tld}`,
|
||||
);
|
||||
|
||||
const emptyUrlString = ['about:blank', 'about:blank#blocked'];
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { CookiesSetDetails, session, WebContents } from 'electron';
|
||||
import { parse } from 'url';
|
||||
import { apiName } from '../common/api-interface';
|
||||
import { isMac } from '../common/env';
|
||||
import { logger } from '../common/logger';
|
||||
@ -14,6 +15,38 @@ enum protocol {
|
||||
SmsProtocol = 'sms:',
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies protocol for a new url to check if it is http or https
|
||||
* @param url URL to be verified
|
||||
*/
|
||||
export const verifyProtocolForNewUrl = (url: string): boolean => {
|
||||
const parsedUrl = parse(url);
|
||||
if (!parsedUrl || !parsedUrl.protocol) {
|
||||
logger.info(
|
||||
`child-window-handler: The url ${url} doesn't have a protocol. Returning false for verification!`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const allowedProtocols = [
|
||||
'http:',
|
||||
'https:',
|
||||
'mailto:',
|
||||
'symphony:',
|
||||
'sms:',
|
||||
'tel:',
|
||||
];
|
||||
// url parse returns protocol with :
|
||||
if (allowedProtocols.includes(parsedUrl.protocol)) {
|
||||
logger.info(
|
||||
`child-window-handler: Protocol of the url ${url} is whitelisted! Returning true for verification!`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
class ProtocolHandler {
|
||||
private static isValidProtocolUri = (uri: string): boolean =>
|
||||
!!(uri && uri.startsWith(protocol.SymphonyProtocol));
|
||||
|
Loading…
Reference in New Issue
Block a user