8000 feat: add session.setPermissionCheckHandler by MarshallOfSound · Pull Request #13925 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add session.setPermissionCheckHandler #13925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 28, 2018

Conversation

MarshallOfSound
Copy link
Member
@MarshallOfSound MarshallOfSound commented Aug 3, 2018

This allows us to call out to JS land for synchronous permission checks (for example the media permission check)

Example usage:

const {session} = require('electron')
session.fromPartition('some-partition').setPermissionCheckHandler((webContents, permission) => {
  return false;
});

Notes: Added session.setPermissionCheckHandler()

@MarshallOfSound MarshallOfSound requested review from a team August 3, 2018 04:34
@MarshallOfSound MarshallOfSound changed the title Feat/session permission checks [wip] Add session.setPermissionCheckHandler Aug 3, 2018
@MarshallOfSound
Copy link
Member Author

Some permission checks aren't a simple granted / not-granted boolean check, for instance the Notification.permission check we currently just return granted for but it has three states.

  • granted
  • default
  • denied

This API probably needs to handle those three types not just a boolean yes/no.

Copy link
Contributor
@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approach lgtm!

base::DictionaryValue details;
details.SetString("securityOrigin", security_origin.spec());
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
// are presented as same type in content_converter.h.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should fix that? It seems relevant to know whether the webcontents is requesting audio or video.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently they both get converted to media, I agree that the user should be able to tell the different between all the content::MediaStreamType's. We could just set the media stream type on the details object 🤔

I did it this way to be consistent with the existing media permission stuff in setPermissionRequestHandler

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right, well we should fix that, but perhaps in a separate PR :)


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)`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be good to add a note that this blocks the main thread & so should return quickly?

@MarshallOfSound MarshallOfSound changed the title [wip] Add session.setPermissionCheckHandler Add session.setPermissionCheckHandler Aug 6, 2018
@MarshallOfSound MarshallOfSound changed the title Add session.setPermissionCheckHandler feat: add session.setPermissionCheckHandler Aug 10, 2018
@MarshallOfSound MarshallOfSound added the semver/minor backwards-compatible functionality label Aug 10, 2018
@@ -23,6 +23,7 @@ class WebContentsPermissionHelper
OPEN_EXTERNAL,
};

// Asyncronous Requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asynchronous

@@ -102,4 +113,26 @@ void WebContentsPermissionHelper::RequestOpenExternalPermission(
callback, user_gesture, &details);
}

std::string MediaStreamTypeToString(content::MediaStreamType type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be in an anonymous namespace

bool CheckPermissionWithDetails(content::PermissionType permission,
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const base::DictionaryValue* details);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a const method

@@ -43,6 +48,9 @@ class WebContentsPermissionHelper
bool user_gesture = false,
const base::DictionaryValue* details = nullptr);

bool CheckPermission(content::PermissionType permission,
const base::DictionaryValue* details);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a const method

@@ -34,6 +35,10 @@ class WebContentsPermissionHelper
bool user_gesture,
const GURL& url);

// Syncronous Checks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synchronous

@@ -34,6 +35,10 @@ class WebContentsPermissionHelper
bool user_gesture,
const GURL& url);

// Syncronous Checks
bool CheckMediaAccessPermission(const GURL& security_origin,
content::MediaStreamType type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a const method

* `webContents` [WebContents](web-contents.md) - WebContents checking the permission.
* `permission` String - Enum of 'media'.
* `requestingOrigin` String - The origin URL of the permission check
* `details` Object - Some properties are only available on certain permission types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code seems to unconditionally set both properties. Which ones aren't available on certain permission types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckerr This is future documentation so that when we add new permission types (currently this method only has one) it doesn't catch people by surprise 👍

@ckerr ckerr merged commit 68da311 into master Aug 28, 2018
@ckerr ckerr deleted the feat/session-permission-checks branch August 28, 2018 14:05
@release-clerk
Copy link
release-clerk bot commented Aug 28, 2018

Release Notes Persisted

Added session.setPermissionCheckHandler()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0