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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ServiceRegistrar.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: Rebased to master. Created 4 years, 5 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/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 a9d7f8f9d8cd64e7457dd7b6371028a611217c61..b5a372dc3a9c1294d39a2e7bc859eb78f61e3136 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,21 @@
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.VibrationManager;
+import org.chromium.mojom.device.nfc.Nfc;
+import org.chromium.ui.base.WindowAndroid;
+import org.chromium.ui.base.WindowAndroidChangedObserver;
/**
* Registers mojo services exposed by the browser in the given registry.
@@ -35,6 +41,54 @@ 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;
+ }
+
+ 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));
+ }
+ }
+
private static class VibrationManagerImplementationFactory
implements ImplementationFactory<VibrationManager> {
private final Context mApplicationContext;
@@ -57,10 +111,13 @@ class ServiceRegistrar {
}
@CalledByNative
- static void registerFrameHostServices(ServiceRegistry registry, Context applicationContext) {
+ static void registerFrameHostServices(ServiceRegistry registry,
+ Context applicationContext, WebContents contents) {
assert applicationContext != null;
registry.addService(VibrationManager.MANAGER,
new VibrationManagerImplementationFactory(applicationContext));
// TODO(avayvod): Register the PresentationService implementation here.
+ registry.addService(Nfc.MANAGER,
+ new NfcImplementationFactory(applicationContext, contents));
}
}

Powered by Google App Engine
This is Rietveld 408576698