diff --git a/app/src/common/chromium/com/igalia/wolvic/browser/api/impl/TabWebContentsDelegate.java b/app/src/common/chromium/com/igalia/wolvic/browser/api/impl/TabWebContentsDelegate.java index 4eb847e737..86be9a226d 100644 --- a/app/src/common/chromium/com/igalia/wolvic/browser/api/impl/TabWebContentsDelegate.java +++ b/app/src/common/chromium/com/igalia/wolvic/browser/api/impl/TabWebContentsDelegate.java @@ -1,11 +1,15 @@ package com.igalia.wolvic.browser.api.impl; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.igalia.wolvic.browser.api.WAllowOrDeny; import com.igalia.wolvic.browser.api.WResult; import com.igalia.wolvic.browser.api.WSession; +import com.igalia.wolvic.ui.adapters.WebApp; +import com.igalia.wolvic.utils.SystemUtils; import org.chromium.base.task.PostTask; import org.chromium.base.task.TaskTraits; @@ -16,8 +20,14 @@ import org.chromium.url.GURL; import org.chromium.wolvic.Tab; import org.chromium.wolvic.WolvicWebContentsDelegate; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; public class TabWebContentsDelegate extends WolvicWebContentsDelegate { + private static final String LOGTAG = SystemUtils.createLogtag(TabWebContentsDelegate.class); + private @NonNull SessionImpl mSession; private @NonNull final WebContents mWebContents; @@ -77,7 +87,20 @@ public void navigationStateChanged(int flags) { } @Override - public void onWebAppManifest(WebContents webContents, @NonNull String manifest) {} + public void onWebAppManifest(WebContents webContents, @NonNull String manifest) { + @Nullable WSession.ContentDelegate delegate = mSession.getContentDelegate(); + if (delegate == null) + return; + // We parse the manifest here to prevent errors later in case it is malformed. + try { + WebApp webAppManifest = new WebApp(new JSONObject(manifest)); + delegate.onWebAppManifest(mSession, webAppManifest); + } catch (JSONException e) { + Log.w(LOGTAG, "Error parsing JSON: " + e.getMessage()); + } catch (IOException e) { + Log.w(LOGTAG, "Error when receiving Web App manifest: " + e.getMessage()); + } + } public class OnNewSessionCallback implements WSession.NavigationDelegate.OnNewSessionCallback { public OnNewSessionCallback(RuntimeImpl runtime, WebContents webContents) {