Chromium Code Reviews| 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..19e093c6afab63016d390d62047586866f81a8b5 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,15 +4,22 @@ |
| package org.chromium.content.browser; |
| +import android.app.Activity; |
| import android.content.Context; |
| +import android.support.annotation.Nullable; |
| 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.VibrationManager; |
| +import org.chromium.mojom.device.nfc.Nfc; |
| + |
| +import java.util.concurrent.Callable; |
| /** |
| * Registers mojo services exposed by the browser in the given registry. |
| @@ -35,6 +42,40 @@ class ServiceRegistrar { |
| } |
| } |
| + private static class NfcImplementationFactory implements ImplementationFactory<Nfc> { |
| + private final Context mContext; |
| + private final WebContents mContents; |
| + |
| + NfcImplementationFactory(Context context, WebContents contents) { |
| + mContext = context; |
| + mContents = contents; |
| + } |
| + |
| + @Nullable |
| + private Activity getActivity() { |
| + 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 activity; |
| + } |
| + |
| + @Override |
| + public Nfc createImpl() { |
| + return new NfcImpl(mContext, new Callable<Activity>() { |
|
Ted C
2016/05/13 22:04:08
to avoid the awkward layering, maybe we can put th
shalamov
2016/05/17 12:30:32
Done.
|
| + public Activity call() { |
| + return getActivity(); |
| + } |
| + }); |
| + } |
| + } |
| + |
| private static class VibrationManagerImplementationFactory |
| implements ImplementationFactory<VibrationManager> { |
| private final Context mApplicationContext; |
| @@ -59,8 +100,11 @@ 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(applicationContext, contents)); |
| } |
| } |