|
@@ -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
|