Commit 86d22b74 authored by Alexander Cooper's avatar Alexander Cooper Committed by Commit Bot

Expose public interfaces for XrConsentHelper

Moves the XrConsentHelper and XrConsentPromptLevel interfaces to
content/public and moves the windows-specific implementation out of
chrome/browser/vr/service. Creates a wrapper method for the windows-
specific singleton to better fit the pattern of the other consent
helpers.

Note that the XrConsentHelpers are currently disabled by default and
intended to be removed once the switch to use permissions has shipped,
but due to the current release changes, this is looking further out.
Thus, these methods are moved temporarily to enable VRService to move.

Bug: 1031622
Change-Id: I54b0ee16d27e0cf95dbe562e064e0f24b7ac30e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2118579
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753344}
parent fae13af5
...@@ -641,7 +641,6 @@ java_cpp_enum("chrome_vr_android_java_enums_srcjar") { ...@@ -641,7 +641,6 @@ java_cpp_enum("chrome_vr_android_java_enums_srcjar") {
"//chrome/browser/android/vr/vr_core_info.h", "//chrome/browser/android/vr/vr_core_info.h",
"//chrome/browser/android/vr/vr_shell_delegate.h", "//chrome/browser/android/vr/vr_shell_delegate.h",
"//chrome/browser/vr/metrics/consent_flow_metrics_helper.h", "//chrome/browser/vr/metrics/consent_flow_metrics_helper.h",
"//chrome/browser/vr/service/xr_consent_prompt_level.h",
"//chrome/browser/vr/text_edit_action.h", "//chrome/browser/vr/text_edit_action.h",
"//chrome/browser/vr/ui_test_input.h", "//chrome/browser/vr/ui_test_input.h",
"//chrome/browser/vr/ui_unsupported_mode.h", "//chrome/browser/vr/ui_unsupported_mode.h",
......
...@@ -20,6 +20,7 @@ import org.chromium.components.url_formatter.SchemeDisplay; ...@@ -20,6 +20,7 @@ import org.chromium.components.url_formatter.SchemeDisplay;
import org.chromium.components.url_formatter.UrlFormatter; import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver; import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.content_public.browser.XrConsentPromptLevel;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties; import org.chromium.ui.modaldialog.ModalDialogProperties;
......
...@@ -5416,8 +5416,10 @@ jumbo_static_library("browser") { ...@@ -5416,8 +5416,10 @@ jumbo_static_library("browser") {
if (is_win) { if (is_win) {
sources += [ sources += [
"vr/service/xr_session_request_consent_manager_impl.cc", "vr/consent/win_xr_consent_helper.cc",
"vr/service/xr_session_request_consent_manager_impl.h", "vr/consent/win_xr_consent_helper.h",
"vr/consent/xr_session_request_consent_manager_impl.cc",
"vr/consent/xr_session_request_consent_manager_impl.h",
"vr/ui_host/vr_ui_host_impl.cc", "vr/ui_host/vr_ui_host_impl.cc",
"vr/ui_host/vr_ui_host_impl.h", "vr/ui_host/vr_ui_host_impl.h",
] ]
...@@ -5441,7 +5443,6 @@ jumbo_static_library("browser") { ...@@ -5441,7 +5443,6 @@ jumbo_static_library("browser") {
"vr/service/browser_xr_runtime_impl.h", "vr/service/browser_xr_runtime_impl.h",
"vr/service/vr_service_impl.cc", "vr/service/vr_service_impl.cc",
"vr/service/vr_service_impl.h", "vr/service/vr_service_impl.h",
"vr/service/xr_consent_helper.h",
"vr/service/xr_runtime_manager_impl.cc", "vr/service/xr_runtime_manager_impl.cc",
"vr/service/xr_runtime_manager_impl.h", "vr/service/xr_runtime_manager_impl.h",
"vr/xr_runtime_manager_statics.h", "vr/xr_runtime_manager_statics.h",
......
...@@ -402,9 +402,6 @@ include_rules = [ ...@@ -402,9 +402,6 @@ include_rules = [
# VRService is being moved to content, this forces documentation of new # VRService is being moved to content, this forces documentation of new
# dependencies that are added to it outside of it's own directory. # dependencies that are added to it outside of it's own directory.
"-chrome/browser/vr/service", "-chrome/browser/vr/service",
# The following VRService interfaces will be moving to content/public
"+chrome/browser/vr/service/xr_consent_helper.h",
"+chrome/browser/vr/service/xr_consent_prompt_level.h",
# Explicitly disallow using SyncMessageFilter to prevent browser from # Explicitly disallow using SyncMessageFilter to prevent browser from
# sending synchronous IPC messages on non-UI threads. # sending synchronous IPC messages on non-UI threads.
...@@ -484,6 +481,5 @@ specific_include_rules = { ...@@ -484,6 +481,5 @@ specific_include_rules = {
# TODO(crbug.com/1031622): Until VRService moves, ChromeBrowserMain is # TODO(crbug.com/1031622): Until VRService moves, ChromeBrowserMain is
# responsible for wiring these up to appropriate factories. # responsible for wiring these up to appropriate factories.
"+chrome/browser/vr/service/vr_service_impl.h", "+chrome/browser/vr/service/vr_service_impl.h",
"+chrome/browser/vr/service/xr_session_request_consent_manager_impl.h",
] ]
} }
...@@ -16,7 +16,7 @@ using base::android::AttachCurrentThread; ...@@ -16,7 +16,7 @@ using base::android::AttachCurrentThread;
namespace vr { namespace vr {
ArCoreConsentPrompt::ArCoreConsentPrompt() ArCoreConsentPrompt::ArCoreConsentPrompt()
: XrConsentHelper(), weak_ptr_factory_(this) {} : content::XrConsentHelper(), weak_ptr_factory_(this) {}
ArCoreConsentPrompt::~ArCoreConsentPrompt() { ArCoreConsentPrompt::~ArCoreConsentPrompt() {
if (!jdelegate_.is_null()) { if (!jdelegate_.is_null()) {
...@@ -27,8 +27,8 @@ ArCoreConsentPrompt::~ArCoreConsentPrompt() { ...@@ -27,8 +27,8 @@ ArCoreConsentPrompt::~ArCoreConsentPrompt() {
void ArCoreConsentPrompt::ShowConsentPrompt( void ArCoreConsentPrompt::ShowConsentPrompt(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
OnUserConsentCallback response_callback) { content::OnXrUserConsentCallback response_callback) {
DCHECK(!on_user_consent_callback_); DCHECK(!on_user_consent_callback_);
on_user_consent_callback_ = std::move(response_callback); on_user_consent_callback_ = std::move(response_callback);
consent_level_ = consent_level; consent_level_ = consent_level;
......
...@@ -11,20 +11,21 @@ ...@@ -11,20 +11,21 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "chrome/browser/vr/service/xr_consent_helper.h"
#include "chrome/browser/vr/vr_export.h" #include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/xr_consent_helper.h"
namespace vr { namespace vr {
class VR_EXPORT ArCoreConsentPrompt : public XrConsentHelper { class VR_EXPORT ArCoreConsentPrompt : public content::XrConsentHelper {
public: public:
ArCoreConsentPrompt(); ArCoreConsentPrompt();
~ArCoreConsentPrompt() override; ~ArCoreConsentPrompt() override;
void ShowConsentPrompt(int render_process_id, void ShowConsentPrompt(
int render_frame_id, int render_process_id,
XrConsentPromptLevel consent_level, int render_frame_id,
OnUserConsentCallback response_callback) override; content::XrConsentPromptLevel consent_level,
content::OnXrUserConsentCallback response_callback) override;
// Called from Java end. // Called from Java end.
void OnUserConsentResult(JNIEnv* env, void OnUserConsentResult(JNIEnv* env,
...@@ -37,8 +38,8 @@ class VR_EXPORT ArCoreConsentPrompt : public XrConsentHelper { ...@@ -37,8 +38,8 @@ class VR_EXPORT ArCoreConsentPrompt : public XrConsentHelper {
return weak_ptr_factory_.GetWeakPtr(); return weak_ptr_factory_.GetWeakPtr();
} }
OnUserConsentCallback on_user_consent_callback_; content::OnXrUserConsentCallback on_user_consent_callback_;
XrConsentPromptLevel consent_level_; content::XrConsentPromptLevel consent_level_;
base::android::ScopedJavaGlobalRef<jobject> jdelegate_; base::android::ScopedJavaGlobalRef<jobject> jdelegate_;
......
...@@ -13,7 +13,7 @@ using base::android::AttachCurrentThread; ...@@ -13,7 +13,7 @@ using base::android::AttachCurrentThread;
namespace vr { namespace vr {
GvrConsentHelper::GvrConsentHelper() : XrConsentHelper() {} GvrConsentHelper::GvrConsentHelper() : content::XrConsentHelper() {}
GvrConsentHelper::~GvrConsentHelper() { GvrConsentHelper::~GvrConsentHelper() {
if (!jdelegate_.is_null()) { if (!jdelegate_.is_null()) {
...@@ -24,8 +24,8 @@ GvrConsentHelper::~GvrConsentHelper() { ...@@ -24,8 +24,8 @@ GvrConsentHelper::~GvrConsentHelper() {
void GvrConsentHelper::ShowConsentPrompt( void GvrConsentHelper::ShowConsentPrompt(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
OnUserConsentCallback on_user_consent_callback) { content::OnXrUserConsentCallback on_user_consent_callback) {
DCHECK(!on_user_consent_callback_); DCHECK(!on_user_consent_callback_);
on_user_consent_callback_ = std::move(on_user_consent_callback); on_user_consent_callback_ = std::move(on_user_consent_callback);
consent_level_ = consent_level; consent_level_ = consent_level;
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/vr/service/xr_consent_helper.h" #include "content/public/browser/xr_consent_helper.h"
namespace vr { namespace vr {
class GvrConsentHelper : public XrConsentHelper { class GvrConsentHelper : public content::XrConsentHelper {
public: public:
GvrConsentHelper(); GvrConsentHelper();
...@@ -19,16 +19,17 @@ class GvrConsentHelper : public XrConsentHelper { ...@@ -19,16 +19,17 @@ class GvrConsentHelper : public XrConsentHelper {
// Caller must ensure not to call this a second time before the first dialog // Caller must ensure not to call this a second time before the first dialog
// is dismissed. // is dismissed.
void ShowConsentPrompt(int render_process_id, void ShowConsentPrompt(
int render_frame_id, int render_process_id,
XrConsentPromptLevel consent_level, int render_frame_id,
OnUserConsentCallback response_callback) override; content::XrConsentPromptLevel consent_level,
content::OnXrUserConsentCallback response_callback) override;
void OnUserConsentResult(JNIEnv* env, jboolean is_granted); void OnUserConsentResult(JNIEnv* env, jboolean is_granted);
private: private:
XrConsentPromptLevel consent_level_; content::XrConsentPromptLevel consent_level_;
OnUserConsentCallback on_user_consent_callback_; content::OnXrUserConsentCallback on_user_consent_callback_;
base::android::ScopedJavaGlobalRef<jobject> jdelegate_; base::android::ScopedJavaGlobalRef<jobject> jdelegate_;
base::WeakPtrFactory<GvrConsentHelper> weak_ptr_{this}; base::WeakPtrFactory<GvrConsentHelper> weak_ptr_{this};
......
...@@ -297,7 +297,7 @@ ...@@ -297,7 +297,7 @@
#if BUILDFLAG(ENABLE_VR) #if BUILDFLAG(ENABLE_VR)
#include "chrome/browser/vr/service/vr_service_impl.h" #include "chrome/browser/vr/service/vr_service_impl.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/vr/service/xr_session_request_consent_manager_impl.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager_impl.h"
#endif #endif
#endif #endif
......
...@@ -18,8 +18,9 @@ namespace vr { ...@@ -18,8 +18,9 @@ namespace vr {
XrSessionRequestConsentDialogDelegate::XrSessionRequestConsentDialogDelegate( XrSessionRequestConsentDialogDelegate::XrSessionRequestConsentDialogDelegate(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback)
: TabModalConfirmDialogDelegate(web_contents), : TabModalConfirmDialogDelegate(web_contents),
response_callback_(std::move(response_callback)), response_callback_(std::move(response_callback)),
consent_level_(consent_level), consent_level_(consent_level),
...@@ -38,8 +39,8 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetTitle() { ...@@ -38,8 +39,8 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetTitle() {
} }
base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() { base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() {
DCHECK_NE(consent_level_, XrConsentPromptLevel::kNone); DCHECK_NE(consent_level_, content::XrConsentPromptLevel::kNone);
if (consent_level_ == XrConsentPromptLevel::kDefault) { if (consent_level_ == content::XrConsentPromptLevel::kDefault) {
return base::string16(); return base::string16();
} }
...@@ -48,13 +49,13 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() { ...@@ -48,13 +49,13 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() {
L"\n"; L"\n";
switch (consent_level_) { switch (consent_level_) {
case XrConsentPromptLevel::kVRFeatures: case content::XrConsentPromptLevel::kVRFeatures:
dialog += l10n_util::GetStringFUTF16( dialog += l10n_util::GetStringFUTF16(
IDS_LIST_BULLET, IDS_LIST_BULLET,
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_XR_CONSENT_DIALOG_DESCRIPTION_PHYSICAL_FEATURES)); IDS_XR_CONSENT_DIALOG_DESCRIPTION_PHYSICAL_FEATURES));
break; break;
case XrConsentPromptLevel::kVRFloorPlan: case content::XrConsentPromptLevel::kVRFloorPlan:
dialog += l10n_util::GetStringFUTF16( dialog += l10n_util::GetStringFUTF16(
IDS_LIST_BULLET, IDS_LIST_BULLET,
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
...@@ -69,8 +70,8 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() { ...@@ -69,8 +70,8 @@ base::string16 XrSessionRequestConsentDialogDelegate::GetDialogMessage() {
// compiler doesn't know that. These are listed here explicltly rather than // compiler doesn't know that. These are listed here explicltly rather than
// a "default" clause to ensure that we get compiler errors if new enum // a "default" clause to ensure that we get compiler errors if new enum
// values are added and not handled. // values are added and not handled.
case XrConsentPromptLevel::kDefault: case content::XrConsentPromptLevel::kDefault:
case XrConsentPromptLevel::kNone: case content::XrConsentPromptLevel::kNone:
NOTREACHED(); NOTREACHED();
return base::string16(); return base::string16();
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
#include "chrome/browser/vr/service/xr_consent_prompt_level.h" #include "content/public/browser/xr_consent_prompt_level.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content { namespace content {
...@@ -28,8 +28,9 @@ class XrSessionRequestConsentDialogDelegate ...@@ -28,8 +28,9 @@ class XrSessionRequestConsentDialogDelegate
public: public:
XrSessionRequestConsentDialogDelegate( XrSessionRequestConsentDialogDelegate(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback); base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback);
~XrSessionRequestConsentDialogDelegate() override; ~XrSessionRequestConsentDialogDelegate() override;
// TabModalConfirmDialogDelegate: // TabModalConfirmDialogDelegate:
...@@ -51,9 +52,10 @@ class XrSessionRequestConsentDialogDelegate ...@@ -51,9 +52,10 @@ class XrSessionRequestConsentDialogDelegate
void OnUserActionTaken(bool allow); void OnUserActionTaken(bool allow);
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback_; base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback_;
XrConsentPromptLevel consent_level_; content::XrConsentPromptLevel consent_level_;
GURL url_; GURL url_;
// Metrics related // Metrics related
......
...@@ -235,6 +235,8 @@ component("vr_common") { ...@@ -235,6 +235,8 @@ component("vr_common") {
"browser_renderer.cc", "browser_renderer.cc",
"browser_renderer.h", "browser_renderer.h",
"browser_renderer_browser_interface.h", "browser_renderer_browser_interface.h",
"consent/xr_session_request_consent_manager.cc",
"consent/xr_session_request_consent_manager.h",
"frame_type.h", "frame_type.h",
"gesture_detector.cc", "gesture_detector.cc",
"gesture_detector.h", "gesture_detector.h",
...@@ -247,8 +249,6 @@ component("vr_common") { ...@@ -247,8 +249,6 @@ component("vr_common") {
"scheduler_delegate.h", "scheduler_delegate.h",
"service/xr_device_service.cc", "service/xr_device_service.cc",
"service/xr_device_service.h", "service/xr_device_service.h",
"service/xr_session_request_consent_manager.cc",
"service/xr_session_request_consent_manager.h",
"sounds_manager_audio_delegate.cc", "sounds_manager_audio_delegate.cc",
"sounds_manager_audio_delegate.h", "sounds_manager_audio_delegate.h",
"vr_export.h", "vr_export.h",
...@@ -377,7 +377,6 @@ component("vr_base") { ...@@ -377,7 +377,6 @@ component("vr_base") {
"pose_util.h", "pose_util.h",
"render_info.h", "render_info.h",
"scheduler_ui_interface.h", "scheduler_ui_interface.h",
"service/xr_consent_prompt_level.h",
"speech_recognizer.cc", "speech_recognizer.cc",
"speech_recognizer.h", "speech_recognizer.h",
"text_edit_action.cc", "text_edit_action.cc",
......
...@@ -27,9 +27,5 @@ specific_include_rules = { ...@@ -27,9 +27,5 @@ specific_include_rules = {
], ],
".*mock.*" : [ ".*mock.*" : [
"+chrome/browser/vr/service", "+chrome/browser/vr/service",
],
".*fake.*" : [
"+chrome/browser/vr/service",
] ]
} }
...@@ -4,27 +4,56 @@ ...@@ -4,27 +4,56 @@
#include "chrome/browser/vr/chrome_xr_integration_client.h" #include "chrome/browser/vr/chrome_xr_integration_client.h"
#include <utility>
#include "base/command_line.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/xr_consent_helper.h"
#include "content/public/browser/xr_install_helper.h" #include "content/public/browser/xr_install_helper.h"
#include "device/vr/buildflags/buildflags.h" #include "device/vr/buildflags/buildflags.h"
#include "device/vr/public/mojom/vr_service.mojom-shared.h" #include "device/vr/public/mojom/vr_service.mojom-shared.h"
#if defined(OS_ANDROID) #if defined(OS_WIN)
#include "chrome/browser/vr/consent/win_xr_consent_helper.h"
#include "chrome/browser/vr/ui_host/vr_ui_host_impl.h"
#elif defined(OS_ANDROID)
#include "chrome/browser/android/vr/gvr_consent_helper.h"
#include "chrome/browser/android/vr/gvr_install_helper.h" #include "chrome/browser/android/vr/gvr_install_helper.h"
#if BUILDFLAG(ENABLE_ARCORE) #if BUILDFLAG(ENABLE_ARCORE)
#include "chrome/browser/android/vr/arcore_device/arcore_consent_prompt.h"
#include "chrome/browser/android/vr/arcore_device/arcore_install_helper.h" #include "chrome/browser/android/vr/arcore_device/arcore_install_helper.h"
#endif #endif // ENABLE_ARCORE
#endif #endif // OS_WIN/OS_ANDROID
#if defined(OS_WIN)
#include "chrome/browser/vr/ui_host/vr_ui_host_impl.h"
#endif
namespace { namespace {
vr::ChromeXrIntegrationClient* g_instance = nullptr; vr::ChromeXrIntegrationClient* g_instance = nullptr;
bool IsXrDeviceConsentPromptDisabledForTesting() {
static bool is_xr_device_consent_prompt_disabled_for_testing =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableXrDeviceConsentPromptForTesting);
return is_xr_device_consent_prompt_disabled_for_testing;
}
} }
namespace vr { namespace vr {
// A version of the XrConsentHelper that can be returned if the consent helper
// should be treated as disabled for testing. It will automatically grant
// consent for the requested consent_level. This implementation is provided over
// just returning nullptr because if the product code does not get an object,
// then it assumes that consent was denied.
class AutoGrantingXrConsentHelperForTesting : public content::XrConsentHelper {
void ShowConsentPrompt(
int render_process_id,
int render_frame_id,
content::XrConsentPromptLevel consent_level,
content::OnXrUserConsentCallback response_callback) override {
std::move(response_callback).Run(consent_level, true);
}
};
ChromeXrIntegrationClient* ChromeXrIntegrationClient::GetInstance() { ChromeXrIntegrationClient* ChromeXrIntegrationClient::GetInstance() {
if (!g_instance) if (!g_instance)
g_instance = new ChromeXrIntegrationClient(); g_instance = new ChromeXrIntegrationClient();
...@@ -49,6 +78,30 @@ ChromeXrIntegrationClient::GetInstallHelper( ...@@ -49,6 +78,30 @@ ChromeXrIntegrationClient::GetInstallHelper(
} }
} }
std::unique_ptr<content::XrConsentHelper>
ChromeXrIntegrationClient::GetConsentHelper(
device::mojom::XRDeviceId device_id) {
if (IsXrDeviceConsentPromptDisabledForTesting())
return std::make_unique<AutoGrantingXrConsentHelperForTesting>();
#if defined(OS_WIN)
return std::make_unique<WinXrConsentHelper>();
#else
switch (device_id) {
#if defined(OS_ANDROID)
case device::mojom::XRDeviceId::GVR_DEVICE_ID:
return std::make_unique<GvrConsentHelper>();
#if BUILDFLAG(ENABLE_ARCORE)
case device::mojom::XRDeviceId::ARCORE_DEVICE_ID:
return std::make_unique<ArCoreConsentPrompt>();
#endif // ENABLE_ARCORE
#endif // OS_ANDROID
default:
return nullptr;
}
#endif
}
#if defined(OS_WIN) #if defined(OS_WIN)
std::unique_ptr<content::VrUiHost> ChromeXrIntegrationClient::CreateVrUiHost( std::unique_ptr<content::VrUiHost> ChromeXrIntegrationClient::CreateVrUiHost(
device::mojom::XRDeviceId device_id, device::mojom::XRDeviceId device_id,
......
...@@ -27,6 +27,8 @@ class ChromeXrIntegrationClient : public content::XrIntegrationClient { ...@@ -27,6 +27,8 @@ class ChromeXrIntegrationClient : public content::XrIntegrationClient {
// XrIntegrationClient // XrIntegrationClient
std::unique_ptr<content::XrInstallHelper> GetInstallHelper( std::unique_ptr<content::XrInstallHelper> GetInstallHelper(
device::mojom::XRDeviceId device_id) override; device::mojom::XRDeviceId device_id) override;
std::unique_ptr<content::XrConsentHelper> GetConsentHelper(
device::mojom::XRDeviceId device_id) override;
// The only class that we have which implements VrUiHost is Win-only. // The only class that we have which implements VrUiHost is Win-only.
#if defined(OS_WIN) #if defined(OS_WIN)
......
// Copyright 2020 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 <utility>
#include "chrome/browser/vr/consent/win_xr_consent_helper.h"
#include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
namespace {
content::WebContents* GetWebContents(int render_process_id,
int render_frame_id) {
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
DCHECK(render_frame_host);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
return web_contents;
}
} // anonymous namespace
namespace vr {
void WinXrConsentHelper::ShowConsentPrompt(
int render_process_id,
int render_frame_id,
content::XrConsentPromptLevel consent_level,
content::OnXrUserConsentCallback response_callback) {
XRSessionRequestConsentManager::Instance()->ShowDialogAndGetConsent(
GetWebContents(render_process_id, render_frame_id), consent_level,
std::move(response_callback));
}
} // namespace vr
// Copyright 2020 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 CHROME_BROWSER_VR_CONSENT_WIN_XR_CONSENT_HELPER_H_
#define CHROME_BROWSER_VR_CONSENT_WIN_XR_CONSENT_HELPER_H_
#include "content/public/browser/xr_consent_helper.h"
namespace vr {
// Windows makes use of a factory singleton to manage its consent prompts. Once
// a prompt has been created, it listens directly to page lifecycle events to
// determine when to tear itself down. This class is a wrapper around that
// factory so that the pattern can be integrated with the |XrIntegrationClient|.
// TODO(crbug.com/1064384): Remove this class and the factory when possible.
class WinXrConsentHelper : public content::XrConsentHelper {
public:
WinXrConsentHelper() = default;
~WinXrConsentHelper() override = default;
WinXrConsentHelper(const WinXrConsentHelper&) = delete;
WinXrConsentHelper& operator=(const WinXrConsentHelper&) = delete;
void ShowConsentPrompt(
int render_process_id,
int render_frame_id,
content::XrConsentPromptLevel consent_level,
content::OnXrUserConsentCallback response_callback) override;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_CONSENT_WIN_XR_CONSENT_HELPER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/vr/service/xr_session_request_consent_manager.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
namespace vr { namespace vr {
namespace { namespace {
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_ #ifndef CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#define CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_ #define CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#include "base/callback.h" #include "base/callback.h"
#include "chrome/browser/vr/service/xr_consent_prompt_level.h"
#include "chrome/browser/vr/vr_export.h" #include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/xr_consent_prompt_level.h"
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -47,11 +47,11 @@ class VR_EXPORT XRSessionRequestConsentManager { ...@@ -47,11 +47,11 @@ class VR_EXPORT XRSessionRequestConsentManager {
// either closes the dialog by any means or clicks on 'cancel' button. // either closes the dialog by any means or clicks on 'cancel' button.
virtual TabModalConfirmDialog* ShowDialogAndGetConsent( virtual TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback) = 0; response_callback) = 0;
}; };
} // namespace vr } // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_ #endif // CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/vr/service/xr_session_request_consent_manager_impl.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager_impl.h"
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -22,8 +22,9 @@ XRSessionRequestConsentManagerImpl::~XRSessionRequestConsentManagerImpl() = ...@@ -22,8 +22,9 @@ XRSessionRequestConsentManagerImpl::~XRSessionRequestConsentManagerImpl() =
TabModalConfirmDialog* TabModalConfirmDialog*
XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent( XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) { base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback) {
auto delegate = std::make_unique<XrSessionRequestConsentDialogDelegate>( auto delegate = std::make_unique<XrSessionRequestConsentDialogDelegate>(
web_contents, consent_level, std::move(response_callback)); web_contents, consent_level, std::move(response_callback));
delegate->OnShowDialog(); delegate->OnShowDialog();
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_ #ifndef CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_
#define CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_ #define CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/service/xr_session_request_consent_manager.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
namespace vr { namespace vr {
...@@ -21,9 +21,9 @@ class XRSessionRequestConsentManagerImpl ...@@ -21,9 +21,9 @@ class XRSessionRequestConsentManagerImpl
// XRSessionRequestConsentManager: // XRSessionRequestConsentManager:
TabModalConfirmDialog* ShowDialogAndGetConsent( TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
override; response_callback) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(XRSessionRequestConsentManagerImpl); DISALLOW_COPY_AND_ASSIGN(XRSessionRequestConsentManagerImpl);
...@@ -31,4 +31,4 @@ class XRSessionRequestConsentManagerImpl ...@@ -31,4 +31,4 @@ class XRSessionRequestConsentManagerImpl
} // namespace vr } // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_ #endif // CHROME_BROWSER_VR_CONSENT_XR_SESSION_REQUEST_CONSENT_MANAGER_IMPL_H_
...@@ -12,25 +12,12 @@ include_rules = [ ...@@ -12,25 +12,12 @@ include_rules = [
"+chrome/browser/vr/metrics/session_metrics_helper.h", "+chrome/browser/vr/metrics/session_metrics_helper.h",
"+chrome/browser/vr/vr_export.h", "+chrome/browser/vr/vr_export.h",
"+chrome/browser/vr/xr_runtime_manager_statics.h", "+chrome/browser/vr/xr_runtime_manager_statics.h",
# TODO(alcooper): Disabling the XRDeviceConsentPrompt needs to be moved to
# either content (or chrome_xr_integration_client with the consent helpers).
"+chrome/common/chrome_switches.h",
] ]
specific_include_rules = { specific_include_rules = {
"browser_xr_runtime_impl.cc": [
# Consent Prompt impls will be moving into the XrIntegrationClient.
"+chrome/browser/android/vr/gvr_consent_helper.h",
"+chrome/browser/android/vr/arcore_device/arcore_consent_prompt.h",
],
"vr_service_impl\.*": [ "vr_service_impl\.*": [
# Permissions Infra will be replaced with content corresponding values. # Permissions Infra will be replaced with content corresponding values.
"+chrome/browser/profiles/profile.h", "+chrome/browser/profiles/profile.h",
"+chrome/browser/permissions/permission_manager_factory.h", "+chrome/browser/permissions/permission_manager_factory.h",
],
# XRSessionRequestConsentManger won't be moving.
"xr_session_request_consent_manager_impl.cc" : [
"+chrome/browser/ui",
] ]
} }
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/vr/chrome_xr_integration_client.h" #include "chrome/browser/vr/chrome_xr_integration_client.h"
#include "chrome/browser/vr/service/vr_service_impl.h" #include "chrome/browser/vr/service/vr_service_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/xr_install_helper.h" #include "content/public/browser/xr_install_helper.h"
#include "content/public/browser/xr_integration_client.h" #include "content/public/browser/xr_integration_client.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
...@@ -25,15 +22,6 @@ ...@@ -25,15 +22,6 @@
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/gfx/transform_util.h" #include "ui/gfx/transform_util.h"
#if defined(OS_WIN)
#include "chrome/browser/vr/service/xr_session_request_consent_manager.h"
#elif defined(OS_ANDROID)
#include "chrome/browser/android/vr/gvr_consent_helper.h"
#if BUILDFLAG(ENABLE_ARCORE)
#include "chrome/browser/android/vr/arcore_device/arcore_consent_prompt.h"
#endif
#endif
namespace vr { namespace vr {
namespace { namespace {
...@@ -219,21 +207,6 @@ bool ContainsFeature( ...@@ -219,21 +207,6 @@ bool ContainsFeature(
return std::find(feature_list.begin(), feature_list.end(), feature) != return std::find(feature_list.begin(), feature_list.end(), feature) !=
feature_list.end(); feature_list.end();
} }
#if defined(OS_WIN)
content::WebContents* GetWebContents(int render_process_id,
int render_frame_id) {
content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
DCHECK(render_frame_host);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
return web_contents;
}
#endif
} // anonymous namespace } // anonymous namespace
BrowserXRRuntimeImpl::BrowserXRRuntimeImpl( BrowserXRRuntimeImpl::BrowserXRRuntimeImpl(
...@@ -255,19 +228,10 @@ BrowserXRRuntimeImpl::BrowserXRRuntimeImpl( ...@@ -255,19 +228,10 @@ BrowserXRRuntimeImpl::BrowserXRRuntimeImpl(
// ContentBrowserClient once BrowserXRRuntimeImpl moves to content. // ContentBrowserClient once BrowserXRRuntimeImpl moves to content.
auto* integration_client = ChromeXrIntegrationClient::GetInstance(); auto* integration_client = ChromeXrIntegrationClient::GetInstance();
if (integration_client) if (integration_client) {
install_helper_ = integration_client->GetInstallHelper(id_); install_helper_ = integration_client->GetInstallHelper(id_);
consent_helper_ = integration_client->GetConsentHelper(id_);
#if defined(OS_ANDROID)
if (id_ == device::mojom::XRDeviceId::GVR_DEVICE_ID) {
consent_helper_ = std::make_unique<GvrConsentHelper>();
}
#if BUILDFLAG(ENABLE_ARCORE)
if (id_ == device::mojom::XRDeviceId::ARCORE_DEVICE_ID) {
consent_helper_ = std::make_unique<ArCoreConsentPrompt>();
} }
#endif
#endif
} }
BrowserXRRuntimeImpl::~BrowserXRRuntimeImpl() { BrowserXRRuntimeImpl::~BrowserXRRuntimeImpl() {
...@@ -536,13 +500,8 @@ void BrowserXRRuntimeImpl::OnRequestSessionResult( ...@@ -536,13 +500,8 @@ void BrowserXRRuntimeImpl::OnRequestSessionResult(
void BrowserXRRuntimeImpl::ShowConsentPrompt( void BrowserXRRuntimeImpl::ShowConsentPrompt(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
OnUserConsentCallback consent_callback) { content::OnXrUserConsentCallback consent_callback) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::Instance()->ShowDialogAndGetConsent(
GetWebContents(render_process_id, render_frame_id), consent_level,
std::move(consent_callback));
#else
// It is the responsibility of the consent prompt to ensure that the callback // It is the responsibility of the consent prompt to ensure that the callback
// is run in the event that we get removed (and it gets destroyed). // is run in the event that we get removed (and it gets destroyed).
if (consent_helper_) { if (consent_helper_) {
...@@ -552,7 +511,6 @@ void BrowserXRRuntimeImpl::ShowConsentPrompt( ...@@ -552,7 +511,6 @@ void BrowserXRRuntimeImpl::ShowConsentPrompt(
} else { } else {
std::move(consent_callback).Run(consent_level, false); std::move(consent_callback).Run(consent_level, false);
} }
#endif
} }
void BrowserXRRuntimeImpl::EnsureInstalled( void BrowserXRRuntimeImpl::EnsureInstalled(
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "chrome/browser/vr/service/vr_service_impl.h" #include "chrome/browser/vr/service/vr_service_impl.h"
#include "chrome/browser/vr/service/xr_consent_helper.h"
#include "content/public/browser/browser_xr_runtime.h" #include "content/public/browser/browser_xr_runtime.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/xr_consent_helper.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom-forward.h" #include "device/vr/public/mojom/isolated_xr_service.mojom-forward.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h" #include "device/vr/public/mojom/vr_service.mojom-forward.h"
#include "device/vr/vr_device.h" #include "device/vr/vr_device.h"
...@@ -62,8 +62,8 @@ class BrowserXRRuntimeImpl : public content::BrowserXRRuntime, ...@@ -62,8 +62,8 @@ class BrowserXRRuntimeImpl : public content::BrowserXRRuntime,
RequestSessionCallback callback); RequestSessionCallback callback);
void ShowConsentPrompt(int render_process_id, void ShowConsentPrompt(int render_process_id,
int render_frame_id, int render_frame_id,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
OnUserConsentCallback consent_callback); content::OnXrUserConsentCallback consent_callback);
void EnsureInstalled(int render_process_id, void EnsureInstalled(int render_process_id,
int render_frame_id, int render_frame_id,
base::OnceCallback<void(bool)> install_callback); base::OnceCallback<void(bool)> install_callback);
...@@ -119,7 +119,7 @@ class BrowserXRRuntimeImpl : public content::BrowserXRRuntime, ...@@ -119,7 +119,7 @@ class BrowserXRRuntimeImpl : public content::BrowserXRRuntime,
this}; this};
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
std::unique_ptr<XrConsentHelper> consent_helper_; std::unique_ptr<content::XrConsentHelper> consent_helper_;
std::unique_ptr<content::XrInstallHelper> install_helper_; std::unique_ptr<content::XrInstallHelper> install_helper_;
base::OnceCallback<void(bool)> install_finished_callback_; base::OnceCallback<void(bool)> install_finished_callback_;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -17,7 +16,6 @@ ...@@ -17,7 +16,6 @@
#include "chrome/browser/vr/metrics/session_metrics_helper.h" #include "chrome/browser/vr/metrics/session_metrics_helper.h"
#include "chrome/browser/vr/service/browser_xr_runtime_impl.h" #include "chrome/browser/vr/service/browser_xr_runtime_impl.h"
#include "chrome/browser/vr/service/xr_runtime_manager_impl.h" #include "chrome/browser/vr/service/xr_runtime_manager_impl.h"
#include "chrome/common/chrome_switches.h"
#include "components/permissions/permission_manager.h" #include "components/permissions/permission_manager.h"
#include "components/ukm/content/source_url_recorder.h" #include "components/ukm/content/source_url_recorder.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -43,26 +41,26 @@ device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions( ...@@ -43,26 +41,26 @@ device::mojom::XRRuntimeSessionOptionsPtr GetRuntimeOptions(
return runtime_options; return runtime_options;
} }
vr::XrConsentPromptLevel GetRequiredConsentLevel( content::XrConsentPromptLevel GetRequiredConsentLevel(
device::mojom::XRSessionMode mode, device::mojom::XRSessionMode mode,
const vr::BrowserXRRuntimeImpl* runtime, const vr::BrowserXRRuntimeImpl* runtime,
const std::set<device::mojom::XRSessionFeature>& requested_features) { const std::set<device::mojom::XRSessionFeature>& requested_features) {
if (base::Contains( if (base::Contains(
requested_features, requested_features,
device::mojom::XRSessionFeature::REF_SPACE_BOUNDED_FLOOR)) { device::mojom::XRSessionFeature::REF_SPACE_BOUNDED_FLOOR)) {
return vr::XrConsentPromptLevel::kVRFloorPlan; return content::XrConsentPromptLevel::kVRFloorPlan;
} }
if (base::Contains(requested_features, if (base::Contains(requested_features,
device::mojom::XRSessionFeature::HIT_TEST)) { device::mojom::XRSessionFeature::HIT_TEST)) {
return vr::XrConsentPromptLevel::kVRFloorPlan; return content::XrConsentPromptLevel::kVRFloorPlan;
} }
// If the device supports a custom IPD and it will be exposed (via immersive), // If the device supports a custom IPD and it will be exposed (via immersive),
// we need to warn about physical features Being exposed. // we need to warn about physical features Being exposed.
if (runtime->SupportsCustomIPD() && if (runtime->SupportsCustomIPD() &&
device::XRSessionModeUtils::IsImmersive(mode)) { device::XRSessionModeUtils::IsImmersive(mode)) {
return vr::XrConsentPromptLevel::kVRFeatures; return content::XrConsentPromptLevel::kVRFeatures;
} }
// If local-floor is requested and the device supports a user inputted or real // If local-floor is requested and the device supports a user inputted or real
...@@ -72,16 +70,16 @@ vr::XrConsentPromptLevel GetRequiredConsentLevel( ...@@ -72,16 +70,16 @@ vr::XrConsentPromptLevel GetRequiredConsentLevel(
if (base::Contains(requested_features, if (base::Contains(requested_features,
device::mojom::XRSessionFeature::REF_SPACE_LOCAL_FLOOR) && device::mojom::XRSessionFeature::REF_SPACE_LOCAL_FLOOR) &&
runtime->SupportsNonEmulatedHeight()) { runtime->SupportsNonEmulatedHeight()) {
return vr::XrConsentPromptLevel::kVRFeatures; return content::XrConsentPromptLevel::kVRFeatures;
} }
// In the absence of other items that need to be consented, inline does not // In the absence of other items that need to be consented, inline does not
// require consent. // require consent.
if (mode == device::mojom::XRSessionMode::kInline) { if (mode == device::mojom::XRSessionMode::kInline) {
return vr::XrConsentPromptLevel::kNone; return content::XrConsentPromptLevel::kNone;
} }
return vr::XrConsentPromptLevel::kDefault; return content::XrConsentPromptLevel::kDefault;
} }
ContentSettingsType GetRequiredPermission(device::mojom::XRSessionMode mode) { ContentSettingsType GetRequiredPermission(device::mojom::XRSessionMode mode) {
...@@ -253,14 +251,6 @@ void VRServiceImpl::OnWebContentsFocusChanged(content::RenderWidgetHost* host, ...@@ -253,14 +251,6 @@ void VRServiceImpl::OnWebContentsFocusChanged(content::RenderWidgetHost* host,
controller->SetFrameDataRestricted(!focused); controller->SetFrameDataRestricted(!focused);
} }
// static
bool VRServiceImpl::IsXrDeviceConsentPromptDisabledForTesting() {
static bool is_xr_device_consent_prompt_disabled_for_testing =
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableXrDeviceConsentPromptForTesting);
return is_xr_device_consent_prompt_disabled_for_testing;
}
void VRServiceImpl::OnInlineSessionCreated( void VRServiceImpl::OnInlineSessionCreated(
SessionRequestData request, SessionRequestData request,
device::mojom::XRSessionPtr session, device::mojom::XRSessionPtr session,
...@@ -431,17 +421,17 @@ void VRServiceImpl::ShowConsentPrompt(SessionRequestData request, ...@@ -431,17 +421,17 @@ void VRServiceImpl::ShowConsentPrompt(SessionRequestData request,
#endif #endif
bool consent_granted = false; bool consent_granted = false;
XrConsentPromptLevel consent_level = GetRequiredConsentLevel( content::XrConsentPromptLevel consent_level = GetRequiredConsentLevel(
request.options->mode, runtime, request.enabled_features); request.options->mode, runtime, request.enabled_features);
if (!base::FeatureList::IsEnabled(features::kWebXrPermissionsApi)) { if (!base::FeatureList::IsEnabled(features::kWebXrPermissionsApi)) {
consent_granted = consent_granted =
((consent_level == XrConsentPromptLevel::kNone) || ((consent_level == content::XrConsentPromptLevel::kNone) ||
IsConsentGrantedForDevice(request.runtime_id, consent_level)); IsConsentGrantedForDevice(request.runtime_id, consent_level));
} }
// Skip the consent prompt if the user has already consented for this device, // Skip the consent prompt if the user has already consented for this device,
// or if consent is not needed. // or if consent is not needed.
if (consent_granted || IsXrDeviceConsentPromptDisabledForTesting()) { if (consent_granted) {
EnsureRuntimeInstalled(std::move(request), runtime); EnsureRuntimeInstalled(std::move(request), runtime);
return; return;
} }
...@@ -474,15 +464,16 @@ void VRServiceImpl::ShowConsentPrompt(SessionRequestData request, ...@@ -474,15 +464,16 @@ void VRServiceImpl::ShowConsentPrompt(SessionRequestData request,
// TODO(alcooper): Once the ConsentFlow can be removed expected_runtime_id and // TODO(alcooper): Once the ConsentFlow can be removed expected_runtime_id and
// consent_level shouldn't be needed. // consent_level shouldn't be needed.
void VRServiceImpl::OnPermissionResult(SessionRequestData request, void VRServiceImpl::OnPermissionResult(
XrConsentPromptLevel consent_level, SessionRequestData request,
ContentSetting setting_value) { content::XrConsentPromptLevel consent_level,
ContentSetting setting_value) {
OnConsentResult(std::move(request), consent_level, OnConsentResult(std::move(request), consent_level,
setting_value == ContentSetting::CONTENT_SETTING_ALLOW); setting_value == ContentSetting::CONTENT_SETTING_ALLOW);
} }
void VRServiceImpl::OnConsentResult(SessionRequestData request, void VRServiceImpl::OnConsentResult(SessionRequestData request,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
bool is_consent_granted) { bool is_consent_granted) {
DVLOG(2) << __func__; DVLOG(2) << __func__;
if (!is_consent_granted) { if (!is_consent_granted) {
...@@ -647,14 +638,14 @@ content::WebContents* VRServiceImpl::GetWebContents() { ...@@ -647,14 +638,14 @@ content::WebContents* VRServiceImpl::GetWebContents() {
bool VRServiceImpl::IsConsentGrantedForDevice( bool VRServiceImpl::IsConsentGrantedForDevice(
device::mojom::XRDeviceId device_id, device::mojom::XRDeviceId device_id,
XrConsentPromptLevel consent_level) { content::XrConsentPromptLevel consent_level) {
auto it = consent_granted_devices_.find(device_id); auto it = consent_granted_devices_.find(device_id);
return it != consent_granted_devices_.end() && it->second >= consent_level; return it != consent_granted_devices_.end() && it->second >= consent_level;
} }
void VRServiceImpl::AddConsentGrantedDevice( void VRServiceImpl::AddConsentGrantedDevice(
device::mojom::XRDeviceId device_id, device::mojom::XRDeviceId device_id,
XrConsentPromptLevel consent_level) { content::XrConsentPromptLevel consent_level) {
auto it = consent_granted_devices_.find(device_id); auto it = consent_granted_devices_.find(device_id);
if (it == consent_granted_devices_.end() || it->second < consent_level) { if (it == consent_granted_devices_.end() || it->second < consent_level) {
consent_granted_devices_[device_id] = consent_level; consent_granted_devices_[device_id] = consent_level;
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "base/util/type_safety/pass_key.h" #include "base/util/type_safety/pass_key.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/vr/metrics/session_metrics_helper.h" #include "chrome/browser/vr/metrics/session_metrics_helper.h"
#include "chrome/browser/vr/service/xr_consent_helper.h"
#include "chrome/browser/vr/service/xr_consent_prompt_level.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/xr_consent_helper.h"
#include "content/public/browser/xr_consent_prompt_level.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h" #include "device/vr/public/mojom/vr_service.mojom-forward.h"
#include "device/vr/vr_device.h" #include "device/vr/vr_device.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
...@@ -42,8 +42,6 @@ class BrowserXRRuntimeImpl; ...@@ -42,8 +42,6 @@ class BrowserXRRuntimeImpl;
class VRServiceImpl : public device::mojom::VRService, class VRServiceImpl : public device::mojom::VRService,
content::WebContentsObserver { content::WebContentsObserver {
public: public:
static bool IsXrDeviceConsentPromptDisabledForTesting();
explicit VRServiceImpl(content::RenderFrameHost* render_frame_host); explicit VRServiceImpl(content::RenderFrameHost* render_frame_host);
// Constructor for tests. // Constructor for tests.
...@@ -123,9 +121,9 @@ class VRServiceImpl : public device::mojom::VRService, ...@@ -123,9 +121,9 @@ class VRServiceImpl : public device::mojom::VRService,
bool InternalSupportsSession(device::mojom::XRSessionOptions* options); bool InternalSupportsSession(device::mojom::XRSessionOptions* options);
bool IsConsentGrantedForDevice(device::mojom::XRDeviceId device_id, bool IsConsentGrantedForDevice(device::mojom::XRDeviceId device_id,
XrConsentPromptLevel consent_level); content::XrConsentPromptLevel consent_level);
void AddConsentGrantedDevice(device::mojom::XRDeviceId device_id, void AddConsentGrantedDevice(device::mojom::XRDeviceId device_id,
XrConsentPromptLevel consent_level); content::XrConsentPromptLevel consent_level);
// The following steps are ordered in the general flow for "RequestSession" // The following steps are ordered in the general flow for "RequestSession"
// If the WebXrPermissionsAPI is enabled ShowConsentPrompt will result in a // If the WebXrPermissionsAPI is enabled ShowConsentPrompt will result in a
...@@ -138,10 +136,10 @@ class VRServiceImpl : public device::mojom::VRService, ...@@ -138,10 +136,10 @@ class VRServiceImpl : public device::mojom::VRService,
BrowserXRRuntimeImpl* runtime); BrowserXRRuntimeImpl* runtime);
void OnConsentResult(SessionRequestData request, void OnConsentResult(SessionRequestData request,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
bool is_consent_granted); bool is_consent_granted);
void OnPermissionResult(SessionRequestData request, void OnPermissionResult(SessionRequestData request,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
ContentSetting setting_value); ContentSetting setting_value);
void EnsureRuntimeInstalled(SessionRequestData request, void EnsureRuntimeInstalled(SessionRequestData request,
...@@ -178,7 +176,7 @@ class VRServiceImpl : public device::mojom::VRService, ...@@ -178,7 +176,7 @@ class VRServiceImpl : public device::mojom::VRService,
bool in_focused_frame_ = false; bool in_focused_frame_ = false;
bool frames_throttled_ = false; bool frames_throttled_ = false;
std::map<device::mojom::XRDeviceId, XrConsentPromptLevel> std::map<device::mojom::XRDeviceId, content::XrConsentPromptLevel>
consent_granted_devices_; consent_granted_devices_;
base::WeakPtrFactory<VRServiceImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<VRServiceImpl> weak_ptr_factory_{this};
......
// 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 CHROME_BROWSER_VR_SERVICE_XR_CONSENT_HELPER_H_
#define CHROME_BROWSER_VR_SERVICE_XR_CONSENT_HELPER_H_
#include "base/callback_forward.h"
#include "chrome/browser/vr/service/xr_consent_prompt_level.h"
namespace vr {
typedef base::OnceCallback<void(XrConsentPromptLevel, bool)>
OnUserConsentCallback;
class XrConsentHelper {
public:
virtual ~XrConsentHelper() = default;
XrConsentHelper(const XrConsentHelper&) = delete;
XrConsentHelper& operator=(const XrConsentHelper&) = delete;
virtual void ShowConsentPrompt(int render_process_id,
int render_frame_id,
XrConsentPromptLevel consent_level,
OnUserConsentCallback) = 0;
protected:
XrConsentHelper() = default;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_SERVICE_XR_CONSENT_HELPER_H_
...@@ -27,8 +27,9 @@ FakeXRSessionRequestConsentManager::~FakeXRSessionRequestConsentManager() = ...@@ -27,8 +27,9 @@ FakeXRSessionRequestConsentManager::~FakeXRSessionRequestConsentManager() =
TabModalConfirmDialog* TabModalConfirmDialog*
FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent( FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) { base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback) {
shown_count_++; shown_count_++;
auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent( auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent(
web_contents, consent_level, std::move(response_callback)); web_contents, consent_level, std::move(response_callback));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_ #define CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/service/xr_session_request_consent_manager.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace vr { namespace vr {
...@@ -27,9 +27,9 @@ class FakeXRSessionRequestConsentManager ...@@ -27,9 +27,9 @@ class FakeXRSessionRequestConsentManager
TabModalConfirmDialog* ShowDialogAndGetConsent( TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel conesent_level, content::XrConsentPromptLevel conesent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
override; response_callback) override;
uint32_t ShownCount() { return shown_count_; } uint32_t ShownCount() { return shown_count_; }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define CHROME_BROWSER_VR_TEST_MOCK_XR_SESSION_REQUEST_CONSENT_MANAGER_H_ #define CHROME_BROWSER_VR_TEST_MOCK_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/service/xr_session_request_consent_manager.h" #include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace vr { namespace vr {
...@@ -20,8 +20,8 @@ class MockXRSessionRequestConsentManager ...@@ -20,8 +20,8 @@ class MockXRSessionRequestConsentManager
MOCK_METHOD3(ShowDialogAndGetConsent, MOCK_METHOD3(ShowDialogAndGetConsent,
TabModalConfirmDialog*( TabModalConfirmDialog*(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback)); response_callback));
private: private:
......
...@@ -28,8 +28,10 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGesture( ...@@ -28,8 +28,10 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_); XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _)) ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke( .WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level, [](content::WebContents*,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) { content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
callback) {
std::move(callback).Run(consent_level, true); std::move(callback).Run(consent_level, true);
return nullptr; return nullptr;
})); }));
......
...@@ -347,6 +347,7 @@ java_cpp_enum("content_public_android_java_enums_srcjar") { ...@@ -347,6 +347,7 @@ java_cpp_enum("content_public_android_java_enums_srcjar") {
"//content/public/browser/invalidate_type.h", "//content/public/browser/invalidate_type.h",
"//content/public/browser/navigation_controller.h", "//content/public/browser/navigation_controller.h",
"//content/public/browser/visibility.h", "//content/public/browser/visibility.h",
"//content/public/browser/xr_consent_prompt_level.h",
"//content/public/common/browser_controls_state.h", "//content/public/common/browser_controls_state.h",
"//content/public/common/console_message_level.h", "//content/public/common/console_message_level.h",
"//content/public/common/screen_orientation_values.h", "//content/public/common/screen_orientation_values.h",
......
...@@ -511,6 +511,8 @@ jumbo_source_set("browser_sources") { ...@@ -511,6 +511,8 @@ jumbo_source_set("browser_sources") {
if (enable_vr) { if (enable_vr) {
sources += [ sources += [
"browser_xr_runtime.h", "browser_xr_runtime.h",
"xr_consent_helper.h",
"xr_consent_prompt_level.h",
"xr_install_helper.h", "xr_install_helper.h",
"xr_integration_client.cc", "xr_integration_client.cc",
"xr_integration_client.h", "xr_integration_client.h",
......
// 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 CONTENT_PUBLIC_BROWSER_XR_CONSENT_HELPER_H_
#define CONTENT_PUBLIC_BROWSER_XR_CONSENT_HELPER_H_
#include "base/callback_forward.h"
#include "content/common/content_export.h"
#include "content/public/browser/xr_consent_prompt_level.h"
namespace content {
using OnXrUserConsentCallback =
base::OnceCallback<void(XrConsentPromptLevel, bool)>;
// Interface class to provide the opportunity for runtimes to ensure that any
// necessary UI is shown to request the appropriate level of user consent
// for the requested session. This is acquired via the |XrInstallHelperFactory|.
// Generally, these steps are specific per runtime, so likely this should be
// implemented for each runtime that has browser-specific installation steps.
// This should be implemented by embedders.
class CONTENT_EXPORT XrConsentHelper {
public:
virtual ~XrConsentHelper() = default;
XrConsentHelper(const XrConsentHelper&) = delete;
XrConsentHelper& operator=(const XrConsentHelper&) = delete;
// Shows UI necessary to prompt the user for the given level of consent.
// render_process_id and render_frame_id are passed in order to ensure that
// any tab specific UI can be shown.
// The callback should be guaranteed to run in the event that the object is
// destroyed, and the object should handle being destroyed as an indication
// that any displayed UI should be cleaned up.
// The Callback should return either the highest level of consent that was
// granted and true (if e.g. the user only granted consent to a lower level
// than was initially requested), or the requested level of consent and false,
// if the user denied consent.
virtual void ShowConsentPrompt(int render_process_id,
int render_frame_id,
XrConsentPromptLevel consent_level,
OnXrUserConsentCallback) = 0;
protected:
XrConsentHelper() = default;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_XR_CONSENT_HELPER_H_
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_SERVICE_XR_CONSENT_PROMPT_LEVEL_H_ #ifndef CONTENT_PUBLIC_BROWSER_XR_CONSENT_PROMPT_LEVEL_H_
#define CHROME_BROWSER_VR_SERVICE_XR_CONSENT_PROMPT_LEVEL_H_ #define CONTENT_PUBLIC_BROWSER_XR_CONSENT_PROMPT_LEVEL_H_
namespace vr { namespace content {
// Consent levels are incremental, granting consent for a higher level // Consent levels are incremental, granting consent for a higher level
// automatically grants consent for all levels below it. For that reason, // automatically grants consent for all levels below it. For that reason,
// these levels should not be used in histograms so that new levels can be // these levels should not be used in histograms so that new levels can be
// added in between the existing levels. // added in between the existing levels.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.vr // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content_public.browser
enum class XrConsentPromptLevel : int { enum class XrConsentPromptLevel : int {
// No consent is needed, typically this is due to the fact that no sensitive // No consent is needed, typically this is due to the fact that no sensitive
// information is exposed (all sensitive information is emulated, or not // information is exposed (all sensitive information is emulated, or not
...@@ -34,5 +34,5 @@ enum class XrConsentPromptLevel : int { ...@@ -34,5 +34,5 @@ enum class XrConsentPromptLevel : int {
kVRFloorPlan = 3 kVRFloorPlan = 3
}; };
} // namespace vr } // namespace content
#endif // CHROME_BROWSER_VR_SERVICE_XR_CONSENT_PROMPT_LEVEL_H_ #endif // CONTENT_PUBLIC_BROWSER_XR_CONSENT_PROMPT_LEVEL_H_
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/public/browser/xr_integration_client.h" #include "content/public/browser/xr_integration_client.h"
#include "content/public/browser/xr_consent_helper.h"
#include "content/public/browser/xr_install_helper.h" #include "content/public/browser/xr_install_helper.h"
#include "device/vr/public/mojom/vr_service.mojom-shared.h" #include "device/vr/public/mojom/vr_service.mojom-shared.h"
...@@ -14,6 +15,11 @@ std::unique_ptr<XrInstallHelper> XrIntegrationClient::GetInstallHelper( ...@@ -14,6 +15,11 @@ std::unique_ptr<XrInstallHelper> XrIntegrationClient::GetInstallHelper(
return nullptr; return nullptr;
} }
std::unique_ptr<XrConsentHelper> XrIntegrationClient::GetConsentHelper(
device::mojom::XRDeviceId device_id) {
return nullptr;
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
std::unique_ptr<VrUiHost> XrIntegrationClient::CreateVrUiHost( std::unique_ptr<VrUiHost> XrIntegrationClient::CreateVrUiHost(
device::mojom::XRDeviceId device_id, device::mojom::XRDeviceId device_id,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#endif #endif
namespace content { namespace content {
class XrConsentHelper;
class XrInstallHelper; class XrInstallHelper;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
...@@ -50,6 +51,12 @@ class CONTENT_EXPORT XrIntegrationClient { ...@@ -50,6 +51,12 @@ class CONTENT_EXPORT XrIntegrationClient {
virtual std::unique_ptr<XrInstallHelper> GetInstallHelper( virtual std::unique_ptr<XrInstallHelper> GetInstallHelper(
device::mojom::XRDeviceId device_id); device::mojom::XRDeviceId device_id);
// Returns the |XrConsentHelper| for the corresponding |XRDeviceId|, or
// nullptr if the requested |XRDeviceId| cannot prompt for consent.
// In this case, consent is assumed to have been denied.
virtual std::unique_ptr<XrConsentHelper> GetConsentHelper(
device::mojom::XRDeviceId device_id);
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// Creates a VrUiHost object for the specified device_id, and takes ownership // Creates a VrUiHost object for the specified device_id, and takes ownership
// of any XRCompositor supplied from the runtime. // of any XRCompositor supplied from the runtime.
......
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