Commit 906ec1c0 authored by Danan S's avatar Danan S Committed by Commit Bot

Add guest flow state support to EduCoexistenceController

These calls allow the guest content to save its state (represented
as an opaque Uint8Array of data) in such a way that it survives
content reloads.  This is needed because the flow redirects through
GAIA, which triggers the content reload which wipes out the flow's
state.

This method is simpler than previous methods used to maintain state across
page reloads and doesn't require extra network round-trips because
the state is saved and retrieved locally via postMessage calls to
the WebUI.


Bug: 1136979
Change-Id: Ic1d3c1dbbf0d253f3e856365c0fafa64b8f55066
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498960
Commit-Queue: Dan S <danan@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821850}
parent 61f7b960
......@@ -48,7 +48,7 @@ const MAX_INITIALIZATION_ATTEMPTS = 8;
/**
* Map that stores references to the methods implemented by the API.
* @private {!Map<string, function(!Array): (Promise|undefined)>}
* @private {!Map<string, function(!Array): (Promise|Object|undefined)>}
*/
this.apiFns_ = new Map();
......@@ -83,8 +83,8 @@ const MAX_INITIALIZATION_ATTEMPTS = 8;
* function.
*
* @param {!string} methodName name of the method to register.
* @param {!function(!Array): (Promise|undefined)} method The function to
* associate with the name.
* @param {!function(!Array): (Promise|Object|undefined)} method The function
* to associate with the name.
*/
registerMethod(methodName, method) {
this.apiFns_.set(methodName, method);
......
......@@ -9,7 +9,10 @@ import {EduCoexistenceBrowserProxyImpl} from './edu_coexistence_browser_proxy.js
/**
* The methods to expose to the hosted content via the PostMessageAPI.
*/
const METHOD_LIST = ['consentValid', 'consentLogged', 'requestClose', 'error'];
const METHOD_LIST = [
'consentValid', 'consentLogged', 'requestClose', 'saveGuestFlowState',
'fetchGuestFlowState', 'error'
];
/**
......@@ -88,6 +91,15 @@ export class EduCoexistenceController extends PostMessageAPIServer {
{urls: ['<all_urls>']}, ['blocking', 'requestHeaders']);
/**
* The state of the guest content, saved as requested by
* the guest content to ensure that its state outlives content
* reload events, which destroy the state of the guest content.
* The value itself is opaque encoded binary data.
* @private {?Uint8Array}
*/
this.guestFlowState_ = null;
/**
* The auth extension host instance.
* @private {Authenticator}
......@@ -125,6 +137,10 @@ export class EduCoexistenceController extends PostMessageAPIServer {
this.registerMethod('consentLogged', this.consentLogged_.bind(this));
this.registerMethod('requestClose', this.requestClose_.bind(this));
this.registerMethod('reportError', this.reportError_.bind(this));
this.registerMethod(
'saveGuestFlowState', this.saveGuestFlowState_.bind(this));
this.registerMethod(
'fetchGuestFlowState', this.fetchGuestFlowState_.bind(this));
// Add listeners for Authenticator.
this.addAuthExtHostListeners_();
......@@ -221,6 +237,24 @@ export class EduCoexistenceController extends PostMessageAPIServer {
this.browserProxy_.dialogClose();
}
/*
* @private
* @param {!Array<Uint8Array>} An array that contains guest flow state in its
* first element.
*/
saveGuestFlowState_(guestFlowState) {
this.guestFlowState_ = guestFlowState[0];
}
/**
* @param {!Array} unused Placeholder unused empty parameter.
* @return {?Object} The guest flow state previously saved
* using saveGuestFlowState().
*/
fetchGuestFlowState_(unused) {
return {'state': this.guestFlowState_};
}
/**
* @private
* Notifies the API that there was an unrecoverable error during the flow.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment