Bug 1468048 - Make GeckoSession.saveState() return a GeckoResult r=droeh,esawin
MozReview-Commit-ID: Ck6EZcaUeV2
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -1142,32 +1142,27 @@ public class GeckoSession extends LayerS
}
/**
* Save the current browsing session state of this GeckoSession. This session state
* includes the history, scroll position, zoom, and any form data that has been entered,
* but does not include information pertaining to the GeckoSession itself (for example,
* this does not include settings on the GeckoSession).
*
- * @param response This is a response which will be called with the state once it has been
- * saved. Can be null if we fail to save the state for any reason.
+ * @return A {@link GeckoResult} containing the {@link SessionState}
*/
- public void saveState(final GeckoResponse<SessionState> response) {
- mEventDispatcher.dispatch("GeckoView:SaveState", null, new EventCallback() {
+ public GeckoResult<SessionState> saveState() {
+ CallbackResult<SessionState> result = new CallbackResult<SessionState>() {
@Override
- public void sendSuccess(final Object result) {
- response.respond(new SessionState((String) result));
+ public void sendSuccess(final Object value) {
+ complete(new SessionState((String)value));
}
-
- @Override
- public void sendError(final Object result) {
- Log.w(LOGTAG, "Failed to save state, as another save is already in progress.");
- response.respond(null);
- }
- });
+ };
+ mEventDispatcher.dispatch("GeckoView:SaveState", null, result);
+ return result;
}
/**
* Restore a saved state to this GeckoSession; only data that is saved (history, scroll
* position, zoom, and form data) will be restored. These will overwrite the corresponding
* state of this GeckoSession.
*
* @param state A saved session state; this should originate from GeckoSession.saveState().
@@ -3021,9 +3016,20 @@ public class GeckoSession extends LayerS
* {@link android.view.inputmethod.InputConnection#requestCursorUpdates}.
* Consequently, this method is <i>not</i> called in viewless mode.
*
* @param session Session instance.
* @param info Cursor-anchor information.
*/
void updateCursorAnchorInfo(@NonNull GeckoSession session, @NonNull CursorAnchorInfo info);
}
+
+ private static abstract class CallbackResult<T> extends GeckoResult<T> implements EventCallback {
+
+ @Override
+ public abstract void sendSuccess(Object response);
+
+ @Override
+ public void sendError(Object response) {
+ completeExceptionally(new Exception(response.toString()));
+ }
+ }
}