| Index: content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java b/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java
|
| index 1840a2dd4df075e1a9c72f243ddb8ce7795c9e5a..0bd9b5457963c99b05a896c79e56bfb823c5ef98 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java
|
| @@ -4,15 +4,20 @@
|
|
|
| package org.chromium.content.browser;
|
|
|
| +import android.app.Activity;
|
| import android.content.Context;
|
|
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.content.browser.InterfaceRegistry.ImplementationFactory;
|
| +import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.device.battery.BatteryMonitorFactory;
|
| +import org.chromium.device.nfc.NfcImpl;
|
| import org.chromium.device.vibration.VibrationManagerImpl;
|
| import org.chromium.mojom.device.BatteryMonitor;
|
| import org.chromium.mojom.device.VibrationManager;
|
| +import org.chromium.mojom.device.nfc.Nfc;
|
| +import org.chromium.ui.base.WindowAndroid;
|
|
|
| /**
|
| * Registers interfaces exposed by the browser in the given registry.
|
| @@ -49,6 +54,54 @@ class InterfaceRegistrar {
|
| }
|
| }
|
|
|
| + private static class NfcImplementationFactory implements ImplementationFactory<Nfc> {
|
| + private final Context mContext;
|
| + private final WebContents mContents;
|
| +
|
| + NfcImplementationFactory(Context context, WebContents contents) {
|
| + mContext = context;
|
| + mContents = contents;
|
| + }
|
| +
|
| + private static class ContextAwareNfcImpl extends NfcImpl implements
|
| + WindowAndroidChangedObserver {
|
| + private final ContentViewCore mContextViewCore;
|
| +
|
| + ContextAwareNfcImpl(Context context, ContentViewCore contextViewCore) {
|
| + super(context);
|
| + mContextViewCore = contextViewCore;
|
| + if (mContextViewCore != null) {
|
| + mContextViewCore.addWindowAndroidChangedObserver(this);
|
| + if (mContextViewCore.getWindowAndroid() != null) {
|
| + setActivity(mContextViewCore.getWindowAndroid().getActivity().get());
|
| + }
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void close() {
|
| + super.close();
|
| + if (mContextViewCore != null) {
|
| + mContextViewCore.removeWindowAndroidChangedObserver(this);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public void onWindowAndroidChanged(WindowAndroid newWindowAndroid) {
|
| + Activity activity = null;
|
| + if (newWindowAndroid != null) {
|
| + activity = newWindowAndroid.getActivity().get();
|
| + }
|
| + setActivity(activity);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public Nfc createImpl() {
|
| + return new ContextAwareNfcImpl(mContext, ContentViewCore.fromWebContents(mContents));
|
| + }
|
| + }
|
| +
|
| @CalledByNative
|
| static void exposeInterfacesToRenderer(InterfaceRegistry registry, Context applicationContext) {
|
| assert applicationContext != null;
|
| @@ -57,10 +110,13 @@ class InterfaceRegistrar {
|
| }
|
|
|
| @CalledByNative
|
| - static void exposeInterfacesToFrame(InterfaceRegistry registry, Context applicationContext) {
|
| + static void exposeInterfacesToFrame(InterfaceRegistry registry,
|
| + Context applicationContext, WebContents contents) {
|
| assert applicationContext != null;
|
| registry.addInterface(VibrationManager.MANAGER,
|
| new VibrationManagerImplementationFactory(applicationContext));
|
| + registry.addInterface(Nfc.MANAGER,
|
| + new NfcImplementationFactory(applicationContext, contents));
|
| // TODO(avayvod): Register the PresentationService implementation here.
|
| }
|
| }
|
|
|