#include "components/permissions/contexts/webxr_permission_context.h"
#include "base/check.h"
#include "build/build_config.h"
#include "device/vr/buildflags/buildflags.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom.h"
#if BUILDFLAG(IS_ANDROID)
#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"
#if BUILDFLAG(ENABLE_VR)
#include "base/feature_list.h"
#include "device/vr/public/cpp/features.h"
#endif
#endif
namespace permissions {
WebXrPermissionContext::WebXrPermissionContext(
content::BrowserContext* browser_context,
ContentSettingsType content_settings_type)
: … { … }
WebXrPermissionContext::~WebXrPermissionContext() = default;
#if BUILDFLAG(IS_ANDROID)
void WebXrPermissionContext::NotifyPermissionSet(
const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
BrowserPermissionCallback callback,
bool persist,
ContentSetting content_setting,
bool is_one_time,
bool is_final_decision) {
const bool is_hands =
content_settings_type_ == ContentSettingsType::HAND_TRACKING;
DCHECK(!is_one_time || is_hands);
DCHECK(is_final_decision);
const bool permission_granted =
content_setting == ContentSetting::CONTENT_SETTING_ALLOW;
const bool is_ar = content_settings_type_ == ContentSettingsType::AR;
bool is_openxr = false;
#if BUILDFLAG(ENABLE_OPENXR)
is_openxr = content_settings_type_ == ContentSettingsType::VR &&
device::features::IsOpenXrEnabled();
#endif
const bool additional_permissions_needed =
permission_granted && (is_ar || is_openxr || is_hands);
if (!additional_permissions_needed) {
PermissionContextBase::NotifyPermissionSet(
id, requesting_origin, embedding_origin, std::move(callback), persist,
content_setting, is_one_time, is_final_decision);
return;
}
if (persist) {
PermissionContextBase::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_};
PermissionRepromptState reprompt_state =
ShouldRepromptUserForPermissions(web_contents, permission_type);
switch (reprompt_state) {
case PermissionRepromptState::kNoNeed:
OnAndroidPermissionDecided(id, requesting_origin, embedding_origin,
std::move(callback),
true );
return;
case PermissionRepromptState::kCannotShow:
OnAndroidPermissionDecided(id, requesting_origin, embedding_origin,
std::move(callback),
false );
return;
case PermissionRepromptState::kShow:
permissions::PermissionsRepromptControllerAndroid::CreateForWebContents(
web_contents);
permissions::PermissionsRepromptControllerAndroid::FromWebContents(
web_contents)
->RepromptPermissionRequest(
permission_type, content_settings_type(),
base::BindOnce(
&WebXrPermissionContext::OnAndroidPermissionDecided,
weak_ptr_factory_.GetWeakPtr(), id, requesting_origin,
embedding_origin, std::move(callback)));
return;
}
}
void WebXrPermissionContext::OnAndroidPermissionDecided(
const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
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 WebXrPermissionContext::UpdateTabContext(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
bool allowed) {
}
#endif
}