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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/InterfaceRegistrar.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.app.Activity;
8 import android.content.Context; 7 import android.content.Context;
9 8
10 import org.chromium.base.annotations.CalledByNative; 9 import org.chromium.base.annotations.CalledByNative;
11 import org.chromium.base.annotations.JNINamespace; 10 import org.chromium.base.annotations.JNINamespace;
12 import org.chromium.content.browser.InterfaceRegistry.ImplementationFactory;
13 import org.chromium.content_public.browser.WebContents; 11 import org.chromium.content_public.browser.WebContents;
14 import org.chromium.device.battery.BatteryMonitorFactory;
15 import org.chromium.device.nfc.NfcImpl;
16 import org.chromium.device.vibration.VibrationManagerImpl;
17 import org.chromium.mojom.device.BatteryMonitor;
18 import org.chromium.mojom.device.VibrationManager;
19 import org.chromium.mojom.device.nfc.Nfc;
20 import org.chromium.ui.base.WindowAndroid;
21 12
22 /** 13 /**
23 * Registers interfaces exposed by the browser in the given registry. 14 * Registers interfaces exposed by the browser in the given registry.
24 */ 15 */
25 @JNINamespace("content") 16 @JNINamespace("content")
26 class InterfaceRegistrar { 17 class InterfaceRegistrar {
boliu 2016/09/22 14:32:18 this looks empty now, can this be removed?
Sam McNally 2016/09/23 01:38:50 Yes. I was going to delete it in a follow up CL: h
27 // BatteryMonitorFactory can't implement ImplementationFactory itself, as we don't depend on
28 // /content in /device. Hence we use BatteryMonitorImplementationFactory as a wrapper.
29 private static class BatteryMonitorImplementationFactory
30 implements ImplementationFactory<BatteryMonitor> {
31 private final BatteryMonitorFactory mFactory;
32
33 BatteryMonitorImplementationFactory(Context applicationContext) {
34 mFactory = new BatteryMonitorFactory(applicationContext);
35 }
36
37 @Override
38 public BatteryMonitor createImpl() {
39 return mFactory.createMonitor();
40 }
41 }
42
43 private static class VibrationManagerImplementationFactory
44 implements ImplementationFactory<VibrationManager> {
45 private final Context mApplicationContext;
46
47 VibrationManagerImplementationFactory(Context applicationContext) {
48 mApplicationContext = applicationContext;
49 }
50
51 @Override
52 public VibrationManager createImpl() {
53 return new VibrationManagerImpl(mApplicationContext);
54 }
55 }
56
57 private static class NfcImplementationFactory implements ImplementationFacto ry<Nfc> {
58 private final Context mContext;
59 private final WebContents mContents;
60
61 NfcImplementationFactory(Context context, WebContents contents) {
62 mContext = context;
63 mContents = contents;
64 }
65
66 private static class ContextAwareNfcImpl extends NfcImpl implements
67 WindowAndroidChangedObserver {
68 private final ContentViewCore mContextViewCore;
69
70 ContextAwareNfcImpl(Context context, ContentViewCore contextViewCore ) {
71 super(context);
72 mContextViewCore = contextViewCore;
73 if (mContextViewCore != null) {
74 mContextViewCore.addWindowAndroidChangedObserver(this);
75 if (mContextViewCore.getWindowAndroid() != null) {
76 setActivity(mContextViewCore.getWindowAndroid().getActiv ity().get());
77 }
78 }
79 }
80
81 @Override
82 public void close() {
83 super.close();
84 if (mContextViewCore != null) {
85 mContextViewCore.removeWindowAndroidChangedObserver(this);
86 }
87 }
88
89 @Override
90 public void onWindowAndroidChanged(WindowAndroid newWindowAndroid) {
91 Activity activity = null;
92 if (newWindowAndroid != null) {
93 activity = newWindowAndroid.getActivity().get();
94 }
95 setActivity(activity);
96 }
97 }
98
99 @Override
100 public Nfc createImpl() {
101 return new ContextAwareNfcImpl(mContext, ContentViewCore.fromWebCont ents(mContents));
102 }
103 }
104
105 @CalledByNative 18 @CalledByNative
106 static void exposeInterfacesToRenderer(InterfaceRegistry registry, Context a pplicationContext) { 19 static void exposeInterfacesToRenderer(InterfaceRegistry registry, Context a pplicationContext) {
107 assert applicationContext != null; 20 assert applicationContext != null;
108 registry.addInterface(BatteryMonitor.MANAGER,
109 new BatteryMonitorImplementationFactory(applicationContext));
110 } 21 }
111 22
112 @CalledByNative 23 @CalledByNative
113 static void exposeInterfacesToFrame(InterfaceRegistry registry, 24 static void exposeInterfacesToFrame(InterfaceRegistry registry,
114 Context applicationContext, WebContents contents) { 25 Context applicationContext, WebContents contents) {
115 assert applicationContext != null; 26 assert applicationContext != null;
116 registry.addInterface(VibrationManager.MANAGER,
117 new VibrationManagerImplementationFactory(applicationContext));
118 registry.addInterface(Nfc.MANAGER,
119 new NfcImplementationFactory(applicationContext, contents));
120 // TODO(avayvod): Register the PresentationService implementation here.
121 } 27 }
122 } 28 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698