Index: content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java b/content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java |
index e8c279eba71fe6d02ad850868bec051be71ac3e7..831726c4fb009c11a6bb75a440c5f326d3bed372 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.java |
@@ -4,14 +4,18 @@ |
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.ServiceRegistry.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.Nfc; |
import org.chromium.mojom.device.VibrationManager; |
/** |
@@ -35,6 +39,29 @@ class ServiceRegistrar { |
} |
} |
+ private static class NfcImplementationFactory implements ImplementationFactory<Nfc> { |
+ private final WebContents mContents; |
+ |
+ NfcImplementationFactory(WebContents contents) { |
+ mContents = contents; |
+ } |
+ |
+ @Override |
+ public Nfc createImpl() { |
+ Activity activity = null; |
+ ContentViewCore viewCore = null; |
+ if (mContents != null) { |
+ viewCore = ContentViewCore.fromWebContents(mContents); |
+ } |
+ |
+ if (viewCore != null && viewCore.getWindowAndroid() != null) { |
+ activity = viewCore.getWindowAndroid().getActivity().get(); |
+ } |
+ |
+ return new NfcImpl(activity); |
+ } |
+ } |
+ |
private static class VibrationManagerImplementationFactory |
implements ImplementationFactory<VibrationManager> { |
private final Context mApplicationContext; |
@@ -59,8 +86,10 @@ class ServiceRegistrar { |
} |
@CalledByNative |
- static void registerFrameHostServices(ServiceRegistry registry, Context applicationContext) { |
+ static void registerFrameHostServices(ServiceRegistry registry, |
+ Context applicationContext, WebContents contents) { |
assert applicationContext != null; |
// TODO(avayvod): Register the PresentationService implementation here. |
+ registry.addService(Nfc.MANAGER, new NfcImplementationFactory(contents)); |
} |
} |