From 93e1e219cfbb3abd6c17a7bbb76ede9823ceba72 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 12 Sep 2018 16:48:20 +1000 Subject: [PATCH] feat: route frame based permission checks through our permission check handler --- atom/browser/atom_permission_manager.cc | 9 +++++++-- docs/api/session.md | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc index 47602ab467499..5a2732b067686 100644 --- a/atom/browser/atom_permission_manager.cc +++ b/atom/browser/atom_permission_manager.cc @@ -214,6 +214,7 @@ blink::mojom::PermissionStatus AtomPermissionManager::GetPermissionStatus( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) { + // TODO(MarshallOfSound): Investigate how we can emit this permission check on a session object return blink::mojom::PermissionStatus::GRANTED; } @@ -245,9 +246,13 @@ bool AtomPermissionManager::CheckPermissionWithDetails( blink::mojom::PermissionStatus AtomPermissionManager::GetPermissionStatusForFrame( content::PermissionType permission, - content::RenderFrameHost* render_frame_host, + content::RenderFrameHost* rfh, const GURL& requesting_origin) { - return blink::mojom::PermissionStatus::GRANTED; + base::DictionaryValue details; + bool granted = CheckPermissionWithDetails(permission, rfh, requesting_origin, + &details); + return granted ? blink::mojom::PermissionStatus::GRANTED + : blink::mojom::PermissionStatus::DENIED; } } // namespace atom diff --git a/docs/api/session.md b/docs/api/session.md index 22f71fda28b7c..e227e65dd6c21 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -315,17 +315,21 @@ session.fromPartition('some-partition').setPermissionRequestHandler((webContents * `handler` Function | null * `webContents` [WebContents](web-contents.md) - WebContents checking the permission. - * `permission` String - Enum of 'media'. + * `permission` String - Enum of 'media', 'midiSysex', 'notifications', 'geolocation', 'mediaKeySystem' or 'midi'. * `requestingOrigin` String - The origin URL of the permission check * `details` Object - Some properties are only available on certain permission types. * `securityOrigin` String - The security orign of the `media` check. * `mediaType` String - The type of media access being requested, can be `video`, - `audio` or `unknown` + `audio` or `unknown`. This property is only set on `media` checks. Sets the handler which can be used to respond to permission checks for the `session`. Returning `true` will allow the permission and `false` will reject it. To clear the handler, call `setPermissionCheckHandler(null)`. +Please note not all syncronous permission checks are passed through this handler, +for instance `Notification.granted` is not routed but `new Notification` will cause +the `permissionRequestHandler` to be fired. + ```javascript const {session} = require('electron') session.fromPartition('some-partition').setPermissionCheckHandler((webContents, permission) => {