#include "chrome/browser/media/webrtc/media_stream_device_permission_context.h"
#include "base/command_line.h"
#include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/permissions/permission_context_base.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/stl_util.h"
#include "components/permissions/android/android_permission_util.h"
#include "components/permissions/android/permissions_reprompt_controller_android.h"
#include "components/permissions/permission_request_id.h"
#include "components/permissions/permissions_client.h"
#include "content/public/browser/web_contents.h"
#endif
namespace {
blink::mojom::PermissionsPolicyFeature GetPermissionsPolicyFeature(
ContentSettingsType type) { … }
}
MediaStreamDevicePermissionContext::MediaStreamDevicePermissionContext(
content::BrowserContext* browser_context,
const ContentSettingsType content_settings_type)
: … { … }
MediaStreamDevicePermissionContext::~MediaStreamDevicePermissionContext() { … }
ContentSetting MediaStreamDevicePermissionContext::GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const { … }
#if BUILDFLAG(IS_ANDROID)
void MediaStreamDevicePermissionContext::NotifyPermissionSet(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
permissions::BrowserPermissionCallback callback,
bool persist,
ContentSetting content_setting,
bool is_one_time,
bool is_final_decision) {
DCHECK(is_final_decision);
DCHECK(content_settings_type_ == ContentSettingsType::MEDIASTREAM_CAMERA ||
content_settings_type_ == ContentSettingsType::MEDIASTREAM_MIC);
if (content_setting != ContentSetting::CONTENT_SETTING_ALLOW) {
PermissionContextBase::NotifyPermissionSet(
id, requesting_origin, embedding_origin, std::move(callback), persist,
content_setting, is_one_time, is_final_decision);
return;
}
if (persist) {
UpdateContentSetting(requesting_origin, embedding_origin, content_setting,
is_one_time);
}
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(
content::RenderFrameHost::FromID(id.global_render_frame_host_id()));
if (!web_contents) {
OnAndroidPermissionDecided(id, requesting_origin, embedding_origin,
std::move(callback),
false );
return;
}
std::vector<ContentSettingsType> permission_type = {content_settings_type_};
permissions::PermissionRepromptState reprompt_state =
permissions::ShouldRepromptUserForPermissions(web_contents,
permission_type);
switch (reprompt_state) {
case permissions::PermissionRepromptState::kNoNeed:
OnAndroidPermissionDecided(id, requesting_origin, embedding_origin,
std::move(callback),
true );
return;
case permissions::PermissionRepromptState::kCannotShow:
OnAndroidPermissionDecided(id, requesting_origin, embedding_origin,
std::move(callback),
false );
return;
case permissions::PermissionRepromptState::kShow:
permissions::PermissionsRepromptControllerAndroid::CreateForWebContents(
web_contents);
permissions::PermissionsRepromptControllerAndroid::FromWebContents(
web_contents)
->RepromptPermissionRequest(
permission_type, content_settings_type_,
base::BindOnce(&MediaStreamDevicePermissionContext::
OnAndroidPermissionDecided,
weak_ptr_factory_.GetWeakPtr(), id,
requesting_origin, embedding_origin,
std::move(callback)));
return;
}
}
void MediaStreamDevicePermissionContext::OnAndroidPermissionDecided(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
permissions::BrowserPermissionCallback callback,
bool permission_granted) {
ContentSetting setting = permission_granted
? ContentSetting::CONTENT_SETTING_ALLOW
: ContentSetting::CONTENT_SETTING_BLOCK;
PermissionContextBase::NotifyPermissionSet(
id, requesting_origin, embedding_origin, std::move(callback),
false , setting, false,
true);
}
void MediaStreamDevicePermissionContext::UpdateTabContext(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
bool allowed) {
}
#endif
void MediaStreamDevicePermissionContext::ResetPermission(
const GURL& requesting_origin,
const GURL& embedding_origin) { … }