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

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: fix vr_shell build 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..bfa5bbfa4eb64790698adf92360414c2c46ff280 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
@@ -10,6 +10,11 @@ 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.BatteryMonitor;
+import org.chromium.device.VibrationManager;
+import org.chromium.device.battery.BatteryMonitorFactory;
+import org.chromium.device.nfc.mojom.Nfc;
+import org.chromium.device.vibration.VibrationManagerImpl;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.services.shell.InterfaceRegistry;
@@ -17,6 +22,8 @@ import org.chromium.services.shell.InterfaceRegistry;
class InterfaceRegistrarImpl {
@CalledByNative
static void createInterfaceRegistryForContext(int nativeHandle, Context applicationContext) {
+ ensureContentRegistrarsAreRegistered();
+
InterfaceRegistry registry = InterfaceRegistry.create(
CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle());
InterfaceRegistrar.Registry.applyContextRegistrars(registry, applicationContext);
@@ -24,8 +31,38 @@ class InterfaceRegistrarImpl {
@CalledByNative
static void createInterfaceRegistryForWebContents(int nativeHandle, WebContents webContents) {
+ ensureContentRegistrarsAreRegistered();
+
InterfaceRegistry registry = InterfaceRegistry.create(
CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle());
InterfaceRegistrar.Registry.applyWebContentsRegistrars(registry, webContents);
}
+
+ private static void ensureContentRegistrarsAreRegistered() {
+ if (sHasRegisteredRegistrars) return;
+ sHasRegisteredRegistrars = true;
+ InterfaceRegistrar.Registry.addContextRegistrar(new ContentContextInterfaceRegistrar());
+ InterfaceRegistrar.Registry.addWebContentsRegistrar(
+ new ContentWebContentsInterfaceRegistrar());
+ }
+
+ private static boolean sHasRegisteredRegistrars = false;
+}
+
+class ContentContextInterfaceRegistrar implements InterfaceRegistrar<Context> {
+ @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));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698