#include "content/browser/xr/service/vr_service_impl.h"
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/dcheck_is_on.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/common/trace_event_common.h"
#include "build/build_config.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/xr/metrics/session_metrics_helper.h"
#include "content/browser/xr/service/browser_xr_runtime_impl.h"
#include "content/browser/xr/service/xr_permission_results.h"
#include "content/browser/xr/service/xr_runtime_manager_impl.h"
#include "content/browser/xr/webxr_internals/mojom/webxr_internals.mojom.h"
#include "content/browser/xr/webxr_internals/webxr_internals_handler_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/permission_request_description.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/origin_util.h"
#include "device/vr/buildflags/buildflags.h"
#include "device/vr/public/cpp/features.h"
#include "device/vr/public/cpp/session_mode.h"
#include "device/vr/public/mojom/vr_service.mojom-shared.h"
#include "device/vr/public/mojom/xr_device.mojom-shared.h"
#include "device/vr/public/mojom/xr_session.mojom-shared.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom-shared.h"
namespace {
device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions(
device::mojom::XRSessionOptions* options) { … }
std::vector<blink::PermissionType> GetRequiredPermissionsForMode(
device::mojom::XRSessionMode mode) { … }
std::vector<blink::PermissionType> GetRequiredPermissionsForFeatures(
const std::unordered_set<device::mojom::XRSessionFeature>&
required_features,
const std::unordered_set<device::mojom::XRSessionFeature>&
optional_features) { … }
std::unordered_set<device::mojom::XRSessionFeature> GetMissingRequiredFeatures(
const std::unordered_set<device::mojom::XRSessionFeature>& enabled_features,
const std::unordered_set<device::mojom::XRSessionFeature>&
required_features) { … }
void RejectSession(device::mojom::VRService::RequestSessionCallback callback,
size_t trace_id,
device::mojom::RequestSessionError error,
const std::string& failure_reason_description,
std::unordered_set<device::mojom::XRSessionFeature>*
rejected_features = nullptr) { … }
}
namespace content {
VRServiceImpl::SessionRequestData::SessionRequestData(
device::mojom::XRSessionOptionsPtr options,
device::mojom::VRService::RequestSessionCallback callback,
device::mojom::XRDeviceId runtime_id)
: … { … }
VRServiceImpl::SessionRequestData::~SessionRequestData() { … }
VRServiceImpl::SessionRequestData::SessionRequestData(SessionRequestData&&) =
default;
VRServiceImpl::XrCompatibleCallback::XrCompatibleCallback(
device::mojom::VRService::MakeXrCompatibleCallback callback)
: … { … }
VRServiceImpl::XrCompatibleCallback::XrCompatibleCallback(
XrCompatibleCallback&& wrapper) { … }
VRServiceImpl::XrCompatibleCallback::~XrCompatibleCallback() { … }
VRServiceImpl::VRServiceImpl(content::RenderFrameHost* render_frame_host)
: … { … }
VRServiceImpl::VRServiceImpl(base::PassKey<XRRuntimeManagerTest>)
: … { … }
VRServiceImpl::~VRServiceImpl() { … }
void VRServiceImpl::Create(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<device::mojom::VRService> receiver) { … }
void VRServiceImpl::InitializationComplete() { … }
void VRServiceImpl::SetClient(
mojo::PendingRemote<device::mojom::VRServiceClient> service_client) { … }
void VRServiceImpl::ResolvePendingRequests() { … }
void VRServiceImpl::RuntimesChanged() { … }
void VRServiceImpl::OnWebContentsFocused(content::RenderWidgetHost* host) { … }
void VRServiceImpl::OnWebContentsLostFocus(content::RenderWidgetHost* host) { … }
void VRServiceImpl::RenderFrameDeleted(content::RenderFrameHost* host) { … }
void VRServiceImpl::OnWebContentsFocusChanged(content::RenderWidgetHost* host,
bool focused) { … }
void VRServiceImpl::OnInlineSessionCreated(
SessionRequestData request,
device::mojom::XRRuntimeSessionResultPtr session_result) { … }
void VRServiceImpl::OnImmersiveSessionCreated(
SessionRequestData request,
device::mojom::XRRuntimeSessionResultPtr session_result) { … }
void VRServiceImpl::OnInlineSessionDisconnected(
mojo::RemoteSetElementId session_id) { … }
SessionMetricsHelper* VRServiceImpl::GetSessionMetricsHelper() { … }
void VRServiceImpl::OnSessionCreated(
SessionRequestData request,
device::mojom::XRSessionPtr session,
mojo::PendingRemote<device::mojom::XRSessionMetricsRecorder>
session_metrics_recorder,
mojo::PendingRemote<device::mojom::WebXrInternalsRendererListener>
xr_internals_listener) { … }
void VRServiceImpl::RequestSession(
device::mojom::XRSessionOptionsPtr options,
device::mojom::VRService::RequestSessionCallback callback) { … }
void VRServiceImpl::GetPermissionStatus(SessionRequestData request,
BrowserXRRuntimeImpl* runtime) { … }
void VRServiceImpl::OnPermissionResultsForMode(
SessionRequestData request,
const std::vector<blink::PermissionType>& permissions,
const std::vector<blink::mojom::PermissionStatus>& permission_statuses) { … }
void VRServiceImpl::OnPermissionResultsForFeatures(
SessionRequestData request,
const std::vector<blink::PermissionType>& permissions,
const std::vector<blink::mojom::PermissionStatus>& permission_statuses) { … }
void VRServiceImpl::EnsureRuntimeInstalled(SessionRequestData request,
BrowserXRRuntimeImpl* runtime) { … }
void VRServiceImpl::OnInstallResult(SessionRequestData request,
bool install_succeeded) { … }
void VRServiceImpl::DoRequestSession(SessionRequestData request) { … }
void VRServiceImpl::SupportsSession(
device::mojom::XRSessionOptionsPtr options,
device::mojom::VRService::SupportsSessionCallback callback) { … }
void VRServiceImpl::ExitPresent(ExitPresentCallback on_exited) { … }
void VRServiceImpl::SetFramesThrottled(bool throttled) { … }
void VRServiceImpl::MakeXrCompatible(
device::mojom::VRService::MakeXrCompatibleCallback callback) { … }
void VRServiceImpl::OnMakeXrCompatibleComplete(
device::mojom::XrCompatibleResult result) { … }
void VRServiceImpl::OnExitPresent() { … }
void VRServiceImpl::OnVisibilityStateChanged(
device::mojom::XRVisibilityState visiblity_state) { … }
content::WebContents* VRServiceImpl::GetWebContents() { … }
}