chromium/third_party/blink/renderer/modules/xr/xr_system.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/xr/xr_system.h"

#include <memory>
#include <utility>

#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"
#include "base/trace_event/trace_id_helper.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "device/vr/public/mojom/vr_service.mojom-blink.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_depth_state_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_tracked_image_init.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/xr/xr_enter_fullscreen_observer.h"
#include "third_party/blink/renderer/modules/xr/xr_exit_fullscreen_observer.h"
#include "third_party/blink/renderer/modules/xr/xr_frame_provider.h"
#include "third_party/blink/renderer/modules/xr/xr_session.h"
#include "third_party/blink/renderer/modules/xr/xr_session_viewport_scaler.h"
#include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

namespace {

constexpr uint64_t kInvalidTraceId =;

const char kNavigatorDetachedError[] =;

const char kPageNotVisible[] =;

const char kFeaturePolicyBlocked[] =;

const char kActiveImmersiveSession[] =;

const char kRequestRequiresUserActivation[] =;

const char kSessionNotSupported[] =;

const char kInvalidRequiredFeatures[] =;

const char kNoDevicesMessage[] =;

const char kImmersiveArModeNotValid[] =;

const char kTrackedImageWidthInvalid[] =;

constexpr device::mojom::XRSessionFeature kDefaultImmersiveVrFeatures[] =;

constexpr device::mojom::XRSessionFeature kDefaultImmersiveArFeatures[] =;

constexpr device::mojom::XRSessionFeature kDefaultInlineFeatures[] =;

device::mojom::blink::XRSessionMode stringToSessionMode(
    const String& mode_string) {}

const char* SessionModeToString(device::mojom::blink::XRSessionMode mode) {}

device::mojom::XRDepthUsage ParseDepthUsage(const V8XRDepthUsage& usage) {}

Vector<device::mojom::XRDepthUsage> ParseDepthUsages(
    const Vector<V8XRDepthUsage>& usages) {}

device::mojom::XRDepthDataFormat ParseDepthFormat(
    const V8XRDepthDataFormat& format) {}

Vector<device::mojom::XRDepthDataFormat> ParseDepthFormats(
    const Vector<V8XRDepthDataFormat>& formats) {}

bool IsFeatureValidForMode(device::mojom::XRSessionFeature feature,
                           device::mojom::blink::XRSessionMode mode,
                           XRSessionInit* session_init,
                           ExecutionContext* execution_context,
                           mojom::blink::ConsoleMessageLevel error_level) {}

bool HasRequiredPermissionsPolicy(ExecutionContext* context,
                                  device::mojom::XRSessionFeature feature) {}

// Ensure that the immersive session request is allowed, if not
// return which security error occurred.
// https://immersive-web.github.io/webxr/#immersive-session-request-is-allowed
const char* CheckImmersiveSessionRequestAllowed(LocalDOMWindow* window) {}

// Helper method to convert the mojom error code into text for displaying in the
// console. The console message will have the format of:
// "Could not create a session because: <this value>"
const char* GetConsoleMessage(device::mojom::RequestSessionError error) {}

bool IsFeatureRequested(
    device::mojom::XRSessionFeatureRequestStatus requestStatus) {}

bool IsImmersiveArAllowedBySettings(LocalDOMWindow* window) {}

}  // namespace

// Ensure that the inline session request is allowed, if not
// return which security error occurred.
// https://immersive-web.github.io/webxr/#inline-session-request-is-allowed
const char* XRSystem::CheckInlineSessionRequestAllowed(
    LocalFrame* frame,
    const PendingRequestSessionQuery& query) {}

XRSystem::PendingSupportsSessionQuery::PendingSupportsSessionQuery(
    ScriptPromiseResolverBase* resolver,
    device::mojom::blink::XRSessionMode session_mode,
    bool throw_on_unsupported)
    :{}

void XRSystem::PendingSupportsSessionQuery::Trace(Visitor* visitor) const {}

void XRSystem::PendingSupportsSessionQuery::Resolve(
    bool supported,
    ExceptionState* exception_state) {}

void XRSystem::PendingSupportsSessionQuery::RejectWithDOMException(
    DOMExceptionCode exception_code,
    const String& message,
    ExceptionState* exception_state) {}

