Commit 22e84af1 authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Delete WebVr from Blink

This change removes all WebVr flags and almost all WebVr blink code.
Future work will begin to remove the device side WebVr code, and then
mojo refactors will be investigated.

Bug: 960132
Change-Id: I3e14b6f20b43c0580a39c0692be1d657ea00ab0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869673
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708905}
parent 7cef5ae8
......@@ -68,7 +68,6 @@ generate_event_interfaces("modules_bindings_generated_event_interfaces") {
"//third_party/blink/renderer/modules/speech/speech_synthesis_error_event.idl",
"//third_party/blink/renderer/modules/speech/speech_synthesis_event.idl",
"//third_party/blink/renderer/modules/storage/storage_event.idl",
"//third_party/blink/renderer/modules/vr/vr_display_event.idl",
"//third_party/blink/renderer/modules/webaudio/audio_processing_event.idl",
"//third_party/blink/renderer/modules/webaudio/offline_audio_completion_event.idl",
"//third_party/blink/renderer/modules/webgl/webgl_context_event.idl",
......
......@@ -346,11 +346,6 @@ DeprecationInfo GetDeprecationInfo(WebFeature feature) {
"https://www.chromestatus.com/features/4964279606312960 for more "
"details."};
case WebFeature::kVREyeParametersOffset:
return {"VREyeParametersOffset", kUnknown,
ReplacedBy("VREyeParameters.offset",
"view matrices provided by VRFrameData")};
case WebFeature::kCSSSelectorInternalMediaControlsOverlayCastButton:
return {
"CSSSelectorInternalMediaControlsOverlayCastButton", kM61,
......@@ -517,14 +512,6 @@ DeprecationInfo GetDeprecationInfo(WebFeature feature) {
ReplacedWillBeRemoved("Atomics.wake", "Atomics.notify", kM76,
"6228189936353280")};
case WebFeature::kVRGetDisplays:
return {"WebVR", kM79,
String::Format("WebVR is deprecated and will be removed as soon "
"as %s. Please use WebXR instead. See "
"https://www.chromestatus.com/feature/"
"4532810371039232 for details.",
MilestoneString(kM79))};
case WebFeature::kCSSValueAppearanceCheckboxForOthersRendered:
return {"CSSValueAppearanceCheckboxForOthersRendered", kM79,
WillBeRemoved("'-webkit-appearance: checkbox' for elements other "
......
......@@ -141,7 +141,6 @@ jumbo_component("modules") {
"//third_party/blink/renderer/modules/srcobject",
"//third_party/blink/renderer/modules/storage",
"//third_party/blink/renderer/modules/vibration",
"//third_party/blink/renderer/modules/vr",
"//third_party/blink/renderer/modules/wake_lock",
"//third_party/blink/renderer/modules/webaudio",
"//third_party/blink/renderer/modules/webdatabase",
......
......@@ -63,7 +63,6 @@
"SpeechRecognition",
"SpeechSynthesis",
"SpeechSynthesisUtterance",
"VRDisplay",
"AudioContext",
"AudioNode",
"MIDIAccess",
......
......@@ -24,8 +24,6 @@ blink_modules_sources("gamepad") {
"gamepad_haptic_actuator.h",
"gamepad_list.cc",
"gamepad_list.h",
"gamepad_pose.cc",
"gamepad_pose.h",
"gamepad_shared_memory_reader.cc",
"gamepad_shared_memory_reader.h",
"navigator_gamepad.cc",
......
......@@ -43,7 +43,6 @@ Gamepad::Gamepad(Client* client,
timestamp_(0.0),
has_vibration_actuator_(false),
vibration_actuator_type_(device::GamepadHapticActuatorType::kDualRumble),
display_id_(0),
is_axis_data_dirty_(true),
is_button_data_dirty_(true),
time_origin_(time_origin),
......@@ -72,21 +71,11 @@ void Gamepad::UpdateFromDeviceState(const device::Gamepad& device_gamepad) {
// also simpler than logic to conditionally call.
SetVibrationActuatorInfo(device_gamepad.vibration_actuator);
if (device_gamepad.is_xr) {
SetPose(device_gamepad.pose);
SetHand(device_gamepad.hand);
}
// These fields are not expected to change and will only be written when the
// gamepad is newly connected.
if (newly_connected) {
SetId(device_gamepad.id);
SetMapping(device_gamepad.mapping);
if (device_gamepad.is_xr && device_gamepad.display_id) {
// Re-map display ids, since we will hand out at most one VRDisplay.
SetDisplayId(1);
}
}
}
......@@ -158,35 +147,6 @@ void Gamepad::SetVibrationActuatorInfo(
vibration_actuator_type_ = actuator.type;
}
void Gamepad::SetPose(const device::GamepadPose& pose) {
if (!pose.not_null) {
if (pose_)
pose_ = nullptr;
return;
}
if (!pose_)
pose_ = MakeGarbageCollected<GamepadPose>();
pose_->SetPose(pose);
}
void Gamepad::SetHand(const device::GamepadHand& hand) {
switch (hand) {
case device::GamepadHand::kNone:
hand_ = "";
break;
case device::GamepadHand::kLeft:
hand_ = "left";
break;
case device::GamepadHand::kRight:
hand_ = "right";
break;
default:
NOTREACHED();
}
}
// Convert the raw timestamp from the device to a relative one and apply the
// floor.
void Gamepad::SetTimestamp(const device::Gamepad& device_gamepad) {
......@@ -209,7 +169,6 @@ void Gamepad::SetTimestamp(const device::Gamepad& device_gamepad) {
void Gamepad::Trace(blink::Visitor* visitor) {
visitor->Trace(client_);
visitor->Trace(buttons_);
visitor->Trace(pose_);
ScriptWrappable::Trace(visitor);
}
......
......@@ -30,7 +30,6 @@
#include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_button.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_haptic_actuator.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_pose.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
......@@ -89,15 +88,6 @@ class MODULES_EXPORT Gamepad final : public ScriptWrappable {
return vibration_actuator_type_;
}
GamepadPose* pose() const { return pose_; }
void SetPose(const device::GamepadPose&);
const String& hand() const { return hand_; }
void SetHand(const device::GamepadHand&);
unsigned displayId() const { return display_id_; }
void SetDisplayId(unsigned val) { display_id_ = val; }
void Trace(blink::Visitor*) override;
private:
......@@ -132,15 +122,6 @@ class MODULES_EXPORT Gamepad final : public ScriptWrappable {
// The type of haptic actuator used for vibration effects.
device::GamepadHapticActuatorType vibration_actuator_type_;
// Snapshot of the gamepad pose.
Member<GamepadPose> pose_;
// A string representing the handedness of the gamepad.
String hand_;
// An identifier for associating a gamepad with a VR headset.
unsigned display_id_;
// True if the data in |axes_| has changed since the last time it was
// accessed.
bool is_axis_data_dirty_;
......
......@@ -53,10 +53,4 @@ interface Gamepad {
// Gamepad vibration is proposed as an extension to the Gamepad API.
// https://github.com/w3c/gamepad/pull/68
[MeasureAs=GamepadVibrationActuator] readonly attribute GamepadHapticActuator? vibrationActuator;
[RuntimeEnabled=WebVR, MeasureAs=GamepadPose] readonly attribute GamepadPose? pose;
[RuntimeEnabled=WebVR, MeasureAs=GamepadHand] readonly attribute GamepadHand hand;
// https://w3c.github.io/webvr/#interface-gamepad
[RuntimeEnabled=WebVR, MeasureAs=GamepadDisplayId] readonly attribute unsigned long displayId;
};
......@@ -127,14 +127,13 @@ bool GamepadStateCompareResult::CompareGamepads(GamepadList* old_gamepads,
CompareAxes(old_gamepad, new_gamepad, i, compare_all_axes);
bool any_button_updated =
CompareButtons(old_gamepad, new_gamepad, i, compare_all_buttons);
bool pose_changed = ComparePose(old_gamepad, new_gamepad);
if (newly_connected)
gamepad_connected_.set(i);
if (newly_disconnected)
gamepad_disconnected_.set(i);
if (newly_connected || newly_disconnected || any_axis_updated ||
any_button_updated || pose_changed) {
any_button_updated) {
any_change = true;
}
}
......@@ -226,67 +225,6 @@ bool GamepadStateCompareResult::CompareButtons(Gamepad* old_gamepad,
return any_button_changed;
}
bool GamepadStateCompareResult::ComparePose(Gamepad* old_gamepad,
Gamepad* new_gamepad) {
if (!new_gamepad)
return false;
const auto* new_pose = new_gamepad->pose();
const auto* old_pose = old_gamepad ? old_gamepad->pose() : nullptr;
if (old_pose && new_pose) {
// Both poses are non-null. Compare pose members until a difference is
// found.
if (CompareFloat32Array(old_pose->orientation(), new_pose->orientation())) {
return true;
}
if (CompareFloat32Array(old_pose->position(), new_pose->position())) {
return true;
}
if (CompareFloat32Array(old_pose->angularVelocity(),
new_pose->angularVelocity())) {
return true;
}
if (CompareFloat32Array(old_pose->linearVelocity(),
new_pose->linearVelocity())) {
return true;
}
if (CompareFloat32Array(old_pose->angularAcceleration(),
new_pose->angularAcceleration())) {
return true;
}
if (CompareFloat32Array(old_pose->linearAcceleration(),
new_pose->linearAcceleration())) {
return true;
}
} else if (old_pose != new_pose) {
// Exactly one pose is non-null.
return true;
}
// Both poses are null, or the poses are identical.
return false;
}
bool GamepadStateCompareResult::CompareFloat32Array(
DOMFloat32Array* old_array,
DOMFloat32Array* new_array) {
if (old_array && new_array) {
// Both arrays are non-null. Compare elements until a difference is found.
uint32_t length = old_array->length();
if (length != new_array->length())
return true;
const float* old_data = old_array->Data();
const float* new_data = new_array->Data();
for (uint32_t i = 0; i < length; ++i) {
if (old_data[i] != new_data[i])
return true;
}
} else if (old_array != new_array) {
// Exactly one array is non-null.
return true;
}
// Both arrays are null, or the arrays are identical.
return false;
}
GamepadStateCompareResult GamepadComparisons::Compare(
GamepadList* old_gamepads,
GamepadList* new_gamepads,
......
......@@ -49,9 +49,6 @@ class MODULES_EXPORT GamepadStateCompareResult {
Gamepad* new_gamepad,
size_t gamepad_index,
bool compare_all);
bool ComparePose(Gamepad* old_gamepad, Gamepad* new_gamepad);
bool CompareFloat32Array(DOMFloat32Array* old_array,
DOMFloat32Array* new_array);
bool any_change_ = false;
std::bitset<device::Gamepads::kItemsLengthCap> gamepad_connected_;
......
......@@ -32,18 +32,6 @@ class GamepadComparisonsTest : public testing::Test {
v.z = 0.f;
}
void InitGamepadPose(device::GamepadPose& p) {
p.not_null = true;
p.has_orientation = true;
p.has_position = true;
InitGamepadQuaternion(p.orientation);
InitGamepadVector(p.position);
InitGamepadVector(p.angular_velocity);
InitGamepadVector(p.linear_velocity);
InitGamepadVector(p.angular_acceleration);
InitGamepadVector(p.linear_acceleration);
}
Gamepad* CreateGamepad() {
base::TimeTicks dummy_time_origin =
base::TimeTicks() + base::TimeDelta::FromMicroseconds(1000);
......@@ -60,14 +48,12 @@ class GamepadComparisonsTest : public testing::Test {
GamepadList* CreateGamepadListWithNeutralGamepad() {
double axes[1] = {0.0};
device::GamepadButton buttons[1] = {{false, false, 0.0}};
device::GamepadPose null_pose;
auto* list = MakeGarbageCollected<GamepadList>();
auto* gamepad = CreateGamepad();
gamepad->SetId("gamepad");
gamepad->SetAxes(1, axes);
gamepad->SetButtons(1, buttons);
gamepad->SetConnected(true);
gamepad->SetPose(null_pose);
list->Set(0, gamepad);
return list;
}
......@@ -138,40 +124,6 @@ class GamepadComparisonsTest : public testing::Test {
return list;
}
GamepadList* CreateGamepadListWithNeutralPose() {
double axes[1] = {0.0};
device::GamepadButton buttons[1] = {{false, false, 0.0}};
device::GamepadPose pose;
InitGamepadPose(pose);
auto* list = MakeGarbageCollected<GamepadList>();
auto* gamepad = CreateGamepad();
gamepad->SetId("gamepad");
gamepad->SetAxes(1, axes);
gamepad->SetButtons(1, buttons);
gamepad->SetConnected(true);
gamepad->SetPose(pose);
list->Set(0, gamepad);
return list;
}
GamepadList* CreateGamepadListWithAlteredPose() {
double axes[1] = {0.0};
device::GamepadButton buttons[1] = {{false, false, 0.0}};
device::GamepadPose pose;
InitGamepadPose(pose);
// Modify the linear velocity.
pose.linear_velocity.x = 100.f;
auto* list = MakeGarbageCollected<GamepadList>();
auto* gamepad = CreateGamepad();
gamepad->SetId("gamepad");
gamepad->SetAxes(1, axes);
gamepad->SetButtons(1, buttons);
gamepad->SetConnected(true);
gamepad->SetPose(pose);
list->Set(0, gamepad);
return list;
}
private:
DISALLOW_COPY_AND_ASSIGN(GamepadComparisonsTest);
};
......@@ -428,31 +380,4 @@ TEST_F(GamepadComparisonsTest, CompareButtonTouchedWithNeutral) {
EXPECT_FALSE(compareResult.IsButtonUp(0, 0));
}
TEST_F(GamepadComparisonsTest, CompareNeutralPoseWithNeutralPose) {
auto* list1 = CreateGamepadListWithNeutralPose();
auto* list2 = CreateGamepadListWithNeutralPose();
auto compareResult = GamepadComparisons::Compare(
list1, list2, /*compare_all_axes=*/false, /*compare_all_buttons=*/false);
EXPECT_FALSE(compareResult.IsDifferent());
}
TEST_F(GamepadComparisonsTest, CompareNullPoseWithNeutralPose) {
auto* list1 = CreateGamepadListWithNeutralGamepad();
auto* list2 = CreateGamepadListWithNeutralPose();
auto compareResult = GamepadComparisons::Compare(
list1, list2, /*compare_all_axes=*/false, /*compare_all_buttons=*/false);
EXPECT_TRUE(compareResult.IsDifferent());
}
TEST_F(GamepadComparisonsTest, CompareNeutralPoseWithAlteredPose) {
auto* list1 = CreateGamepadListWithNeutralPose();
auto* list2 = CreateGamepadListWithAlteredPose();
auto compareResult = GamepadComparisons::Compare(
list1, list2, /*compare_all_axes=*/false, /*compare_all_buttons=*/false);
EXPECT_TRUE(compareResult.IsDifferent());
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/gamepad/gamepad_pose.h"
#include "device/gamepad/public/cpp/gamepad.h"
namespace blink {
namespace {
DOMFloat32Array* VecToFloat32Array(const device::GamepadVector& vec) {
if (vec.not_null) {
DOMFloat32Array* out = DOMFloat32Array::Create(3);
out->Data()[0] = vec.x;
out->Data()[1] = vec.y;
out->Data()[2] = vec.z;
return out;
}
return nullptr;
}
DOMFloat32Array* QuatToFloat32Array(const device::GamepadQuaternion& quat) {
if (quat.not_null) {
DOMFloat32Array* out = DOMFloat32Array::Create(4);
out->Data()[0] = quat.x;
out->Data()[1] = quat.y;
out->Data()[2] = quat.z;
out->Data()[3] = quat.w;
return out;
}
return nullptr;
}
} // namespace
GamepadPose::GamepadPose() = default;
void GamepadPose::SetPose(const device::GamepadPose& state) {
if (state.not_null) {
has_orientation_ = state.has_orientation;
has_position_ = state.has_position;
orientation_ = QuatToFloat32Array(state.orientation);
position_ = VecToFloat32Array(state.position);
angular_velocity_ = VecToFloat32Array(state.angular_velocity);
linear_velocity_ = VecToFloat32Array(state.linear_velocity);
angular_acceleration_ = VecToFloat32Array(state.angular_acceleration);
linear_acceleration_ = VecToFloat32Array(state.linear_acceleration);
}
}
void GamepadPose::Trace(blink::Visitor* visitor) {
visitor->Trace(orientation_);
visitor->Trace(position_);
visitor->Trace(angular_velocity_);
visitor->Trace(linear_velocity_);
visitor->Trace(angular_acceleration_);
visitor->Trace(linear_acceleration_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_POSE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_GAMEPAD_GAMEPAD_POSE_H_
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/member.h"
namespace device {
class GamepadPose;
}
namespace blink {
class GamepadPose final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
GamepadPose();
bool hasOrientation() const { return has_orientation_; }
bool hasPosition() const { return has_position_; }
DOMFloat32Array* orientation() const { return orientation_; }
DOMFloat32Array* position() const { return position_; }
DOMFloat32Array* angularVelocity() const { return angular_velocity_; }
DOMFloat32Array* linearVelocity() const { return linear_velocity_; }
DOMFloat32Array* angularAcceleration() const { return angular_acceleration_; }
DOMFloat32Array* linearAcceleration() const { return linear_acceleration_; }
void SetPose(const device::GamepadPose& state);
void Trace(blink::Visitor*) override;
private:
bool has_orientation_;
bool has_position_;
Member<DOMFloat32Array> orientation_;
Member<DOMFloat32Array> position_;
Member<DOMFloat32Array> angular_velocity_;
Member<DOMFloat32Array> linear_velocity_;
Member<DOMFloat32Array> angular_acceleration_;
Member<DOMFloat32Array> linear_acceleration_;
};
} // namespace blink
#endif // VRPose_h
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/gamepad/extensions.html#gamepadpose-interface
[
RuntimeEnabled=WebVR
] interface GamepadPose {
[MeasureAs=GamepadPoseHasOrientation] readonly attribute boolean hasOrientation;
[MeasureAs=GamepadPoseHasPosition] readonly attribute boolean hasPosition;
[MeasureAs=GamepadPosePosition] readonly attribute Float32Array? position;
[MeasureAs=GamepadPoseLinearVelocity] readonly attribute Float32Array? linearVelocity;
[MeasureAs=GamepadPoseLinearAcceleration] readonly attribute Float32Array? linearAcceleration;
[MeasureAs=GamepadPoseOrientation] readonly attribute Float32Array? orientation;
[MeasureAs=GamepadPoseAngularVelocity] readonly attribute Float32Array? angularVelocity;
[MeasureAs=GamepadPoseAngularAcceleration] readonly attribute Float32Array? angularAcceleration;
};
......@@ -40,7 +40,6 @@
#include "third_party/blink/renderer/modules/gamepad/gamepad_dispatcher.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_event.h"
#include "third_party/blink/renderer/modules/gamepad/gamepad_list.h"
#include "third_party/blink/renderer/modules/vr/navigator_vr.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink {
......@@ -57,20 +56,6 @@ bool HasConnectionEventListeners(LocalDOMWindow* window) {
window->HasEventListeners(event_type_names::kGamepaddisconnected);
}
// XR-backed controllers are only exposed via this path for WebVR (not
// WebXR). Controllers are only exposed during VR presentation, so we can
// just check if WebVR has been used. WebXR cannot be used once WebVR has been.
bool ShouldIncludeXrGamepads(LocalFrame* frame) {
if (!frame)
return false;
Document* document = frame->GetDocument();
if (!document)
return false;
return NavigatorVR::HasWebVrBeenUsed(*document);
}
} // namespace
// static
......@@ -132,13 +117,12 @@ void NavigatorGamepad::SampleGamepads() {
device::Gamepads gamepads;
gamepad_dispatcher_->SampleGamepads(gamepads);
bool include_xr_gamepads = ShouldIncludeXrGamepads(GetFrame());
for (uint32_t i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
device::Gamepad& device_gamepad = gamepads.items[i];
bool hide_xr_gamepad = device_gamepad.is_xr && !include_xr_gamepads;
if (hide_xr_gamepad) {
// All WebXR gamepads should be hidden
if (device_gamepad.is_xr) {
gamepads_back_->Set(i, nullptr);
} else if (device_gamepad.connected) {
Gamepad* gamepad = gamepads_back_->item(i);
......
......@@ -164,7 +164,6 @@ modules_idl_files =
"gamepad/gamepad_event.idl",
"gamepad/gamepad_haptic_actuator.idl",
"gamepad/gamepad_list.idl",
"gamepad/gamepad_pose.idl",
"geolocation/geolocation.idl",
"geolocation/geolocation_coordinates.idl",
"geolocation/geolocation_position.idl",
......@@ -347,13 +346,6 @@ modules_idl_files =
"sms/sms_receiver.idl",
"storage/storage.idl",
"storage/storage_event.idl",
"vr/vr_display.idl",
"vr/vr_display_capabilities.idl",
"vr/vr_display_event.idl",
"vr/vr_eye_parameters.idl",
"vr/vr_frame_data.idl",
"vr/vr_pose.idl",
"vr/vr_stage_parameters.idl",
"wake_lock/wake_lock.idl",
"wake_lock/wake_lock_sentinel.idl",
"webaudio/analyser_node.idl",
......@@ -802,8 +794,6 @@ modules_dictionary_idl_files =
"speech/speech_synthesis_error_event_init.idl",
"speech/speech_synthesis_event_init.idl",
"storage/storage_event_init.idl",
"vr/vr_display_event_init.idl",
"vr/vr_layer_init.idl",
"webaudio/analyser_options.idl",
"webaudio/audio_buffer_options.idl",
"webaudio/audio_buffer_source_options.idl",
......@@ -1012,7 +1002,6 @@ modules_dependency_idl_files =
"srcobject/html_media_element_src_object.idl",
"storage/window_storage.idl",
"vibration/navigator_vibration.idl",
"vr/navigator_vr.idl",
"wake_lock/navigator_wake_lock.idl",
"wake_lock/worker_navigator_wake_lock.idl",
"webdatabase/window_web_database.idl",
......
......@@ -74,8 +74,6 @@
#include "third_party/blink/renderer/modules/storage/dom_window_storage_controller.h"
#include "third_party/blink/renderer/modules/storage/inspector_dom_storage_agent.h"
#include "third_party/blink/renderer/modules/storage/storage_namespace.h"
#include "third_party/blink/renderer/modules/vr/navigator_vr.h"
#include "third_party/blink/renderer/modules/vr/vr_controller.h"
#include "third_party/blink/renderer/modules/webaudio/audio_graph_tracer.h"
#include "third_party/blink/renderer/modules/webaudio/inspector_web_audio_agent.h"
#include "third_party/blink/renderer/modules/webdatabase/database_client.h"
......@@ -241,8 +239,6 @@ void ModulesInitializer::OnClearWindowObjectInMainWorld(
NavigatorGamepad::From(document);
NavigatorServiceWorker::From(document);
DOMWindowStorageController::From(document);
if (RuntimeEnabledFeatures::WebVREnabled(document.GetExecutionContext()))
NavigatorVR::From(document);
if (RuntimeEnabledFeatures::WebXREnabled(document.GetExecutionContext()))
NavigatorXR::From(document);
if (RuntimeEnabledFeatures::PresentationEnabled() &&
......
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("vr") {
sources = [
"navigator_vr.cc",
"navigator_vr.h",
"vr_controller.cc",
"vr_controller.h",
"vr_display.cc",
"vr_display.h",
"vr_display_capabilities.h",
"vr_display_event.cc",
"vr_display_event.h",
"vr_eye_parameters.cc",
"vr_eye_parameters.h",
"vr_field_of_view.h",
"vr_frame_data.cc",
"vr_frame_data.h",
"vr_pose.cc",
"vr_pose.h",
"vr_stage_parameters.cc",
"vr_stage_parameters.h",
]
deps = [
"//device/vr/public/mojom:mojom_blink",
"//services/metrics/public/cpp:ukm_builders",
]
}
bajones@chromium.org
klausw@chromium.org
# TEAM: xr-dev@chromium.org
# COMPONENT: Blink>WebXR>VR
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/vr/navigator_vr.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.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/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/vr/vr_controller.h"
#include "third_party/blink/renderer/modules/vr/vr_pose.h"
#include "third_party/blink/renderer/modules/xr/navigator_xr.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
namespace blink {
namespace {
const char kFeaturePolicyBlockedMessage[] =
"Access to the feature \"vr\" is disallowed by feature policy.";
const char kNotAssociatedWithDocumentMessage[] =
"The object is no longer associated with a document.";
const char kCannotUseBothNewAndOldAPIMessage[] =
"Cannot use navigator.getVRDisplays if WebXR is already in use.";
} // namespace
bool NavigatorVR::HasWebVrBeenUsed(Document& document) {
if (!document.GetFrame())
return false;
Navigator& navigator = *document.GetFrame()->DomWindow()->navigator();
NavigatorVR* supplement = Supplement<Navigator>::From<NavigatorVR>(navigator);
if (!supplement) {
// No supplement means WebVR has not been used.
return false;
}
return NavigatorVR::From(navigator).did_use_webvr_;
}
NavigatorVR* NavigatorVR::From(Document& document) {
if (!document.GetFrame())
return nullptr;
Navigator& navigator = *document.GetFrame()->DomWindow()->navigator();
return &From(navigator);
}
NavigatorVR& NavigatorVR::From(Navigator& navigator) {
NavigatorVR* supplement = Supplement<Navigator>::From<NavigatorVR>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorVR>(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
ScriptPromise NavigatorVR::getVRDisplays(ScriptState* script_state,
Navigator& navigator) {
if (!navigator.GetFrame()) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError,
kNotAssociatedWithDocumentMessage));
}
return NavigatorVR::From(navigator).getVRDisplays(script_state);
}
ScriptPromise NavigatorVR::getVRDisplays(ScriptState* script_state) {
did_use_webvr_ = true;
auto* document = GetDocument();
if (!document) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError,
kNotAssociatedWithDocumentMessage));
}
if (!did_log_getVRDisplays_ && document->IsInMainFrame()) {
did_log_getVRDisplays_ = true;
ukm::builders::XR_WebXR(document->UkmSourceID())
.SetDidRequestAvailableDevices(1)
.Record(document->UkmRecorder());
}
if (!document->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kSecurityError,
kFeaturePolicyBlockedMessage));
}
// Block developers from using WebVR if they've already used WebXR.
if (NavigatorXR::HasWebXrBeenUsed(*document)) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError,
kCannotUseBothNewAndOldAPIMessage));
}
Deprecation::CountDeprecation(*document, WebFeature::kVRGetDisplays);
ExecutionContext* execution_context = ExecutionContext::From(script_state);
if (!execution_context->IsSecureContext())
UseCounter::Count(*document, WebFeature::kVRGetDisplaysInsecureOrigin);
Platform::Current()->RecordRapporURL("VR.WebVR.GetDisplays", document->Url());
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
Controller()->GetDisplays(resolver);
return promise;
}
VRController* NavigatorVR::Controller() {
if (!GetSupplementable()->GetFrame())
return nullptr;
if (!controller_) {
controller_ = MakeGarbageCollected<VRController>(this);
controller_->SetListeningForActivate(focused_ && listening_for_activate_);
controller_->FocusChanged();
}
return controller_;
}
Document* NavigatorVR::GetDocument() {
if (!GetSupplementable() || !GetSupplementable()->GetFrame())
return nullptr;
return GetSupplementable()->GetFrame()->GetDocument();
}
void NavigatorVR::Trace(blink::Visitor* visitor) {
visitor->Trace(controller_);
Supplement<Navigator>::Trace(visitor);
}
NavigatorVR::NavigatorVR(Navigator& navigator)
: Supplement<Navigator>(navigator),
FocusChangedObserver(navigator.GetFrame()->GetPage()) {
navigator.GetFrame()->DomWindow()->RegisterEventListenerObserver(this);
FocusedFrameChanged();
}
NavigatorVR::~NavigatorVR() = default;
const char NavigatorVR::kSupplementName[] = "NavigatorVR";
void NavigatorVR::EnqueueVREvent(VRDisplayEvent* event) {
if (!GetSupplementable()->GetFrame())
return;
GetSupplementable()->GetFrame()->DomWindow()->EnqueueWindowEvent(
*event, TaskType::kMiscPlatformAPI);
}
void NavigatorVR::DispatchVREvent(VRDisplayEvent* event) {
if (!(GetSupplementable()->GetFrame()))
return;
LocalDOMWindow* window = GetSupplementable()->GetFrame()->DomWindow();
DCHECK(window);
event->SetTarget(window);
window->DispatchEvent(*event);
}
void NavigatorVR::FocusedFrameChanged() {
bool focused = IsFrameFocused(GetSupplementable()->GetFrame());
if (focused == focused_)
return;
focused_ = focused;
if (controller_) {
controller_->SetListeningForActivate(listening_for_activate_ && focused);
controller_->FocusChanged();
}
}
void NavigatorVR::DidAddEventListener(LocalDOMWindow* window,
const AtomicString& event_type) {
if (event_type == event_type_names::kVrdisplayactivate) {
listening_for_activate_ = true;
Controller()->SetListeningForActivate(focused_);
} else if (event_type == event_type_names::kVrdisplayconnect) {
// If the page is listening for connection events make sure we've created a
// controller so that we'll be notified of new devices.
Controller();
}
}
void NavigatorVR::DidRemoveEventListener(LocalDOMWindow* window,
const AtomicString& event_type) {
if (event_type == event_type_names::kVrdisplayactivate &&
!window->HasEventListeners(event_type_names::kVrdisplayactivate)) {
listening_for_activate_ = false;
Controller()->SetListeningForActivate(false);
}
}
void NavigatorVR::DidRemoveAllEventListeners(LocalDOMWindow* window) {
if (!controller_)
return;
controller_->SetListeningForActivate(false);
listening_for_activate_ = false;
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_VR_NAVIGATOR_VR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_VR_NAVIGATOR_VR_H_
#include "base/macros.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/page/focus_changed_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/vr/vr_display.h"
#include "third_party/blink/renderer/modules/vr/vr_display_event.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Document;
class VRController;
class MODULES_EXPORT NavigatorVR final
: public GarbageCollected<NavigatorVR>,
public Supplement<Navigator>,
public LocalDOMWindow::EventListenerObserver,
public FocusChangedObserver {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorVR);
public:
static const char kSupplementName[];
// Returns whether WebVR has beeen used in the document.
// If no supplement has been created, it returns false without creating one.
// This allows it to be used in cases where creating objects is not allowed,
// such as within NavigatorGamepad::DidAddEventListener().
static bool HasWebVrBeenUsed(Document&);
static NavigatorVR* From(Document&);
static NavigatorVR& From(Navigator&);
explicit NavigatorVR(Navigator&);
~NavigatorVR() override;
// Legacy API
static ScriptPromise getVRDisplays(ScriptState*, Navigator&);
ScriptPromise getVRDisplays(ScriptState*);
VRController* Controller();
Document* GetDocument();
bool IsFocused() const { return focused_; }
// Queues up event to be fired soon.
void EnqueueVREvent(VRDisplayEvent*);
// Dispatches an event immediately.
void DispatchVREvent(VRDisplayEvent*);
// Inherited from FocusChangedObserver.
void FocusedFrameChanged() override;
// Inherited from LocalDOMWindow::EventListenerObserver.
void DidAddEventListener(LocalDOMWindow*, const AtomicString&) override;
void DidRemoveEventListener(LocalDOMWindow*, const AtomicString&) override;
void DidRemoveAllEventListeners(LocalDOMWindow*) override;
void Trace(blink::Visitor*) override;
private:
friend class VRDisplay;
friend class VRGetDevicesCallback;
void FireVRDisplayPresentChange(VRDisplay*);
Member<VRController> controller_;
// Whether this page is listening for vrdisplayactivate event.
bool listening_for_activate_ = false;
bool focused_ = false;
bool did_use_webvr_ = false;
// Metrics data - indicates whether we've already measured this data so we
// don't do it every frame.
bool did_log_getVRDisplays_ = false;
DISALLOW_COPY_AND_ASSIGN(NavigatorVR);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_VR_NAVIGATOR_VR_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://immersive-web.github.io/webvr/spec/1.1/#interface-navigator
[
ImplementedAs=NavigatorVR
] partial interface Navigator {
[RuntimeEnabled=WebVR, CallWith=ScriptState] Promise<sequence<VRDisplay>> getVRDisplays();
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/vr/vr_controller.h"
#include "device/vr/public/mojom/vr_service.mojom-blink.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.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/frame/local_frame.h"
#include "third_party/blink/renderer/modules/vr/navigator_vr.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace blink {
VRController::VRController(NavigatorVR* navigator_vr)
: ContextLifecycleObserver(navigator_vr->GetDocument()),
navigator_vr_(navigator_vr),
feature_handle_for_scheduler_(
navigator_vr->GetDocument()->GetScheduler()->RegisterFeature(
SchedulingPolicy::Feature::kWebVR,
{SchedulingPolicy::RecordMetricsForBackForwardCache()})) {
// See https://bit.ly/2S0zRAS for task types.
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
navigator_vr->GetDocument()->GetTaskRunner(TaskType::kMiscPlatformAPI);
navigator_vr->GetDocument()->GetBrowserInterfaceBroker().GetInterface(
service_.BindNewPipeAndPassReceiver(task_runner));
service_.set_disconnect_handler(
WTF::Bind(&VRController::Dispose, WrapWeakPersistent(this)));
service_->SetClient(receiver_.BindNewPipeAndPassRemote(task_runner));
// Request display info. If we get it, we have a device.
service_->GetImmersiveVRDisplayInfo(WTF::Bind(
&VRController::OnImmersiveDisplayInfoReturned, WrapPersistent(this)));
// Request a non-immersive session immediately as WebVR 1.1 expects to be able
// to get non-immersive poses as soon as the display is returned.
device::mojom::blink::XRSessionOptionsPtr options =
device::mojom::blink::XRSessionOptions::New();
options->immersive = false;
options->is_legacy_webvr = true;
service_->RequestSession(
std::move(options),
WTF::Bind(&VRController::OnNonImmersiveSessionRequestReturned,
WrapPersistent(this)));
}
VRController::~VRController() = default;
bool VRController::ShouldResolveGetDisplays() {
return have_latest_immersive_info_ && nonimmersive_session_returned_;
}
void VRController::EnsureDisplay() {
if (!display_) {
// We have a display for the first time.
display_ = VRDisplay::Create(navigator_vr_);
if (pending_listening_for_activate_) {
SetListeningForActivate(pending_listening_for_activate_);
pending_listening_for_activate_ = false;
}
display_->OnConnected();
display_->FocusChanged();
}
// If we have a non-immersive session, give it to the display so we can
// satisfy inline animation frame requests.
if (nonimmersive_session_)
display_->SetNonImmersiveSession(std::move(nonimmersive_session_));
}
void VRController::GetDisplays(ScriptPromiseResolver* resolver) {
// If we've previously synced the VRDisplays or no longer have a valid service
// connection just return the current list. In the case of the service being
// disconnected this will be an empty array.
if (!service_ || ShouldResolveGetDisplays()) {
LogGetDisplayResult();
HeapVector<Member<VRDisplay>> displays;
if (display_)
displays.push_back(display_);
resolver->Resolve(displays);
return;
}
// Otherwise we're still waiting for the full list of displays to be populated
// so queue up the promise resolver for resolution when OnGetDisplays is
// called.
pending_promise_resolvers_.push_back(resolver);
}
void VRController::SetListeningForActivate(bool listening) {
if (!service_ || !display_) {
pending_listening_for_activate_ = listening;
return;
}
if (listening_for_activate_ && listening) {
// We're already listening so leave things as is.
return;
}
listening_for_activate_ = listening;
if (listening)
service_->SetListeningForActivate(display_->GetDisplayClient());
else
service_->SetListeningForActivate(mojo::NullRemote());
}
void VRController::OnDeviceChanged() {
if (!have_latest_immersive_info_) {
// We're already underway checking if there is a device.
return;
}
have_latest_immersive_info_ = false;
// Get updated display info.
service_->GetImmersiveVRDisplayInfo(WTF::Bind(
&VRController::OnImmersiveDisplayInfoReturned, WrapPersistent(this)));
}
void VRController::FocusChanged() {
if (display_)
display_->FocusChanged();
}
void VRController::OnImmersiveDisplayInfoReturned(
device::mojom::blink::VRDisplayInfoPtr info) {
if (disposed_) {
return;
}
if (info) {
has_presentation_capable_display_ = info->capabilities->can_present;
} else {
has_presentation_capable_display_ = false;
}
if (info) {
EnsureDisplay();
display_->OnChanged(std::move(info), true /* is_immersive */);
}
// We know whether there is a display at this point.
have_latest_immersive_info_ = true;
if (ShouldResolveGetDisplays())
OnGetDisplays();
}
void VRController::LogGetDisplayResult() {
Document* doc = navigator_vr_->GetDocument();
if (display_ && doc && doc->IsInMainFrame()) {
ukm::builders::XR_WebXR ukm_builder(doc->UkmSourceID());
ukm_builder.SetReturnedDevice(1);
if (has_presentation_capable_display_) {
ukm_builder.SetReturnedPresentationCapableDevice(1);
}
ukm_builder.Record(doc->UkmRecorder());
}
}
void VRController::OnGetDisplays() {
while (!pending_promise_resolvers_.IsEmpty()) {
LogGetDisplayResult();
HeapVector<Member<VRDisplay>> displays;
if (display_)
displays.push_back(display_);
auto promise_resolver = pending_promise_resolvers_.TakeFirst();
OnGetDevicesSuccess(promise_resolver, displays);
}
}
void VRController::OnNonImmersiveSessionRequestReturned(
device::mojom::blink::RequestSessionResultPtr result) {
if (disposed_) {
return;
}
nonimmersive_session_returned_ = true;
nonimmersive_session_ = std::move(result);
// If we support non-immersive, we have a display.
if (nonimmersive_session_->is_session())
EnsureDisplay();
if (ShouldResolveGetDisplays())
OnGetDisplays();
}
void VRController::OnGetDevicesSuccess(ScriptPromiseResolver* resolver,
VRDisplayVector displays) {
bool display_supports_presentation = false;
for (auto display : displays) {
if (display->capabilities()->canPresent()) {
display_supports_presentation = true;
}
}
if (display_supports_presentation) {
ExecutionContext* execution_context =
ExecutionContext::From(resolver->GetScriptState());
UseCounter::Count(execution_context,
WebFeature::kVRGetDisplaysSupportsPresent);
}
resolver->Resolve(displays);
}
void VRController::ContextDestroyed(ExecutionContext*) {
Dispose();
}
void VRController::Dispose() {
// If the document context was destroyed, shut down the client connection
// and never call the mojo service again.
service_.reset();
receiver_.reset();
// Shutdown all displays' message pipe
if (display_) {
display_->Dispose();
display_ = nullptr;
}
disposed_ = true;
// Ensure that any outstanding getDisplays promises are resolved.
OnGetDisplays();
}
void VRController::Trace(blink::Visitor* visitor) {
visitor->Trace(navigator_vr_);
visitor->Trace(display_);
visitor->Trace(pending_promise_resolvers_);
ContextLifecycleObserver::Trace(visitor);
}
} // namespace blink
This diff is collapsed.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
enum VREye {
"left",
"right"
};
// https://w3c.github.io/webvr/#interface-vrdisplay
[
ActiveScriptWrappable,
RuntimeEnabled=WebVR
] interface VRDisplay : EventTarget {
// An identifier for this device unique across VRDisplays.
readonly attribute unsigned long displayId;
// A user-readable name identifying the device.
[MeasureAs=VRDisplayDisplayName] readonly attribute DOMString displayName;
readonly attribute boolean isPresenting;
// [Constant]?
readonly attribute VRDisplayCapabilities capabilities;
readonly attribute VRStageParameters stageParameters;
[MeasureAs=VRDisplayGetFrameData] boolean getFrameData(VRFrameData frameData);
attribute double depthNear;
attribute double depthFar;
VREyeParameters getEyeParameters(VREye whichEye);
long requestAnimationFrame(FrameRequestCallback callback);
void cancelAnimationFrame(long handle);
// Begin presenting to the VRDisplay. Must be called in response to a user
// gesture. Repeat calls while already presenting will update the layer
// being displayed.
[CallWith=ScriptState] Promise<void> requestPresent(sequence<VRLayerInit> layers);
// Stops presenting to the VRDisplay.
[CallWith=ScriptState] Promise<void> exitPresent();
// Get the sources currently being presented.
sequence<VRLayerInit> getLayers();
// The layer provided to the `VRDisplay` will be captured and presented
// in the HMD. Calling this function has the same effect on the source
// canvas as any other operation that uses its source image, and canvases
// created without preserveDrawingBuffer set to true will be cleared.
void submitFrame();
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_CAPABILITIES_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_CAPABILITIES_H_
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class VRDisplayCapabilities final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
VRDisplayCapabilities() = default;
bool hasPosition() const { return has_position_; }
bool hasExternalDisplay() const { return has_external_display_; }
bool canPresent() const { return can_present_; }
unsigned maxLayers() const { return max_layers_; }
void SetHasPosition(bool value) { has_position_ = value; }
void SetHasExternalDisplay(bool value) { has_external_display_ = value; }
void SetCanPresent(bool value) { can_present_ = value; }
void SetMaxLayers(unsigned value) { max_layers_ = value; }
private:
bool has_position_ = false;
bool has_external_display_ = false;
bool can_present_ = false;
unsigned max_layers_ = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_CAPABILITIES_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vrdisplaycapabilities
[
RuntimeEnabled=WebVR
] interface VRDisplayCapabilities {
// Whether or not the VR display is capable of reporting user position.
// If false position may still be reported using simulated values like
// neck modeling.
readonly attribute boolean hasPosition;
// Whether or not the VRDisplay is separate from the devices primary display.
// If presenting VR content will obscure other content on the device, this
// should be false. When false VR content should not be mirrored.
readonly attribute boolean hasExternalDisplay;
// Whether or not the VRDisplay is capable of presenting content to an HMD or
// similar device. Can be used to indicate magic window devices that are
// capable of 6DoF tracking but for which requestPresent is not meaningful. If
// false then calls to requestPresent should always fail, and getEyeParameters
// should return null.
readonly attribute boolean canPresent;
// The maximum length of the array that VRDisplay.requestPresent will accept.
readonly attribute unsigned long maxLayers;
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/vr/vr_display_event.h"
namespace blink {
namespace {
String VRDisplayEventReasonToString(
device::mojom::blink::VRDisplayEventReason reason) {
switch (reason) {
case device::mojom::blink::VRDisplayEventReason::NONE:
return "";
case device::mojom::blink::VRDisplayEventReason::NAVIGATION:
return "navigation";
case device::mojom::blink::VRDisplayEventReason::MOUNTED:
return "mounted";
case device::mojom::blink::VRDisplayEventReason::UNMOUNTED:
return "unmounted";
}
NOTREACHED();
return "";
}
} // namespace
VRDisplayEvent* VRDisplayEvent::Create(
const AtomicString& type,
VRDisplay* display,
device::mojom::blink::VRDisplayEventReason reason) {
return MakeGarbageCollected<VRDisplayEvent>(
type, display, VRDisplayEventReasonToString(reason));
}
VRDisplayEvent::VRDisplayEvent() = default;
VRDisplayEvent::VRDisplayEvent(const AtomicString& type,
VRDisplay* display,
String reason)
: Event(type, Bubbles::kYes, Cancelable::kNo),
display_(display),
reason_(reason) {}
VRDisplayEvent::VRDisplayEvent(const AtomicString& type,
const VRDisplayEventInit* initializer)
: Event(type, initializer) {
if (initializer->hasDisplay())
display_ = initializer->display();
if (initializer->hasReason())
reason_ = initializer->reason();
}
VRDisplayEvent::~VRDisplayEvent() = default;
const AtomicString& VRDisplayEvent::InterfaceName() const {
return event_interface_names::kVRDisplayEvent;
}
void VRDisplayEvent::Trace(blink::Visitor* visitor) {
visitor->Trace(display_);
Event::Trace(visitor);
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_EVENT_H_
#include "third_party/blink/renderer/modules/event_modules.h"
#include "third_party/blink/renderer/modules/vr/vr_display.h"
#include "third_party/blink/renderer/modules/vr/vr_display_event_init.h"
namespace blink {
class VRDisplayEvent final : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
static VRDisplayEvent* Create() {
return MakeGarbageCollected<VRDisplayEvent>();
}
static VRDisplayEvent* Create(const AtomicString& type,
VRDisplay* display,
String reason) {
return MakeGarbageCollected<VRDisplayEvent>(type, display, reason);
}
static VRDisplayEvent* Create(const AtomicString& type,
VRDisplay*,
device::mojom::blink::VRDisplayEventReason);
static VRDisplayEvent* Create(const AtomicString& type,
const VRDisplayEventInit* initializer) {
return MakeGarbageCollected<VRDisplayEvent>(type, initializer);
}
VRDisplayEvent();
VRDisplayEvent(const AtomicString& type, VRDisplay*, String);
VRDisplayEvent(const AtomicString&, const VRDisplayEventInit*);
~VRDisplayEvent() override;
VRDisplay* display() const { return display_.Get(); }
const String& reason() const { return reason_; }
const AtomicString& InterfaceName() const override;
void Trace(blink::Visitor*) override;
private:
Member<VRDisplay> display_;
String reason_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_DISPLAY_EVENT_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
enum VRDisplayEventReason {
"connected",
"disconnected",
"navigation",
"mounted",
"unmounted"
};
// https://w3c.github.io/webvr/#interface-vrdisplayevent
[
RuntimeEnabled=WebVR,
Constructor(DOMString type, optional VRDisplayEventInit eventInitDict)
] interface VRDisplayEvent : Event {
readonly attribute VRDisplay display;
readonly attribute VRDisplayEventReason reason;
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vrdisplayeventinit
dictionary VRDisplayEventInit : EventInit {
// TODO(foolip): |display| should be required and not nullable.
// https://crbug.com/647693
// https://github.com/w3c/webvr/issues/83
VRDisplay? display;
VRDisplayEventReason reason;
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vreyeparameters
[
RuntimeEnabled=WebVR
] interface VREyeParameters {
/* These values will vary after a FOV has been set */
[DeprecateAs=VREyeParametersOffset] readonly attribute Float32Array offset;
readonly attribute unsigned long renderWidth;
readonly attribute unsigned long renderHeight;
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_FIELD_OF_VIEW_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_FIELD_OF_VIEW_H_
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class VRFieldOfView final : public GarbageCollected<VRFieldOfView> {
public:
VRFieldOfView()
: up_degrees_(0.0),
down_degrees_(0.0),
left_degrees_(0.0),
right_degrees_(0.0) {}
VRFieldOfView(double up_degrees,
double right_degrees,
double down_degrees,
double left_degrees)
: up_degrees_(0.0),
down_degrees_(0.0),
left_degrees_(0.0),
right_degrees_(0.0) {}
explicit VRFieldOfView(const VRFieldOfView& fov)
: up_degrees_(fov.up_degrees_),
down_degrees_(fov.down_degrees_),
left_degrees_(fov.left_degrees_),
right_degrees_(fov.right_degrees_) {}
double UpDegrees() const { return up_degrees_; }
double DownDegrees() const { return down_degrees_; }
double LeftDegrees() const { return left_degrees_; }
double RightDegrees() const { return right_degrees_; }
void SetUpDegrees(double value) { up_degrees_ = value; }
void SetDownDegrees(double value) { down_degrees_ = value; }
void SetLeftDegrees(double value) { left_degrees_ = value; }
void SetRightDegrees(double value) { right_degrees_ = value; }
void Trace(blink::Visitor* visitor) {}
private:
double up_degrees_;
double down_degrees_;
double left_degrees_;
double right_degrees_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_VR_VR_FIELD_OF_VIEW_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vrframedata
[
RuntimeEnabled=WebVR,
Constructor
] interface VRFrameData {
readonly attribute Float32Array leftProjectionMatrix;
readonly attribute Float32Array leftViewMatrix;
readonly attribute Float32Array rightProjectionMatrix;
readonly attribute Float32Array rightViewMatrix;
readonly attribute VRPose pose;
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
typedef (HTMLCanvasElement or OffscreenCanvas) VRSource;
// https://w3c.github.io/webvr/#interface-vrlayerinit
dictionary VRLayerInit {
// The canvas to be presented to the VRDisplay
VRSource? source = null;
// The left and right bounds contain 4 git statvalues defining the texture bounds
// within the canvas to present to the eye in UV space.
// [0] left offset of the bounds (0.0 - 1.0)
// [1] top offset of the bounds (0.0 - 1.0)
// [2] width of the bounds (0.0 - 1.0)
// [3] height of the bounds (0.0 - 1.0)
sequence<float> leftBounds = []; //= [0.0, 0.0, 0.5, 1.0];
sequence<float> rightBounds = []; //= [0.5, 0.0, 0.5, 1.0];
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vrpose
[
RuntimeEnabled=WebVR
] interface VRPose {
readonly attribute Float32Array? position;
[MeasureAs=VRPoseLinearVelocity] readonly attribute Float32Array? linearVelocity;
[MeasureAs=VRPoseLinearAcceleration] readonly attribute Float32Array? linearAcceleration;
readonly attribute Float32Array? orientation;
[MeasureAs=VRPoseAngularVelocity] readonly attribute Float32Array? angularVelocity;
[MeasureAs=VRPoseAngularAcceleration] readonly attribute Float32Array? angularAcceleration;
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/webvr/#interface-vrstageparameters
[
RuntimeEnabled=WebVR
] interface VRStageParameters {
// A 16 element array containing the components of a 4x4 transform
// matrix. This matrix transforms the sitting space position
// returned by get{Immediate}Pose() to a standing space position.
readonly attribute Float32Array sittingToStandingTransform;
// Dimensions of the play area bounds. The bounds are defined
// as an axis aligned rectangle on the floor.
// The center of the rectangle is at (0,0,0) in standing space
// coordinates.
// These bounds are defined for safety purposes.
// Content should not require the user to move beyond these
// bounds; however, it is possible for the user to ignore
// the bounds resulting in position values outside of
// this rectangle.
readonly attribute float sizeX;
readonly attribute float sizeZ;
};
......@@ -10,27 +10,12 @@
#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/inspector/console_message.h"
#include "third_party/blink/renderer/modules/vr/navigator_vr.h"
#include "third_party/blink/renderer/modules/xr/xr.h"
namespace blink {
const char NavigatorXR::kSupplementName[] = "NavigatorXR";
bool NavigatorXR::HasWebXrBeenUsed(Document& document) {
if (!document.GetFrame())
return false;
Navigator& navigator = *document.GetFrame()->DomWindow()->navigator();
NavigatorXR* supplement = Supplement<Navigator>::From<NavigatorXR>(navigator);
if (!supplement) {
// No supplement means WebXR has not been used.
return false;
}
return NavigatorXR::From(navigator).did_use_webxr_;
}
NavigatorXR* NavigatorXR::From(Document& document) {
if (!document.GetFrame())
return nullptr;
......@@ -72,16 +57,9 @@ XR* NavigatorXR::xr() {
}
if (!xr_) {
if (NavigatorVR::HasWebVrBeenUsed(*document)) {
document->AddConsoleMessage(ConsoleMessage::Create(
mojom::ConsoleMessageSource::kOther,
mojom::ConsoleMessageLevel::kError,
"Cannot use navigator.xr if WebVR is already in use."));
return nullptr;
}
did_use_webxr_ = true;
xr_ = XR::Create(*document->GetFrame(), document->UkmSourceID());
}
return xr_;
}
......
......@@ -22,11 +22,6 @@ class MODULES_EXPORT NavigatorXR final : public GarbageCollected<NavigatorXR>,
public:
static const char kSupplementName[];
// Returns whether WebXR has beeen used in the document.
// If no supplement has been created, it returns false without creating one.
// TODO(https://crbug.com/960132): Remove when WebVR is removed.
static bool HasWebXrBeenUsed(Document&);
static NavigatorXR* From(Document&);
static NavigatorXR& From(Navigator&);
......@@ -42,8 +37,6 @@ class MODULES_EXPORT NavigatorXR final : public GarbageCollected<NavigatorXR>,
Member<XR> xr_;
bool did_use_webxr_ = false;
// Gates metrics collection once per local DOM window frame.
bool did_log_navigator_xr_ = false;
......
......@@ -1766,9 +1766,6 @@
status: "stable",
depends_on: ["WebUSB"],
},
{
name: "WebVR",
},
{
name: "WebVTTRegions",
status: "experimental",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment