Commit 62e4262b authored by Alexander Cooper's avatar Alexander Cooper Committed by Commit Bot

Migrate ArCoreInstallHelper to use components/infobars

In order to migrate the InstallHelpers out of chrome, their dependency
on SimpleConfirmInfoBarBuilder needs to be broken. This change creates a
class that both InstallHelpers can use, XrInstallInfoBar, which inherits
from the components ConfirmInfoBar. ArCoreInstallHelper is also modified
to take in a ContentInfoBarManager to display this item, so that it can
be moved to components when the corresponding ArCoreInstallUtils java
class can be moved. Unfortunately, content does not have a good way to
get the specific InfoBarManager at this time, so a wrapper class is
created to get the embedder-specific InfoBarManager.

Note that due to the dependency on the ArCoreShim, ArCoreInstallUtils
cannot be moved out of //chrome just yet.

Due to the fact that the VrCoreInstallHelper lives in the VR DFM, some
issues arose around strings when attempting to port it, so this change
only ports the ArCoreInstallHelper to the new classes.

Bug:1064073,960542

Change-Id: Icec9bd2535dde0378c16aafc9bafd98db4927ed2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442990
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814368}
parent f0f9fdd5
......@@ -716,6 +716,7 @@ java_cpp_enum("chrome_android_java_enums_srcjar") {
java_cpp_enum("chrome_vr_android_java_enums_srcjar") {
sources = [
"//chrome/browser/android/vr/arcore_device/arcore_install_helper.h",
"//chrome/browser/android/vr/vrcore_install_helper.h",
"//chrome/browser/vr/text_edit_action.h",
"//chrome/browser/vr/ui_test_input.h",
......
......@@ -13,9 +13,6 @@ import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.ui.messages.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
......@@ -68,22 +65,23 @@ public class ArCoreInstallUtils implements ApplicationStatus.ActivityStateListen
mNativeArCoreInstallUtils = nativeArCoreInstallUtils;
}
private static @ArCoreShim.Availability int getArCoreInstallStatus() {
@CalledByNative
private static @ArCoreAvailability int getArCoreInstallStatus() {
try {
return getArCoreShimInstance().checkAvailability(ContextUtils.getApplicationContext());
} catch (RuntimeException e) {
Log.w(TAG, "ARCore availability check failed with error: %s", e.toString());
return ArCoreShim.Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE;
return ArCoreAvailability.UNSUPPORTED_DEVICE_NOT_CAPABLE;
}
}
@CalledByNative
private static boolean shouldRequestInstallSupportedArCore() {
@ArCoreShim.Availability
@ArCoreAvailability
int availability = getArCoreInstallStatus();
// Skip ARCore installation if we are certain that it is already installed.
// In all other cases, we might as well try to install it and handle installation failures.
return availability != ArCoreShim.Availability.SUPPORTED_INSTALLED;
return availability != ArCoreAvailability.SUPPORTED_INSTALLED;
}
@Override
......@@ -117,47 +115,6 @@ public class ArCoreInstallUtils implements ApplicationStatus.ActivityStateListen
return;
}
@ArCoreShim.Availability
int arCoreAvailability = getArCoreInstallStatus();
String infobarText = null;
String buttonText = null;
switch (arCoreAvailability) {
case ArCoreShim.Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE:
maybeNotifyNativeOnRequestInstallSupportedArCoreResult(false);
break;
case ArCoreShim.Availability.UNKNOWN_CHECKING:
case ArCoreShim.Availability.UNKNOWN_ERROR:
case ArCoreShim.Availability.UNKNOWN_TIMED_OUT:
case ArCoreShim.Availability.SUPPORTED_NOT_INSTALLED:
infobarText = activity.getString(R.string.ar_core_check_infobar_install_text);
buttonText = activity.getString(R.string.app_banner_install);
break;
case ArCoreShim.Availability.SUPPORTED_APK_TOO_OLD:
infobarText = activity.getString(R.string.ar_core_check_infobar_update_text);
buttonText = activity.getString(R.string.update_from_market);
break;
case ArCoreShim.Availability.SUPPORTED_INSTALLED:
assert false;
break;
}
if (infobarText == null || buttonText == null) {
// The action was something other than "install" or "update", log this
// and exit early to avoid showing an empty infobar.
Log.w(TAG, "ARCore unavailable, status code %d", arCoreAvailability);
return;
}
SimpleConfirmInfoBarBuilder.Listener listener = new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {
maybeNotifyNativeOnRequestInstallSupportedArCoreResult(
!shouldRequestInstallSupportedArCore());
}
@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
try {
assert sRequestInstallInstance == null;
@ArCoreShim.InstallStatus
......@@ -175,29 +132,14 @@ public class ArCoreInstallUtils implements ApplicationStatus.ActivityStateListen
} catch (ArCoreShim.UnavailableDeviceNotCompatibleException e) {
sRequestInstallInstance = null;
Log.w(TAG, "ARCore installation request failed with exception: %s",
e.toString());
Log.w(TAG, "ARCore installation request failed with exception: %s", e.toString());
maybeNotifyNativeOnRequestInstallSupportedArCoreResult(false);
} catch (ArCoreShim.UnavailableUserDeclinedInstallationException e) {
maybeNotifyNativeOnRequestInstallSupportedArCoreResult(false);
}
return false;
}
@Override
public boolean onInfoBarLinkClicked() {
return false;
}
};
ApplicationStatus.registerStateListenerForActivity(this, activity);
// TODO(ijamardo, https://crbug.com/838833): Add icon for AR info bar.
SimpleConfirmInfoBarBuilder.create(webContents, listener,
InfoBarIdentifier.AR_CORE_UPGRADE_ANDROID, activity,
R.drawable.ic_error_outline_googblue_24dp, infobarText, buttonText, null, null,
true);
}
/**
......
......@@ -32,31 +32,10 @@ public interface ArCoreShim {
int INSTALL_REQUESTED = 1;
}
/**
* Equivalent of ArCoreApk.Availability enum.
*
* For detailed description, please see:
* https://developers.google.com/ar/reference/java/arcore/reference/com/google/ar/core/ArCoreApk.Availability
*/
@IntDef({Availability.SUPPORTED_APK_TOO_OLD, Availability.SUPPORTED_INSTALLED,
Availability.SUPPORTED_NOT_INSTALLED, Availability.UNKNOWN_CHECKING,
Availability.UNKNOWN_ERROR, Availability.UNKNOWN_TIMED_OUT,
Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface Availability {
int SUPPORTED_APK_TOO_OLD = 0;
int SUPPORTED_INSTALLED = 1;
int SUPPORTED_NOT_INSTALLED = 2;
int UNKNOWN_CHECKING = 3;
int UNKNOWN_ERROR = 4;
int UNKNOWN_TIMED_OUT = 5;
int UNSUPPORTED_DEVICE_NOT_CAPABLE = 6;
}
/**
* Equivalent of ArCoreApk.checkAvailability.
*/
public @Availability int checkAvailability(Context applicationContext);
public @ArCoreAvailability int checkAvailability(Context applicationContext);
/**
* Equivalent of ArCoreApk.requestInstall.
......
......@@ -11,7 +11,6 @@ import com.google.ar.core.ArCoreApk;
import org.chromium.base.StrictModeContext;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.chrome.browser.vr.ArCoreShim.Availability;
import org.chromium.chrome.browser.vr.ArCoreShim.InstallStatus;
@UsedByReflection("ArCoreJavaUtils.java")
......@@ -35,7 +34,7 @@ class ArCoreShimImpl implements ArCoreShim {
}
@Override
public @Availability int checkAvailability(Context applicationContext) {
public @ArCoreAvailability int checkAvailability(Context applicationContext) {
// ARCore's checkAvailability reads shared preferences via ArCoreContentProvider, need to
// turn off strict mode to allow that.
// TODO(https://crbug.com/1038757): Remove the disk write context when the disk write is
......@@ -60,22 +59,22 @@ class ArCoreShimImpl implements ArCoreShim {
}
}
private @Availability int mapArCoreApkAvailability(ArCoreApk.Availability availability) {
private @ArCoreAvailability int mapArCoreApkAvailability(ArCoreApk.Availability availability) {
switch (availability) {
case SUPPORTED_APK_TOO_OLD:
return Availability.SUPPORTED_APK_TOO_OLD;
return ArCoreAvailability.SUPPORTED_APK_TOO_OLD;
case SUPPORTED_INSTALLED:
return Availability.SUPPORTED_INSTALLED;
return ArCoreAvailability.SUPPORTED_INSTALLED;
case SUPPORTED_NOT_INSTALLED:
return Availability.SUPPORTED_NOT_INSTALLED;
return ArCoreAvailability.SUPPORTED_NOT_INSTALLED;
case UNKNOWN_CHECKING:
return Availability.UNKNOWN_CHECKING;
return ArCoreAvailability.UNKNOWN_CHECKING;
case UNKNOWN_ERROR:
return Availability.UNKNOWN_ERROR;
return ArCoreAvailability.UNKNOWN_ERROR;
case UNKNOWN_TIMED_OUT:
return Availability.UNKNOWN_TIMED_OUT;
return ArCoreAvailability.UNKNOWN_TIMED_OUT;
case UNSUPPORTED_DEVICE_NOT_CAPABLE:
return Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE;
return ArCoreAvailability.UNSUPPORTED_DEVICE_NOT_CAPABLE;
default:
throw new RuntimeException(
String.format("Unknown value of Availability: %s", availability));
......
......@@ -81,6 +81,21 @@
Site can use MIDI
</message>
</if>
<if expr="enable_arcore">
<!-- ARCore check infobar -->
<message name="IDS_AR_CORE_CHECK_INFOBAR_INSTALL_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and it is not installed, an infobar will be shown to the user prompting them to install ARCore.">
To view augmented reality content, install ARCore
</message>
<message name="IDS_AR_CORE_CHECK_INFOBAR_UPDATE_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and the installed ARCore is not up to date to the version needed by the implementation, an infobar will be shown to the user prompting them to update ARCore.">
To view augmented reality content, update ARCore
</message>
<message name="IDS_AR_CORE_CHECK_INFOBAR_INSTALL_BUTTON" desc="Text to be displayed in the ARCore check infobar confirm button for installing.">
Install
</message>
<message name="IDS_AR_CORE_CHECK_INFOBAR_UPDATE_BUTTON" desc="Title of button that will direct the user to update an app from the market (Play Store)">
Update
</message>
</if>
<!-- VR browser -->
<!-- TODO(https://crbug.com/731802): Only build these when the VR browser is supported. -->
......
0c5ff3801cdd9746c79d06f5e5e275e50da2d1d1
\ No newline at end of file
53e9d9669c1b11a5768ff5a4134ccdf097c8de42
\ No newline at end of file
42a5bb8f363828fa231b343659f2483f80dd8e07
\ No newline at end of file
c2cf80e15c7b64119f4cb102448080a1d25829cf
\ No newline at end of file
......@@ -46,6 +46,9 @@ DECLARE_RESOURCE_ID(IDR_ANDROID_INFOBAR_TRANSLATE, R.drawable.infobar_translate)
LINK_RESOURCE_ID(IDR_AUTOFILL_GOOGLE_PAY_WITH_DIVIDER,
R.drawable.google_pay_with_divider)
DECLARE_RESOURCE_ID(IDR_ERROR_OUTLINE_GOOGBLUE_24DP,
R.drawable.ic_error_outline_googblue_24dp)
// Autofill popup and keyboard accessory images.
// We use Android's |VectorDrawableCompat| for the following images that are
// displayed using |DropdownAdapter|.
......
......@@ -61,6 +61,8 @@ static_library("vr_android") {
"vr_shell_delegate.h",
"vrcore_install_helper.cc",
"vrcore_install_helper.h",
"xr_install_infobar.cc",
"xr_install_infobar.h",
]
if (enable_arcore) {
......@@ -71,6 +73,8 @@ static_library("vr_android") {
"arcore_device/arcore_install_helper.h",
"arcore_device/arcore_java_utils.cc",
"arcore_device/arcore_java_utils.h",
"chrome_arcore_install_helper.cc",
"chrome_arcore_install_helper.h",
]
}
......@@ -85,6 +89,7 @@ static_library("vr_android") {
"//chrome/common:constants",
"//components/browser_ui/util/android",
"//components/content_settings/core/browser",
"//components/infobars/core",
"//components/language/core/browser",
"//components/omnibox/browser",
"//components/page_info",
......
......@@ -9,8 +9,7 @@
namespace vr {
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents(
int render_process_id,
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);
......@@ -20,7 +19,14 @@ base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents(
content::WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
return web_contents->GetJavaWebContents();
return web_contents;
}
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents(
int render_process_id,
int render_frame_id) {
return GetWebContents(render_process_id, render_frame_id)
->GetJavaWebContents();
}
} // namespace vr
......@@ -7,11 +7,18 @@
#include "base/android/jni_android.h"
namespace content {
class WebContents;
}
// Functions in this file are currently GVR/ArCore specific functions. If other
// platforms need the same function here, please move it to
// chrome/browser/vr/*util.cc|h
namespace vr {
content::WebContents* GetWebContents(int render_process_id,
int render_frame_id);
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents(
int render_process_id,
int render_frame_id);
......
......@@ -8,9 +8,16 @@
#include <utility>
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/android_theme_resources.h"
#include "chrome/browser/android/vr/android_vr_utils.h"
#include "chrome/browser/android/vr/ar_jni_headers/ArCoreInstallUtils_jni.h"
#include "chrome/browser/android/vr/arcore_device/arcore_device_provider.h"
#include "chrome/browser/android/vr/xr_install_infobar.h"
#include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "components/infobars/core/infobar_manager.h"
#include "device/vr/android/arcore/arcore_device_provider_factory.h"
using base::android::AttachCurrentThread;
......@@ -36,7 +43,7 @@ ArCoreDeviceProviderFactoryImpl::CreateDeviceProvider() {
} // namespace
ArCoreInstallHelper::ArCoreInstallHelper() : XrInstallHelper() {
ArCoreInstallHelper::ArCoreInstallHelper() {
// As per documentation, it's recommended to issue a call to
// ArCoreApk.checkAvailability() early in application lifecycle & ignore the
// result so that subsequent calls can return cached result:
......@@ -63,6 +70,7 @@ ArCoreInstallHelper::~ArCoreInstallHelper() {
void ArCoreInstallHelper::EnsureInstalled(
int render_process_id,
int render_frame_id,
infobars::InfoBarManager* infobar_manager,
base::OnceCallback<void(bool)> install_callback) {
DCHECK(!install_finished_callback_);
install_finished_callback_ = std::move(install_callback);
......@@ -72,14 +80,10 @@ void ArCoreInstallHelper::EnsureInstalled(
return;
}
JNIEnv* env = AttachCurrentThread();
if (Java_ArCoreInstallUtils_shouldRequestInstallSupportedArCore(env)) {
// ARCore is not installed or requires an update.
// When completed, java will call: OnRequestInstallSupportedArCoreResult
Java_ArCoreInstallUtils_requestInstallSupportedArCore(
env, java_install_utils_,
GetJavaWebContents(render_process_id, render_frame_id));
if (Java_ArCoreInstallUtils_shouldRequestInstallSupportedArCore(
AttachCurrentThread())) {
ShowInfoBar(render_process_id, render_frame_id, infobar_manager);
return;
}
......@@ -88,6 +92,76 @@ void ArCoreInstallHelper::EnsureInstalled(
OnRequestInstallSupportedArCoreResult(nullptr, true);
}
void ArCoreInstallHelper::ShowInfoBar(
int render_process_id,
int render_frame_id,
infobars::InfoBarManager* infobar_manager) {
// We can't show an infobar without an |infobar_manager|, so if it's null,
// report that we are not installed and stop processing.
if (!infobar_manager) {
RunInstallFinishedCallback(false);
return;
}
ArCoreAvailability availability = static_cast<ArCoreAvailability>(
Java_ArCoreInstallUtils_getArCoreInstallStatus(AttachCurrentThread()));
int message_text = -1;
int button_text = -1;
switch (availability) {
case ArCoreAvailability::kUnsupportedDeviceNotCapable: {
RunInstallFinishedCallback(false);
return; // No need to process further
}
case ArCoreAvailability::kUnknownChecking:
case ArCoreAvailability::kUnknownError:
case ArCoreAvailability::kUnknownTimedOut:
case ArCoreAvailability::kSupportedNotInstalled: {
message_text = IDS_AR_CORE_CHECK_INFOBAR_INSTALL_TEXT;
button_text = IDS_AR_CORE_CHECK_INFOBAR_INSTALL_BUTTON;
break;
}
case ArCoreAvailability::kSupportedApkTooOld: {
message_text = IDS_AR_CORE_CHECK_INFOBAR_UPDATE_TEXT;
button_text = IDS_AR_CORE_CHECK_INFOBAR_UPDATE_BUTTON;
break;
}
case ArCoreAvailability::kSupportedInstalled:
NOTREACHED();
break;
}
DCHECK_NE(-1, message_text);
DCHECK_NE(-1, button_text);
// Binding ourself as a weak ref is okay, since our destructor will still
// guarantee that the callback is run if we are destroyed while waiting for
// the callback from the infobar.
// TODO(ijamardo, https://crbug.com/838833): Add icon for AR info bar.
auto delegate = std::make_unique<XrInstallInfoBar>(
infobars::InfoBarDelegate::InfoBarIdentifier::AR_CORE_UPGRADE_ANDROID,
IDR_ERROR_OUTLINE_GOOGBLUE_24DP, message_text, button_text,
base::BindOnce(&ArCoreInstallHelper::OnInfoBarResponse,
weak_ptr_factory_.GetWeakPtr(), render_process_id,
render_frame_id));
infobar_manager->AddInfoBar(
infobar_manager->CreateConfirmInfoBar(std::move(delegate)));
}
void ArCoreInstallHelper::OnInfoBarResponse(int render_process_id,
int render_frame_id,
bool try_install) {
if (!try_install) {
OnRequestInstallSupportedArCoreResult(nullptr, false);
return;
}
// When completed, java will call: OnRequestInstallSupportedArCoreResult
Java_ArCoreInstallUtils_requestInstallSupportedArCore(
AttachCurrentThread(), java_install_utils_,
GetJavaWebContents(render_process_id, render_frame_id));
}
void ArCoreInstallHelper::OnRequestInstallSupportedArCoreResult(JNIEnv* env,
bool success) {
DVLOG(1) << __func__;
......
......@@ -8,33 +8,57 @@
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
#include "base/threading/thread_checker.h"
#include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/xr_install_helper.h"
#include "base/memory/weak_ptr.h"
namespace infobars {
class InfoBarManager;
}
namespace vr {
// Equivalent of ArCoreApk.Availability enum.
// For detailed description, please see:
// https://developers.google.com/ar/reference/java/arcore/reference/com/google/ar/core/ArCoreApk.Availability
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.vr
enum class ArCoreAvailability : int {
kSupportedApkTooOld = 0,
kSupportedInstalled = 1,
kSupportedNotInstalled = 2,
kUnknownChecking = 3,
kUnknownError = 4,
kUnknownTimedOut = 5,
kUnsupportedDeviceNotCapable = 6,
};
class VR_EXPORT ArCoreInstallHelper : public content::XrInstallHelper {
class ArCoreInstallHelper {
public:
ArCoreInstallHelper();
~ArCoreInstallHelper() override;
virtual ~ArCoreInstallHelper();
ArCoreInstallHelper(const ArCoreInstallHelper&) = delete;
ArCoreInstallHelper& operator=(const ArCoreInstallHelper&) = delete;
void EnsureInstalled(
int render_process_id,
void EnsureInstalled(int render_process_id,
int render_frame_id,
base::OnceCallback<void(bool)> install_callback) override;
infobars::InfoBarManager* infobar_manager,
base::OnceCallback<void(bool)> install_callback);
// Called from Java end.
void OnRequestInstallSupportedArCoreResult(JNIEnv* env, bool success);
private:
void ShowInfoBar(int render_process_id,
int render_frame_id,
infobars::InfoBarManager* infobar_manager);
void OnInfoBarResponse(int render_process_id,
int render_frame_id,
bool try_install);
void RunInstallFinishedCallback(bool succeeded);
base::OnceCallback<void(bool)> install_finished_callback_;
base::android::ScopedJavaGlobalRef<jobject> java_install_utils_;
// Must be last.
base::WeakPtrFactory<ArCoreInstallHelper> weak_ptr_factory_{this};
};
} // 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.
#include "chrome/browser/android/vr/chrome_arcore_install_helper.h"
#include "chrome/browser/android/vr/android_vr_utils.h"
#include "chrome/browser/android/vr/arcore_device/arcore_install_helper.h"
#include "chrome/browser/infobars/infobar_service.h"
using base::android::AttachCurrentThread;
namespace vr {
ChromeArCoreInstallHelper::ChromeArCoreInstallHelper() = default;
ChromeArCoreInstallHelper::~ChromeArCoreInstallHelper() = default;
void ChromeArCoreInstallHelper::EnsureInstalled(
int render_process_id,
int render_frame_id,
base::OnceCallback<void(bool)> install_callback) {
auto* infobar_manager = InfoBarService::FromWebContents(
GetWebContents(render_process_id, render_frame_id));
DCHECK(infobar_manager);
arcore_install_helper_.EnsureInstalled(render_process_id, render_frame_id,
infobar_manager,
std::move(install_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_ANDROID_VR_CHROME_ARCORE_INSTALL_HELPER_H_
#define CHROME_BROWSER_ANDROID_VR_CHROME_ARCORE_INSTALL_HELPER_H_
#include "base/callback.h"
#include "chrome/browser/android/vr/arcore_device/arcore_install_helper.h"
#include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/xr_install_helper.h"
namespace vr {
// The Actual ArCoreInstallHelper needs an InfoBarManager interface, which
// content/browser is unable to provide, as it has no means of accessing the
// embedder specific factory method, to that end we make a small wrapper class
// to extract the relevant InfoBarManager.
class VR_EXPORT ChromeArCoreInstallHelper : public content::XrInstallHelper {
public:
ChromeArCoreInstallHelper();
~ChromeArCoreInstallHelper() override;
ChromeArCoreInstallHelper(const ChromeArCoreInstallHelper&) = delete;
ChromeArCoreInstallHelper& operator=(const ChromeArCoreInstallHelper&) =
delete;
void EnsureInstalled(
int render_process_id,
int render_frame_id,
base::OnceCallback<void(bool)> install_callback) override;
private:
ArCoreInstallHelper arcore_install_helper_;
};
} // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_CHROME_ARCORE_INSTALL_HELPER_H_
// Copyright (c) 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 "chrome/browser/android/vr/xr_install_infobar.h"
#include "base/callback.h"
#include "base/strings/string16.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "ui/base/l10n/l10n_util.h"
namespace vr {
XrInstallInfoBar::XrInstallInfoBar(
InfoBarIdentifier identifier,
int icon_id,
int message_id,
int ok_button_id,
base::OnceCallback<void(bool)> install_callback)
: identifier_(identifier),
icon_id_(icon_id),
message_id_(message_id),
ok_button_id_(ok_button_id),
install_callback_(std::move(install_callback)) {}
XrInstallInfoBar::~XrInstallInfoBar() = default;
infobars::InfoBarDelegate::InfoBarIdentifier XrInstallInfoBar::GetIdentifier()
const {
return identifier_;
}
int XrInstallInfoBar::GetIconId() const {
return icon_id_;
}
int XrInstallInfoBar::GetButtons() const {
return BUTTON_OK;
}
base::string16 XrInstallInfoBar::GetButtonLabel(InfoBarButton button) const {
DCHECK_EQ(BUTTON_OK, button);
return l10n_util::GetStringUTF16(ok_button_id_);
}
base::string16 XrInstallInfoBar::GetMessageText() const {
return l10n_util::GetStringUTF16(message_id_);
}
bool XrInstallInfoBar::Accept() {
std::move(install_callback_).Run(true);
return true;
}
bool XrInstallInfoBar::Cancel() {
std::move(install_callback_).Run(false);
return true;
}
void XrInstallInfoBar::InfoBarDismissed() {
std::move(install_callback_).Run(false);
}
} // namespace vr
// Copyright (c) 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_ANDROID_VR_XR_INSTALL_INFOBAR_H_
#define CHROME_BROWSER_ANDROID_VR_XR_INSTALL_INFOBAR_H_
#include "base/callback.h"
#include "base/strings/string16.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
namespace vr {
// An interface derived from InfoBarDelegate implemented by objects wishing to
// control a ConfirmInfoBar.
class XrInstallInfoBar : public ConfirmInfoBarDelegate {
public:
XrInstallInfoBar(InfoBarIdentifier identifier,
int icon_id,
int message_id,
int ok_button_id,
base::OnceCallback<void(bool)> install_callback);
~XrInstallInfoBar() override;
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
int GetIconId() const override;
base::string16 GetMessageText() const override;
int GetButtons() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override;
private:
// Called when the OK button is pressed. If this function returns true, the
// infobar is then immediately closed. Subclasses MUST NOT return true if in
// handling this call something triggers the infobar to begin closing.
bool Accept() override;
// Called when the Cancel button is pressed. If this function returns true,
// the infobar is then immediately closed. Subclasses MUST NOT return true if
// in handling this call something triggers the infobar to begin closing.
bool Cancel() override;
// Called when the user clicks on the close button to dismiss the infobar.
void InfoBarDismissed() override;
const infobars::InfoBarDelegate::InfoBarIdentifier identifier_;
const int icon_id_;
const int message_id_;
const int ok_button_id_;
base::OnceCallback<void(bool)> install_callback_;
};
} // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_XR_INSTALL_INFOBAR_H_
......@@ -3594,23 +3594,10 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n
</message>
<if expr="enable_arcore">
<!-- ARCore check infobar -->
<message name="IDS_AR_CORE_CHECK_INFOBAR_INSTALL_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and it is not installed, an infobar will be shown to the user prompting them to install ARCore.">
To view augmented reality content, install ARCore
</message>
<message name="IDS_AR_CORE_CHECK_INFOBAR_UPDATE_TEXT" desc="Text to be displayed in the ARCore check infobar. When a WebXR page is loaded, if ARCore is needed to display AR content and the installed ARCore is not up to date to the version needed by the implementation, an infobar will be shown to the user prompting them to update ARCore.">
To view augmented reality content, update ARCore
</message>
<!-- AR module -->
<message name="IDS_AR_MODULE_TITLE" desc="Text shown when the AR module is referenced in install start, success, failure UI (e.g. in IDS_MODULE_INSTALL_START_TEXT, which will expand to 'Installing Augmented Reality for Chrome…').">
Augmented Reality
</message>
<!-- App upgrade from Play Store -->
<message name="IDS_UPDATE_FROM_MARKET" desc="Title of button that will direct the user to update an app from the market (Play Store)">
Update
</message>
</if>
<!-- Dynamic feature modules -->
......
......@@ -23,7 +23,7 @@
#include "chrome/browser/android/vr/gvr_install_helper.h"
#include "device/vr/android/gvr/gvr_device_provider.h"
#if BUILDFLAG(ENABLE_ARCORE)
#include "chrome/browser/android/vr/arcore_device/arcore_install_helper.h"
#include "chrome/browser/android/vr/chrome_arcore_install_helper.h"
#include "device/vr/android/arcore/arcore_device_provider_factory.h"
#endif // ENABLE_ARCORE
#endif // OS_WIN/OS_ANDROID
......@@ -39,7 +39,7 @@ ChromeXrIntegrationClient::GetInstallHelper(
return std::make_unique<GvrInstallHelper>();
#if BUILDFLAG(ENABLE_ARCORE)
case device::mojom::XRDeviceId::ARCORE_DEVICE_ID:
return std::make_unique<ArCoreInstallHelper>();
return std::make_unique<ChromeArCoreInstallHelper>();
#endif // ENABLE_ARCORE
#endif // OS_ANDROID
default:
......
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