зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1322586 - 1. Add "always listen" option for GeckoViewHandler; r=esawin
It would be nice to reuse GeckoViewHandler for delegates too (e.g. for the new PermissionDelegate), but delegates need to always listen to their events. This patch adds an "always listen" option for GeckoViewHandler that still keeps track of the current listener/delegate instance, but registers for all events at initialization rather than only when there is a listener. MozReview-Commit-ID: JtskpZMy9T4 --HG-- extra : rebase_source : 99170bc0b19d605dde4dbf08690bb31d310ed113
This commit is contained in:
Родитель
963412d5e3
Коммит
ec84922bdd
|
@ -20,13 +20,25 @@ import android.util.Log;
|
|||
private static final boolean DEBUG = false;
|
||||
|
||||
private Listener mListener;
|
||||
private final boolean mAlwaysListen;
|
||||
private final String mModuleName;
|
||||
private final String[] mEvents;
|
||||
|
||||
|
||||
GeckoViewHandler(final String module, final GeckoView view,
|
||||
final String[] events) {
|
||||
this(module, view, events, /* alwaysListen */ false);
|
||||
}
|
||||
|
||||
GeckoViewHandler(final String module, final GeckoView view,
|
||||
final String[] events, final boolean alwaysListen) {
|
||||
mAlwaysListen = alwaysListen;
|
||||
mModuleName = module;
|
||||
mEvents = events;
|
||||
|
||||
if (alwaysListen) {
|
||||
register(view.getEventDispatcher());
|
||||
}
|
||||
}
|
||||
|
||||
public Listener getListener() {
|
||||
|
@ -35,20 +47,29 @@ import android.util.Log;
|
|||
|
||||
public void setListener(final Listener listener, final GeckoView view) {
|
||||
final EventDispatcher eventDispatcher = view.getEventDispatcher();
|
||||
if (mListener == listener) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mListener != null && mListener != listener) {
|
||||
if (!mAlwaysListen && mListener != null) {
|
||||
unregister(eventDispatcher);
|
||||
}
|
||||
|
||||
mListener = listener;
|
||||
|
||||
if (!mAlwaysListen && mListener != null) {
|
||||
register(eventDispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
private void unregister(final EventDispatcher eventDispatcher) {
|
||||
final GeckoBundle msg = new GeckoBundle(1);
|
||||
msg.putString("module", mModuleName);
|
||||
eventDispatcher.dispatch("GeckoView:Unregister", msg);
|
||||
eventDispatcher.unregisterUiThreadListener(this, mEvents);
|
||||
}
|
||||
|
||||
mListener = listener;
|
||||
|
||||
if (mListener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void register(final EventDispatcher eventDispatcher) {
|
||||
final GeckoBundle msg = new GeckoBundle(1);
|
||||
msg.putString("module", mModuleName);
|
||||
eventDispatcher.dispatch("GeckoView:Register", msg);
|
||||
|
|
Загрузка…
Ссылка в новой задаче