Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement onWebAppManifest in TabWebContentsDelegate #1624

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Loading