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

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

Issue 2214383002: Move registration of Java mojo interfaces to the new InterfaceRegistrar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java-content-interface-registry
Patch Set: Created 4 years, 3 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/InterfaceRegistrarImpl.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java b/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java
index b1d920a97f8a9bfc25699749fbcdb504077b9c47..e65195c89de711109de6ffd79e5687c571294225 100644
--- a/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java
+++ b/content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrarImpl.java
@@ -4,14 +4,23 @@
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_public.browser.InterfaceRegistrar;
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.mojo.system.impl.CoreImpl;
+import org.chromium.mojom.device.BatteryMonitor;
+import org.chromium.mojom.device.VibrationManager;
+import org.chromium.mojom.device.nfc.Nfc;
+import org.chromium.services.shell.InterfaceFactory;
import org.chromium.services.shell.InterfaceRegistry;
+import org.chromium.ui.base.WindowAndroid;
@JNINamespace("content")
class InterfaceRegistrarImpl {
@@ -28,4 +37,77 @@ class InterfaceRegistrarImpl {
CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle());
InterfaceRegistrar.Registry.applyWebContentsRegistrars(registry, webContents);
}
+
+ static {
boliu 2016/09/22 14:32:18 static blocks executes when the class is loaded by
Sam McNally 2016/09/23 01:38:50 Done.
+ InterfaceRegistrar.Registry.addContextRegistrar(new ContentContextInterfaceRegistrar());
+ InterfaceRegistrar.Registry.addWebContentsRegistrar(
+ new ContentWebContentsInterfaceRegistrar());
+ }
+}
+
+class ContentContextInterfaceRegistrar implements InterfaceRegistrar<Context> {
boliu 2016/09/22 14:32:18 question, not really about this CL <Context> mean
Sam McNally 2016/09/23 01:38:50 Potentially yes; the interface lifetimes are contr
+ @Override
+ public void registerInterfaces(InterfaceRegistry registry, final Context applicationContext) {
+ registry.addInterface(
+ VibrationManager.MANAGER, new VibrationManagerImpl.Factory(applicationContext));
+ registry.addInterface(
+ BatteryMonitor.MANAGER, new BatteryMonitorFactory(applicationContext));
+ // TODO(avayvod): Register the PresentationService implementation here.
+ }
+}
+
+class ContentWebContentsInterfaceRegistrar implements InterfaceRegistrar<WebContents> {
+ @Override
+ public void registerInterfaces(InterfaceRegistry registry, final WebContents webContents) {
+ registry.addInterface(Nfc.MANAGER, new NfcFactory(webContents));
+ }
+
+ // TODO(sammc): Move this into its own file.
boliu 2016/09/22 14:32:18 why wait? you are moving this code in this CL alre
Sam McNally 2016/09/23 01:38:50 Done.
+ private static class NfcFactory implements InterfaceFactory<Nfc> {
+ private final WebContents mContents;
+
+ NfcFactory(WebContents contents) {
+ mContents = contents;
+ }
+
+ private static class ContextAwareNfcImpl
+ extends NfcImpl implements WindowAndroidChangedObserver {
+ private final ContentViewCore mContentViewCore;
+
+ ContextAwareNfcImpl(ContentViewCore contentViewCore) {
+ super(contentViewCore.getContext().getApplicationContext());
+ mContentViewCore = contentViewCore;
+ mContentViewCore.addWindowAndroidChangedObserver(this);
+ if (mContentViewCore.getWindowAndroid() != null) {
+ setActivity(mContentViewCore.getWindowAndroid().getActivity().get());
+ }
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ if (mContentViewCore != null) {
+ mContentViewCore.removeWindowAndroidChangedObserver(this);
+ }
+ }
+
+ @Override
+ public void onWindowAndroidChanged(WindowAndroid newWindowAndroid) {
+ Activity activity = null;
+ if (newWindowAndroid != null) {
+ activity = newWindowAndroid.getActivity().get();
+ }
+ setActivity(activity);
+ }
+ }
+
+ @Override
+ public Nfc createImpl() {
+ ContentViewCore contentViewCore = ContentViewCore.fromWebContents(mContents);
+ if (contentViewCore == null) {
+ return null;
+ }
+ return new ContextAwareNfcImpl(contentViewCore);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698