Warkop v5.73.0版本的 MD5 值为:a4330ec2d6f5e146f59fc7622f3cdb45

以下内容为反编译后的 HtmlNormalizer.java 源代码,内容仅作参考


package com.exponea.sdk.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Base64;
import com.exponea.sdk.repository.BitmapCache;
import com.exponea.sdk.repository.FontCacheImpl;
import com.exponea.sdk.repository.InAppContentBlockBitmapCacheImpl;
import com.exponea.sdk.repository.SimpleFileCache;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.o0;
import kotlin.text.MatchGroup;
import kotlin.text.Regex;
import kotlin.text.h;
import kotlin.text.k;
import kotlin.text.o;
import kotlin.text.v;
import kotlin.text.w;
import no.i;
import org.jetbrains.annotations.NotNull;
import p029do.c0;
import p029do.c1;
import p029do.p;
import p029do.t;
import ps.d;
import sinet.startup.inDriver.core.data.data.ReasonData;
import wt.f;
import wt.j;

@Metadata(d1 = {"\u0000p\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0006\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u001e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\t\u0018\u0000 =2\u00020\u0001:\u0006>=?@ABB!\b\u0010\u0012\u0006\u00100\u001a\u00020/\u0012\u0006\u00103\u001a\u000202\u0012\u0006\u00105\u001a\u00020\u0004¢\u0006\u0004\b8\u00109B\u0019\b\u0016\u0012\u0006\u0010;\u001a\u00020:\u0012\u0006\u00105\u001a\u00020\u0004¢\u0006\u0004\b8\u0010<J\b\u0010\u0003\u001a\u00020\u0002H\u0002J\u0010\u0010\u0006\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0002J\u001c\u0010\t\u001a\u00020\u00022\u0006\u0010\u0007\u001a\u00020\u00042\n\b\u0002\u0010\b\u001a\u0004\u0018\u00010\u0004H\u0002J\b\u0010\n\u001a\u00020\u0004H\u0002J\u000e\u0010\r\u001a\b\u0012\u0004\u0012\u00020\f0\u000bH\u0002J\u0016\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\f0\u000b2\u0006\u0010\u000f\u001a\u00020\u000eH\u0002J\u0016\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\f0\u000b2\u0006\u0010\u000f\u001a\u00020\u000eH\u0002J\u0012\u0010\u0014\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0013\u001a\u00020\u0012H\u0002J\b\u0010\u0015\u001a\u00020\u0002H\u0002J\b\u0010\u0016\u001a\u00020\u0002H\u0002J\u0010\u0010\u0018\u001a\u00020\u00042\u0006\u0010\u0017\u001a\u00020\u0004H\u0002J\u0016\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\u001a0\u000b2\u0006\u0010\u0019\u001a\u00020\u0004H\u0002J\b\u0010\u001c\u001a\u00020\u0002H\u0002J\b\u0010\u001d\u001a\u00020\u0002H\u0002J\u0010\u0010\u001f\u001a\u00020\u00042\u0006\u0010\u001e\u001a\u00020\u0004H\u0002J\u0010\u0010!\u001a\u00020\u00042\u0006\u0010 \u001a\u00020\u0004H\u0002J\u0010\u0010$\u001a\u00020#2\u0006\u0010\"\u001a\u00020\u0004H\u0002J\u0012\u0010&\u001a\u0004\u0018\u00010%2\u0006\u0010\"\u001a\u00020\u0004H\u0002J\u0010\u0010(\u001a\u00020\u00122\u0006\u0010'\u001a\u00020\u0004H\u0002J\u0012\u0010,\u001a\u00020+2\b\b\u0002\u0010*\u001a\u00020)H\u0007J\f\u0010.\u001a\b\u0012\u0004\u0012\u00020\u00040-R\u0014\u00100\u001a\u00020/8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b0\u00101R\u0014\u00103\u001a\u0002028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b3\u00104R\u0014\u00105\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b5\u00106R\u0016\u0010\u000f\u001a\u0004\u0018\u00010\u000e8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u000f\u00107¨\u0006C"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer;", "", "Lco/g0;", "cleanHtml", "", "selector", "removeElements", "attribute", "skipTag", "removeAttributes", "exportHtml", "", "Lcom/exponea/sdk/util/HtmlNormalizer$ActionInfo;", "ensureActionButtons", "Lwt/f;", "document", "collectAnchorLinkButtons", "collectDataLinkButtons", "", "ensureCloseButton", "detectCloseButton", "makeResourcesToBeOffline", "makeStyleAttributesToBeOffline", "styleSource", "downloadOnlineResources", "cssStyle", "Lcom/exponea/sdk/util/HtmlNormalizer$CssOnlineUrl;", "collectOnlineUrlStatements", "makeStylesheetsToBeOffline", "makeImageTagsToBeOffline", "imageSource", "asBase64Image", "fontSource", "asBase64Font", "url", "Ljava/io/File;", "getFileFromUrl", "Landroid/graphics/Bitmap;", "getImageFromUrl", "uri", "isBase64Uri", "Lcom/exponea/sdk/util/HtmlNormalizer$HtmlNormalizerConfig;", "config", "Lcom/exponea/sdk/util/HtmlNormalizer$NormalizedResult;", "normalize", "", "collectImages", "Lcom/exponea/sdk/repository/BitmapCache;", "imageCache", "Lcom/exponea/sdk/repository/BitmapCache;", "Lcom/exponea/sdk/repository/SimpleFileCache;", "fontCache", "Lcom/exponea/sdk/repository/SimpleFileCache;", "originalHtml", "Ljava/lang/String;", "Lwt/f;", "<init>", "(Lcom/exponea/sdk/repository/BitmapCache;Lcom/exponea/sdk/repository/SimpleFileCache;Ljava/lang/String;)V", "Landroid/content/Context;", "context", "(Landroid/content/Context;Ljava/lang/String;)V", "Companion", "ActionInfo", "CssOnlineUrl", "DefaultConfig", "HtmlNormalizerConfig", "NormalizedResult", "sdk_release"}, k = 1, mv = {1, 7, 1})
public final class HtmlNormalizer {

    @NotNull
    private static final String ANCHOR_BUTTON_SELECTOR = "a[href]";

    @NotNull
    private static final String[] ANCHOR_LINK_ATTRIBUTES;

    @NotNull
    private static final String ANCHOR_TAG_SELECTOR = "a";

    @NotNull
    private static final String CLOSE_ACTION_COMMAND = "close_action";

    @NotNull
    private static final String CLOSE_BUTTON_ATTR_DEF = "data-actiontype='close'";

    @NotNull
    private static final String CLOSE_BUTTON_SELECTOR = "[data-actiontype='close']";

    @NotNull
    public static final Companion INSTANCE = new Companion(null);

    @NotNull
    private static final String DATALINK_BUTTON_ATTR = "data-link";

    @NotNull
    private static final String DATALINK_BUTTON_SELECTOR = "[data-link]";

    @NotNull
    private static final String FONT_MIMETYPE = "application/font";

    @NotNull
    private static final String HREF_ATTR = "href";

    @NotNull
    private static final String IFRAME_TAG_SELECTOR = "iframe";

    @NotNull
    private static final String IMAGE_MIMETYPE = "image/png";

    @NotNull
    private static final String[] INLINE_SCRIPT_ATTRIBUTES;

    @NotNull
    private static final String LINK_TAG_SELECTOR = "link";

    @NotNull
    private static final String META_TAG_SELECTOR = "meta:not([name='viewport'])";

    @NotNull
    private static final String SCRIPT_TAG_SELECTOR = "script";

    @NotNull
    private static final String[] SUPPORTED_CSS_URL_PROPERTIES;

    @NotNull
    private static final String TITLE_TAG_SELECTOR = "title";

    @NotNull
    private static final Regex cssAttributeRegexp;

    @NotNull
    private static final String cssDelimiterFormat = "[\\s]*:[\\s]*";

    @NotNull
    private static final Regex cssImportUrlRegexp;

    @NotNull
    private static final String cssKeyFormat = "-?[_a-zA-Z]+[_a-zA-Z0-9-]*";

    @NotNull
    private static final Regex cssUrlRegexp;

    @NotNull
    private static final String cssValueFormat = "[^;\\n]+";

    @NotNull
    private static final String keyGroupName = "attrKey";

    @NotNull
    private static final Set<k> regExpOptions;

    @NotNull
    private static final String valueGroupName = "attrVal";
    private final f document;

    @NotNull
    private final SimpleFileCache fontCache;

    @NotNull
    private final BitmapCache imageCache;

    @NotNull
    private final String originalHtml;

    @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0006\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005R\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\u0007¨\u0006\t"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$ActionInfo;", "", "buttonText", "", "actionUrl", "(Ljava/lang/String;Ljava/lang/String;)V", "getActionUrl", "()Ljava/lang/String;", "getButtonText", "sdk_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static final class ActionInfo {

        @NotNull
        private final String actionUrl;

        @NotNull
        private final String buttonText;

        public ActionInfo(@NotNull String str, @NotNull String str2) {
            this.buttonText = str;
            this.actionUrl = str2;
        }

        @NotNull
        public final String getActionUrl() {
            return this.actionUrl;
        }

        @NotNull
        public final String getButtonText() {
            return this.buttonText;
        }
    }

    @Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u0011\n\u0002\u0010\u000e\n\u0002\b\u0017\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\"\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0086\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b)\u0010*R \u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00030\u00028\u0000X\u0080\u0004¢\u0006\f\n\u0004\b\u0004\u0010\u0005\u001a\u0004\b\u0006\u0010\u0007R \u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00030\u00028\u0000X\u0080\u0004¢\u0006\f\n\u0004\b\b\u0010\u0005\u001a\u0004\b\t\u0010\u0007R\u0014\u0010\n\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\n\u0010\u000bR\u001a\u0010\f\u001a\b\u0012\u0004\u0012\u00020\u00030\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\f\u0010\u0005R\u0014\u0010\r\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\r\u0010\u000bR\u0014\u0010\u000e\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u000e\u0010\u000bR\u0014\u0010\u000f\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u000f\u0010\u000bR\u0014\u0010\u0010\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0010\u0010\u000bR\u0014\u0010\u0011\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0011\u0010\u000bR\u0014\u0010\u0012\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0012\u0010\u000bR\u0014\u0010\u0013\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0013\u0010\u000bR\u0014\u0010\u0014\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0014\u0010\u000bR\u0014\u0010\u0015\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0015\u0010\u000bR\u0014\u0010\u0016\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0016\u0010\u000bR\u0014\u0010\u0017\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0017\u0010\u000bR\u0014\u0010\u0018\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0018\u0010\u000bR\u0014\u0010\u0019\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0019\u0010\u000bR\u0014\u0010\u001a\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u001a\u0010\u000bR\u0014\u0010\u001c\u001a\u00020\u001b8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001c\u0010\u001dR\u0014\u0010\u001e\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u001e\u0010\u000bR\u0014\u0010\u001f\u001a\u00020\u001b8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001f\u0010\u001dR\u0014\u0010 \u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b \u0010\u000bR\u0014\u0010!\u001a\u00020\u001b8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b!\u0010\u001dR\u0014\u0010\"\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b\"\u0010\u000bR\u0014\u0010#\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b#\u0010\u000bR\u001a\u0010&\u001a\b\u0012\u0004\u0012\u00020%0$8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b&\u0010'R\u0014\u0010(\u001a\u00020\u00038\u0002X\u0082T¢\u0006\u0006\n\u0004\b(\u0010\u000b¨\u0006+"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$Companion;", "", "", "", "INLINE_SCRIPT_ATTRIBUTES", "[Ljava/lang/String;", "getINLINE_SCRIPT_ATTRIBUTES$sdk_release", "()[Ljava/lang/String;", "SUPPORTED_CSS_URL_PROPERTIES", "getSUPPORTED_CSS_URL_PROPERTIES$sdk_release", "ANCHOR_BUTTON_SELECTOR", "Ljava/lang/String;", "ANCHOR_LINK_ATTRIBUTES", "ANCHOR_TAG_SELECTOR", "CLOSE_ACTION_COMMAND", "CLOSE_BUTTON_ATTR_DEF", "CLOSE_BUTTON_SELECTOR", "DATALINK_BUTTON_ATTR", "DATALINK_BUTTON_SELECTOR", "FONT_MIMETYPE", "HREF_ATTR", "IFRAME_TAG_SELECTOR", "IMAGE_MIMETYPE", "LINK_TAG_SELECTOR", "META_TAG_SELECTOR", "SCRIPT_TAG_SELECTOR", "TITLE_TAG_SELECTOR", "Lkotlin/text/Regex;", "cssAttributeRegexp", "Lkotlin/text/Regex;", "cssDelimiterFormat", "cssImportUrlRegexp", "cssKeyFormat", "cssUrlRegexp", "cssValueFormat", "keyGroupName", "", "Lkotlin/text/k;", "regExpOptions", "Ljava/util/Set;", "valueGroupName", "<init>", "()V", "sdk_release"}, k = 1, mv = {1, 7, 1})
    public static final class Companion {
        private Companion() {
        }

        public Companion(kotlin.jvm.internal.k kVar) {
            this();
        }

        @NotNull
        public final String[] getINLINE_SCRIPT_ATTRIBUTES$sdk_release() {
            return HtmlNormalizer.INLINE_SCRIPT_ATTRIBUTES;
        }

        @NotNull
        public final String[] getSUPPORTED_CSS_URL_PROPERTIES$sdk_release() {
            return HtmlNormalizer.SUPPORTED_CSS_URL_PROPERTIES;
        }
    }

    @Metadata(d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\t\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\b\u0082\b\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005J\t\u0010\t\u001a\u00020\u0003HÆ\u0003J\t\u0010\n\u001a\u00020\u0003HÆ\u0003J\u001d\u0010\u000b\u001a\u00020\u00002\b\b\u0002\u0010\u0002\u001a\u00020\u00032\b\b\u0002\u0010\u0004\u001a\u00020\u0003HÆ\u0001J\u0013\u0010\f\u001a\u00020\r2\b\u0010\u000e\u001a\u0004\u0018\u00010\u0001HÖ\u0003J\t\u0010\u000f\u001a\u00020\u0010HÖ\u0001J\t\u0010\u0011\u001a\u00020\u0003HÖ\u0001R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007R\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\u0007¨\u0006\u0012"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$CssOnlineUrl;", "", "mimeType", "", "url", "(Ljava/lang/String;Ljava/lang/String;)V", "getMimeType", "()Ljava/lang/String;", "getUrl", "component1", "component2", "copy", "equals", "", ReasonData.TYPE_OTHER, "hashCode", "", "toString", "sdk_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static final class CssOnlineUrl {

        @NotNull
        private final String mimeType;

        @NotNull
        private final String url;

        public CssOnlineUrl(@NotNull String str, @NotNull String str2) {
            this.mimeType = str;
            this.url = str2;
        }

        public static CssOnlineUrl copy$default(CssOnlineUrl cssOnlineUrl, String str, String str2, int i15, Object obj) {
            if ((i15 & 1) != 0) {
                str = cssOnlineUrl.mimeType;
            }
            if ((i15 & 2) != 0) {
                str2 = cssOnlineUrl.url;
            }
            return cssOnlineUrl.copy(str, str2);
        }

        @NotNull
        public final String getMimeType() {
            return this.mimeType;
        }

        @NotNull
        public final String getUrl() {
            return this.url;
        }

        @NotNull
        public final CssOnlineUrl copy(@NotNull String mimeType, @NotNull String url) {
            return new CssOnlineUrl(mimeType, url);
        }

        public boolean equals(Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof CssOnlineUrl)) {
                return false;
            }
            CssOnlineUrl cssOnlineUrl = (CssOnlineUrl) other;
            return Intrinsics.g(this.mimeType, cssOnlineUrl.mimeType) && Intrinsics.g(this.url, cssOnlineUrl.url);
        }

        @NotNull
        public final String getMimeType() {
            return this.mimeType;
        }

        @NotNull
        public final String getUrl() {
            return this.url;
        }

        public int hashCode() {
            return (this.mimeType.hashCode() * 31) + this.url.hashCode();
        }

        @NotNull
        public String toString() {
            return "CssOnlineUrl(mimeType=" + this.mimeType + ", url=" + this.url + ')';
        }
    }

    @Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0002\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002¨\u0006\u0003"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$DefaultConfig;", "Lcom/exponea/sdk/util/HtmlNormalizer$HtmlNormalizerConfig;", "()V", "sdk_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static final class DefaultConfig extends HtmlNormalizerConfig {
        public DefaultConfig() {
            super(true, true);
        }
    }

    @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0006\b\u0016\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005R\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\u0007¨\u0006\t"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$HtmlNormalizerConfig;", "", "makeResourcesOffline", "", "ensureCloseButton", "(ZZ)V", "getEnsureCloseButton", "()Z", "getMakeResourcesOffline", "sdk_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static class HtmlNormalizerConfig {
        private final boolean ensureCloseButton;
        private final boolean makeResourcesOffline;

        public HtmlNormalizerConfig(boolean z15, boolean z16) {
            this.makeResourcesOffline = z15;
            this.ensureCloseButton = z16;
        }

        public final boolean getEnsureCloseButton() {
            return this.ensureCloseButton;
        }

        public final boolean getMakeResourcesOffline() {
            return this.makeResourcesOffline;
        }
    }

    @Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u000e\n\u0002\b\b\n\u0002\u0010\u000b\n\u0002\b\t\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0019\u001a\u0004\u0018\u00010\u00052\u0006\u0010\u001a\u001a\u00020\u000bJ\u0010\u0010\u001b\u001a\u00020\u00142\b\u0010\u001a\u001a\u0004\u0018\u00010\u000bJ\u0010\u0010\u001c\u001a\u00020\u00142\b\u0010\u001a\u001a\u0004\u0018\u00010\u000bR\"\u0010\u0003\u001a\n\u0012\u0004\u0012\u00020\u0005\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0006\u0010\u0007\"\u0004\b\b\u0010\tR\u001c\u0010\n\u001a\u0004\u0018\u00010\u000bX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\f\u0010\r\"\u0004\b\u000e\u0010\u000fR\u001c\u0010\u0010\u001a\u0004\u0018\u00010\u000bX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0011\u0010\r\"\u0004\b\u0012\u0010\u000fR\u001a\u0010\u0013\u001a\u00020\u0014X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0015\u0010\u0016\"\u0004\b\u0017\u0010\u0018¨\u0006\u001d"}, d2 = {"Lcom/exponea/sdk/util/HtmlNormalizer$NormalizedResult;", "", "()V", "actions", "", "Lcom/exponea/sdk/util/HtmlNormalizer$ActionInfo;", "getActions", "()Ljava/util/List;", "setActions", "(Ljava/util/List;)V", "closeActionUrl", "", "getCloseActionUrl", "()Ljava/lang/String;", "setCloseActionUrl", "(Ljava/lang/String;)V", "html", "getHtml", "setHtml", "valid", "", "getValid", "()Z", "setValid", "(Z)V", "findActionByUrl", "url", "isActionUrl", "isCloseAction", "sdk_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
    public static final class NormalizedResult {
        private List<ActionInfo> actions;
        private String closeActionUrl;
        private String html;
        private boolean valid = true;

        public final ActionInfo findActionByUrl(@NotNull String url) {
            List<ActionInfo> list = this.actions;
            Object obj = null;
            if (list == null) {
                return null;
            }
            Iterator<T> it = list.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                Object next = it.next();
                if (URLUtils.INSTANCE.areEqualAsURLs(((ActionInfo) next).getActionUrl(), url)) {
                    obj = next;
                    break;
                }
            }
            return (ActionInfo) obj;
        }

        public final List<ActionInfo> getActions() {
            return this.actions;
        }

        public final String getCloseActionUrl() {
            return this.closeActionUrl;
        }

        public final String getHtml() {
            return this.html;
        }

        public final boolean getValid() {
            return this.valid;
        }

        public final boolean isActionUrl(String url) {
            if (url != null && !isCloseAction(url) && findActionByUrl(url) != null) {
                return true;
            }
            return false;
        }

        public final boolean isCloseAction(String url) {
            if (url != null) {
                return url.equals(this.closeActionUrl);
            }
            return false;
        }

        public final void setActions(List<ActionInfo> list) {
            this.actions = list;
        }

        public final void setCloseActionUrl(String str) {
            this.closeActionUrl = str;
        }

        public final void setHtml(String str) {
            this.html = str;
        }

        public final void setValid(boolean z15) {
            this.valid = z15;
        }
    }

    static {
        Set<k> k15;
        k15 = c1.k(k.f85996e, k.f86001j);
        regExpOptions = k15;
        cssUrlRegexp = new Regex("url\\((.+?)\\)", k15);
        cssImportUrlRegexp = new Regex("@import[\\s]+url\\(.+?\\)", k15);
        cssAttributeRegexp = new Regex("(?<attrKey>-?[_a-zA-Z]+[_a-zA-Z0-9-]*)[\\s]*:[\\s]*(?<attrVal>[^;\\n]+)", k15);
        INLINE_SCRIPT_ATTRIBUTES = new String[]{"onafterprint", "onbeforeprint", "onbeforeunload", "onerror", "onhashchange", "onload", "onmessage", "onoffline", "ononline", "onpagehide", "onpageshow", "onpopstate", "onresize", "onstorage", "onunload", "onblur", "onchange", "oncontextmenu", "onfocus", "oninput", "oninvalid", "onreset", "onsearch", "onselect", "onsubmit", "onkeydown", "onkeypress", "onkeyup", "onclick", "ondblclick", "onmousedown", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onmousewheel", "onwheel", "ondrag", "ondragend", "ondragenter", "ondragleave", "ondragover", "ondragstart", "ondrop", "onscroll", "oncopy", "oncut", "onpaste", "onabort", "oncanplay", "oncanplaythrough", "oncuechange", "ondurationchange", "onemptied", "onended", "onerror", "onloadeddata", "onloadedmetadata", "onloadstart", "onpause", "onplay", "onplaying", "onprogress", "onratechange", "onseeked", "onseeking", "onstalled", "onsuspend", "ontimeupdate", "onvolumechange", "onwaiting", "ontoggle"};
        ANCHOR_LINK_ATTRIBUTES = new String[]{"download", "ping", "target"};
        SUPPORTED_CSS_URL_PROPERTIES = new String[]{"background", "background-image", "border-image", "border-image-source", "content", "cursor", "filter", "list-style", "list-style-image", "mask", "mask-image", "offset-path", "src"};
    }

    public HtmlNormalizer(@NotNull BitmapCache bitmapCache, @NotNull SimpleFileCache simpleFileCache, @NotNull String str) {
        f fVar;
        this.imageCache = bitmapCache;
        this.fontCache = simpleFileCache;
        this.originalHtml = str;
        try {
            fVar = tt.a.a(str);
        } catch (Exception unused) {
            Logger.INSTANCE.i(this, "[HTML] Unable to parse original HTML source code " + str);
            fVar = null;
        }
        this.document = fVar;
    }

    private final String asBase64Font(String fontSource) {
        byte[] f15;
        if (!isBase64Uri(fontSource)) {
            f15 = i.f(getFileFromUrl(fontSource));
            return "data:application/font;charset=utf-8;base64," + Base64.encodeToString(f15, 2);
        }
        return fontSource;
    }

    private final String asBase64Image(String imageSource) {
        if (isBase64Uri(imageSource)) {
            return imageSource;
        }
        Bitmap imageFromUrl = getImageFromUrl(imageSource);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        imageFromUrl.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        String encodeToString = Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2);
        d.m(byteArrayOutputStream);
        return "data:image/png;base64," + encodeToString;
    }

    private final void cleanHtml() {
        removeAttributes(HREF_ATTR, ANCHOR_TAG_SELECTOR);
        for (String str : ANCHOR_LINK_ATTRIBUTES) {
            removeAttributes$default(this, str, null, 2, null);
        }
        for (String str2 : INLINE_SCRIPT_ATTRIBUTES) {
            removeAttributes$default(this, str2, null, 2, null);
        }
        removeElements(META_TAG_SELECTOR);
        removeElements(SCRIPT_TAG_SELECTOR);
        removeElements("title");
        removeElements("link");
        removeElements(IFRAME_TAG_SELECTOR);
    }

    private final List<ActionInfo> collectAnchorLinkButtons(f document) {
        boolean I;
        ArrayList arrayList = new ArrayList();
        Iterator<j> it = document.b1(ANCHOR_BUTTON_SELECTOR).iterator();
        while (it.hasNext()) {
            j next = it.next();
            String e15 = next.e(HREF_ATTR);
            if (e15 != null) {
                I = v.I(e15);
                if (!I) {
                    arrayList.add(new ActionInfo(next.g1(), e15));
                }
            }
            Logger.INSTANCE.e(this, "[HTML] Action button found but with empty action");
        }
        return arrayList;
    }

    private final List<ActionInfo> collectDataLinkButtons(f document) {
        boolean I;
        ArrayList arrayList = new ArrayList();
        Iterator<j> it = document.b1(DATALINK_BUTTON_SELECTOR).iterator();
        while (it.hasNext()) {
            j next = it.next();
            String e15 = next.e(DATALINK_BUTTON_ATTR);
            if (e15 != null) {
                I = v.I(e15);
                if (!I) {
                    if (next.K0(ANCHOR_TAG_SELECTOR)) {
                        next.q0(HREF_ATTR, e15);
                    } else if (!next.z() || !next.M().K0(ANCHOR_TAG_SELECTOR)) {
                        Logger.INSTANCE.i(this, "[HTML] Wrapping Action button with a-href");
                        String str = "action-button-href-" + UUID.randomUUID();
                        document.p1().k0("<style>." + str + " {    text-decoration: none;}</style>");
                        next.m1("<a href='" + e15 + "' class='" + str + "'></a>");
                    }
                    arrayList.add(new ActionInfo(next.g1(), e15));
                }
            }
            Logger.INSTANCE.e(this, "[HTML] Action button found but with empty action");
        }
        return arrayList;
    }

    private final List<CssOnlineUrl> collectOnlineUrlStatements(String cssStyle) {
        String str;
        boolean I;
        String str2;
        String str3;
        Object z05;
        String t15;
        Object z06;
        String t16;
        ArrayList arrayList = new ArrayList();
        Iterator it = Regex.e(cssImportUrlRegexp, cssStyle, 0, 2, null).iterator();
        while (it.hasNext()) {
            Iterator it4 = Regex.e(cssUrlRegexp, ((h) it.next()).getValue(), 0, 2, null).iterator();
            while (it4.hasNext()) {
                z06 = c0.z0(((h) it4.next()).c());
                t16 = w.t1((String) z06, '\'', '\"');
                arrayList.add(new CssOnlineUrl(FONT_MIMETYPE, t16));
            }
        }
        for (h hVar : Regex.e(cssAttributeRegexp, cssStyle, 0, 2, null)) {
            MatchGroup a15 = ir.a.a(hVar.b(), keyGroupName);
            if (a15 != null) {
                str = a15.getValue();
            } else {
                str = null;
            }
            if (str != null) {
                I = p.I(SUPPORTED_CSS_URL_PROPERTIES, str.toLowerCase(Locale.ROOT));
                if (I) {
                    MatchGroup a16 = ir.a.a(hVar.b(), valueGroupName);
                    if (a16 != null) {
                        str2 = a16.getValue();
                    } else {
                        str2 = null;
                    }
                    if (str2 != null) {
                        for (h hVar2 : Regex.e(cssUrlRegexp, str2, 0, 2, null)) {
                            if (Intrinsics.g(str, "src")) {
                                str3 = FONT_MIMETYPE;
                            } else {
                                str3 = IMAGE_MIMETYPE;
                            }
                            z05 = c0.z0(hVar2.c());
                            t15 = w.t1((String) z05, '\'', '\"');
                            arrayList.add(new CssOnlineUrl(str3, t15));
                        }
                    }
                }
            }
        }
        return arrayList;
    }

    private final String detectCloseButton(boolean ensureCloseButton) {
        boolean F;
        String g15;
        yt.b b15 = this.document.b1(CLOSE_BUTTON_SELECTOR);
        if (b15.isEmpty() && ensureCloseButton) {
            Logger.INSTANCE.i(this, "[HTML] Adding default close-button");
            String str = "close-button-" + UUID.randomUUID();
            this.document.n1().k0("<div data-actiontype='close' class='" + str + "'><div>");
            j p15 = this.document.p1();
            g15 = o.g("\n                <style>\n                    ." + str + " {\n                      display: inline-block;\n                      position: absolute;\n                      width: max(min(5vw, 5vh), 16px);\n                      height: max(min(5vw, 5vh), 16px);\n                      top: 10px;\n                      right: 10px;\n                      cursor: pointer;\n                      border-radius: 50%;\n                      background-color: rgba(250, 250, 250, 0.6);\n                     }\n                    ." + str + ":before {\n                      content: '×';\n                      position: absolute;\n                      display: flex;\n                      justify-content: center;\n                      width: max(min(5vw, 5vh), 16px);\n                      height: max(min(5vw, 5vh), 16px);\n                      color: rgb(0, 0, 0);\n                      font-size: max(min(5vw, 5vh), 16px);\n                      line-height: max(min(5vw, 5vh), 16px);\n                    }\n                </style>\n            ");
            p15.k0(g15);
            b15 = this.document.b1(CLOSE_BUTTON_SELECTOR);
        }
        if (b15.isEmpty()) {
            if (!ensureCloseButton) {
                return null;
            }
            throw new IllegalStateException("Action close cannot be ensured");
        }
        String str2 = "close-button-href-" + UUID.randomUUID();
        j b16 = b15.b();
        if (b16.z() && b16.M().K0(ANCHOR_TAG_SELECTOR)) {
            F = v.F(b16.M().e(HREF_ATTR), "https://exponea.com/close_action", true);
            if (!F) {
                Logger.INSTANCE.i(this, "[HTML] Fixing parent a-href link to close action");
                b16.M().q0(HREF_ATTR, "https://exponea.com/close_action");
                b16.M().i0(str2);
            }
        } else {
            Logger.INSTANCE.i(this, "[HTML] Wrapping Close button with a-href");
            b16.m1("<a href='https://exponea.com/close_action' class='" + str2 + "'></a>");
        }
        return "https://exponea.com/close_action";
    }

    private final String downloadOnlineResources(String styleSource) {
        String str;
        boolean I;
        String str2 = styleSource;
        for (CssOnlineUrl cssOnlineUrl : collectOnlineUrlStatements(styleSource)) {
            String mimeType = cssOnlineUrl.getMimeType();
            if (Intrinsics.g(mimeType, FONT_MIMETYPE)) {
                str = asBase64Font(cssOnlineUrl.getUrl());
            } else if (Intrinsics.g(mimeType, IMAGE_MIMETYPE)) {
                str = asBase64Image(cssOnlineUrl.getUrl());
            } else {
                Logger.INSTANCE.e(this, "Unsupported mime type " + cssOnlineUrl.getMimeType());
                str = null;
            }
            String str3 = str;
            if (str3 != null) {
                I = v.I(str3);
                if (!I) {
                    str2 = v.P(str2, cssOnlineUrl.getUrl(), str3, false, 4, null);
                }
            }
            Logger.INSTANCE.e(this, "Unable to make offline resource " + cssOnlineUrl.getUrl());
        }
        return str2;
    }

    private final List<ActionInfo> ensureActionButtons() {
        List<ActionInfo> h15;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        f fVar = this.document;
        if (fVar != null) {
            for (ActionInfo actionInfo : collectDataLinkButtons(fVar)) {
                linkedHashMap.put(actionInfo.getActionUrl(), actionInfo);
            }
            for (ActionInfo actionInfo2 : collectAnchorLinkButtons(fVar)) {
                linkedHashMap.put(actionInfo2.getActionUrl(), actionInfo2);
            }
        }
        h15 = c0.h1(linkedHashMap.values());
        return h15;
    }

    private final String exportHtml() {
        return this.document.G0();
    }

    private final File getFileFromUrl(String url) {
        List<String> e15;
        o0 o0Var = new o0();
        ?? file = this.fontCache.getFile(url);
        o0Var.f85779c = file;
        if (!file.exists()) {
            CountDownLatch countDownLatch = new CountDownLatch(1);
            SimpleFileCache simpleFileCache = this.fontCache;
            e15 = t.e(url);
            simpleFileCache.preload(e15, new HtmlNormalizer$getFileFromUrl$1(o0Var, this, url, countDownLatch));
            countDownLatch.await(10L, TimeUnit.SECONDS);
        }
        if (((File) o0Var.f85779c).exists()) {
            return (File) o0Var.f85779c;
        }
        Logger.INSTANCE.e(this, "Unable to load file " + url + " for HTML");
        throw new IllegalStateException("File is not preloaded");
    }

    private final Bitmap getImageFromUrl(String url) {
        List<String> e15;
        o0 o0Var = new o0();
        ?? r15 = this.imageCache.get(url);
        o0Var.f85779c = r15;
        if (r15 == 0) {
            CountDownLatch countDownLatch = new CountDownLatch(1);
            BitmapCache bitmapCache = this.imageCache;
            e15 = t.e(url);
            bitmapCache.preload(e15, new HtmlNormalizer$getImageFromUrl$1(o0Var, this, url, countDownLatch));
            countDownLatch.await(10L, TimeUnit.SECONDS);
        }
        T t15 = o0Var.f85779c;
        if (t15 != 0) {
            return (Bitmap) t15;
        }
        Logger.INSTANCE.e(this, "Unable to load image " + url + " for HTML");
        throw new IllegalStateException("Image is not preloaded");
    }

    private final boolean isBase64Uri(String uri) {
        boolean T;
        boolean Y;
        T = v.T(uri, "data:image/", true);
        if (T) {
            Y = w.Y(uri, "base64,", true);
            if (Y) {
                return true;
            }
        }
        return false;
    }

    private final void makeImageTagsToBeOffline() {
        Iterator<j> it = this.document.b1("img").iterator();
        while (it.hasNext()) {
            j next = it.next();
            String e15 = next.e("src");
            if (e15 != null && e15.length() != 0) {
                try {
                    next.q0("src", asBase64Image(e15));
                } catch (Exception e16) {
                    Logger.INSTANCE.w(this, "[HTML] Image url " + e15 + " has not been preloaded");
                    throw e16;
                }
            }
        }
    }

    private final void makeResourcesToBeOffline() {
        makeImageTagsToBeOffline();
        makeStylesheetsToBeOffline();
        makeStyleAttributesToBeOffline();
    }

    private final void makeStyleAttributesToBeOffline() {
        Iterator<j> it = this.document.b1("[style]").iterator();
        while (it.hasNext()) {
            j next = it.next();
            String e15 = next.e("style");
            if (e15 != null && e15.length() != 0) {
                next.q0("style", downloadOnlineResources(e15));
            }
        }
    }

    private final void makeStylesheetsToBeOffline() {
        Iterator<j> it = this.document.b1("style").iterator();
        while (it.hasNext()) {
            j next = it.next();
            next.h1(downloadOnlineResources(next.A0()));
        }
    }

    public static NormalizedResult normalize$default(HtmlNormalizer htmlNormalizer, HtmlNormalizerConfig htmlNormalizerConfig, int i15, Object obj) {
        if ((i15 & 1) != 0) {
            htmlNormalizerConfig = new DefaultConfig();
        }
        return htmlNormalizer.normalize(htmlNormalizerConfig);
    }

    private final void removeAttributes(String str, String str2) {
        Iterator<j> it = this.document.b1('[' + str + ']').iterator();
        while (it.hasNext()) {
            j next = it.next();
            if (str2 == null || !next.K0(str2)) {
                next.Y0(str);
            }
        }
    }

    static void removeAttributes$default(HtmlNormalizer htmlNormalizer, String str, String str2, int i15, Object obj) {
        if ((i15 & 2) != 0) {
            str2 = null;
        }
        htmlNormalizer.removeAttributes(str, str2);
    }

    private final void removeElements(String str) {
        Iterator<j> it = this.document.b1(str).iterator();
        while (it.hasNext()) {
            it.next().Q();
        }
    }

    @NotNull
    public final Collection<String> collectImages() {
        boolean I;
        int v15;
        int v16;
        if (this.document == null) {
            return Collections.emptyList();
        }
        ArrayList arrayList = new ArrayList();
        Iterator<j> it = this.document.b1("img").iterator();
        while (it.hasNext()) {
            String e15 = it.next().e("src");
            if (e15 != null && e15.length() != 0 && !isBase64Uri(e15)) {
                arrayList.add(e15);
            }
        }
        Iterator<j> it4 = this.document.b1("style").iterator();
        while (it4.hasNext()) {
            List<CssOnlineUrl> collectOnlineUrlStatements = collectOnlineUrlStatements(it4.next().A0());
            ArrayList arrayList2 = new ArrayList();
            for (Object obj : collectOnlineUrlStatements) {
                if (Intrinsics.g(((CssOnlineUrl) obj).getMimeType(), IMAGE_MIMETYPE)) {
                    arrayList2.add(obj);
                }
            }
            v16 = p029do.v.v(arrayList2, 10);
            ArrayList arrayList3 = new ArrayList(v16);
            Iterator it5 = arrayList2.iterator();
            while (it5.hasNext()) {
                arrayList3.add(((CssOnlineUrl) it5.next()).getUrl());
            }
            arrayList.addAll(arrayList3);
        }
        Iterator<j> it6 = this.document.b1("[style]").iterator();
        while (it6.hasNext()) {
            String e16 = it6.next().e("style");
            if (e16 != null) {
                I = v.I(e16);
                if (!I) {
                    List<CssOnlineUrl> collectOnlineUrlStatements2 = collectOnlineUrlStatements(e16);
                    ArrayList arrayList4 = new ArrayList();
                    for (Object obj2 : collectOnlineUrlStatements2) {
                        if (Intrinsics.g(((CssOnlineUrl) obj2).getMimeType(), IMAGE_MIMETYPE)) {
                            arrayList4.add(obj2);
                        }
                    }
                    v15 = p029do.v.v(arrayList4, 10);
                    ArrayList arrayList5 = new ArrayList(v15);
                    Iterator it7 = arrayList4.iterator();
                    while (it7.hasNext()) {
                        arrayList5.add(((CssOnlineUrl) it7.next()).getUrl());
                    }
                    arrayList.addAll(arrayList5);
                }
            }
        }
        return arrayList;
    }

    @NotNull
    public final NormalizedResult normalize(@NotNull HtmlNormalizerConfig config) {
        NormalizedResult normalizedResult = new NormalizedResult();
        if (this.document == null) {
            Logger.INSTANCE.i(this, "[HTML] Original HTML code is invalid, unable to normalize");
            normalizedResult.setValid(false);
            return normalizedResult;
        }
        try {
            cleanHtml();
            if (config.getMakeResourcesOffline()) {
                makeResourcesToBeOffline();
            }
            normalizedResult.setActions(ensureActionButtons());
            normalizedResult.setCloseActionUrl(detectCloseButton(config.getEnsureCloseButton()));
            normalizedResult.setHtml(exportHtml());
            normalizedResult.setValid(true);
        } catch (Exception e15) {
            Logger.INSTANCE.w(this, "[HTML] HTML parsing failed " + e15.getLocalizedMessage());
            normalizedResult.setValid(false);
        }
        return normalizedResult;
    }

    public HtmlNormalizer(@NotNull Context context, @NotNull String str) {
        this(new InAppContentBlockBitmapCacheImpl(context), new FontCacheImpl(context), str);
    }
}