Bug 1570115 - Add default handler for OnLoad{Request,Error}. r=droeh

Differential Revision: https://phabricator.services.mozilla.com/D44049

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2019-09-20 18:15:33 +00:00
Родитель 278a0d3de7
Коммит 29e0543f01
2 изменённых файлов: 37 добавлений и 3 удалений

Просмотреть файл

@ -517,9 +517,11 @@ public class GeckoSession implements Parcelable {
"GeckoViewNavigation", this, "GeckoViewNavigation", this,
new String[]{ new String[]{
"GeckoView:LocationChange", "GeckoView:LocationChange",
"GeckoView:OnNewSession"
},
new String[] {
"GeckoView:OnLoadError", "GeckoView:OnLoadError",
"GeckoView:OnLoadRequest", "GeckoView:OnLoadRequest",
"GeckoView:OnNewSession"
} }
) { ) {
// This needs to match nsIBrowserDOMWindow.idl // This needs to match nsIBrowserDOMWindow.idl
@ -533,6 +535,20 @@ public class GeckoSession implements Parcelable {
} }
} }
@Override
public void handleDefaultMessage(final String event,
final GeckoBundle message,
final EventCallback callback) {
if ("GeckoView:OnLoadRequest".equals(event)) {
callback.sendSuccess(false);
} else if ("GeckoView:OnLoadError".equals(event)) {
callback.sendSuccess(null);
} else {
super.handleDefaultMessage(event, message, callback);
}
}
@Override @Override
public void handleMessage(final NavigationDelegate delegate, public void handleMessage(final NavigationDelegate delegate,
final String event, final String event,

Просмотреть файл

@ -27,10 +27,20 @@ import android.util.Log;
/* package */ GeckoSessionHandler(final String module, /* package */ GeckoSessionHandler(final String module,
final GeckoSession session, final GeckoSession session,
final String[] events) { final String[] events) {
this(module, session, events, new String[]{});
}
/* package */ GeckoSessionHandler(final String module,
final GeckoSession session,
final String[] events,
final String[] defaultEvents) {
session.handlersCount++; session.handlersCount++;
mModuleName = module; mModuleName = module;
mEvents = events; mEvents = events;
// Default events are always active
session.getEventDispatcher().registerUiThreadListener(this, defaultEvents);
} }
public Delegate getDelegate() { public Delegate getDelegate() {
@ -78,8 +88,8 @@ import android.util.Log;
if (mDelegate != null) { if (mDelegate != null) {
handleMessage(mDelegate, event, message, callback); handleMessage(mDelegate, event, message, callback);
} else if (callback != null) { } else {
callback.sendError("No delegate registered"); handleDefaultMessage(event, message, callback);
} }
} }
@ -87,4 +97,12 @@ import android.util.Log;
final String event, final String event,
final GeckoBundle message, final GeckoBundle message,
final EventCallback callback); final EventCallback callback);
protected void handleDefaultMessage(final String event,
final GeckoBundle message,
final EventCallback callback) {
if (callback != null) {
callback.sendError("No delegate registered");
}
}
} }