Commit f7e31a7b authored by Lachlan Ford's avatar Lachlan Ford Committed by Commit Bot

Implemented querying of appcontainer support in OpenXR

If the browser is running in sandboxed mode on win32, only OpenXR
runtimes that support running in an appcontainer should be used.
Runtimes declare this support through the
XR_EXT_win32_appcontainer_compatible extension.

Fixes: 1036527
Change-Id: Ia4d18542439712e1d169b0b54588ab9b47489ef5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1979526
Commit-Queue: Lachlan Ford <laford@microsoft.com>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728773}
parent dc48f7ef
......@@ -227,6 +227,7 @@ if (enable_vr) {
"openxr/openxr_api_wrapper.h",
"openxr/openxr_controller.cc",
"openxr/openxr_controller.h",
"openxr/openxr_defs.h",
"openxr/openxr_device.cc",
"openxr/openxr_device.h",
"openxr/openxr_input_helper.cc",
......@@ -353,6 +354,7 @@ if (enable_openxr) {
include_dirs = [ "//third_party/openxr/src/include" ]
sources = [
"openxr/openxr_defs.h",
"openxr/openxr_util.cc",
"openxr/openxr_util.h",
"openxr/test/fake_openxr_impl_api.cc",
......
// Copyright 2019 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 DEVICE_VR_OPENXR_OPENXR_DEFS_H_
#define DEVICE_VR_OPENXR_OPENXR_DEFS_H_
namespace device {
constexpr char kWin32AppcontainerCompatibleExtensionName[] =
"XR_EXT_win32_appcontainer_compatible";
} // namespace device
#endif // DEVICE_VR_OPENXR_OPENXR_DEFS_H_
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "device/vr/openxr/openxr_util.h"
#include "device/vr/openxr/openxr_defs.h"
#include <d3d11.h>
#include <string>
......@@ -10,6 +11,8 @@
#include "base/stl_util.h"
#include "base/version.h"
#include "base/win/scoped_handle.h"
#include "build/build_config.h"
#include "components/version_info/version_info.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
......@@ -27,6 +30,31 @@ XrResult GetSystem(XrInstance instance, XrSystemId* system) {
return xrGetSystem(instance, &system_info, system);
}
#if defined(OS_WIN)
bool IsRunningInWin32AppContainer() {
base::win::ScopedHandle scopedProcessToken;
HANDLE processToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &processToken)) {
return false;
}
scopedProcessToken.Set(processToken);
BOOL isAppContainer;
DWORD dwSize = sizeof(BOOL);
if (!GetTokenInformation(scopedProcessToken.Get(), TokenIsAppContainer,
&isAppContainer, dwSize, &dwSize)) {
return false;
}
return isAppContainer;
}
#else
bool IsRunningInWin32AppContainer() {
return false;
}
#endif
XrResult CreateInstance(XrInstance* instance,
OpenXRInstanceMetadata* metadata) {
XrInstanceCreateInfo instance_create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
......@@ -72,6 +100,15 @@ XrResult CreateInstance(XrInstance* instance,
// the XR_KHR_D3D11_ENABLE_EXTENSION_NAME is required.
std::vector<const char*> extensions{XR_KHR_D3D11_ENABLE_EXTENSION_NAME};
// If we are in an app container, we must require the app container extension
// to ensure robust execution of the OpenXR runtime
if (IsRunningInWin32AppContainer()) {
// Add the win32 app container compatible extension to our list of
// extensions. If this runtime does not support execution in an app
// container environment, one of xrCreateInstance or xrGetSystem will fail.
extensions.push_back(kWin32AppcontainerCompatibleExtensionName);
}
// XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME, is required for optional
// functionality (unbounded reference spaces) and thus only requested if it is
// available.
......
......@@ -17,6 +17,7 @@
#include "base/optional.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "device/vr/openxr/openxr_defs.h"
#include "device/vr/test/test_hook.h"
#include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
......@@ -130,7 +131,8 @@ class OpenXrTestHelper : public device::ServiceTestHook {
// Properties of the mock OpenXR runtime that do not change are created
static constexpr const char* const kExtensions[] = {
XR_KHR_D3D11_ENABLE_EXTENSION_NAME};
XR_KHR_D3D11_ENABLE_EXTENSION_NAME,
device::kWin32AppcontainerCompatibleExtensionName};
static constexpr uint32_t kDimension = 128;
static constexpr uint32_t kSwapCount = 1;
static constexpr uint32_t kMinSwapchainBuffering = 3;
......
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