| 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));
|
| + }
|
| }
|
|
|