package com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.z;
import androidx.media3.common.C;
import com.bytedance.sdk.component.pglcrypt.PglCryptUtils;
import com.pichillilorenzo.flutter_inappwebview_android.InAppWebViewFlutterPlugin;
import com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.CustomTabsSecondaryToolbar;
import defpackage.e;
import ed.q;
import ed.t;
import ed.u;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import xyz.stream.download.config.InnerConstant;

/* JADX INFO: loaded from: classes.dex */
public class ChromeCustomTabsChannelDelegate extends ChannelDelegateImpl {

    @Nullable
    private ChromeCustomTabsActivity chromeCustomTabsActivity;

    public ChromeCustomTabsChannelDelegate(@NonNull ChromeCustomTabsActivity chromeCustomTabsActivity, @NonNull u uVar) {
        super(uVar);
        this.chromeCustomTabsActivity = chromeCustomTabsActivity;
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        super.dispose();
        this.chromeCustomTabsActivity = null;
    }

    public void onClosed() {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onClosed", new HashMap());
    }

    public void onCompletedInitialLoad() {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onCompletedInitialLoad", new HashMap());
    }

    public void onGreatestScrollPercentageIncreased(int i10) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("scrollPercentage", Integer.valueOf(i10));
        channel.invokeMethod("onGreatestScrollPercentageIncreased", map);
    }

    public void onItemActionPerform(int i10, String str, String str2) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put(InnerConstant.Db.f36069id, Integer.valueOf(i10));
        map.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str);
        map.put(IjkMediaMeta.IJKM_KEY_TITLE, str2);
        channel.invokeMethod("onItemActionPerform", map);
    }

    public void onMessageChannelReady() {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onMessageChannelReady", new HashMap());
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.IChannelDelegate, ed.s
    public void onMethodCall(@NonNull q qVar, @NonNull t tVar) {
        z zVar;
        InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin;
        Activity activity;
        String str = qVar.f25842a;
        str.getClass();
        byte b10 = -1;
        switch (str.hashCode()) {
            case -1526944655:
                if (str.equals("isEngagementSignalsApiAvailable")) {
                    b10 = 0;
                }
                break;
            case -675108676:
                if (str.equals("launchUrl")) {
                    b10 = 1;
                }
                break;
            case -334843312:
                if (str.equals("updateSecondaryToolbar")) {
                    b10 = 2;
                }
                break;
            case 50870385:
                if (str.equals("updateActionButton")) {
                    b10 = 3;
                }
                break;
            case 94756344:
                if (str.equals("close")) {
                    b10 = 4;
                }
                break;
            case 1256059502:
                if (str.equals("validateRelationship")) {
                    b10 = 5;
                }
                break;
            case 1392239787:
                if (str.equals("requestPostMessageChannel")) {
                    b10 = 6;
                }
                break;
            case 1490029383:
                if (str.equals("postMessage")) {
                    b10 = 7;
                }
                break;
            case 2000053463:
                if (str.equals("mayLaunchUrl")) {
                    b10 = 8;
                }
                break;
        }
        switch (b10) {
            case 0:
                ChromeCustomTabsActivity chromeCustomTabsActivity = this.chromeCustomTabsActivity;
                if (chromeCustomTabsActivity == null || (zVar = chromeCustomTabsActivity.customTabsSession) == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    try {
                        tVar.success(Boolean.valueOf(zVar.b(new Bundle())));
                    } catch (Throwable unused) {
                        tVar.success(Boolean.FALSE);
                        return;
                    }
                }
                break;
            case 1:
                if (this.chromeCustomTabsActivity == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    String str2 = (String) qVar.argument(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL);
                    if (str2 == null) {
                        tVar.success(Boolean.FALSE);
                    } else {
                        this.chromeCustomTabsActivity.launchUrl(str2, (Map) qVar.argument("headers"), (String) qVar.argument("referrer"), (List) qVar.argument("otherLikelyURLs"));
                        tVar.success(Boolean.TRUE);
                    }
                }
                break;
            case 2:
                if (this.chromeCustomTabsActivity == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    this.chromeCustomTabsActivity.updateSecondaryToolbar(CustomTabsSecondaryToolbar.fromMap((Map) qVar.argument("secondaryToolbar")));
                    tVar.success(Boolean.TRUE);
                }
                break;
            case 3:
                if (this.chromeCustomTabsActivity == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    this.chromeCustomTabsActivity.updateActionButton((byte[]) qVar.argument("icon"), (String) qVar.argument("description"));
                    tVar.success(Boolean.TRUE);
                }
                break;
            case 4:
                ChromeCustomTabsActivity chromeCustomTabsActivity2 = this.chromeCustomTabsActivity;
                if (chromeCustomTabsActivity2 == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    chromeCustomTabsActivity2.onStop();
                    this.chromeCustomTabsActivity.onDestroy();
                    this.chromeCustomTabsActivity.close();
                    ChromeSafariBrowserManager chromeSafariBrowserManager = this.chromeCustomTabsActivity.manager;
                    if (chromeSafariBrowserManager != null && (inAppWebViewFlutterPlugin = chromeSafariBrowserManager.plugin) != null && (activity = inAppWebViewFlutterPlugin.activity) != null) {
                        Intent intent = new Intent(activity, activity.getClass());
                        intent.addFlags(C.BUFFER_FLAG_NOT_DEPENDED_ON);
                        intent.addFlags(C.BUFFER_FLAG_LAST_SAMPLE);
                        activity.startActivity(intent);
                    }
                    this.chromeCustomTabsActivity.dispose();
                    tVar.success(Boolean.TRUE);
                }
                break;
            case 5:
                ChromeCustomTabsActivity chromeCustomTabsActivity3 = this.chromeCustomTabsActivity;
                if (chromeCustomTabsActivity3 == null || chromeCustomTabsActivity3.customTabsSession == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    tVar.success(Boolean.valueOf(this.chromeCustomTabsActivity.customTabsSession.validateRelationship(((Integer) qVar.argument("relation")).intValue(), Uri.parse((String) qVar.argument("origin")), null)));
                }
                break;
            case 6:
                ChromeCustomTabsActivity chromeCustomTabsActivity4 = this.chromeCustomTabsActivity;
                if (chromeCustomTabsActivity4 == null || chromeCustomTabsActivity4.customTabsSession == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    String str3 = (String) qVar.argument("sourceOrigin");
                    String str4 = (String) qVar.argument("targetOrigin");
                    tVar.success(Boolean.valueOf(this.chromeCustomTabsActivity.customTabsSession.requestPostMessageChannel(Uri.parse(str3), str4 != null ? Uri.parse(str4) : null, new Bundle())));
                }
                break;
            case 7:
                ChromeCustomTabsActivity chromeCustomTabsActivity5 = this.chromeCustomTabsActivity;
                if (chromeCustomTabsActivity5 == null || chromeCustomTabsActivity5.customTabsSession == null) {
                    tVar.success(-3);
                } else {
                    tVar.success(Integer.valueOf(this.chromeCustomTabsActivity.customTabsSession.postMessage((String) qVar.argument(PglCryptUtils.KEY_MESSAGE), new Bundle())));
                }
                break;
            case 8:
                if (this.chromeCustomTabsActivity == null) {
                    tVar.success(Boolean.FALSE);
                } else {
                    tVar.success(Boolean.valueOf(this.chromeCustomTabsActivity.mayLaunchUrl((String) qVar.argument(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL), (List) qVar.argument("otherLikelyURLs"))));
                }
                break;
            default:
                tVar.notImplemented();
                break;
        }
    }

    public void onNavigationEvent(int i10) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("navigationEvent", Integer.valueOf(i10));
        channel.invokeMethod("onNavigationEvent", map);
    }

    public void onOpened() {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onOpened", new HashMap());
    }

    public void onPostMessage(@NonNull String str) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put(PglCryptUtils.KEY_MESSAGE, str);
        channel.invokeMethod("onPostMessage", map);
    }

    public void onRelationshipValidationResult(int i10, @NonNull Uri uri, boolean z10) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("relation", Integer.valueOf(i10));
        map.put("requestedOrigin", uri.toString());
        map.put("result", Boolean.valueOf(z10));
        channel.invokeMethod("onRelationshipValidationResult", map);
    }

    public void onSecondaryItemActionPerform(String str, String str2) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onSecondaryItemActionPerform", e.u("name", str, IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str2));
    }

    public void onServiceConnected() {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("onServiceConnected", new HashMap());
    }

    public void onSessionEnded(boolean z10) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("didUserInteract", Boolean.valueOf(z10));
        channel.invokeMethod("onSessionEnded", map);
    }

    public void onVerticalScrollEvent(boolean z10) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        HashMap map = new HashMap();
        map.put("isDirectionUp", Boolean.valueOf(z10));
        channel.invokeMethod("onVerticalScrollEvent", map);
    }
}
