fix: undefined details.requestingUrl from session.setPermissionCheckHandler (#35281)
fix: undefined details.requestingUrl from setPermissionCheckHandler
This commit is contained in:
parent
221bb51326
commit
33325e3608
2 changed files with 95 additions and 4 deletions
|
@ -339,9 +339,16 @@ blink::mojom::PermissionStatus
|
||||||
ElectronPermissionManager::GetPermissionStatusForCurrentDocument(
|
ElectronPermissionManager::GetPermissionStatusForCurrentDocument(
|
||||||
blink::PermissionType permission,
|
blink::PermissionType permission,
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
return GetPermissionStatus(
|
base::Value::Dict details;
|
||||||
permission, render_frame_host->GetLastCommittedOrigin().GetURL(),
|
details.Set("embeddingOrigin",
|
||||||
content::PermissionUtil::GetLastCommittedOriginAsURL(render_frame_host));
|
content::PermissionUtil::GetLastCommittedOriginAsURL(
|
||||||
|
render_frame_host->GetMainFrame())
|
||||||
|
.spec());
|
||||||
|
bool granted = CheckPermissionWithDetails(
|
||||||
|
permission, render_frame_host,
|
||||||
|
render_frame_host->GetLastCommittedOrigin().GetURL(), std::move(details));
|
||||||
|
return granted ? blink::mojom::PermissionStatus::GRANTED
|
||||||
|
: blink::mojom::PermissionStatus::DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
blink::mojom::PermissionStatus
|
blink::mojom::PermissionStatus
|
||||||
|
|
|
@ -4,7 +4,7 @@ import * as https from 'https';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as ChildProcess from 'child_process';
|
import * as ChildProcess from 'child_process';
|
||||||
import { app, session, BrowserWindow, net, ipcMain, Session } from 'electron/main';
|
import { app, session, BrowserWindow, net, ipcMain, Session, webFrameMain, WebFrameMain } from 'electron/main';
|
||||||
import * as send from 'send';
|
import * as send from 'send';
|
||||||
import * as auth from 'basic-auth';
|
import * as auth from 'basic-auth';
|
||||||
import { closeAllWindows } from './window-helpers';
|
import { closeAllWindows } from './window-helpers';
|
||||||
|
@ -1043,6 +1043,90 @@ describe('session module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ses.setPermissionCheckHandler(handler)', () => {
|
||||||
|
afterEach(closeAllWindows);
|
||||||
|
it('details provides requestingURL for mainFrame', async () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
partition: 'very-temp-permission-handler'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const ses = w.webContents.session;
|
||||||
|
const loadUrl = 'https://myfakesite/';
|
||||||
|
let handlerDetails : Electron.PermissionCheckHandlerHandlerDetails;
|
||||||
|
|
||||||
|
ses.protocol.interceptStringProtocol('https', (req, cb) => {
|
||||||
|
cb('<html><script>console.log(\'test\');</script></html>');
|
||||||
|
});
|
||||||
|
|
||||||
|
ses.setPermissionCheckHandler((wc, permission, requestingOrigin, details) => {
|
||||||
|
if (permission === 'clipboard-read') {
|
||||||
|
handlerDetails = details;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
const readClipboardPermission: any = () => {
|
||||||
|
return w.webContents.executeJavaScript(`
|
||||||
|
navigator.permissions.query({name: 'clipboard-read'})
|
||||||
|
.then(permission => permission.state).catch(err => err.message);
|
||||||
|
`, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
await w.loadURL(loadUrl);
|
||||||
|
const state = await readClipboardPermission();
|
||||||
|
expect(state).to.equal('granted');
|
||||||
|
expect(handlerDetails!.requestingUrl).to.equal(loadUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('details provides requestingURL for cross origin subFrame', async () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
partition: 'very-temp-permission-handler'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const ses = w.webContents.session;
|
||||||
|
const loadUrl = 'https://myfakesite/';
|
||||||
|
let handlerDetails : Electron.PermissionCheckHandlerHandlerDetails;
|
||||||
|
|
||||||
|
ses.protocol.interceptStringProtocol('https', (req, cb) => {
|
||||||
|
cb('<html><script>console.log(\'test\');</script></html>');
|
||||||
|
});
|
||||||
|
|
||||||
|
ses.setPermissionCheckHandler((wc, permission, requestingOrigin, details) => {
|
||||||
|
if (permission === 'clipboard-read') {
|
||||||
|
handlerDetails = details;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
const readClipboardPermission: any = (frame: WebFrameMain) => {
|
||||||
|
return frame.executeJavaScript(`
|
||||||
|
navigator.permissions.query({name: 'clipboard-read'})
|
||||||
|
.then(permission => permission.state).catch(err => err.message);
|
||||||
|
`, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
await w.loadFile(path.join(fixtures, 'api', 'blank.html'));
|
||||||
|
w.webContents.executeJavaScript(`
|
||||||
|
var iframe = document.createElement('iframe');
|
||||||
|
iframe.src = '${loadUrl}';
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
null;
|
||||||
|
`);
|
||||||
|
const [,, frameProcessId, frameRoutingId] = await emittedOnce(w.webContents, 'did-frame-finish-load');
|
||||||
|
const state = await readClipboardPermission(webFrameMain.fromId(frameProcessId, frameRoutingId));
|
||||||
|
expect(state).to.equal('granted');
|
||||||
|
expect(handlerDetails!.requestingUrl).to.equal(loadUrl);
|
||||||
|
expect(handlerDetails!.isMainFrame).to.be.false();
|
||||||
|
expect(handlerDetails!.embeddingOrigin).to.equal('file:///');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ses.isPersistent()', () => {
|
describe('ses.isPersistent()', () => {
|
||||||
afterEach(closeAllWindows);
|
afterEach(closeAllWindows);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue