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

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: Avoid caching Activity. Created 4 years, 7 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
« no previous file with comments | « content/public/android/BUILD.gn ('k') | device/nfc/android/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
}
« no previous file with comments | « content/public/android/BUILD.gn ('k') | device/nfc/android/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698