1717
1818import java .io .Serializable ;
1919import java .util .Date ;
20+ import java .util .Objects ;
2021import java .util .TimeZone ;
2122import java .util .function .Function ;
2223
@@ -442,21 +443,23 @@ void setColorScheme(ColorScheme.Value colorScheme) {
442443 }
443444
444445 /**
445- * Creates an ExtendedClientDetails instance from browser details JSON
446- * object. This is intended for internal use when browser details are
447- * provided as JSON (e.g., during UI initialization or refresh).
446+ * Parses browser details from the given JSON and updates the UI from them:
447+ * stores the resulting {@link ExtendedClientDetails} on the UI's internals
448+ * and seeds the page-visibility and geolocation-availability signals from
449+ * the same payload.
448450 * <p>
449451 * For internal use only.
450452 *
451453 * @param ui
452- * the UI instance that owns this ExtendedClientDetails
454+ * the UI to update, not {@code null}
453455 * @param json
454456 * the JSON object containing browser details parameters
455- * @return a new ExtendedClientDetails instance
457+ * @return the parsed details
456458 * @throws RuntimeException
457459 * if the JSON is not a valid object
458460 */
459- public static ExtendedClientDetails fromJson (UI ui , JsonNode json ) {
461+ public static ExtendedClientDetails updateFromJson (UI ui , JsonNode json ) {
462+ Objects .requireNonNull (ui , "UI must not be null" );
460463 if (!(json instanceof ObjectNode )) {
461464 throw new RuntimeException ("Expected a JSON object" );
462465 }
@@ -494,8 +497,9 @@ public static ExtendedClientDetails fromJson(UI ui, JsonNode json) {
494497 getStringElseNull .apply ("v-np" ),
495498 getStringElseNull .apply ("v-cs" ),
496499 getStringElseNull .apply ("v-tn" ));
500+ ui .getInternals ().setExtendedClientDetails (details );
497501 String ga = getStringElseNull .apply ("v-ga" );
498- if (ga != null && ui != null ) {
502+ if (ga != null ) {
499503 try {
500504 ui .getInternals ().setGeolocationAvailability (
501505 GeolocationAvailability .valueOf (ga ));
@@ -519,8 +523,7 @@ public static ExtendedClientDetails fromJson(UI ui, JsonNode json) {
519523 public void refresh (SerializableConsumer <ExtendedClientDetails > callback ) {
520524 final String js = "return Vaadin.Flow.getBrowserDetailsParameters();" ;
521525 final SerializableConsumer <JsonNode > resultHandler = json -> {
522- ExtendedClientDetails details = fromJson (ui , json );
523- ui .getInternals ().setExtendedClientDetails (details );
526+ ExtendedClientDetails details = updateFromJson (ui , json );
524527 if (callback != null ) {
525528 callback .accept (details );
526529 }
0 commit comments