Sign-in popups & FedCM
Sites sign users in with another site's account in two ways: a popup that sends the result back to the page, and FedCM, which "Sign in with" prompts use. Both need the app to show something. Available from 0.19.0.
Popups
By default a popup (window.open, a
target=_blank link) is loaded in the same browser, and the page
loses its reference to it. A sign-in or payment popup needs that reference:
it posts the result to window.opener and closes. Give the
window a browser of its own:
browser.setPopupHandler(new CefriumBrowser.PopupHandler() {
@Override public boolean onOpenPopup(String url, boolean userGesture) {
return false; // only for windows onCreateWindow declines
}
@Override public boolean onCreateWindow(CefriumBrowser popup, String url,
boolean userGesture) {
container.addView(popup.getSurfaceContainer());
return true;
}
@Override public void onCloseWindow(CefriumBrowser popup) {
container.removeView(popup.getSurfaceContainer()); // window.close()
}
});
popupis in the opener's mode and profile, so it shares its cookies. A surface browser's popup is a surface browser; an off-screen browser's popup is an off-screen browser of the same size, which you render like any other.- Return false and the URL goes to
onOpenPopup, as before; the browser made for it is closed. - Close the popup with
close()when your UI dismisses it.
FedCM
navigator.credentials.get({identity: ...}) asks the browser
to show the user's accounts at an identity provider. A surface browser
shows a default dialog. An off-screen browser shows it on the activity
given to setDialogActivity; with neither, the request fails.
To draw your own chooser:
browser.setIdentityHandler((site, accounts, request) -> {
showAccounts(site, accounts, chosen -> {
if (chosen != null) request.select(chosen); else request.cancel();
});
return true;
});
Each account has its id, name, email, picture URL and identity
provider. onAccountChooserClosed tells you when the page gave
up and your chooser should go away.
Google's own sign-in page works in Cefrium: it is a full Chromium, not a WebView, and Google treats it as one.
Sample: cefrium-sample/sign-in runs both flows against an identity provider inside the app.