Commit 2b751bd7 authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

JNI refactor: @NativeMethods conversion (//chrome/android/features).

To create this change:
  * cd chrome/android/features
  * base/android/jni_generator/jni_refactorer.py -R --nonstatic
  * base/android/jni_generator/jni_refactorer.py -R
  * Change the native side of VrShellDelegateJni#recordVrStartAction
    to not pass the Java object

Bug: 929661
Change-Id: I1d2c57e0f7a30a8b7e50e9e3ce905172cbb761cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1749737
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Eric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687674}
parent f18f41a5
...@@ -30,6 +30,7 @@ android_library("java") { ...@@ -30,6 +30,7 @@ android_library("java") {
deps = [ deps = [
":java_resources", ":java_resources",
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
"//chrome/android:chrome_public_java", "//chrome/android:chrome_public_java",
"//chrome/android/public/profiles:java", "//chrome/android/public/profiles:java",
...@@ -130,6 +131,7 @@ android_library("java") { ...@@ -130,6 +131,7 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/AssistantVerticalExpander.java", "java/src/org/chromium/chrome/browser/autofill_assistant/payment/AssistantVerticalExpander.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/payment/AssistantVerticalExpanderAccordion.java", "java/src/org/chromium/chrome/browser/autofill_assistant/payment/AssistantVerticalExpanderAccordion.java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
generate_jni("jni_headers") { generate_jni("jni_headers") {
...@@ -171,9 +173,11 @@ android_library("autofill_assistant_java_test_support") { ...@@ -171,9 +173,11 @@ android_library("autofill_assistant_java_test_support") {
deps = [ deps = [
":java", ":java",
":test_support_jni_headers", ":test_support_jni_headers",
"//base:jni_java",
"//components/autofill_assistant/browser:proto_java", "//components/autofill_assistant/browser:proto_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java", "//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
android_library("test_java") { android_library("test_java") {
......
...@@ -14,6 +14,7 @@ import org.chromium.base.Callback; ...@@ -14,6 +14,7 @@ import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.OAuth2TokenService; import org.chromium.components.signin.OAuth2TokenService;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -68,7 +69,7 @@ class AutofillAssistantClient { ...@@ -68,7 +69,7 @@ class AutofillAssistantClient {
/** Returns the client for the given web contents, creating it if necessary. */ /** Returns the client for the given web contents, creating it if necessary. */
public static AutofillAssistantClient fromWebContents(WebContents webContents) { public static AutofillAssistantClient fromWebContents(WebContents webContents) {
return nativeFromWebContents(webContents); return AutofillAssistantClientJni.get().fromWebContents(webContents);
} }
private AutofillAssistantClient(long nativeClientAndroid) { private AutofillAssistantClient(long nativeClientAndroid) {
...@@ -105,7 +106,8 @@ class AutofillAssistantClient { ...@@ -105,7 +106,8 @@ class AutofillAssistantClient {
checkNativeClientIsAliveOrThrow(); checkNativeClientIsAliveOrThrow();
chooseAccountAsyncIfNecessary(parameters.get(PARAMETER_USER_EMAIL), intentExtras); chooseAccountAsyncIfNecessary(parameters.get(PARAMETER_USER_EMAIL), intentExtras);
return nativeStart(mNativeClientAndroid, initialUrl, experimentIds, return AutofillAssistantClientJni.get().start(mNativeClientAndroid,
AutofillAssistantClient.this, initialUrl, experimentIds,
parameters.keySet().toArray(new String[parameters.size()]), parameters.keySet().toArray(new String[parameters.size()]),
parameters.values().toArray(new String[parameters.size()]), onboardingCoordinator, parameters.values().toArray(new String[parameters.size()]), onboardingCoordinator,
AutofillAssistantServiceInjector.getServiceToInject()); AutofillAssistantServiceInjector.getServiceToInject());
...@@ -117,7 +119,8 @@ class AutofillAssistantClient { ...@@ -117,7 +119,8 @@ class AutofillAssistantClient {
public void destroyUi() { public void destroyUi() {
if (mNativeClientAndroid == 0) return; if (mNativeClientAndroid == 0) return;
nativeDestroyUI(mNativeClientAndroid); AutofillAssistantClientJni.get().destroyUI(
mNativeClientAndroid, AutofillAssistantClient.this);
} }
/** /**
...@@ -130,7 +133,8 @@ class AutofillAssistantClient { ...@@ -130,7 +133,8 @@ class AutofillAssistantClient {
public void transferUiTo(WebContents otherWebContents) { public void transferUiTo(WebContents otherWebContents) {
if (mNativeClientAndroid == 0) return; if (mNativeClientAndroid == 0) return;
nativeTransferUITo(mNativeClientAndroid, otherWebContents); AutofillAssistantClientJni.get().transferUITo(
mNativeClientAndroid, AutofillAssistantClient.this, otherWebContents);
} }
/** Lists available direct actions. */ /** Lists available direct actions. */
...@@ -145,7 +149,8 @@ class AutofillAssistantClient { ...@@ -145,7 +149,8 @@ class AutofillAssistantClient {
// The native side calls sendDirectActionList() on the callback once the controller has // The native side calls sendDirectActionList() on the callback once the controller has
// results. // results.
nativeListDirectActions(mNativeClientAndroid, experimentIds, AutofillAssistantClientJni.get().listDirectActions(mNativeClientAndroid,
AutofillAssistantClient.this, experimentIds,
arguments.keySet().toArray(new String[arguments.size()]), arguments.keySet().toArray(new String[arguments.size()]),
arguments.values().toArray(new String[arguments.size()]), callback); arguments.values().toArray(new String[arguments.size()]), callback);
} }
...@@ -168,7 +173,8 @@ class AutofillAssistantClient { ...@@ -168,7 +173,8 @@ class AutofillAssistantClient {
// Note that only listDirectActions can start AA, so only it needs // Note that only listDirectActions can start AA, so only it needs
// chooseAccountAsyncIfNecessary. // chooseAccountAsyncIfNecessary.
return nativePerformDirectAction(mNativeClientAndroid, actionId, experimentIds, return AutofillAssistantClientJni.get().performDirectAction(mNativeClientAndroid,
AutofillAssistantClient.this, actionId, experimentIds,
arguments.keySet().toArray(new String[arguments.size()]), arguments.keySet().toArray(new String[arguments.size()]),
arguments.values().toArray(new String[arguments.size()]), onboardingCoordinator); arguments.values().toArray(new String[arguments.size()]), onboardingCoordinator);
} }
...@@ -190,8 +196,9 @@ class AutofillAssistantClient { ...@@ -190,8 +196,9 @@ class AutofillAssistantClient {
onAccountChosen(accounts.get(0)); onAccountChosen(accounts.get(0));
return; return;
} }
Account signedIn = Account signedIn = findAccountByName(accounts,
findAccountByName(accounts, nativeGetPrimaryAccountName(mNativeClientAndroid)); AutofillAssistantClientJni.get().getPrimaryAccountName(
mNativeClientAndroid, AutofillAssistantClient.this));
if (signedIn != null) { if (signedIn != null) {
// TODO(crbug.com/806868): Compare against account name from extras and complain if // TODO(crbug.com/806868): Compare against account name from extras and complain if
// they don't match. // they don't match.
...@@ -253,7 +260,9 @@ class AutofillAssistantClient { ...@@ -253,7 +260,9 @@ class AutofillAssistantClient {
return; return;
} }
if (mAccount == null) { if (mAccount == null) {
if (mNativeClientAndroid != 0) nativeOnAccessToken(mNativeClientAndroid, true, ""); if (mNativeClientAndroid != 0)
AutofillAssistantClientJni.get().onAccessToken(
mNativeClientAndroid, AutofillAssistantClient.this, true, "");
return; return;
} }
...@@ -262,14 +271,16 @@ class AutofillAssistantClient { ...@@ -262,14 +271,16 @@ class AutofillAssistantClient {
@Override @Override
public void onGetTokenSuccess(String token) { public void onGetTokenSuccess(String token) {
if (mNativeClientAndroid != 0) { if (mNativeClientAndroid != 0) {
nativeOnAccessToken(mNativeClientAndroid, true, token); AutofillAssistantClientJni.get().onAccessToken(mNativeClientAndroid,
AutofillAssistantClient.this, true, token);
} }
} }
@Override @Override
public void onGetTokenFailure(boolean isTransientError) { public void onGetTokenFailure(boolean isTransientError) {
if (!isTransientError && mNativeClientAndroid != 0) { if (!isTransientError && mNativeClientAndroid != 0) {
nativeOnAccessToken(mNativeClientAndroid, false, ""); AutofillAssistantClientJni.get().onAccessToken(
mNativeClientAndroid, AutofillAssistantClient.this, false, "");
} }
} }
}); });
...@@ -324,18 +335,24 @@ class AutofillAssistantClient { ...@@ -324,18 +335,24 @@ class AutofillAssistantClient {
mNativeClientAndroid = 0; mNativeClientAndroid = 0;
} }
private static native AutofillAssistantClient nativeFromWebContents(WebContents webContents); @NativeMethods
private native boolean nativeStart(long nativeClientAndroid, String initialUrl, interface Natives {
AutofillAssistantClient fromWebContents(WebContents webContents);
boolean start(long nativeClientAndroid, AutofillAssistantClient caller, String initialUrl,
String experimentIds, String[] parameterNames, String[] parameterValues, String experimentIds, String[] parameterNames, String[] parameterValues,
@Nullable AssistantOnboardingCoordinator onboardingCoordinator, long nativeService); @Nullable AssistantOnboardingCoordinator onboardingCoordinator, long nativeService);
private native void nativeOnAccessToken( void onAccessToken(long nativeClientAndroid, AutofillAssistantClient caller,
long nativeClientAndroid, boolean success, String accessToken); boolean success, String accessToken);
private native String nativeGetPrimaryAccountName(long nativeClientAndroid); String getPrimaryAccountName(long nativeClientAndroid, AutofillAssistantClient caller);
private native void nativeDestroyUI(long nativeClientAndroid); void destroyUI(long nativeClientAndroid, AutofillAssistantClient caller);
private native void nativeTransferUITo(long nativeClientAndroid, Object otherWebContents); void transferUITo(
private native void nativeListDirectActions(long nativeClientAndroid, String experimentIds, long nativeClientAndroid, AutofillAssistantClient caller, Object otherWebContents);
String[] argumentNames, String[] argumentValues, Object callback); void listDirectActions(long nativeClientAndroid, AutofillAssistantClient caller,
private native boolean nativePerformDirectAction(long nativeClientAndroid, String actionId, String experimentIds, String[] argumentNames, String[] argumentValues,
String experimentId, String[] argumentNames, String[] argumentValues, Object callback);
boolean performDirectAction(long nativeClientAndroid, AutofillAssistantClient caller,
String actionId, String experimentId, String[] argumentNames,
String[] argumentValues,
@Nullable AssistantOnboardingCoordinator onboardingCoordinator); @Nullable AssistantOnboardingCoordinator onboardingCoordinator);
}
} }
...@@ -8,6 +8,7 @@ import android.support.annotation.Nullable; ...@@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.chrome.autofill_assistant.R; import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
...@@ -314,38 +315,62 @@ class AutofillAssistantUiController { ...@@ -314,38 +315,62 @@ class AutofillAssistantUiController {
// Native methods. // Native methods.
private void safeSnackbarResult(boolean undo) { private void safeSnackbarResult(boolean undo) {
if (mNativeUiController != 0) nativeSnackbarResult(mNativeUiController, undo); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().snackbarResult(
mNativeUiController, AutofillAssistantUiController.this, undo);
} }
private native void nativeSnackbarResult(long nativeUiControllerAndroid, boolean undo);
private void safeNativeStop(@DropOutReason int reason) { private void safeNativeStop(@DropOutReason int reason) {
if (mNativeUiController != 0) nativeStop(mNativeUiController, reason); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().stop(
mNativeUiController, AutofillAssistantUiController.this, reason);
} }
private native void nativeStop(long nativeUiControllerAndroid, @DropOutReason int reason);
private void safeNativeOnFatalError(String message, @DropOutReason int reason) { private void safeNativeOnFatalError(String message, @DropOutReason int reason) {
if (mNativeUiController != 0) nativeOnFatalError(mNativeUiController, message, reason); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().onFatalError(
mNativeUiController, AutofillAssistantUiController.this, message, reason);
} }
private native void nativeOnFatalError(
long nativeUiControllerAndroid, String message, @DropOutReason int reason);
private void safeNativeOnUserActionSelected(int index) { private void safeNativeOnUserActionSelected(int index) {
if (mNativeUiController != 0) nativeOnUserActionSelected(mNativeUiController, index); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().onUserActionSelected(
mNativeUiController, AutofillAssistantUiController.this, index);
} }
private native void nativeOnUserActionSelected(long nativeUiControllerAndroid, int index);
private void safeNativeOnCancelButtonClicked(int index) { private void safeNativeOnCancelButtonClicked(int index) {
if (mNativeUiController != 0) nativeOnCancelButtonClicked(mNativeUiController, index); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().onCancelButtonClicked(
mNativeUiController, AutofillAssistantUiController.this, index);
} }
private native void nativeOnCancelButtonClicked(long nativeUiControllerAndroid, int index);
private void safeNativeOnCloseButtonClicked() { private void safeNativeOnCloseButtonClicked() {
if (mNativeUiController != 0) nativeOnCloseButtonClicked(mNativeUiController); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().onCloseButtonClicked(
mNativeUiController, AutofillAssistantUiController.this);
} }
private native void nativeOnCloseButtonClicked(long nativeUiControllerAndroid);
private void safeNativeSetVisible(boolean visible) { private void safeNativeSetVisible(boolean visible) {
if (mNativeUiController != 0) nativeSetVisible(mNativeUiController, visible); if (mNativeUiController != 0)
AutofillAssistantUiControllerJni.get().setVisible(
mNativeUiController, AutofillAssistantUiController.this, visible);
}
@NativeMethods
interface Natives {
void snackbarResult(
long nativeUiControllerAndroid, AutofillAssistantUiController caller, boolean undo);
void stop(long nativeUiControllerAndroid, AutofillAssistantUiController caller,
@DropOutReason int reason);
void onFatalError(long nativeUiControllerAndroid, AutofillAssistantUiController caller,
String message, @DropOutReason int reason);
void onUserActionSelected(
long nativeUiControllerAndroid, AutofillAssistantUiController caller, int index);
void onCancelButtonClicked(
long nativeUiControllerAndroid, AutofillAssistantUiController caller, int index);
void onCloseButtonClicked(
long nativeUiControllerAndroid, AutofillAssistantUiController caller);
void setVisible(long nativeUiControllerAndroid, AutofillAssistantUiController caller,
boolean visible);
} }
private native void nativeSetVisible(long nativeUiControllerAndroid, boolean visible);
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.form; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.form;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/** Delegate for the form UI. */ /** Delegate for the form UI. */
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
...@@ -23,13 +24,14 @@ class AssistantFormDelegate { ...@@ -23,13 +24,14 @@ class AssistantFormDelegate {
void onCounterChanged(int inputIndex, int counterIndex, int value) { void onCounterChanged(int inputIndex, int counterIndex, int value) {
if (mNativeAssistantFormDelegate != 0) { if (mNativeAssistantFormDelegate != 0) {
nativeOnCounterChanged(mNativeAssistantFormDelegate, inputIndex, counterIndex, value); AssistantFormDelegateJni.get().onCounterChanged(mNativeAssistantFormDelegate,
AssistantFormDelegate.this, inputIndex, counterIndex, value);
} }
} }
void onChoiceSelectionChanged(int inputIndex, int choiceIndex, boolean selected) { void onChoiceSelectionChanged(int inputIndex, int choiceIndex, boolean selected) {
if (mNativeAssistantFormDelegate != 0) { if (mNativeAssistantFormDelegate != 0) {
nativeOnChoiceSelectionChanged( AssistantFormDelegateJni.get().onChoiceSelectionChanged(mNativeAssistantFormDelegate,
mNativeAssistantFormDelegate, inputIndex, choiceIndex, selected); AssistantFormDelegate.this, inputIndex, choiceIndex, selected);
} }
} }
...@@ -38,8 +40,11 @@ class AssistantFormDelegate { ...@@ -38,8 +40,11 @@ class AssistantFormDelegate {
mNativeAssistantFormDelegate = 0; mNativeAssistantFormDelegate = 0;
} }
private native void nativeOnCounterChanged(long nativeAssistantFormDelegate, int inputIndex, @NativeMethods
int counterIndex, long nativeAssistantOverlayDelegate); interface Natives {
private native void nativeOnChoiceSelectionChanged( void onCounterChanged(long nativeAssistantFormDelegate, AssistantFormDelegate caller,
long nativeAssistantFormDelegate, int inputIndex, int choiceIndex, boolean selected); int inputIndex, int counterIndex, long nativeAssistantOverlayDelegate);
void onChoiceSelectionChanged(long nativeAssistantFormDelegate,
AssistantFormDelegate caller, int inputIndex, int choiceIndex, boolean selected);
}
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.header; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.header;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
class AssistantHeaderDelegate { class AssistantHeaderDelegate {
...@@ -22,7 +23,8 @@ class AssistantHeaderDelegate { ...@@ -22,7 +23,8 @@ class AssistantHeaderDelegate {
void onFeedbackButtonClicked() { void onFeedbackButtonClicked() {
if (mNativeAssistantHeaderDelegate != 0) { if (mNativeAssistantHeaderDelegate != 0) {
nativeOnFeedbackButtonClicked(mNativeAssistantHeaderDelegate); AssistantHeaderDelegateJni.get().onFeedbackButtonClicked(
mNativeAssistantHeaderDelegate, AssistantHeaderDelegate.this);
} }
} }
...@@ -31,5 +33,9 @@ class AssistantHeaderDelegate { ...@@ -31,5 +33,9 @@ class AssistantHeaderDelegate {
mNativeAssistantHeaderDelegate = 0; mNativeAssistantHeaderDelegate = 0;
} }
private native void nativeOnFeedbackButtonClicked(long nativeAssistantHeaderDelegate); @NativeMethods
interface Natives {
void onFeedbackButtonClicked(
long nativeAssistantHeaderDelegate, AssistantHeaderDelegate caller);
}
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.overlay; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.autofill_assistant.overlay;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/** Delegate for the overlay. */ /** Delegate for the overlay. */
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
...@@ -24,14 +25,16 @@ class AssistantOverlayDelegate { ...@@ -24,14 +25,16 @@ class AssistantOverlayDelegate {
/** Called after a certain number of unexpected taps. */ /** Called after a certain number of unexpected taps. */
void onUnexpectedTaps() { void onUnexpectedTaps() {
if (mNativeAssistantOverlayDelegate != 0) { if (mNativeAssistantOverlayDelegate != 0) {
nativeOnUnexpectedTaps(mNativeAssistantOverlayDelegate); AssistantOverlayDelegateJni.get().onUnexpectedTaps(
mNativeAssistantOverlayDelegate, AssistantOverlayDelegate.this);
} }
} }
/** Asks for an update of the touchable area. */ /** Asks for an update of the touchable area. */
void updateTouchableArea() { void updateTouchableArea() {
if (mNativeAssistantOverlayDelegate != 0) { if (mNativeAssistantOverlayDelegate != 0) {
nativeUpdateTouchableArea(mNativeAssistantOverlayDelegate); AssistantOverlayDelegateJni.get().updateTouchableArea(
mNativeAssistantOverlayDelegate, AssistantOverlayDelegate.this);
} }
} }
...@@ -41,7 +44,8 @@ class AssistantOverlayDelegate { ...@@ -41,7 +44,8 @@ class AssistantOverlayDelegate {
*/ */
void onUserInteractionInsideTouchableArea() { void onUserInteractionInsideTouchableArea() {
if (mNativeAssistantOverlayDelegate != 0) { if (mNativeAssistantOverlayDelegate != 0) {
nativeOnUserInteractionInsideTouchableArea(mNativeAssistantOverlayDelegate); AssistantOverlayDelegateJni.get().onUserInteractionInsideTouchableArea(
mNativeAssistantOverlayDelegate, AssistantOverlayDelegate.this);
} }
} }
...@@ -50,8 +54,12 @@ class AssistantOverlayDelegate { ...@@ -50,8 +54,12 @@ class AssistantOverlayDelegate {
mNativeAssistantOverlayDelegate = 0; mNativeAssistantOverlayDelegate = 0;
} }
private native void nativeOnUnexpectedTaps(long nativeAssistantOverlayDelegate); @NativeMethods
private native void nativeUpdateTouchableArea(long nativeAssistantOverlayDelegate); interface Natives {
private native void nativeOnUserInteractionInsideTouchableArea( void onUnexpectedTaps(long nativeAssistantOverlayDelegate, AssistantOverlayDelegate caller);
long nativeAssistantOverlayDelegate); void updateTouchableArea(
long nativeAssistantOverlayDelegate, AssistantOverlayDelegate caller);
void onUserInteractionInsideTouchableArea(
long nativeAssistantOverlayDelegate, AssistantOverlayDelegate caller);
}
} }
...@@ -8,6 +8,7 @@ import android.support.annotation.Nullable; ...@@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.payments.AutofillAddress; import org.chromium.chrome.browser.payments.AutofillAddress;
import org.chromium.chrome.browser.payments.AutofillContact; import org.chromium.chrome.browser.payments.AutofillContact;
...@@ -41,14 +42,18 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe ...@@ -41,14 +42,18 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe
email = contact.getPayerEmail(); email = contact.getPayerEmail();
} }
nativeOnContactInfoChanged(mNativeAssistantPaymentRequestDelegate, name, phone, email); AssistantPaymentRequestNativeDelegateJni.get().onContactInfoChanged(
mNativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate.this, name, phone, email);
} }
} }
@Override @Override
public void onShippingAddressChanged(@Nullable AutofillAddress address) { public void onShippingAddressChanged(@Nullable AutofillAddress address) {
if (mNativeAssistantPaymentRequestDelegate != 0) { if (mNativeAssistantPaymentRequestDelegate != 0) {
nativeOnShippingAddressChanged(mNativeAssistantPaymentRequestDelegate, AssistantPaymentRequestNativeDelegateJni.get().onShippingAddressChanged(
mNativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate.this,
address != null ? address.getProfile() : null); address != null ? address.getProfile() : null);
} }
} }
...@@ -56,7 +61,9 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe ...@@ -56,7 +61,9 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe
@Override @Override
public void onPaymentMethodChanged(@Nullable AutofillPaymentInstrument paymentInstrument) { public void onPaymentMethodChanged(@Nullable AutofillPaymentInstrument paymentInstrument) {
if (mNativeAssistantPaymentRequestDelegate != 0) { if (mNativeAssistantPaymentRequestDelegate != 0) {
nativeOnCreditCardChanged(mNativeAssistantPaymentRequestDelegate, AssistantPaymentRequestNativeDelegateJni.get().onCreditCardChanged(
mNativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate.this,
paymentInstrument != null ? paymentInstrument.getCard() : null); paymentInstrument != null ? paymentInstrument.getCard() : null);
} }
} }
...@@ -64,14 +71,18 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe ...@@ -64,14 +71,18 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe
@Override @Override
public void onTermsAndConditionsChanged(@AssistantTermsAndConditionsState int state) { public void onTermsAndConditionsChanged(@AssistantTermsAndConditionsState int state) {
if (mNativeAssistantPaymentRequestDelegate != 0) { if (mNativeAssistantPaymentRequestDelegate != 0) {
nativeOnTermsAndConditionsChanged(mNativeAssistantPaymentRequestDelegate, state); AssistantPaymentRequestNativeDelegateJni.get().onTermsAndConditionsChanged(
mNativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate.this, state);
} }
} }
@Override @Override
public void onTermsAndConditionsLinkClicked(int link) { public void onTermsAndConditionsLinkClicked(int link) {
if (mNativeAssistantPaymentRequestDelegate != 0) { if (mNativeAssistantPaymentRequestDelegate != 0) {
nativeOnTermsAndConditionsLinkClicked(mNativeAssistantPaymentRequestDelegate, link); AssistantPaymentRequestNativeDelegateJni.get().onTermsAndConditionsLinkClicked(
mNativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate.this, link);
} }
} }
...@@ -80,14 +91,20 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe ...@@ -80,14 +91,20 @@ public class AssistantPaymentRequestNativeDelegate implements AssistantPaymentRe
mNativeAssistantPaymentRequestDelegate = 0; mNativeAssistantPaymentRequestDelegate = 0;
} }
private native void nativeOnContactInfoChanged(long nativeAssistantPaymentRequestDelegate, @NativeMethods
@Nullable String payerName, @Nullable String payerPhone, @Nullable String payerEmail); interface Natives {
private native void nativeOnShippingAddressChanged(long nativeAssistantPaymentRequestDelegate, void onContactInfoChanged(long nativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate caller, @Nullable String payerName,
@Nullable String payerPhone, @Nullable String payerEmail);
void onShippingAddressChanged(long nativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate caller,
@Nullable PersonalDataManager.AutofillProfile address); @Nullable PersonalDataManager.AutofillProfile address);
private native void nativeOnCreditCardChanged(long nativeAssistantPaymentRequestDelegate, void onCreditCardChanged(long nativeAssistantPaymentRequestDelegate,
AssistantPaymentRequestNativeDelegate caller,
@Nullable PersonalDataManager.CreditCard card); @Nullable PersonalDataManager.CreditCard card);
private native void nativeOnTermsAndConditionsChanged( void onTermsAndConditionsChanged(long nativeAssistantPaymentRequestDelegate,
long nativeAssistantPaymentRequestDelegate, int state); AssistantPaymentRequestNativeDelegate caller, int state);
private native void nativeOnTermsAndConditionsLinkClicked( void onTermsAndConditionsLinkClicked(long nativeAssistantPaymentRequestDelegate,
long nativeAssistantPaymentRequestDelegate, int link); AssistantPaymentRequestNativeDelegate caller, int link);
}
} }
...@@ -8,6 +8,7 @@ import com.google.protobuf.ByteString; ...@@ -8,6 +8,7 @@ import com.google.protobuf.ByteString;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.autofill_assistant.proto.ActionsResponseProto; import org.chromium.chrome.browser.autofill_assistant.proto.ActionsResponseProto;
import org.chromium.chrome.browser.autofill_assistant.proto.SupportsScriptResponseProto; import org.chromium.chrome.browser.autofill_assistant.proto.SupportsScriptResponseProto;
...@@ -38,7 +39,7 @@ public class AutofillAssistantTestService ...@@ -38,7 +39,7 @@ public class AutofillAssistantTestService
public long createNativeService() { public long createNativeService() {
// Ask native to create and return a wrapper around |this|. The wrapper will be injected // Ask native to create and return a wrapper around |this|. The wrapper will be injected
// upon startup, at which point the native controller will take ownership of the wrapper. // upon startup, at which point the native controller will take ownership of the wrapper.
return nativeJavaServiceCreate(this); return AutofillAssistantTestServiceJni.get().javaServiceCreate(this);
} }
/** @see AutofillAssistantService#getScriptsForUrl(String) */ /** @see AutofillAssistantService#getScriptsForUrl(String) */
...@@ -93,5 +94,8 @@ public class AutofillAssistantTestService ...@@ -93,5 +94,8 @@ public class AutofillAssistantTestService
return getNextActions(globalPayload, scriptPayload).toByteArray(); return getNextActions(globalPayload, scriptPayload).toByteArray();
} }
private static native long nativeJavaServiceCreate(AutofillAssistantTestService service); @NativeMethods
interface Natives {
long javaServiceCreate(AutofillAssistantTestService service);
}
} }
...@@ -9,6 +9,7 @@ android_library("internal_java") { ...@@ -9,6 +9,7 @@ android_library("internal_java") {
deps = [ deps = [
":java_resources", ":java_resources",
"//base:base_java", "//base:base_java",
"//base:jni_java",
# TODO(crbug/951695): Cyclic dependency. Depend on public only when ready. # TODO(crbug/951695): Cyclic dependency. Depend on public only when ready.
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
...@@ -76,6 +77,7 @@ android_library("internal_java") { ...@@ -76,6 +77,7 @@ android_library("internal_java") {
"java/src/org/chromium/chrome/browser/keyboard_accessory/tab_layout_component/KeyboardAccessoryTabLayoutView.java", "java/src/org/chromium/chrome/browser/keyboard_accessory/tab_layout_component/KeyboardAccessoryTabLayoutView.java",
"java/src/org/chromium/chrome/browser/keyboard_accessory/tab_layout_component/KeyboardAccessoryTabLayoutViewBinder.java", "java/src/org/chromium/chrome/browser/keyboard_accessory/tab_layout_component/KeyboardAccessoryTabLayoutViewBinder.java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
android_resources("java_resources") { android_resources("java_resources") {
......
...@@ -9,6 +9,7 @@ import android.content.DialogInterface; ...@@ -9,6 +9,7 @@ import android.content.DialogInterface;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.keyboard_accessory.data.PropertyProvider; import org.chromium.chrome.browser.keyboard_accessory.data.PropertyProvider;
...@@ -41,20 +42,25 @@ public class AutofillKeyboardAccessoryViewBridge ...@@ -41,20 +42,25 @@ public class AutofillKeyboardAccessoryViewBridge
@Override @Override
public void dismissed() { public void dismissed() {
if (mNativeAutofillKeyboardAccessory == 0) return; if (mNativeAutofillKeyboardAccessory == 0) return;
nativeViewDismissed(mNativeAutofillKeyboardAccessory); AutofillKeyboardAccessoryViewBridgeJni.get().viewDismissed(
mNativeAutofillKeyboardAccessory, AutofillKeyboardAccessoryViewBridge.this);
} }
@Override @Override
public void suggestionSelected(int listIndex) { public void suggestionSelected(int listIndex) {
mManualFillingComponent.dismiss(); mManualFillingComponent.dismiss();
if (mNativeAutofillKeyboardAccessory == 0) return; if (mNativeAutofillKeyboardAccessory == 0) return;
nativeSuggestionSelected(mNativeAutofillKeyboardAccessory, listIndex); AutofillKeyboardAccessoryViewBridgeJni.get().suggestionSelected(
mNativeAutofillKeyboardAccessory, AutofillKeyboardAccessoryViewBridge.this,
listIndex);
} }
@Override @Override
public void deleteSuggestion(int listIndex) { public void deleteSuggestion(int listIndex) {
if (mNativeAutofillKeyboardAccessory == 0) return; if (mNativeAutofillKeyboardAccessory == 0) return;
nativeDeletionRequested(mNativeAutofillKeyboardAccessory, listIndex); AutofillKeyboardAccessoryViewBridgeJni.get().deletionRequested(
mNativeAutofillKeyboardAccessory, AutofillKeyboardAccessoryViewBridge.this,
listIndex);
} }
@Override @Override
...@@ -64,7 +70,8 @@ public class AutofillKeyboardAccessoryViewBridge ...@@ -64,7 +70,8 @@ public class AutofillKeyboardAccessoryViewBridge
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
assert which == DialogInterface.BUTTON_POSITIVE; assert which == DialogInterface.BUTTON_POSITIVE;
if (mNativeAutofillKeyboardAccessory == 0) return; if (mNativeAutofillKeyboardAccessory == 0) return;
nativeDeletionConfirmed(mNativeAutofillKeyboardAccessory); AutofillKeyboardAccessoryViewBridgeJni.get().deletionConfirmed(
mNativeAutofillKeyboardAccessory, AutofillKeyboardAccessoryViewBridge.this);
} }
/** /**
...@@ -159,10 +166,15 @@ public class AutofillKeyboardAccessoryViewBridge ...@@ -159,10 +166,15 @@ public class AutofillKeyboardAccessoryViewBridge
false /* isBoldLabel */); false /* isBoldLabel */);
} }
private native void nativeViewDismissed(long nativeAutofillKeyboardAccessoryView); @NativeMethods
private native void nativeSuggestionSelected( interface Natives {
long nativeAutofillKeyboardAccessoryView, int listIndex); void viewDismissed(long nativeAutofillKeyboardAccessoryView,
private native void nativeDeletionRequested( AutofillKeyboardAccessoryViewBridge caller);
long nativeAutofillKeyboardAccessoryView, int listIndex); void suggestionSelected(long nativeAutofillKeyboardAccessoryView,
private native void nativeDeletionConfirmed(long nativeAutofillKeyboardAccessoryView); AutofillKeyboardAccessoryViewBridge caller, int listIndex);
void deletionRequested(long nativeAutofillKeyboardAccessoryView,
AutofillKeyboardAccessoryViewBridge caller, int listIndex);
void deletionConfirmed(long nativeAutofillKeyboardAccessoryView,
AutofillKeyboardAccessoryViewBridge caller);
}
} }
...@@ -11,6 +11,7 @@ import android.util.SparseArray; ...@@ -11,6 +11,7 @@ import android.util.SparseArray;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.AccessorySheetData; import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.AccessorySheetData;
import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.Action; import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.Action;
...@@ -76,8 +77,9 @@ class ManualFillingComponentBridge { ...@@ -76,8 +77,9 @@ class ManualFillingComponentBridge {
: "Controller has been destroyed but the bridge wasn't cleaned up!"; : "Controller has been destroyed but the bridge wasn't cleaned up!";
ManualFillingMetricsRecorder.recordActionSelected( ManualFillingMetricsRecorder.recordActionSelected(
AccessoryAction.GENERATE_PASSWORD_AUTOMATIC); AccessoryAction.GENERATE_PASSWORD_AUTOMATIC);
nativeOnOptionSelected( ManualFillingComponentBridgeJni.get().onOptionSelected(mNativeView,
mNativeView, AccessoryAction.GENERATE_PASSWORD_AUTOMATIC); ManualFillingComponentBridge.this,
AccessoryAction.GENERATE_PASSWORD_AUTOMATIC);
})}; })};
} else { } else {
generationAction = new Action[0]; generationAction = new Action[0];
...@@ -141,7 +143,8 @@ class ManualFillingComponentBridge { ...@@ -141,7 +143,8 @@ class ManualFillingComponentBridge {
assert mNativeView != 0 : "Controller was destroyed but the bridge wasn't!"; assert mNativeView != 0 : "Controller was destroyed but the bridge wasn't!";
ManualFillingMetricsRecorder.recordSuggestionSelected( ManualFillingMetricsRecorder.recordSuggestionSelected(
sheetType, field.isObfuscated()); sheetType, field.isObfuscated());
nativeOnFillingTriggered(mNativeView, sheetType, field); ManualFillingComponentBridgeJni.get().onFillingTriggered(
mNativeView, ManualFillingComponentBridge.this, sheetType, field);
}; };
} }
((UserInfo) objUserInfo) ((UserInfo) objUserInfo)
...@@ -156,42 +159,48 @@ class ManualFillingComponentBridge { ...@@ -156,42 +159,48 @@ class ManualFillingComponentBridge {
.getFooterCommands() .getFooterCommands()
.add(new FooterCommand(displayText, (footerCommand) -> { .add(new FooterCommand(displayText, (footerCommand) -> {
assert mNativeView != 0 : "Controller was destroyed but the bridge wasn't!"; assert mNativeView != 0 : "Controller was destroyed but the bridge wasn't!";
nativeOnOptionSelected(mNativeView, accessoryAction); ManualFillingComponentBridgeJni.get().onOptionSelected(
mNativeView, ManualFillingComponentBridge.this, accessoryAction);
})); }));
} }
public void fetchFavicon(@Px int desiredSize, Callback<Bitmap> faviconCallback) { public void fetchFavicon(@Px int desiredSize, Callback<Bitmap> faviconCallback) {
assert mNativeView != 0 : "Favicon was requested after the bridge was destroyed!"; assert mNativeView != 0 : "Favicon was requested after the bridge was destroyed!";
nativeOnFaviconRequested(mNativeView, desiredSize, faviconCallback); ManualFillingComponentBridgeJni.get().onFaviconRequested(
mNativeView, ManualFillingComponentBridge.this, desiredSize, faviconCallback);
} }
@VisibleForTesting @VisibleForTesting
public static void cachePasswordSheetData( public static void cachePasswordSheetData(
WebContents webContents, String[] userNames, String[] passwords) { WebContents webContents, String[] userNames, String[] passwords) {
nativeCachePasswordSheetDataForTesting(webContents, userNames, passwords); ManualFillingComponentBridgeJni.get().cachePasswordSheetDataForTesting(
webContents, userNames, passwords);
} }
@VisibleForTesting @VisibleForTesting
public static void notifyFocusedFieldType(WebContents webContents, int focusedFieldType) { public static void notifyFocusedFieldType(WebContents webContents, int focusedFieldType) {
nativeNotifyFocusedFieldTypeForTesting(webContents, focusedFieldType); ManualFillingComponentBridgeJni.get().notifyFocusedFieldTypeForTesting(
webContents, focusedFieldType);
} }
@VisibleForTesting @VisibleForTesting
public static void signalAutoGenerationStatus(WebContents webContents, boolean available) { public static void signalAutoGenerationStatus(WebContents webContents, boolean available) {
nativeSignalAutoGenerationStatusForTesting(webContents, available); ManualFillingComponentBridgeJni.get().signalAutoGenerationStatusForTesting(
} webContents, available);
}
private native void nativeOnFaviconRequested(long nativeManualFillingViewAndroid,
int desiredSizeInPx, Callback<Bitmap> faviconCallback); @NativeMethods
private native void nativeOnFillingTriggered( interface Natives {
long nativeManualFillingViewAndroid, int tabType, UserInfoField userInfoField); void onFaviconRequested(long nativeManualFillingViewAndroid,
private native void nativeOnOptionSelected( ManualFillingComponentBridge caller, int desiredSizeInPx,
long nativeManualFillingViewAndroid, int accessoryAction); Callback<Bitmap> faviconCallback);
void onFillingTriggered(long nativeManualFillingViewAndroid,
private static native void nativeCachePasswordSheetDataForTesting( ManualFillingComponentBridge caller, int tabType, UserInfoField userInfoField);
void onOptionSelected(long nativeManualFillingViewAndroid,
ManualFillingComponentBridge caller, int accessoryAction);
void cachePasswordSheetDataForTesting(
WebContents webContents, String[] userNames, String[] passwords); WebContents webContents, String[] userNames, String[] passwords);
private static native void nativeNotifyFocusedFieldTypeForTesting( void notifyFocusedFieldTypeForTesting(WebContents webContents, int focusedFieldType);
WebContents webContents, int focusedFieldType); void signalAutoGenerationStatusForTesting(WebContents webContents, boolean available);
private static native void nativeSignalAutoGenerationStatusForTesting( }
WebContents webContents, boolean available);
} }
...@@ -14,6 +14,7 @@ android_library("java") { ...@@ -14,6 +14,7 @@ android_library("java") {
"$google_play_services_package:google_play_services_cast_framework_java", "$google_play_services_package:google_play_services_cast_framework_java",
"$google_play_services_package:google_play_services_cast_java", "$google_play_services_package:google_play_services_cast_java",
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
"//services/media_session/public/cpp/android:media_session_java", "//services/media_session/public/cpp/android:media_session_java",
"//third_party/android_deps:android_support_v7_appcompat_java", "//third_party/android_deps:android_support_v7_appcompat_java",
...@@ -64,6 +65,7 @@ android_library("java") { ...@@ -64,6 +65,7 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/media/router/caf/remoting/RemotingSessionController.java", "java/src/org/chromium/chrome/browser/media/router/caf/remoting/RemotingSessionController.java",
"java/src/org/chromium/chrome/browser/media/router/caf/remoting/StreamPositionExtrapolator.java", "java/src/org/chromium/chrome/browser/media/router/caf/remoting/StreamPositionExtrapolator.java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
generate_jni("jni_headers") { generate_jni("jni_headers") {
......
...@@ -17,6 +17,7 @@ import org.chromium.base.SysUtils; ...@@ -17,6 +17,7 @@ import org.chromium.base.SysUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.AppHooks; import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.media.router.caf.CafMediaRouteProvider; import org.chromium.chrome.browser.media.router.caf.CafMediaRouteProvider;
import org.chromium.chrome.browser.media.router.caf.remoting.CafRemotingMediaRouteProvider; import org.chromium.chrome.browser.media.router.caf.remoting.CafRemotingMediaRouteProvider;
...@@ -145,8 +146,8 @@ public class ChromeMediaRouter implements MediaRouteManager { ...@@ -145,8 +146,8 @@ public class ChromeMediaRouter implements MediaRouteManager {
mSinksPerSource.put(sourceId, allSinksPerSource); mSinksPerSource.put(sourceId, allSinksPerSource);
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnSinksReceived( ChromeMediaRouterJni.get().onSinksReceived(mNativeMediaRouterAndroidBridge,
mNativeMediaRouterAndroidBridge, sourceId, allSinksPerSource.size()); ChromeMediaRouter.this, sourceId, allSinksPerSource.size());
} }
} }
...@@ -155,22 +156,24 @@ public class ChromeMediaRouter implements MediaRouteManager { ...@@ -155,22 +156,24 @@ public class ChromeMediaRouter implements MediaRouteManager {
MediaRouteProvider provider, boolean wasLaunched) { MediaRouteProvider provider, boolean wasLaunched) {
mRouteIdsToProviders.put(mediaRouteId, provider); mRouteIdsToProviders.put(mediaRouteId, provider);
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnRouteCreated(mNativeMediaRouterAndroidBridge, mediaRouteId, mediaSinkId, ChromeMediaRouterJni.get().onRouteCreated(mNativeMediaRouterAndroidBridge,
requestId, wasLaunched); ChromeMediaRouter.this, mediaRouteId, mediaSinkId, requestId, wasLaunched);
} }
} }
@Override @Override
public void onRouteRequestError(String errorText, int requestId) { public void onRouteRequestError(String errorText, int requestId) {
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnRouteRequestError(mNativeMediaRouterAndroidBridge, errorText, requestId); ChromeMediaRouterJni.get().onRouteRequestError(
mNativeMediaRouterAndroidBridge, ChromeMediaRouter.this, errorText, requestId);
} }
} }
@Override @Override
public void onRouteTerminated(String mediaRouteId) { public void onRouteTerminated(String mediaRouteId) {
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnRouteTerminated(mNativeMediaRouterAndroidBridge, mediaRouteId); ChromeMediaRouterJni.get().onRouteTerminated(
mNativeMediaRouterAndroidBridge, ChromeMediaRouter.this, mediaRouteId);
} }
mRouteIdsToProviders.remove(mediaRouteId); mRouteIdsToProviders.remove(mediaRouteId);
} }
...@@ -178,7 +181,8 @@ public class ChromeMediaRouter implements MediaRouteManager { ...@@ -178,7 +181,8 @@ public class ChromeMediaRouter implements MediaRouteManager {
@Override @Override
public void onRouteClosed(String mediaRouteId, String error) { public void onRouteClosed(String mediaRouteId, String error) {
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnRouteClosed(mNativeMediaRouterAndroidBridge, mediaRouteId, error); ChromeMediaRouterJni.get().onRouteClosed(
mNativeMediaRouterAndroidBridge, ChromeMediaRouter.this, mediaRouteId, error);
} }
mRouteIdsToProviders.remove(mediaRouteId); mRouteIdsToProviders.remove(mediaRouteId);
} }
...@@ -186,7 +190,8 @@ public class ChromeMediaRouter implements MediaRouteManager { ...@@ -186,7 +190,8 @@ public class ChromeMediaRouter implements MediaRouteManager {
@Override @Override
public void onMessage(String mediaRouteId, String message) { public void onMessage(String mediaRouteId, String message) {
if (mNativeMediaRouterAndroidBridge != 0) { if (mNativeMediaRouterAndroidBridge != 0) {
nativeOnMessage(mNativeMediaRouterAndroidBridge, mediaRouteId, message); ChromeMediaRouterJni.get().onMessage(
mNativeMediaRouterAndroidBridge, ChromeMediaRouter.this, mediaRouteId, message);
} }
} }
...@@ -392,15 +397,20 @@ public class ChromeMediaRouter implements MediaRouteManager { ...@@ -392,15 +397,20 @@ public class ChromeMediaRouter implements MediaRouteManager {
return null; return null;
} }
native void nativeOnSinksReceived( @NativeMethods
long nativeMediaRouterAndroidBridge, String sourceUrn, int count); interface Natives {
native void nativeOnRouteCreated(long nativeMediaRouterAndroidBridge, String mediaRouteId, void onSinksReceived(long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller,
String mediaSinkId, int createRouteRequestId, boolean wasLaunched); String sourceUrn, int count);
native void nativeOnRouteRequestError( void onRouteCreated(long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller,
long nativeMediaRouterAndroidBridge, String errorText, int createRouteRequestId); String mediaRouteId, String mediaSinkId, int createRouteRequestId,
native void nativeOnRouteTerminated(long nativeMediaRouterAndroidBridge, String mediaRouteId); boolean wasLaunched);
native void nativeOnRouteClosed( void onRouteRequestError(long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller,
long nativeMediaRouterAndroidBridge, String mediaRouteId, String message); String errorText, int createRouteRequestId);
native void nativeOnMessage( void onRouteTerminated(
long nativeMediaRouterAndroidBridge, String mediaRouteId, String message); long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller, String mediaRouteId);
void onRouteClosed(long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller,
String mediaRouteId, String message);
void onMessage(long nativeMediaRouterAndroidBridge, ChromeMediaRouter caller,
String mediaRouteId, String message);
}
} }
...@@ -10,6 +10,7 @@ import android.support.v7.media.MediaRouteSelector; ...@@ -10,6 +10,7 @@ import android.support.v7.media.MediaRouteSelector;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.media.router.caf.CastMediaSource; import org.chromium.chrome.browser.media.router.caf.CastMediaSource;
import org.chromium.chrome.browser.media.router.caf.remoting.RemotingMediaSource; import org.chromium.chrome.browser.media.router.caf.remoting.RemotingMediaSource;
...@@ -54,7 +55,8 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -54,7 +55,8 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector(); MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector();
if (routeSelector == null) { if (routeSelector == null) {
nativeOnMediaSourceNotSupported(mNativeDialogController); ChromeMediaRouterDialogControllerJni.get().onMediaSourceNotSupported(
mNativeDialogController, ChromeMediaRouterDialogController.this);
return; return;
} }
...@@ -78,7 +80,8 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -78,7 +80,8 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector(); MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector();
if (routeSelector == null) { if (routeSelector == null) {
nativeOnMediaSourceNotSupported(mNativeDialogController); ChromeMediaRouterDialogControllerJni.get().onMediaSourceNotSupported(
mNativeDialogController, ChromeMediaRouterDialogController.this);
return; return;
} }
...@@ -109,13 +112,15 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -109,13 +112,15 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
@Override @Override
public void onSinkSelected(String sourceUrn, MediaSink sink) { public void onSinkSelected(String sourceUrn, MediaSink sink) {
mDialogManager = null; mDialogManager = null;
nativeOnSinkSelected(mNativeDialogController, sourceUrn, sink.getId()); ChromeMediaRouterDialogControllerJni.get().onSinkSelected(mNativeDialogController,
ChromeMediaRouterDialogController.this, sourceUrn, sink.getId());
} }
@Override @Override
public void onRouteClosed(String mediaRouteId) { public void onRouteClosed(String mediaRouteId) {
mDialogManager = null; mDialogManager = null;
nativeOnRouteClosed(mNativeDialogController, mediaRouteId); ChromeMediaRouterDialogControllerJni.get().onRouteClosed(
mNativeDialogController, ChromeMediaRouterDialogController.this, mediaRouteId);
} }
@Override @Override
...@@ -127,16 +132,23 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -127,16 +132,23 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
if (mDialogManager == null) return; if (mDialogManager == null) return;
mDialogManager = null; mDialogManager = null;
nativeOnDialogCancelled(mNativeDialogController); ChromeMediaRouterDialogControllerJni.get().onDialogCancelled(
mNativeDialogController, ChromeMediaRouterDialogController.this);
} }
private ChromeMediaRouterDialogController(long nativeDialogController) { private ChromeMediaRouterDialogController(long nativeDialogController) {
mNativeDialogController = nativeDialogController; mNativeDialogController = nativeDialogController;
} }
native void nativeOnDialogCancelled(long nativeMediaRouterDialogControllerAndroid); @NativeMethods
native void nativeOnSinkSelected( interface Natives {
long nativeMediaRouterDialogControllerAndroid, String sourceUrn, String sinkId); void onDialogCancelled(long nativeMediaRouterDialogControllerAndroid,
native void nativeOnRouteClosed(long nativeMediaRouterDialogControllerAndroid, String routeId); ChromeMediaRouterDialogController caller);
native void nativeOnMediaSourceNotSupported(long nativeMediaRouterDialogControllerAndroid); void onSinkSelected(long nativeMediaRouterDialogControllerAndroid,
ChromeMediaRouterDialogController caller, String sourceUrn, String sinkId);
void onRouteClosed(long nativeMediaRouterDialogControllerAndroid,
ChromeMediaRouterDialogController caller, String routeId);
void onMediaSourceNotSupported(long nativeMediaRouterDialogControllerAndroid,
ChromeMediaRouterDialogController caller);
}
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.media.router; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.media.router;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/** /**
* A wrapper around a FlingingController that allows the native code to use it * A wrapper around a FlingingController that allows the native code to use it
...@@ -55,7 +56,8 @@ public class FlingingControllerBridge implements MediaStatusObserver { ...@@ -55,7 +56,8 @@ public class FlingingControllerBridge implements MediaStatusObserver {
@Override @Override
public void onMediaStatusUpdate(MediaStatusBridge status) { public void onMediaStatusUpdate(MediaStatusBridge status) {
if (mNativeFlingingControllerBridge != 0) { if (mNativeFlingingControllerBridge != 0) {
nativeOnMediaStatusUpdated(mNativeFlingingControllerBridge, status); FlingingControllerBridgeJni.get().onMediaStatusUpdated(
mNativeFlingingControllerBridge, FlingingControllerBridge.this, status);
} }
} }
...@@ -71,6 +73,9 @@ public class FlingingControllerBridge implements MediaStatusObserver { ...@@ -71,6 +73,9 @@ public class FlingingControllerBridge implements MediaStatusObserver {
mNativeFlingingControllerBridge = 0; mNativeFlingingControllerBridge = 0;
} }
private native void nativeOnMediaStatusUpdated( @NativeMethods
long nativeFlingingControllerBridge, MediaStatusBridge status); interface Natives {
void onMediaStatusUpdated(long nativeFlingingControllerBridge,
FlingingControllerBridge caller, MediaStatusBridge status);
}
} }
...@@ -117,6 +117,7 @@ android_library("java") { ...@@ -117,6 +117,7 @@ android_library("java") {
deps = [ deps = [
":java_resources", ":java_resources",
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/android:chrome_java", "//chrome/android:chrome_java",
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
"//content/public/android:content_java", "//content/public/android:content_java",
...@@ -135,6 +136,7 @@ android_library("java") { ...@@ -135,6 +136,7 @@ android_library("java") {
if (async_vr) { if (async_vr) {
proguard_configs = [ "//base/android/proguard/chromium_code.flags" ] proguard_configs = [ "//base/android/proguard/chromium_code.flags" ]
} }
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
generate_jni("jni_headers") { generate_jni("jni_headers") {
......
...@@ -10,6 +10,7 @@ import android.view.View; ...@@ -10,6 +10,7 @@ import android.view.View;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.content_public.browser.MotionEventSynthesizer; import org.chromium.content_public.browser.MotionEventSynthesizer;
/** /**
...@@ -24,7 +25,8 @@ public class AndroidUiGestureTarget { ...@@ -24,7 +25,8 @@ public class AndroidUiGestureTarget {
public AndroidUiGestureTarget( public AndroidUiGestureTarget(
View target, float scaleFactor, float scrollRatio, int touchSlop) { View target, float scaleFactor, float scrollRatio, int touchSlop) {
mMotionEventSynthesizer = MotionEventSynthesizer.create(target); mMotionEventSynthesizer = MotionEventSynthesizer.create(target);
mNativePointer = nativeInit(scaleFactor, scrollRatio, touchSlop); mNativePointer = AndroidUiGestureTargetJni.get().init(
AndroidUiGestureTarget.this, scaleFactor, scrollRatio, touchSlop);
} }
@CalledByNative @CalledByNative
...@@ -61,5 +63,9 @@ public class AndroidUiGestureTarget { ...@@ -61,5 +63,9 @@ public class AndroidUiGestureTarget {
return mNativePointer; return mNativePointer;
} }
private native long nativeInit(float scaleFactor, float scrollRatio, int touchSlop); @NativeMethods
interface Natives {
long init(
AndroidUiGestureTarget caller, float scaleFactor, float scrollRatio, int touchSlop);
}
} }
...@@ -11,6 +11,7 @@ import android.view.WindowManager; ...@@ -11,6 +11,7 @@ import android.view.WindowManager;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/** /**
* Helper class for interfacing with the Android Choreographer from native code. * Helper class for interfacing with the Android Choreographer from native code.
...@@ -23,7 +24,8 @@ public class AndroidVSyncHelper { ...@@ -23,7 +24,8 @@ public class AndroidVSyncHelper {
@Override @Override
public void doFrame(long frameTimeNanos) { public void doFrame(long frameTimeNanos) {
if (mNativeAndroidVSyncHelper == 0) return; if (mNativeAndroidVSyncHelper == 0) return;
nativeOnVSync(mNativeAndroidVSyncHelper, frameTimeNanos); AndroidVSyncHelperJni.get().onVSync(
mNativeAndroidVSyncHelper, AndroidVSyncHelper.this, frameTimeNanos);
} }
}; };
...@@ -54,5 +56,8 @@ public class AndroidVSyncHelper { ...@@ -54,5 +56,8 @@ public class AndroidVSyncHelper {
return windowManager.getDefaultDisplay().getRefreshRate(); return windowManager.getDefaultDisplay().getRefreshRate();
} }
private native void nativeOnVSync(long nativeAndroidVSyncHelper, long frameTimeNanos); @NativeMethods
interface Natives {
void onVSync(long nativeAndroidVSyncHelper, AndroidVSyncHelper caller, long frameTimeNanos);
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.vr; package org.chromium.chrome.browser.vr;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
/** /**
* Container class to provide the version and the compatibility with Chrome of the installed VrCore. * Container class to provide the version and the compatibility with Chrome of the installed VrCore.
...@@ -34,11 +35,15 @@ public class VrCoreInfo { ...@@ -34,11 +35,15 @@ public class VrCoreInfo {
} }
public long makeNativeVrCoreInfo() { public long makeNativeVrCoreInfo() {
return (gvrVersion == null) ? nativeInit(0, 0, 0, compatibility) return (gvrVersion == null)
: nativeInit(gvrVersion.majorVersion, gvrVersion.minorVersion, ? VrCoreInfoJni.get().init(VrCoreInfo.this, 0, 0, 0, compatibility)
gvrVersion.patchVersion, compatibility); : VrCoreInfoJni.get().init(VrCoreInfo.this, gvrVersion.majorVersion,
gvrVersion.minorVersion, gvrVersion.patchVersion, compatibility);
} }
private native long nativeInit( @NativeMethods
int majorVersion, int minorVersion, int patchVersion, int compatibility); interface Natives {
long init(VrCoreInfo caller, int majorVersion, int minorVersion, int patchVersion,
int compatibility);
}
} }
...@@ -12,6 +12,7 @@ import android.view.inputmethod.InputConnection; ...@@ -12,6 +12,7 @@ import android.view.inputmethod.InputConnection;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.vr.keyboard.TextEditAction; import org.chromium.chrome.browser.vr.keyboard.TextEditAction;
import org.chromium.content_public.browser.ImeAdapter; import org.chromium.content_public.browser.ImeAdapter;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -65,7 +66,8 @@ public class VrInputConnection { ...@@ -65,7 +66,8 @@ public class VrInputConnection {
mImeThreadResponseHandler.post(new Runnable() { mImeThreadResponseHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
nativeUpdateTextState(mNativeVrInputConnection, textState); VrInputConnectionJni.get().updateTextState(
mNativeVrInputConnection, VrInputConnection.this, textState);
} }
}); });
} }
...@@ -127,5 +129,8 @@ public class VrInputConnection { ...@@ -127,5 +129,8 @@ public class VrInputConnection {
}); });
} }
private native void nativeUpdateTextState(long nativeVrInputConnection, String text); @NativeMethods
interface Natives {
void updateTextState(long nativeVrInputConnection, VrInputConnection caller, String text);
}
} }
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.vr; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.vr;
import org.chromium.base.BundleUtils; import org.chromium.base.BundleUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.modules.ModuleInstallUi; import org.chromium.chrome.browser.modules.ModuleInstallUi;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -34,7 +35,7 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener { ...@@ -34,7 +35,7 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener {
*/ */
public static void maybeInit() { public static void maybeInit() {
if (!VrBuildConfig.IS_VR_ENABLED) return; if (!VrBuildConfig.IS_VR_ENABLED) return;
nativeInit(); VrModuleProviderJni.get().init();
// Always install the VR module on Daydream-ready devices. // Always install the VR module on Daydream-ready devices.
maybeRequestModuleIfDaydreamReady(); maybeRequestModuleIfDaydreamReady();
} }
...@@ -103,7 +104,7 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener { ...@@ -103,7 +104,7 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener {
// TODO(crbug.com/870055): JNI should be registered in the shared VR library's JNI_OnLoad // TODO(crbug.com/870055): JNI should be registered in the shared VR library's JNI_OnLoad
// function. Do this once we have a shared VR library. // function. Do this once we have a shared VR library.
/* package */ static void registerJni() { /* package */ static void registerJni() {
nativeRegisterJni(); VrModuleProviderJni.get().registerJni();
} }
private static VrDelegateProvider getDelegateProvider() { private static VrDelegateProvider getDelegateProvider() {
...@@ -137,7 +138,8 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener { ...@@ -137,7 +138,8 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener {
@Override @Override
public void onCancel() { public void onCancel() {
if (mNativeVrModuleProvider != 0) { if (mNativeVrModuleProvider != 0) {
nativeOnInstalledModule(mNativeVrModuleProvider, false); VrModuleProviderJni.get().onInstalledModule(
mNativeVrModuleProvider, VrModuleProvider.this, false);
} }
} }
...@@ -162,12 +164,17 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener { ...@@ -162,12 +164,17 @@ public class VrModuleProvider implements ModuleInstallUi.FailureUiListener {
return; return;
} }
ui.showInstallSuccessUi(); ui.showInstallSuccessUi();
nativeOnInstalledModule(mNativeVrModuleProvider, success); VrModuleProviderJni.get().onInstalledModule(
mNativeVrModuleProvider, VrModuleProvider.this, success);
} }
}); });
} }
private static native void nativeInit(); @NativeMethods
private static native void nativeRegisterJni(); interface Natives {
private native void nativeOnInstalledModule(long nativeVrModuleProvider, boolean success); void init();
void registerJni();
void onInstalledModule(
long nativeVrModuleProvider, VrModuleProvider caller, boolean success);
}
} }
...@@ -32,6 +32,7 @@ import org.chromium.base.ThreadUtils; ...@@ -32,6 +32,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.task.PostTask; import org.chromium.base.task.PostTask;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -250,7 +251,7 @@ public class VrShell extends GvrLayout ...@@ -250,7 +251,7 @@ public class VrShell extends GvrLayout
mViewEventSink = ViewEventSink.from(tab.getWebContents()); mViewEventSink = ViewEventSink.from(tab.getWebContents());
if (mViewEventSink != null) mViewEventSink.onWindowFocusChanged(true); if (mViewEventSink != null) mViewEventSink.onWindowFocusChanged(true);
} }
nativeSwapContents(mNativeVrShell, tab); VrShellJni.get().swapContents(mNativeVrShell, VrShell.this, tab);
updateHistoryButtonsVisibility(); updateHistoryButtonsVisibility();
} }
...@@ -265,7 +266,8 @@ public class VrShell extends GvrLayout ...@@ -265,7 +266,8 @@ public class VrShell extends GvrLayout
@Override @Override
public void onLoadProgressChanged(Tab tab, int progress) { public void onLoadProgressChanged(Tab tab, int progress) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
nativeOnLoadProgressChanged(mNativeVrShell, progress / 100.0); VrShellJni.get().onLoadProgressChanged(
mNativeVrShell, VrShell.this, progress / 100.0);
} }
@Override @Override
...@@ -300,7 +302,8 @@ public class VrShell extends GvrLayout ...@@ -300,7 +302,8 @@ public class VrShell extends GvrLayout
@Override @Override
public void onNewTabCreated(Tab tab) { public void onNewTabCreated(Tab tab) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
nativeOnTabUpdated(mNativeVrShell, tab.isIncognito(), tab.getId(), tab.getTitle()); VrShellJni.get().onTabUpdated(mNativeVrShell, VrShell.this, tab.isIncognito(),
tab.getId(), tab.getTitle());
} }
}; };
...@@ -309,11 +312,11 @@ public class VrShell extends GvrLayout ...@@ -309,11 +312,11 @@ public class VrShell extends GvrLayout
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
nativeOnTriggerEvent(mNativeVrShell, true); VrShellJni.get().onTriggerEvent(mNativeVrShell, VrShell.this, true);
return true; return true;
} else if (event.getActionMasked() == MotionEvent.ACTION_UP } else if (event.getActionMasked() == MotionEvent.ACTION_UP
|| event.getActionMasked() == MotionEvent.ACTION_CANCEL) { || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
nativeOnTriggerEvent(mNativeVrShell, false); VrShellJni.get().onTriggerEvent(mNativeVrShell, VrShell.this, false);
return true; return true;
} }
return false; return false;
...@@ -418,8 +421,8 @@ public class VrShell extends GvrLayout ...@@ -418,8 +421,8 @@ public class VrShell extends GvrLayout
boolean hasOrCanRequestRecordAudioPermission = boolean hasOrCanRequestRecordAudioPermission =
hasRecordAudioPermission() || canRequestRecordAudioPermission(); hasRecordAudioPermission() || canRequestRecordAudioPermission();
boolean supportsRecognition = FeatureUtilities.isRecognitionIntentPresent(mActivity, false); boolean supportsRecognition = FeatureUtilities.isRecognitionIntentPresent(mActivity, false);
mNativeVrShell = nativeInit(mDelegate, forWebVr, !mVrBrowsingEnabled, mNativeVrShell = VrShellJni.get().init(VrShell.this, mDelegate, forWebVr,
hasOrCanRequestRecordAudioPermission && supportsRecognition, !mVrBrowsingEnabled, hasOrCanRequestRecordAudioPermission && supportsRecognition,
getGvrApi().getNativeGvrContext(), mReprojectedRendering, displayWidthMeters, getGvrApi().getNativeGvrContext(), mReprojectedRendering, displayWidthMeters,
displayHeightMeters, dm.widthPixels, dm.heightPixels, pauseContent, lowDensity, displayHeightMeters, dm.widthPixels, dm.heightPixels, pauseContent, lowDensity,
isStandaloneVrDevice); isStandaloneVrDevice);
...@@ -436,7 +439,8 @@ public class VrShell extends GvrLayout ...@@ -436,7 +439,8 @@ public class VrShell extends GvrLayout
mAndroidUiGestureTarget = new AndroidUiGestureTarget(mNonVrViews.getInputTarget(), mAndroidUiGestureTarget = new AndroidUiGestureTarget(mNonVrViews.getInputTarget(),
mContentVrWindowAndroid.getDisplay().getDipScale(), getNativePageScrollRatio(), mContentVrWindowAndroid.getDisplay().getDipScale(), getNativePageScrollRatio(),
getTouchSlop()); getTouchSlop());
nativeSetAndroidGestureTarget(mNativeVrShell, mAndroidUiGestureTarget); VrShellJni.get().setAndroidGestureTarget(
mNativeVrShell, VrShell.this, mAndroidUiGestureTarget);
} }
} }
...@@ -454,7 +458,7 @@ public class VrShell extends GvrLayout ...@@ -454,7 +458,7 @@ public class VrShell extends GvrLayout
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
incognitoTabs[i] = incognito.getTabAt(i); incognitoTabs[i] = incognito.getTabAt(i);
} }
nativeOnTabListCreated(mNativeVrShell, mainTabs, incognitoTabs); VrShellJni.get().onTabListCreated(mNativeVrShell, VrShell.this, mainTabs, incognitoTabs);
} }
private void swapToForegroundTab() { private void swapToForegroundTab() {
...@@ -583,7 +587,8 @@ public class VrShell extends GvrLayout ...@@ -583,7 +587,8 @@ public class VrShell extends GvrLayout
// doesn't happen, so we need to notify native // doesn't happen, so we need to notify native
// UI of the permission change immediately. // UI of the permission change immediately.
if (mNativeVrShell != 0) { if (mNativeVrShell != 0) {
nativeRequestRecordAudioPermissionResult(mNativeVrShell, VrShellJni.get().requestRecordAudioPermissionResult(
mNativeVrShell, VrShell.this,
grantResults[0] == PackageManager.PERMISSION_GRANTED); grantResults[0] == PackageManager.PERMISSION_GRANTED);
} }
} }
...@@ -673,8 +678,8 @@ public class VrShell extends GvrLayout ...@@ -673,8 +678,8 @@ public class VrShell extends GvrLayout
int overlayWidth = (int) Math.ceil(width * dip); int overlayWidth = (int) Math.ceil(width * dip);
int overlayHeight = (int) Math.ceil(height * dip); int overlayHeight = (int) Math.ceil(height * dip);
nativeBufferBoundsChanged( VrShellJni.get().bufferBoundsChanged(mNativeVrShell, VrShell.this, contentWidth,
mNativeVrShell, contentWidth, contentHeight, overlayWidth, overlayHeight); contentHeight, overlayWidth, overlayHeight);
if (mContentSurface != null) { if (mContentSurface != null) {
if (surfaceUninitialized) { if (surfaceUninitialized) {
mVrCompositorSurfaceManager.setSurface( mVrCompositorSurfaceManager.setSurface(
...@@ -747,8 +752,8 @@ public class VrShell extends GvrLayout ...@@ -747,8 +752,8 @@ public class VrShell extends GvrLayout
if (mNativeVrShell != 0) { if (mNativeVrShell != 0) {
// Refreshing the viewer profile may accesses disk under some circumstances outside of // Refreshing the viewer profile may accesses disk under some circumstances outside of
// our control. // our control.
try (StrictModeContext smc = StrictModeContext.allowDiskWrites()) { try (StrictModeContext ignored = StrictModeContext.allowDiskWrites()) {
nativeOnResume(mNativeVrShell); VrShellJni.get().onResume(mNativeVrShell, VrShell.this);
} }
} }
} }
...@@ -758,7 +763,7 @@ public class VrShell extends GvrLayout ...@@ -758,7 +763,7 @@ public class VrShell extends GvrLayout
if (mPaused != null && mPaused) return; if (mPaused != null && mPaused) return;
mPaused = true; mPaused = true;
super.onPause(); super.onPause();
if (mNativeVrShell != 0) nativeOnPause(mNativeVrShell); if (mNativeVrShell != 0) VrShellJni.get().onPause(mNativeVrShell, VrShell.this);
} }
@Override @Override
...@@ -779,7 +784,7 @@ public class VrShell extends GvrLayout ...@@ -779,7 +784,7 @@ public class VrShell extends GvrLayout
} }
reparentAllTabs(mActivity.getWindowAndroid()); reparentAllTabs(mActivity.getWindowAndroid());
if (mNativeVrShell != 0) { if (mNativeVrShell != 0) {
nativeDestroy(mNativeVrShell); VrShellJni.get().destroy(mNativeVrShell, VrShell.this);
mNativeVrShell = 0; mNativeVrShell = 0;
} }
mTabModelSelector.removeObserver(mTabModelSelectorObserver); mTabModelSelector.removeObserver(mTabModelSelectorObserver);
...@@ -823,7 +828,7 @@ public class VrShell extends GvrLayout ...@@ -823,7 +828,7 @@ public class VrShell extends GvrLayout
} }
public boolean hasUiFinishedLoading() { public boolean hasUiFinishedLoading() {
return nativeHasUiFinishedLoading(mNativeVrShell); return VrShellJni.get().hasUiFinishedLoading(mNativeVrShell, VrShell.this);
} }
/** /**
...@@ -841,7 +846,7 @@ public class VrShell extends GvrLayout ...@@ -841,7 +846,7 @@ public class VrShell extends GvrLayout
*/ */
@Override @Override
public void closeVrDialog() { public void closeVrDialog() {
nativeCloseAlertDialog(mNativeVrShell); VrShellJni.get().closeAlertDialog(mNativeVrShell, VrShell.this);
mVrUiViewContainer.removeAllViews(); mVrUiViewContainer.removeAllViews();
mVrDialogDismissHandler = null; mVrDialogDismissHandler = null;
} }
...@@ -851,8 +856,8 @@ public class VrShell extends GvrLayout ...@@ -851,8 +856,8 @@ public class VrShell extends GvrLayout
*/ */
@Override @Override
public void setDialogSize(int width, int height) { public void setDialogSize(int width, int height) {
nativeSetDialogBufferSize(mNativeVrShell, width, height); VrShellJni.get().setDialogBufferSize(mNativeVrShell, VrShell.this, width, height);
nativeSetAlertDialogSize(mNativeVrShell, width, height); VrShellJni.get().setAlertDialogSize(mNativeVrShell, VrShell.this, width, height);
} }
/** /**
...@@ -865,12 +870,13 @@ public class VrShell extends GvrLayout ...@@ -865,12 +870,13 @@ public class VrShell extends GvrLayout
float w = mLastContentWidth * dipScale; float w = mLastContentWidth * dipScale;
float h = mLastContentHeight * dipScale; float h = mLastContentHeight * dipScale;
float scale = mContentVrWindowAndroid.getDisplay().getAndroidUIScaling(); float scale = mContentVrWindowAndroid.getDisplay().getAndroidUIScaling();
nativeSetDialogLocation(mNativeVrShell, x * scale / w, y * scale / h); VrShellJni.get().setDialogLocation(
mNativeVrShell, VrShell.this, x * scale / w, y * scale / h);
} }
@Override @Override
public void setDialogFloating(boolean floating) { public void setDialogFloating(boolean floating) {
nativeSetDialogFloating(mNativeVrShell, floating); VrShellJni.get().setDialogFloating(mNativeVrShell, VrShell.this, floating);
} }
/** /**
...@@ -878,11 +884,12 @@ public class VrShell extends GvrLayout ...@@ -878,11 +884,12 @@ public class VrShell extends GvrLayout
*/ */
@Override @Override
public void initVrDialog(int width, int height) { public void initVrDialog(int width, int height) {
nativeSetAlertDialog(mNativeVrShell, width, height); VrShellJni.get().setAlertDialog(mNativeVrShell, VrShell.this, width, height);
mAndroidDialogGestureTarget = mAndroidDialogGestureTarget =
new AndroidUiGestureTarget(mVrUiViewContainer.getInputTarget(), 1.0f, new AndroidUiGestureTarget(mVrUiViewContainer.getInputTarget(), 1.0f,
getNativePageScrollRatio(), getTouchSlop()); getNativePageScrollRatio(), getTouchSlop());
nativeSetDialogGestureTarget(mNativeVrShell, mAndroidDialogGestureTarget); VrShellJni.get().setDialogGestureTarget(
mNativeVrShell, VrShell.this, mAndroidDialogGestureTarget);
} }
/** /**
...@@ -890,7 +897,7 @@ public class VrShell extends GvrLayout ...@@ -890,7 +897,7 @@ public class VrShell extends GvrLayout
*/ */
@Override @Override
public void showToast(CharSequence text) { public void showToast(CharSequence text) {
nativeShowToast(mNativeVrShell, text.toString()); VrShellJni.get().showToast(mNativeVrShell, VrShell.this, text.toString());
} }
/** /**
...@@ -898,11 +905,12 @@ public class VrShell extends GvrLayout ...@@ -898,11 +905,12 @@ public class VrShell extends GvrLayout
*/ */
@Override @Override
public void cancelToast() { public void cancelToast() {
nativeCancelToast(mNativeVrShell); VrShellJni.get().cancelToast(mNativeVrShell, VrShell.this);
} }
public void setWebVrModeEnabled(boolean enabled) { public void setWebVrModeEnabled(boolean enabled) {
if (mNativeVrShell != 0) nativeSetWebVrMode(mNativeVrShell, enabled); if (mNativeVrShell != 0)
VrShellJni.get().setWebVrMode(mNativeVrShell, VrShell.this, enabled);
if (!enabled) { if (!enabled) {
mContentVrWindowAndroid.setVSyncPaused(false); mContentVrWindowAndroid.setVSyncPaused(false);
mPendingVSyncPause = false; mPendingVSyncPause = false;
...@@ -925,19 +933,20 @@ public class VrShell extends GvrLayout ...@@ -925,19 +933,20 @@ public class VrShell extends GvrLayout
public boolean getWebVrModeEnabled() { public boolean getWebVrModeEnabled() {
if (mNativeVrShell == 0) return false; if (mNativeVrShell == 0) return false;
return nativeGetWebVrMode(mNativeVrShell); return VrShellJni.get().getWebVrMode(mNativeVrShell, VrShell.this);
} }
public boolean isDisplayingUrlForTesting() { public boolean isDisplayingUrlForTesting() {
assert mNativeVrShell != 0; assert mNativeVrShell != 0;
return PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, return PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, () -> {
() -> { return nativeIsDisplayingUrlForTesting(mNativeVrShell); }); return VrShellJni.get().isDisplayingUrlForTesting(mNativeVrShell, VrShell.this);
});
} }
@VisibleForTesting @VisibleForTesting
public VrInputConnection getVrInputConnectionForTesting() { public VrInputConnection getVrInputConnectionForTesting() {
assert mNativeVrShell != 0; assert mNativeVrShell != 0;
return nativeGetVrInputConnectionForTesting(mNativeVrShell); return VrShellJni.get().getVrInputConnectionForTesting(mNativeVrShell, VrShell.this);
} }
public FrameLayout getContainer() { public FrameLayout getContainer() {
...@@ -948,14 +957,15 @@ public class VrShell extends GvrLayout ...@@ -948,14 +957,15 @@ public class VrShell extends GvrLayout
if (topContentOffset != 0) return; if (topContentOffset != 0) return;
// Wait until a new frame is definitely available. // Wait until a new frame is definitely available.
mActivity.getCompositorViewHolder().getCompositorView().surfaceRedrawNeededAsync(() -> { mActivity.getCompositorViewHolder().getCompositorView().surfaceRedrawNeededAsync(() -> {
if (mNativeVrShell != 0) nativeResumeContentRendering(mNativeVrShell); if (mNativeVrShell != 0)
VrShellJni.get().resumeContentRendering(mNativeVrShell, VrShell.this);
}); });
} }
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
nativeSetSurface(mNativeVrShell, holder.getSurface()); VrShellJni.get().setSurface(mNativeVrShell, VrShell.this, holder.getSurface());
} }
@Override @Override
...@@ -976,24 +986,27 @@ public class VrShell extends GvrLayout ...@@ -976,24 +986,27 @@ public class VrShell extends GvrLayout
@Override @Override
public void onTitleUpdated(Tab tab) { public void onTitleUpdated(Tab tab) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
nativeOnTabUpdated(mNativeVrShell, tab.isIncognito(), tab.getId(), tab.getTitle()); VrShellJni.get().onTabUpdated(mNativeVrShell, VrShell.this, tab.isIncognito(),
tab.getId(), tab.getTitle());
} }
@Override @Override
public void onClosingStateChanged(Tab tab, boolean closing) { public void onClosingStateChanged(Tab tab, boolean closing) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
if (closing) { if (closing) {
nativeOnTabRemoved(mNativeVrShell, tab.isIncognito(), tab.getId()); VrShellJni.get().onTabRemoved(
mNativeVrShell, VrShell.this, tab.isIncognito(), tab.getId());
} else { } else {
nativeOnTabUpdated( VrShellJni.get().onTabUpdated(mNativeVrShell, VrShell.this, tab.isIncognito(),
mNativeVrShell, tab.isIncognito(), tab.getId(), tab.getTitle()); tab.getId(), tab.getTitle());
} }
} }
@Override @Override
public void onDestroyed(Tab tab) { public void onDestroyed(Tab tab) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
nativeOnTabRemoved(mNativeVrShell, tab.isIncognito(), tab.getId()); VrShellJni.get().onTabRemoved(
mNativeVrShell, VrShell.this, tab.isIncognito(), tab.getId());
} }
}; };
} }
...@@ -1006,9 +1019,9 @@ public class VrShell extends GvrLayout ...@@ -1006,9 +1019,9 @@ public class VrShell extends GvrLayout
public void requestToExitVr(@UiUnsupportedMode int reason, boolean showExitPromptBeforeDoff) { public void requestToExitVr(@UiUnsupportedMode int reason, boolean showExitPromptBeforeDoff) {
if (mNativeVrShell == 0) return; if (mNativeVrShell == 0) return;
if (showExitPromptBeforeDoff) { if (showExitPromptBeforeDoff) {
nativeRequestToExitVr(mNativeVrShell, reason); VrShellJni.get().requestToExitVr(mNativeVrShell, VrShell.this, reason);
} else { } else {
nativeLogUnsupportedModeUserMetric(mNativeVrShell, reason); VrShellJni.get().logUnsupportedModeUserMetric(mNativeVrShell, VrShell.this, reason);
mDelegate.onExitVrRequestResult(true); mDelegate.onExitVrRequestResult(true);
} }
} }
...@@ -1016,7 +1029,8 @@ public class VrShell extends GvrLayout ...@@ -1016,7 +1029,8 @@ public class VrShell extends GvrLayout
@CalledByNative @CalledByNative
private void onExitVrRequestResult(@UiUnsupportedMode int reason, boolean shouldExit) { private void onExitVrRequestResult(@UiUnsupportedMode int reason, boolean shouldExit) {
if (shouldExit) { if (shouldExit) {
if (mNativeVrShell != 0) nativeLogUnsupportedModeUserMetric(mNativeVrShell, reason); if (mNativeVrShell != 0)
VrShellJni.get().logUnsupportedModeUserMetric(mNativeVrShell, VrShell.this, reason);
} }
mDelegate.onExitVrRequestResult(shouldExit); mDelegate.onExitVrRequestResult(shouldExit);
} }
...@@ -1109,7 +1123,8 @@ public class VrShell extends GvrLayout ...@@ -1109,7 +1123,8 @@ public class VrShell extends GvrLayout
if (mTab == null) { if (mTab == null) {
mCanGoBack = false; mCanGoBack = false;
mCanGoForward = false; mCanGoForward = false;
nativeSetHistoryButtonsEnabled(mNativeVrShell, mCanGoBack, mCanGoForward); VrShellJni.get().setHistoryButtonsEnabled(
mNativeVrShell, VrShell.this, mCanGoBack, mCanGoForward);
return; return;
} }
boolean willCloseTab = false; boolean willCloseTab = false;
...@@ -1127,7 +1142,8 @@ public class VrShell extends GvrLayout ...@@ -1127,7 +1142,8 @@ public class VrShell extends GvrLayout
} }
mCanGoBack = canGoBack; mCanGoBack = canGoBack;
mCanGoForward = canGoForward; mCanGoForward = canGoForward;
nativeSetHistoryButtonsEnabled(mNativeVrShell, mCanGoBack, mCanGoForward); VrShellJni.get().setHistoryButtonsEnabled(
mNativeVrShell, VrShell.this, mCanGoBack, mCanGoForward);
} }
private float getNativePageScrollRatio() { private float getNativePageScrollRatio() {
...@@ -1147,12 +1163,14 @@ public class VrShell extends GvrLayout ...@@ -1147,12 +1163,14 @@ public class VrShell extends GvrLayout
@Override @Override
public void onVrViewEmpty() { public void onVrViewEmpty() {
if (mNativeVrShell != 0) nativeOnOverlayTextureEmptyChanged(mNativeVrShell, true); if (mNativeVrShell != 0)
VrShellJni.get().onOverlayTextureEmptyChanged(mNativeVrShell, VrShell.this, true);
} }
@Override @Override
public void onVrViewNonEmpty() { public void onVrViewNonEmpty() {
if (mNativeVrShell != 0) nativeOnOverlayTextureEmptyChanged(mNativeVrShell, false); if (mNativeVrShell != 0)
VrShellJni.get().onOverlayTextureEmptyChanged(mNativeVrShell, VrShell.this, false);
} }
@Override @Override
...@@ -1220,15 +1238,15 @@ public class VrShell extends GvrLayout ...@@ -1220,15 +1238,15 @@ public class VrShell extends GvrLayout
@Override @Override
public void showSoftInput(boolean show) { public void showSoftInput(boolean show) {
assert mNativeVrShell != 0; assert mNativeVrShell != 0;
nativeShowSoftInput(mNativeVrShell, show); VrShellJni.get().showSoftInput(mNativeVrShell, VrShell.this, show);
} }
@Override @Override
public void updateIndices( public void updateIndices(
int selectionStart, int selectionEnd, int compositionStart, int compositionEnd) { int selectionStart, int selectionEnd, int compositionStart, int compositionEnd) {
assert mNativeVrShell != 0; assert mNativeVrShell != 0;
nativeUpdateWebInputIndices( VrShellJni.get().updateWebInputIndices(mNativeVrShell, VrShell.this, selectionStart,
mNativeVrShell, selectionStart, selectionEnd, compositionStart, compositionEnd); selectionEnd, compositionStart, compositionEnd);
} }
@VisibleForTesting @VisibleForTesting
...@@ -1237,18 +1255,19 @@ public class VrShell extends GvrLayout ...@@ -1237,18 +1255,19 @@ public class VrShell extends GvrLayout
} }
public void acceptDoffPromptForTesting() { public void acceptDoffPromptForTesting() {
nativeAcceptDoffPromptForTesting(mNativeVrShell); VrShellJni.get().acceptDoffPromptForTesting(mNativeVrShell, VrShell.this);
} }
public void performControllerActionForTesting( public void performControllerActionForTesting(
int elementName, int actionType, PointF position) { int elementName, int actionType, PointF position) {
nativePerformControllerActionForTesting( VrShellJni.get().performControllerActionForTesting(
mNativeVrShell, elementName, actionType, position.x, position.y); mNativeVrShell, VrShell.this, elementName, actionType, position.x, position.y);
} }
public void performKeyboardInputForTesting(int inputType, String inputString) { public void performKeyboardInputForTesting(int inputType, String inputString) {
PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runSynchronously(UiThreadTaskTraits.DEFAULT, () -> {
nativePerformKeyboardInputForTesting(mNativeVrShell, inputType, inputString); VrShellJni.get().performKeyboardInputForTesting(
mNativeVrShell, VrShell.this, inputType, inputString);
}); });
} }
...@@ -1272,15 +1291,17 @@ public class VrShell extends GvrLayout ...@@ -1272,15 +1291,17 @@ public class VrShell extends GvrLayout
// In the case of the UI activity quiescence callback type, we need to let the native UI // In the case of the UI activity quiescence callback type, we need to let the native UI
// know how long to wait before timing out. // know how long to wait before timing out.
if (actionType == UiTestOperationType.UI_ACTIVITY_RESULT) { if (actionType == UiTestOperationType.UI_ACTIVITY_RESULT) {
nativeSetUiExpectingActivityForTesting(mNativeVrShell, operationData.timeoutMs); VrShellJni.get().setUiExpectingActivityForTesting(
mNativeVrShell, VrShell.this, operationData.timeoutMs);
} else if (actionType == UiTestOperationType.ELEMENT_VISIBILITY_STATUS) { } else if (actionType == UiTestOperationType.ELEMENT_VISIBILITY_STATUS) {
nativeWatchElementForVisibilityStatusForTesting(mNativeVrShell, VrShellJni.get().watchElementForVisibilityStatusForTesting(mNativeVrShell, VrShell.this,
operationData.elementName, operationData.timeoutMs, operationData.visibility); operationData.elementName, operationData.timeoutMs, operationData.visibility);
} }
} }
public void saveNextFrameBufferToDiskForTesting(String filepathBase) { public void saveNextFrameBufferToDiskForTesting(String filepathBase) {
nativeSaveNextFrameBufferToDiskForTesting(mNativeVrShell, filepathBase); VrShellJni.get().saveNextFrameBufferToDiskForTesting(
mNativeVrShell, VrShell.this, filepathBase);
} }
public int getLastUiOperationResultForTesting(int actionType) { public int getLastUiOperationResultForTesting(int actionType) {
...@@ -1294,63 +1315,66 @@ public class VrShell extends GvrLayout ...@@ -1294,63 +1315,66 @@ public class VrShell extends GvrLayout
mUiOperationResultCallbacks.set(actionType, null); mUiOperationResultCallbacks.set(actionType, null);
} }
private native long nativeInit(VrShellDelegate delegate, boolean forWebVR, @NativeMethods
interface Natives {
long init(VrShell caller, VrShellDelegate delegate, boolean forWebVR,
boolean browsingDisabled, boolean hasOrCanRequestRecordAudioPermission, long gvrApi, boolean browsingDisabled, boolean hasOrCanRequestRecordAudioPermission, long gvrApi,
boolean reprojectedRendering, float displayWidthMeters, float displayHeightMeters, boolean reprojectedRendering, float displayWidthMeters, float displayHeightMeters,
int displayWidthPixels, int displayHeightPixels, boolean pauseContent, int displayWidthPixels, int displayHeightPixels, boolean pauseContent,
boolean lowDensity, boolean isStandaloneVrDevice); boolean lowDensity, boolean isStandaloneVrDevice);
private native boolean nativeHasUiFinishedLoading(long nativeVrShell); boolean hasUiFinishedLoading(long nativeVrShell, VrShell caller);
private native void nativeSetSurface(long nativeVrShell, Surface surface); void setSurface(long nativeVrShell, VrShell caller, Surface surface);
private native void nativeSwapContents(long nativeVrShell, Tab tab); void swapContents(long nativeVrShell, VrShell caller, Tab tab);
private native void nativeSetAndroidGestureTarget( void setAndroidGestureTarget(
long nativeVrShell, AndroidUiGestureTarget androidUiGestureTarget); long nativeVrShell, VrShell caller, AndroidUiGestureTarget androidUiGestureTarget);
private native void nativeSetDialogGestureTarget( void setDialogGestureTarget(
long nativeVrShell, AndroidUiGestureTarget dialogGestureTarget); long nativeVrShell, VrShell caller, AndroidUiGestureTarget dialogGestureTarget);
private native void nativeDestroy(long nativeVrShell); void destroy(long nativeVrShell, VrShell caller);
private native void nativeOnTriggerEvent(long nativeVrShell, boolean touched); void onTriggerEvent(long nativeVrShell, VrShell caller, boolean touched);
private native void nativeOnPause(long nativeVrShell); void onPause(long nativeVrShell, VrShell caller);
private native void nativeOnResume(long nativeVrShell); void onResume(long nativeVrShell, VrShell caller);
private native void nativeOnLoadProgressChanged(long nativeVrShell, double progress); void onLoadProgressChanged(long nativeVrShell, VrShell caller, double progress);
private native void nativeBufferBoundsChanged(long nativeVrShell, int contentWidth, void bufferBoundsChanged(long nativeVrShell, VrShell caller, int contentWidth,
int contentHeight, int overlayWidth, int overlayHeight); int contentHeight, int overlayWidth, int overlayHeight);
private native void nativeSetWebVrMode(long nativeVrShell, boolean enabled); void setWebVrMode(long nativeVrShell, VrShell caller, boolean enabled);
private native boolean nativeGetWebVrMode(long nativeVrShell); boolean getWebVrMode(long nativeVrShell, VrShell caller);
private native boolean nativeIsDisplayingUrlForTesting(long nativeVrShell); boolean isDisplayingUrlForTesting(long nativeVrShell, VrShell caller);
private native void nativeOnTabListCreated( void onTabListCreated(
long nativeVrShell, Tab[] mainTabs, Tab[] incognitoTabs); long nativeVrShell, VrShell caller, Tab[] mainTabs, Tab[] incognitoTabs);
private native void nativeOnTabUpdated( void onTabUpdated(
long nativeVrShell, boolean incognito, int id, String title); long nativeVrShell, VrShell caller, boolean incognito, int id, String title);
private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito, int id); void onTabRemoved(long nativeVrShell, VrShell caller, boolean incognito, int id);
private native void nativeCloseAlertDialog(long nativeVrShell); void closeAlertDialog(long nativeVrShell, VrShell caller);
private native void nativeSetAlertDialog(long nativeVrShell, float width, float height); void setAlertDialog(long nativeVrShell, VrShell caller, float width, float height);
private native void nativeSetDialogBufferSize(long nativeVrShell, int width, int height); void setDialogBufferSize(long nativeVrShell, VrShell caller, int width, int height);
private native void nativeSetAlertDialogSize(long nativeVrShell, float width, float height); void setAlertDialogSize(long nativeVrShell, VrShell caller, float width, float height);
private native void nativeSetDialogLocation(long nativeVrShell, float x, float y); void setDialogLocation(long nativeVrShell, VrShell caller, float x, float y);
private native void nativeSetDialogFloating(long nativeVrShell, boolean floating); void setDialogFloating(long nativeVrShell, VrShell caller, boolean floating);
private native void nativeShowToast(long nativeVrShell, String text); void showToast(long nativeVrShell, VrShell caller, String text);
private native void nativeCancelToast(long nativeVrShell); void cancelToast(long nativeVrShell, VrShell caller);
private native void nativeSetHistoryButtonsEnabled( void setHistoryButtonsEnabled(
long nativeVrShell, boolean canGoBack, boolean canGoForward); long nativeVrShell, VrShell caller, boolean canGoBack, boolean canGoForward);
private native void nativeRequestToExitVr(long nativeVrShell, @UiUnsupportedMode int reason); void requestToExitVr(long nativeVrShell, VrShell caller, @UiUnsupportedMode int reason);
private native void nativeLogUnsupportedModeUserMetric( void logUnsupportedModeUserMetric(
long nativeVrShell, @UiUnsupportedMode int mode); long nativeVrShell, VrShell caller, @UiUnsupportedMode int mode);
private native void nativeShowSoftInput(long nativeVrShell, boolean show); void showSoftInput(long nativeVrShell, VrShell caller, boolean show);
private native void nativeUpdateWebInputIndices(long nativeVrShell, int selectionStart, void updateWebInputIndices(long nativeVrShell, VrShell caller, int selectionStart,
int selectionEnd, int compositionStart, int compositionEnd); int selectionEnd, int compositionStart, int compositionEnd);
private native VrInputConnection nativeGetVrInputConnectionForTesting(long nativeVrShell); VrInputConnection getVrInputConnectionForTesting(long nativeVrShell, VrShell caller);
private native void nativeAcceptDoffPromptForTesting(long nativeVrShell); void acceptDoffPromptForTesting(long nativeVrShell, VrShell caller);
private native void nativePerformControllerActionForTesting( void performControllerActionForTesting(long nativeVrShell, VrShell caller, int elementName,
long nativeVrShell, int elementName, int actionType, float x, float y); int actionType, float x, float y);
private native void nativePerformKeyboardInputForTesting( void performKeyboardInputForTesting(
long nativeVrShell, int inputType, String inputString); long nativeVrShell, VrShell caller, int inputType, String inputString);
private native void nativeSetUiExpectingActivityForTesting( void setUiExpectingActivityForTesting(
long nativeVrShell, int quiescenceTimeoutMs); long nativeVrShell, VrShell caller, int quiescenceTimeoutMs);
private native void nativeSaveNextFrameBufferToDiskForTesting( void saveNextFrameBufferToDiskForTesting(
long nativeVrShell, String filepathBase); long nativeVrShell, VrShell caller, String filepathBase);
private native void nativeWatchElementForVisibilityStatusForTesting( void watchElementForVisibilityStatusForTesting(long nativeVrShell, VrShell caller,
long nativeVrShell, int elementName, int timeoutMs, boolean visibility); int elementName, int timeoutMs, boolean visibility);
private native void nativeResumeContentRendering(long nativeVrShell); void resumeContentRendering(long nativeVrShell, VrShell caller);
private native void nativeOnOverlayTextureEmptyChanged(long nativeVrShell, boolean empty); void onOverlayTextureEmptyChanged(long nativeVrShell, VrShell caller, boolean empty);
private native void nativeRequestRecordAudioPermissionResult( void requestRecordAudioPermissionResult(
long nativeVrShell, boolean canRecordAudio); long nativeVrShell, VrShell caller, boolean canRecordAudio);
}
} }
...@@ -41,6 +41,7 @@ import org.chromium.base.ThreadUtils; ...@@ -41,6 +41,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.AsyncTask; import org.chromium.base.task.AsyncTask;
...@@ -240,7 +241,7 @@ public class VrShellDelegate ...@@ -240,7 +241,7 @@ public class VrShellDelegate
// If we didn't request WebVR then we're not coming from a request present call. // If we didn't request WebVR then we're not coming from a request present call.
// If we didn't set mStartedFromVrIntent this isn't an intent from another app. // If we didn't set mStartedFromVrIntent this isn't an intent from another app.
// Therefore we can assume this was triggered by NFC. // Therefore we can assume this was triggered by NFC.
sInstance.nativeRecordVrStartAction( VrShellDelegateJni.get().recordVrStartAction(
sInstance.mNativeVrShellDelegate, VrStartAction.HEADSET_ACTIVATION); sInstance.mNativeVrShellDelegate, VrStartAction.HEADSET_ACTIVATION);
} }
...@@ -341,7 +342,7 @@ public class VrShellDelegate ...@@ -341,7 +342,7 @@ public class VrShellDelegate
*/ */
public static void onNativeLibraryAvailable() { public static void onNativeLibraryAvailable() {
VrModuleProvider.registerJni(); VrModuleProvider.registerJni();
nativeOnLibraryAvailable(); VrShellDelegateJni.get().onLibraryAvailable();
} }
/** /**
...@@ -712,7 +713,7 @@ public class VrShellDelegate ...@@ -712,7 +713,7 @@ public class VrShellDelegate
private static void registerVrAssetsComponentIfDaydreamUser(boolean isDaydreamCurrentViewer) { private static void registerVrAssetsComponentIfDaydreamUser(boolean isDaydreamCurrentViewer) {
assert !sRegisteredVrAssetsComponent; assert !sRegisteredVrAssetsComponent;
if (isDaydreamCurrentViewer) { if (isDaydreamCurrentViewer) {
nativeRegisterVrAssetsComponent(); VrShellDelegateJni.get().registerVrAssetsComponent();
sRegisteredVrAssetsComponent = true; sRegisteredVrAssetsComponent = true;
} }
ChromePreferenceManager.getInstance().writeBoolean( ChromePreferenceManager.getInstance().writeBoolean(
...@@ -897,7 +898,7 @@ public class VrShellDelegate ...@@ -897,7 +898,7 @@ public class VrShellDelegate
// If an activity isn't resumed at the point, it must have been paused. // If an activity isn't resumed at the point, it must have been paused.
mPaused = ApplicationStatus.getStateForActivity(activity) != ActivityState.RESUMED; mPaused = ApplicationStatus.getStateForActivity(activity) != ActivityState.RESUMED;
mVisible = activity.hasWindowFocus(); mVisible = activity.hasWindowFocus();
mNativeVrShellDelegate = nativeInit(); mNativeVrShellDelegate = VrShellDelegateJni.get().init(VrShellDelegate.this);
updateVrSupportLevel(null); updateVrSupportLevel(null);
mFeedbackFrequency = VrFeedbackStatus.getFeedbackFrequency(); mFeedbackFrequency = VrFeedbackStatus.getFeedbackFrequency();
ensureLifecycleObserverInitialized(); ensureLifecycleObserverInitialized();
...@@ -1049,7 +1050,8 @@ public class VrShellDelegate ...@@ -1049,7 +1050,8 @@ public class VrShellDelegate
private void maybeSetPresentResult(boolean result) { private void maybeSetPresentResult(boolean result) {
if (mNativeVrShellDelegate == 0 || !mRequestedWebVr) return; if (mNativeVrShellDelegate == 0 || !mRequestedWebVr) return;
nativeSetPresentResult(mNativeVrShellDelegate, result); VrShellDelegateJni.get().setPresentResult(
mNativeVrShellDelegate, VrShellDelegate.this, result);
mRequestedWebVr = false; mRequestedWebVr = false;
} }
...@@ -1071,7 +1073,7 @@ public class VrShellDelegate ...@@ -1071,7 +1073,7 @@ public class VrShellDelegate
} }
enterVr(mActivateFromHeadsetInsertion); enterVr(mActivateFromHeadsetInsertion);
if (mActivateFromHeadsetInsertion && mListeningForWebVrActivate) { if (mActivateFromHeadsetInsertion && mListeningForWebVrActivate) {
nativeDisplayActivate(mNativeVrShellDelegate); VrShellDelegateJni.get().displayActivate(mNativeVrShellDelegate, VrShellDelegate.this);
mActivateFromHeadsetInsertion = false; mActivateFromHeadsetInsertion = false;
} }
...@@ -1170,7 +1172,9 @@ public class VrShellDelegate ...@@ -1170,7 +1172,9 @@ public class VrShellDelegate
return; return;
} }
if (!mInVr) nativeRecordVrStartAction(mNativeVrShellDelegate, VrStartAction.INTENT_LAUNCH); if (!mInVr)
VrShellDelegateJni.get().recordVrStartAction(
mNativeVrShellDelegate, VrStartAction.INTENT_LAUNCH);
mStartedFromVrIntent = true; mStartedFromVrIntent = true;
// Setting DON succeeded will cause us to enter VR when resuming. // Setting DON succeeded will cause us to enter VR when resuming.
...@@ -1464,7 +1468,8 @@ public class VrShellDelegate ...@@ -1464,7 +1468,8 @@ public class VrShellDelegate
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try { try {
if (mNativeVrShellDelegate != 0) nativeOnResume(mNativeVrShellDelegate); if (mNativeVrShellDelegate != 0)
VrShellDelegateJni.get().onResume(mNativeVrShellDelegate, VrShellDelegate.this);
} finally { } finally {
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} }
...@@ -1551,7 +1556,8 @@ public class VrShellDelegate ...@@ -1551,7 +1556,8 @@ public class VrShellDelegate
} }
if (mInVr) mVrShell.pause(); if (mInVr) mVrShell.pause();
if (mNativeVrShellDelegate != 0) nativeOnPause(mNativeVrShellDelegate); if (mNativeVrShellDelegate != 0)
VrShellDelegateJni.get().onPause(mNativeVrShellDelegate, VrShellDelegate.this);
mIsDaydreamCurrentViewer = null; mIsDaydreamCurrentViewer = null;
} }
...@@ -1660,7 +1666,8 @@ public class VrShellDelegate ...@@ -1660,7 +1666,8 @@ public class VrShellDelegate
if (mActivateFromHeadsetInsertion) { if (mActivateFromHeadsetInsertion) {
// Dispatch vrdisplayactivate so that the WebVr page can call requestPresent // Dispatch vrdisplayactivate so that the WebVr page can call requestPresent
// to start presentation. // to start presentation.
nativeDisplayActivate(mNativeVrShellDelegate); VrShellDelegateJni.get().displayActivate(
mNativeVrShellDelegate, VrShellDelegate.this);
mActivateFromHeadsetInsertion = false; mActivateFromHeadsetInsertion = false;
} }
} else { } else {
...@@ -1946,18 +1953,22 @@ public class VrShellDelegate ...@@ -1946,18 +1953,22 @@ public class VrShellDelegate
private void destroy() { private void destroy() {
if (sInstance == null) return; if (sInstance == null) return;
shutdownVr(false /* disableVrMode */, false /* stayingInChrome */); shutdownVr(false /* disableVrMode */, false /* stayingInChrome */);
if (mNativeVrShellDelegate != 0) nativeDestroy(mNativeVrShellDelegate); if (mNativeVrShellDelegate != 0)
VrShellDelegateJni.get().destroy(mNativeVrShellDelegate, VrShellDelegate.this);
mNativeVrShellDelegate = 0; mNativeVrShellDelegate = 0;
sInstance = null; sInstance = null;
} }
private native long nativeInit(); @NativeMethods
private static native void nativeOnLibraryAvailable(); interface Natives {
private native void nativeSetPresentResult(long nativeVrShellDelegate, boolean result); long init(VrShellDelegate caller);
private native void nativeRecordVrStartAction(long nativeVrShellDelegate, int startAction); void onLibraryAvailable();
private native void nativeDisplayActivate(long nativeVrShellDelegate); void setPresentResult(long nativeVrShellDelegate, VrShellDelegate caller, boolean result);
private native void nativeOnPause(long nativeVrShellDelegate); void recordVrStartAction(long nativeVrShellDelegate, int startAction);
private native void nativeOnResume(long nativeVrShellDelegate); void displayActivate(long nativeVrShellDelegate, VrShellDelegate caller);
private native void nativeDestroy(long nativeVrShellDelegate); void onPause(long nativeVrShellDelegate, VrShellDelegate caller);
private static native void nativeRegisterVrAssetsComponent(); void onResume(long nativeVrShellDelegate, VrShellDelegate caller);
void destroy(long nativeVrShellDelegate, VrShellDelegate caller);
void registerVrAssetsComponent();
}
} }
...@@ -150,7 +150,6 @@ void VrShellDelegate::SetPresentResult(JNIEnv* env, ...@@ -150,7 +150,6 @@ void VrShellDelegate::SetPresentResult(JNIEnv* env,
void VrShellDelegate::RecordVrStartAction( void VrShellDelegate::RecordVrStartAction(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jint start_action) { jint start_action) {
VrStartAction action = static_cast<VrStartAction>(start_action); VrStartAction action = static_cast<VrStartAction>(start_action);
......
...@@ -58,7 +58,6 @@ class VrShellDelegate : public device::GvrDelegateProvider, ...@@ -58,7 +58,6 @@ class VrShellDelegate : public device::GvrDelegateProvider,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
jboolean success); jboolean success);
void RecordVrStartAction(JNIEnv* env, void RecordVrStartAction(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jint start_action); jint start_action);
void DisplayActivate(JNIEnv* env, void DisplayActivate(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
......
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