Commit a10038e6 authored by Luis G Garcia's avatar Luis G Garcia Committed by Commit Bot

WebXR: Validate view belongs to provided frame.

Validate the provided view for XrWebGLBinding::getCameraImage(...) is
contained within the provided frame.

Design Doc: https://docs.google.com/document/d/1X4zhSCYqzOKrbC4iGA5SOV983vmI0mqz9tQxRvyrYlk/edit?usp=sharing

Fixed: 1100978
Change-Id: I0177303e67d7ffc7da7a79d5b781d5f2b9b51959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315639
Commit-Queue: Luis Garcia <luisggarcia@google.com>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791967}
parent 281c417f
...@@ -47,7 +47,7 @@ XRFrame::XRFrame(XRSession* session, XRWorldInformation* world_information) ...@@ -47,7 +47,7 @@ XRFrame::XRFrame(XRSession* session, XRWorldInformation* world_information)
: world_information_(world_information), session_(session) {} : world_information_(world_information), session_(session) {}
XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space, XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space,
ExceptionState& exception_state) const { ExceptionState& exception_state) {
DVLOG(3) << __func__; DVLOG(3) << __func__;
if (!is_active_) { if (!is_active_) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
...@@ -92,8 +92,7 @@ XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space, ...@@ -92,8 +92,7 @@ XRViewerPose* XRFrame::getViewerPose(XRReferenceSpace* reference_space,
return nullptr; return nullptr;
} }
return MakeGarbageCollected<XRViewerPose>(session(), return MakeGarbageCollected<XRViewerPose>(this, *offset_space_from_viewer);
*offset_space_from_viewer);
} }
XRAnchorSet* XRFrame::trackedAnchors() const { XRAnchorSet* XRFrame::trackedAnchors() const {
......
...@@ -42,7 +42,7 @@ class XRFrame final : public ScriptWrappable { ...@@ -42,7 +42,7 @@ class XRFrame final : public ScriptWrappable {
XRSession* session() const { return session_; } XRSession* session() const { return session_; }
XRViewerPose* getViewerPose(XRReferenceSpace*, ExceptionState&) const; XRViewerPose* getViewerPose(XRReferenceSpace*, ExceptionState&);
XRPose* getPose(XRSpace*, XRSpace*, ExceptionState&); XRPose* getPose(XRSpace*, XRSpace*, ExceptionState&);
XRWorldInformation* worldInformation() const { return world_information_; } XRWorldInformation* worldInformation() const { return world_information_; }
XRAnchorSet* trackedAnchors() const; XRAnchorSet* trackedAnchors() const;
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#include "third_party/blink/renderer/modules/xr/xr_view.h" #include "third_party/blink/renderer/modules/xr/xr_view.h"
#include "third_party/blink/renderer/modules/xr/xr_frame.h" #include "third_party/blink/renderer/modules/xr/xr_frame.h"
#include "third_party/blink/renderer/modules/xr/xr_session.h"
#include "third_party/blink/renderer/modules/xr/xr_utils.h" #include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include "third_party/blink/renderer/platform/geometry/float_point_3d.h" #include "third_party/blink/renderer/platform/geometry/float_point_3d.h"
namespace blink { namespace blink {
XRView::XRView(XRSession* session, const XRViewData& view_data) XRView::XRView(XRFrame* frame, const XRViewData& view_data)
: eye_(view_data.Eye()), session_(session) { : eye_(view_data.Eye()), frame_(frame) {
switch (eye_) { switch (eye_) {
case kEyeLeft: case kEyeLeft:
eye_string_ = "left"; eye_string_ = "left";
...@@ -29,8 +28,12 @@ XRView::XRView(XRSession* session, const XRViewData& view_data) ...@@ -29,8 +28,12 @@ XRView::XRView(XRSession* session, const XRViewData& view_data)
transformationMatrixToDOMFloat32Array(view_data.ProjectionMatrix()); transformationMatrixToDOMFloat32Array(view_data.ProjectionMatrix());
} }
XRFrame* XRView::frame() const {
return frame_;
}
XRSession* XRView::session() const { XRSession* XRView::session() const {
return session_; return frame_->session();
} }
DOMFloat32Array* XRView::projectionMatrix() const { DOMFloat32Array* XRView::projectionMatrix() const {
...@@ -142,7 +145,7 @@ XRRigidTransform* XRView::transform() const { ...@@ -142,7 +145,7 @@ XRRigidTransform* XRView::transform() const {
} }
void XRView::Trace(Visitor* visitor) const { void XRView::Trace(Visitor* visitor) const {
visitor->Trace(session_); visitor->Trace(frame_);
visitor->Trace(projection_matrix_); visitor->Trace(projection_matrix_);
visitor->Trace(ref_space_from_eye_); visitor->Trace(ref_space_from_eye_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
namespace blink { namespace blink {
class XRFrame;
class XRSession; class XRSession;
class XRViewData; class XRViewData;
...@@ -24,13 +25,14 @@ class MODULES_EXPORT XRView final : public ScriptWrappable { ...@@ -24,13 +25,14 @@ class MODULES_EXPORT XRView final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
XRView(XRSession*, const XRViewData&); XRView(XRFrame*, const XRViewData&);
enum XREye { kEyeNone = 0, kEyeLeft = 1, kEyeRight = 2 }; enum XREye { kEyeNone = 0, kEyeLeft = 1, kEyeRight = 2 };
const String& eye() const { return eye_string_; } const String& eye() const { return eye_string_; }
XREye EyeValue() const { return eye_; } XREye EyeValue() const { return eye_; }
XRFrame* frame() const;
XRSession* session() const; XRSession* session() const;
DOMFloat32Array* projectionMatrix() const; DOMFloat32Array* projectionMatrix() const;
XRRigidTransform* transform() const; XRRigidTransform* transform() const;
...@@ -47,7 +49,7 @@ class MODULES_EXPORT XRView final : public ScriptWrappable { ...@@ -47,7 +49,7 @@ class MODULES_EXPORT XRView final : public ScriptWrappable {
private: private:
XREye eye_; XREye eye_;
String eye_string_; String eye_string_;
Member<XRSession> session_; Member<XRFrame> frame_;
Member<XRRigidTransform> ref_space_from_eye_; Member<XRRigidTransform> ref_space_from_eye_;
Member<DOMFloat32Array> projection_matrix_; Member<DOMFloat32Array> projection_matrix_;
}; };
......
...@@ -4,23 +4,31 @@ ...@@ -4,23 +4,31 @@
#include "third_party/blink/renderer/modules/xr/xr_viewer_pose.h" #include "third_party/blink/renderer/modules/xr/xr_viewer_pose.h"
#include "third_party/blink/renderer/modules/xr/xr_frame.h"
#include "third_party/blink/renderer/modules/xr/xr_rigid_transform.h" #include "third_party/blink/renderer/modules/xr/xr_rigid_transform.h"
#include "third_party/blink/renderer/modules/xr/xr_session.h" #include "third_party/blink/renderer/modules/xr/xr_session.h"
#include "third_party/blink/renderer/modules/xr/xr_view.h" #include "third_party/blink/renderer/modules/xr/xr_view.h"
namespace blink { namespace blink {
XRViewerPose::XRViewerPose(XRSession* session, XRViewerPose::XRViewerPose(XRFrame* frame,
const TransformationMatrix& pose_model_matrix) const TransformationMatrix& pose_model_matrix)
: XRPose(pose_model_matrix, session->EmulatedPosition()) { : XRPose(pose_model_matrix, frame->session()->EmulatedPosition()) {
DVLOG(3) << __func__ << ": emulatedPosition()=" << emulatedPosition(); DVLOG(3) << __func__ << ": emulatedPosition()=" << emulatedPosition();
Vector<XRViewData>& view_data = session->views(); Vector<XRViewData>& view_data = frame->session()->views();
bool camera_access_enabled = frame->session()->IsFeatureEnabled(
device::mojom::XRSessionFeature::CAMERA_ACCESS);
// Snapshot the session's current views. // Snapshot the session's current views.
for (XRViewData& view : view_data) { for (XRViewData& view : view_data) {
view.UpdatePoseMatrix(transform_->TransformMatrix()); view.UpdatePoseMatrix(transform_->TransformMatrix());
views_.push_back(MakeGarbageCollected<XRView>(session, view)); XRView* xr_view = MakeGarbageCollected<XRView>(frame, view);
views_.push_back(xr_view);
if (camera_access_enabled) {
camera_views_.push_back(xr_view);
}
} }
} }
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
namespace blink { namespace blink {
class XRSession; class XRFrame;
class XRView; class XRView;
class XRViewerPose final : public XRPose { class XRViewerPose final : public XRPose {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
XRViewerPose(XRSession*, const TransformationMatrix&); XRViewerPose(XRFrame*, const TransformationMatrix&);
~XRViewerPose() override = default; ~XRViewerPose() override = default;
const HeapVector<Member<XRView>>& views() const { return views_; } const HeapVector<Member<XRView>>& views() const { return views_; }
......
...@@ -88,7 +88,9 @@ WebGLTexture* XRWebGLBinding::getCameraImage(XRFrame* frame, XRView* view) { ...@@ -88,7 +88,9 @@ WebGLTexture* XRWebGLBinding::getCameraImage(XRFrame* frame, XRView* view) {
return nullptr; return nullptr;
} }
// TODO(https://crbug.com/1100978): Verify view is in camera_views_. if (frame != view->frame()) {
return nullptr;
}
XRWebGLLayer* base_layer = view->session()->renderState()->baseLayer(); XRWebGLLayer* base_layer = view->session()->renderState()->baseLayer();
DCHECK(base_layer); DCHECK(base_layer);
......
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