void XRSystem::PendingSupportsSessionQuery::RejectWithSecurityError(
    const String& message,
    ExceptionState* exception_state) {}

void XRSystem::PendingSupportsSessionQuery::RejectWithTypeError(
    const String& message,
    ExceptionState* exception_state) {}

device::mojom::blink::XRSessionMode
XRSystem::PendingSupportsSessionQuery::mode() const {}

XRSystem::PendingRequestSessionQuery::PendingRequestSessionQuery(
    int64_t ukm_source_id,
    ScriptPromiseResolver<XRSession>* resolver,
    device::mojom::blink::XRSessionMode session_mode,
    RequestedXRSessionFeatureSet required_features,
    RequestedXRSessionFeatureSet optional_features)
    :{}

void XRSystem::PendingRequestSessionQuery::Resolve(
    XRSession* session,
    mojo::PendingRemote<device::mojom::blink::XRSessionMetricsRecorder>
        metrics_recorder) {}

void XRSystem::PendingRequestSessionQuery::RejectWithDOMException(
    DOMExceptionCode exception_code,
    const String& message,
    ExceptionState* exception_state) {}

void XRSystem::PendingRequestSessionQuery::RejectWithSecurityError(
    const String& message,
    ExceptionState* exception_state) {}

void XRSystem::PendingRequestSessionQuery::RejectWithTypeError(
    const String& message,
    ExceptionState* exception_state) {}

device::mojom::XRSessionFeatureRequestStatus
XRSystem::PendingRequestSessionQuery::GetFeatureRequestStatus(
    device::mojom::XRSessionFeature feature,
    const XRSession* session) const {}

void XRSystem::PendingRequestSessionQuery::ReportRequestSessionResult(
    SessionRequestStatus status,
    XRSession* session,
    mojo::PendingRemote<device::mojom::blink::XRSessionMetricsRecorder>
        metrics_recorder) {}

device::mojom::blink::XRSessionMode XRSystem::PendingRequestSessionQuery::mode()
    const {}

const XRSessionFeatureSet&
XRSystem::PendingRequestSessionQuery::RequiredFeatures() const {}

const XRSessionFeatureSet&
XRSystem::PendingRequestSessionQuery::OptionalFeatures() const {}

bool XRSystem::PendingRequestSessionQuery::HasFeature(
    device::mojom::XRSessionFeature feature) const {}

bool XRSystem::PendingRequestSessionQuery::InvalidRequiredFeatures() const {}

bool XRSystem::PendingRequestSessionQuery::InvalidOptionalFeatures() const {}

ScriptState* XRSystem::PendingRequestSessionQuery::GetScriptState() const {}

void XRSystem::PendingRequestSessionQuery::ParseSensorRequirement() {}

void XRSystem::PendingRequestSessionQuery::Trace(Visitor* visitor) const {}

device::mojom::blink::XRSessionOptionsPtr XRSystem::XRSessionOptionsFromQuery(
    const PendingRequestSessionQuery& query) {}

const char XRSystem::kSupplementName[] =;

XRSystem* XRSystem::FromIfExists(Document& document) {}

XRSystem* XRSystem::From(Document& document) {}

XRSystem* XRSystem::xr(Navigator& navigator) {}

XRSystem::XRSystem(Navigator& navigator)
    :{}

void XRSystem::FocusedFrameChanged() {}

bool XRSystem::IsFrameFocused() {}

ExecutionContext* XRSystem::GetExecutionContext() const {}

const AtomicString& XRSystem::InterfaceName() const {}

XRFrameProvider* XRSystem::frameProvider() {}

device::mojom::blink::XREnvironmentIntegrationProvider*
XRSystem::xrEnvironmentProviderRemote() {}

device::mojom::blink::VRService* XRSystem::BrowserService() {}

void XRSystem::AddEnvironmentProviderErrorHandler(
    EnvironmentProviderErrorCallback callback) {}

void XRSystem::ExitPresent(base::OnceClosure on_exited) {}

void XRSystem::SetFramesThrottled(const XRSession* session, bool throttled) {}

ScriptPromise<IDLUndefined> XRSystem::supportsSession(
    ScriptState* script_state,
    const String& mode,
    ExceptionState& exception_state) {}

ScriptPromise<IDLBoolean> XRSystem::isSessionSupported(
    ScriptState* script_state,
    const String& mode,
    ExceptionState& exception_state) {}

void XRSystem::AddConsoleMessage(mojom::blink::ConsoleMessageLevel error_level,
                                 const String& message) {}

void XRSystem::AddWebXrInternalsMessage(const String& message) {}

void XRSystem::InternalIsSessionSupported(ScriptPromiseResolverBase* resolver,
                                          const String& mode,
                                          ExceptionState& exception_state,
                                          bool throw_on_unsupported) {}

void XRSystem::RequestSessionInternal(
    device::mojom::blink::XRSessionMode session_mode,
    PendingRequestSessionQuery* query,
    ExceptionState* exception_state) {}

void XRSystem::RequestImmersiveSession(PendingRequestSessionQuery* query,
                                       ExceptionState* exception_state) {}

void XRSystem::DoRequestSession(
    PendingRequestSessionQuery* query,
    device::mojom::blink::XRSessionOptionsPtr session_options) {}

void XRSystem::RequestInlineSession(PendingRequestSessionQuery* query,
                                    ExceptionState* exception_state) {}

XRSystem::RequestedXRSessionFeatureSet XRSystem::ParseRequestedFeatures(
    const HeapVector<ScriptValue>& features,
    const device::mojom::blink::XRSessionMode& session_mode,
    XRSessionInit* session_init,
    mojom::blink::ConsoleMessageLevel error_level) {}

ScriptPromise<XRSession> XRSystem::requestSession(
    ScriptState* script_state,
    const String& mode,
    XRSessionInit* session_init,
    ExceptionState& exception_state) {}

void XRSystem::MakeXrCompatibleAsync(
    device::mojom::blink::VRService::MakeXrCompatibleCallback callback) {}

void XRSystem::MakeXrCompatibleSync(
    device::mojom::XrCompatibleResult* xr_compatible_result) {}

void XRSystem::OnSessionEnded(XRSession* session) {}

// This will be called when the XR hardware or capabilities have potentially
// changed. For example, if a new physical device was connected to the system,
// it might be able to support immersive sessions, where it couldn't before.
void XRSystem::OnDeviceChanged() {}

void XRSystem::OnSupportsSessionReturned(PendingSupportsSessionQuery* query,
                                         bool supports_session) {}

void XRSystem::OnRequestSessionReturned(
    PendingRequestSessionQuery* query,
    device::mojom::blink::RequestSessionResultPtr result) {}

void XRSystem::OnFullscreenConfigured(
    PendingRequestSessionQuery* query,
    device::mojom::blink::RequestSessionResultPtr result,
    bool fullscreen_succeeded) {}

void XRSystem::FinishSessionCreation(
    PendingRequestSessionQuery* query,
    device::mojom::blink::RequestSessionResultPtr result) {}

void XRSystem::AddedEventListener(
    const AtomicString& event_type,
    RegisteredEventListener& registered_listener) {}

void XRSystem::ContextDestroyed() {}

// A session is always created and returned.
XRSession* XRSystem::CreateSession(
    device::mojom::blink::XRSessionMode mode,
    device::mojom::blink::XREnvironmentBlendMode blend_mode,
    device::mojom::blink::XRInteractionMode interaction_mode,
    mojo::PendingReceiver<device::mojom::blink::XRSessionClient>
        client_receiver,
    device::mojom::blink::XRSessionDeviceConfigPtr device_config,
    XRSessionFeatureSet enabled_features,
    uint64_t trace_id,
    bool sensorless_session) {}

XRSession* XRSystem::CreateSensorlessInlineSession() {}

void XRSystem::Dispose(DisposeType dispose_type) {}

void XRSystem::OnEnvironmentProviderDisconnect() {}

void XRSystem::TryEnsureService() {}

bool XRSystem::IsImmersiveArAllowed() {}

void XRSystem::Trace(Visitor* visitor) const {}

device::mojom::blink::WebXrInternalsRendererListener*
XRSystem::GetWebXrInternalsRendererListener() {}

}  // namespace blink