Skip to content

Commit

Permalink
feat: route frame based permission checks through our permission chec…
Browse files Browse the repository at this point in the history
…k handler
  • Loading branch information
MarshallOfSound committed Sep 12, 2018
1 parent ebbaa4f commit 93e1e21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions atom/browser/atom_permission_manager.cc
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions docs/api/session.md
Expand Up @@ -315,17 +315,21 @@ session.fromPartition('some-partition').setPermissionRequestHandler((webContents

* `handler` Function<Boolean> | 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) => {
Expand Down

0 comments on commit 93e1e21

Please sign in to comment.