feat(desktop): add notification permission for renderer (#28119)
This commit is contained in:
@@ -9,6 +9,8 @@ const rendererRoot = join(root, "../renderer")
|
|||||||
const rendererProtocol = "oc"
|
const rendererProtocol = "oc"
|
||||||
const rendererHost = "renderer"
|
const rendererHost = "renderer"
|
||||||
const clipboardWritePermission = "clipboard-sanitized-write"
|
const clipboardWritePermission = "clipboard-sanitized-write"
|
||||||
|
const notificationPermission = "notifications"
|
||||||
|
const rendererPermissions = new Set([clipboardWritePermission, notificationPermission])
|
||||||
|
|
||||||
protocol.registerSchemesAsPrivileged([
|
protocol.registerSchemesAsPrivileged([
|
||||||
{
|
{
|
||||||
@@ -109,7 +111,7 @@ export function createMainWindow() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
allowClipboardWrite(win)
|
allowRendererPermissions(win)
|
||||||
|
|
||||||
win.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
|
win.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||||
const { requestHeaders } = details
|
const { requestHeaders } = details
|
||||||
@@ -162,7 +164,7 @@ export function createLoadingWindow() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
allowClipboardWrite(win)
|
allowRendererPermissions(win)
|
||||||
|
|
||||||
loadWindow(win, "loading.html")
|
loadWindow(win, "loading.html")
|
||||||
|
|
||||||
@@ -199,16 +201,16 @@ function loadWindow(win: BrowserWindow, html: string) {
|
|||||||
void win.loadURL(`${rendererProtocol}://${rendererHost}/${html}`)
|
void win.loadURL(`${rendererProtocol}://${rendererHost}/${html}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function allowClipboardWrite(win: BrowserWindow) {
|
function allowRendererPermissions(win: BrowserWindow) {
|
||||||
win.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
|
win.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
|
||||||
callback(
|
callback(
|
||||||
permission === clipboardWritePermission &&
|
rendererPermissions.has(permission) &&
|
||||||
isTrustedRendererUrl(details.requestingUrl) &&
|
isTrustedRendererUrl(details.requestingUrl) &&
|
||||||
webContents.id === win.webContents.id,
|
webContents.id === win.webContents.id,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
win.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
|
win.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
|
||||||
if (permission !== clipboardWritePermission) return false
|
if (!rendererPermissions.has(permission)) return false
|
||||||
if (webContents && webContents.id !== win.webContents.id) return false
|
if (webContents && webContents.id !== win.webContents.id) return false
|
||||||
return isTrustedRendererUrl(details.requestingUrl) || isTrustedRendererUrl(requestingOrigin)
|
return isTrustedRendererUrl(details.requestingUrl) || isTrustedRendererUrl(requestingOrigin)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user