From 29e0543f01b950a0d12103d9937e3d7624eb3c3c Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Fri, 20 Sep 2019 18:15:33 +0000 Subject: [PATCH] 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 --- .../org/mozilla/geckoview/GeckoSession.java | 18 ++++++++++++++- .../geckoview/GeckoSessionHandler.java | 22 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java index 8bf066b9c039..aaab32a0a73f 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java @@ -517,9 +517,11 @@ public class GeckoSession implements Parcelable { "GeckoViewNavigation", this, new String[]{ "GeckoView:LocationChange", + "GeckoView:OnNewSession" + }, + new String[] { "GeckoView:OnLoadError", "GeckoView:OnLoadRequest", - "GeckoView:OnNewSession" } ) { // 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 public void handleMessage(final NavigationDelegate delegate, final String event, diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java index fe6cd455dcbf..033c116cfb8d 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionHandler.java @@ -27,10 +27,20 @@ import android.util.Log; /* package */ GeckoSessionHandler(final String module, final GeckoSession session, 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++; mModuleName = module; mEvents = events; + + // Default events are always active + session.getEventDispatcher().registerUiThreadListener(this, defaultEvents); } public Delegate getDelegate() { @@ -78,8 +88,8 @@ import android.util.Log; if (mDelegate != null) { handleMessage(mDelegate, event, message, callback); - } else if (callback != null) { - callback.sendError("No delegate registered"); + } else { + handleDefaultMessage(event, message, callback); } } @@ -87,4 +97,12 @@ import android.util.Log; final String event, final GeckoBundle message, final EventCallback callback); + + protected void handleDefaultMessage(final String event, + final GeckoBundle message, + final EventCallback callback) { + if (callback != null) { + callback.sendError("No delegate registered"); + } + } }