Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1892)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.java

Issue 1486043002: [webnfc] Implement push method for Android nfc mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@step_6_add_mojo_service_CL
Patch Set: Move WindowAndroidChangedObserver to other observers in content layer Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
}
}

Powered by Google App Engine
This is Rietveld 408576698