feat: add session.setPermissionCheckHandler (#13925)
* feat: add session.setPermissionCheckHandler to handle syncornous permission checks vs requests * spec: add tests for session.setPermissionCheckHandler * docs: add docs for session.setPermissionCheckHandler * feat: add mediaType to media permission checks * chore: cleanup check impl
This commit is contained in:
parent
afdb6c5f90
commit
68da311ed1
10 changed files with 142 additions and 1 deletions
|
@ -14,6 +14,21 @@
|
|||
|
||||
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPermissionHelper);
|
||||
|
||||
namespace {
|
||||
|
||||
std::string MediaStreamTypeToString(content::MediaStreamType type) {
|
||||
switch (type) {
|
||||
case content::MediaStreamType::MEDIA_DEVICE_AUDIO_CAPTURE:
|
||||
return "audio";
|
||||
case content::MediaStreamType::MEDIA_DEVICE_VIDEO_CAPTURE:
|
||||
return "video";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
@ -63,6 +78,17 @@ void WebContentsPermissionHelper::RequestPermission(
|
|||
base::Bind(&OnPermissionResponse, callback));
|
||||
}
|
||||
|
||||
bool WebContentsPermissionHelper::CheckPermission(
|
||||
content::PermissionType permission,
|
||||
const base::DictionaryValue* details) const {
|
||||
auto* rfh = web_contents_->GetMainFrame();
|
||||
auto* permission_manager = static_cast<AtomPermissionManager*>(
|
||||
web_contents_->GetBrowserContext()->GetPermissionManager());
|
||||
auto origin = web_contents_->GetLastCommittedURL();
|
||||
return permission_manager->CheckPermissionWithDetails(permission, rfh, origin,
|
||||
details);
|
||||
}
|
||||
|
||||
void WebContentsPermissionHelper::RequestFullscreenPermission(
|
||||
const base::Callback<void(bool)>& callback) {
|
||||
RequestPermission(
|
||||
|
@ -102,4 +128,15 @@ void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
|||
callback, user_gesture, &details);
|
||||
}
|
||||
|
||||
bool WebContentsPermissionHelper::CheckMediaAccessPermission(
|
||||
const GURL& security_origin,
|
||||
content::MediaStreamType type) const {
|
||||
base::DictionaryValue details;
|
||||
details.SetString("securityOrigin", security_origin.spec());
|
||||
details.SetString("mediaType", MediaStreamTypeToString(type));
|
||||
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
|
||||
// are presented as same type in content_converter.h.
|
||||
return CheckPermission(content::PermissionType::AUDIO_CAPTURE, &details);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue