QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.mtt.external.resourcesniffer;

import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.webkit.ValueCallback;
import com.tencent.common.data.MediaFileType;
import com.tencent.common.featuretoggle.FeatureToggle;
import com.tencent.common.manifest.EventEmiter;
import com.tencent.common.manifest.EventMessage;
import com.tencent.common.manifest.annotation.CreateMethod;
import com.tencent.common.manifest.annotation.EventReceiver;
import com.tencent.common.manifest.annotation.EventThreadMode;
import com.tencent.common.manifest.annotation.ServiceImpl;
import com.tencent.common.task.QBTask;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.FileUtilsF;
import com.tencent.common.utils.ThreadUtils;
import com.tencent.common.utils.UrlUtils;
import com.tencent.library.BuildConfig;
import com.tencent.mtt.base.skin.MttResources;
import com.tencent.mtt.base.stat.StatManager;
import com.tencent.mtt.base.webview.QBWebView;
import com.tencent.mtt.base.wup.DomainListDataManager;
import com.tencent.mtt.browser.multiwindow.facade.IMultiWindowService;
import com.tencent.mtt.browser.multiwindow.facade.MultiWindowStateListener;
import com.tencent.mtt.browser.plugin.facade.IPluginService;
import com.tencent.mtt.browser.resourcesniff.facade.IResourceSnifferService;
import com.tencent.mtt.browser.window.WindowManager;
import com.tencent.mtt.external.pagetoolbox.facade.IPageToolBoxGuideService;
import com.tencent.mtt.external.pagetoolbox.facade.PageToolBoxGuideBean;
import com.tencent.mtt.external.resourcesniffer.data.WebResourceCollector;
import com.tencent.mtt.external.resourcesniffer.data.WebResourceConfigManager;
import com.tencent.mtt.external.resourcesniffer.data.WebResourceInfo;
import com.tencent.mtt.external.resourcesniffer.data.WebResourceInjectJsHelper;
import com.tencent.mtt.external.resourcesniffer.data.WebResourcesData;
import com.tencent.mtt.external.resourcesniffer.stat.WebResourceQAReportHelper;
import com.tencent.mtt.external.resourcesniffer.stat.WebSniffStatUtil;
import com.tencent.mtt.external.resourcesniffer.ui.WebResourceBkgController;
import com.tencent.mtt.external.resourcesniffer.ui.WebResourceController;
import com.tencent.mtt.log.access.Logs;
import com.tencent.mtt.qbcontext.core.QBContext;
import com.tencent.mtt.video.export.H5VideoInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Callable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@ServiceImpl(createMethod = CreateMethod.GET, service = IResourceSnifferService.class)
public class WebResourceSnifferEngine implements Handler.Callback, MultiWindowStateListener, IResourceSnifferService {
    private static volatile WebResourceSnifferEngine e;

    protected WebResourceInjectJsHelper f59232c;

    protected WebResourceQAReportHelper f59233d;
    private boolean g;
    private boolean f = true;

    protected boolean f59231b = false;

    protected Handler f59230a = new Handler(BrowserExecutorSupplier.getLooperForRunShortTime(), this);

    public class MenuTipsShowRes {

        boolean f59251a;

        String f59252b;

        protected MenuTipsShowRes() {
        }
    }

    private WebResourceSnifferEngine() {
        ((IMultiWindowService) QBContext.getInstance().getService(IMultiWindowService.class)).addStateListener(this);
        this.f59232c = new WebResourceInjectJsHelper();
        this.f59233d = new WebResourceQAReportHelper();
        this.g = FeatureToggle.a(BuildConfig.FEATURE_TOGGLE_865914239);
    }

    private void a(String str, String str2) {
        if (b(str)) {
            final int a2 = this.f59232c.a(str, str2);
            if (this.g) {
                a();
            } else {
                this.f = true;
            }
            if (this.f) {
                if (a2 == 2 || a2 == 3) {
                    a((String) null, true, new ValueCallback<MenuTipsShowRes>() {
                        @Override
                        public void onReceiveValue(MenuTipsShowRes menuTipsShowRes) {
                            if (menuTipsShowRes != null) {
                                if (a2 == 3) {
                                    WebResourceSnifferEngine.this.f59233d.a(menuTipsShowRes.f59252b, menuTipsShowRes.f59251a);
                                } else {
                                    WebResourceSnifferEngine.this.f59233d.b(menuTipsShowRes.f59252b, menuTipsShowRes.f59251a);
                                }
                            }
                        }
                    });
                }
            }
        }
    }

    public void b() {
        if (this.g) {
            if (ThreadUtils.isMainThread()) {
                c();
            } else {
                BrowserExecutorSupplier.forMainThreadTasks().execute(new Runnable() {
                    @Override
                    public void run() {
                        WebResourceSnifferEngine.this.c();
                    }
                });
            }
        }
    }

    private void b(QBWebView qBWebView, String str) {
        if (b(str)) {
            this.f59232c.a(qBWebView, str);
        }
    }

    private boolean b(String str, String str2) {
        ArrayList<String> a2 = DomainListDataManager.a().a(449);
        ArrayList<WebResourceInfo> a3 = WebResourceCollector.a().a(str);
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || a2 == null || a3 == null) {
            return false;
        }
        HashMap hashMap = new HashMap();
        Iterator<WebResourceInfo> it = a3.iterator();
        while (it.hasNext()) {
            String str3 = it.next().e;
            if (!TextUtils.isEmpty(str3) && hashMap.get(str3) == null) {
                hashMap.put(str3, 0);
            }
        }
        return a(a2, hashMap);
    }

    public void c() {
        String v = WindowManager.a().v();
        ArrayList<WebResourceInfo> a2 = WebResourceCollector.a().a(v);
        if (TextUtils.isEmpty(v) || !UrlUtils.isWebUrl(v) || !b(v) || a2 == null) {
            this.f = true;
            return;
        }
        final PageToolBoxGuideBean pageToolBoxGuideBean = new PageToolBoxGuideBean();
        pageToolBoxGuideBean.f56136a = IPluginService.PLUGIN_RESOURCE_SNIFFER;
        pageToolBoxGuideBean.f56137b = v;
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                WebResourceSnifferEngine.this.showSniffResultList();
                WebSniffStatUtil.a("sniff1_001", pageToolBoxGuideBean.f56137b, 1);
            }
        };
        pageToolBoxGuideBean.e = runnable;
        pageToolBoxGuideBean.g = runnable;
        if (!f(v)) {
            this.f = true;
            return;
        }
        pageToolBoxGuideBean.f56138c = String.valueOf(a2.size());
        this.f = false;
        WebSniffStatUtil.a("sniff1_002", pageToolBoxGuideBean.f56137b, 1);
        EventEmiter.getDefault().emit(new EventMessage(IPageToolBoxGuideService.EVENT_TOOL_SNIFF, pageToolBoxGuideBean));
    }

    private boolean c(String str, String str2) {
        ArrayList<String> a2 = DomainListDataManager.a().a(450);
        if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2) && a2 != null) {
            Iterator<String> it = a2.iterator();
            while (it.hasNext()) {
                String next = it.next();
                if (next.startsWith("%") && next.endsWith("%")) {
                    String substring = next.substring(1, next.length() - 1);
                    if (!substring.equals("") && (str.contains(substring) || str2.contains(substring))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private void d(String str, String str2) {
        PageToolBoxGuideBean pageToolBoxGuideBean = new PageToolBoxGuideBean();
        pageToolBoxGuideBean.f56138c = str;
        pageToolBoxGuideBean.f56137b = str2;
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                WebResourceSnifferEngine.this.showSniffResultList();
            }
        };
        pageToolBoxGuideBean.e = runnable;
        pageToolBoxGuideBean.g = runnable;
        if (this.g) {
            EventEmiter.getDefault().emit(new EventMessage(IPageToolBoxGuideService.EVENT_TOOL_SNIFF, pageToolBoxGuideBean));
        }
    }

    private boolean e(String str) {
        return b(str);
    }

    private boolean f(String str) {
        String host = UrlUtils.getHost(str);
        return c(str, host) || b(str, host);
    }

    public static WebResourceSnifferEngine getInstance() {
        if (e == null) {
            synchronized (WebResourceSnifferEngine.class) {
                if (e == null) {
                    e = new WebResourceSnifferEngine();
                }
            }
        }
        return e;
    }

    public int a(String str, JSONArray jSONArray, int i) throws JSONException {
        int i2 = 1;
        if (jSONArray != null && jSONArray.length() > 0) {
            for (int i3 = 0; i3 < jSONArray.length(); i3++) {
                Object obj = jSONArray.get(i3);
                if (obj instanceof String) {
                    WebResourceInfo a2 = WebResourceUtils.a((String) obj, str, i);
                    if (a2 != null) {
                        a2.f = 2;
                        boolean a3 = WebResourceCollector.a().a(str, a2);
                        if (i2 == 3) {
                        }
                    }
                } else if (obj instanceof JSONObject) {
                    JSONObject jSONObject = (JSONObject) obj;
                    String string = jSONObject.getString("url");
                    String optString = jSONObject.optString("title");
                    WebResourceInfo a4 = WebResourceUtils.a(string, str, i);
                    if (a4 != null) {
                        a4.f = 2;
                        if (!TextUtils.isEmpty(optString)) {
                            a4.f59262b = optString;
                        }
                        boolean a5 = WebResourceCollector.a().a(str, a4);
                        if (i2 == 3) {
                        }
                    }
                }
            }
        }
        return i2;
    }

    public int a(HashMap<String, ArrayList<Object>> hashMap) {
        if (hashMap.size() <= 0) {
            return 1;
        }
        int i = 1;
        for (Map.Entry<String, ArrayList<Object>> entry : hashMap.entrySet()) {
            String key = entry.getKey();
            ArrayList<Object> value = entry.getValue();
            if (b(key) && value != null && value.size() > 0) {
                Iterator<Object> it = value.iterator();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (next instanceof String) {
                        WebResourceInfo a2 = WebResourceUtils.a((String) next, key, -1);
                        if (a2 != null && a2.f59264d != 4) {
                            a2.f = 1;
                            boolean a3 = WebResourceCollector.a().a(key, a2);
                            if (i != 3) {
                                i = a3 ? 3 : 2;
                            }
                        }
                    } else if (next instanceof H5VideoInfo) {
                        H5VideoInfo h5VideoInfo = (H5VideoInfo) next;
                        if (!TextUtils.isEmpty(h5VideoInfo.mVideoUrl) && UrlUtils.isWebUrl(h5VideoInfo.mVideoUrl)) {
                            WebResourceInfo webResourceInfo = new WebResourceInfo();
                            String str = null;
                            String guessFileName = UrlUtils.guessFileName(h5VideoInfo.mVideoUrl, null, null);
                            if (MediaFileType.Utils.d(guessFileName)) {
                                str = FileUtilsF.a(guessFileName);
                            } else {
                                String b2 = FileUtilsF.b(UrlUtils.decode(h5VideoInfo.mVideoUrl));
                                if (MediaFileType.Utils.d(b2)) {
                                    str = FileUtilsF.a(b2);
                                    guessFileName = b2;
                                }
                            }
                            if (TextUtils.isEmpty(str)) {
                                str = "mp4";
                            }
                            webResourceInfo.f59262b = !TextUtils.isEmpty(h5VideoInfo.mWebTitle) ? h5VideoInfo.mWebTitle : WebResourceUtils.f(guessFileName);
                            webResourceInfo.f59261a = h5VideoInfo.mWebUrl;
                            webResourceInfo.f59263c = h5VideoInfo.mVideoUrl;
                            webResourceInfo.e = str;
                            webResourceInfo.f59264d = 1;
                            webResourceInfo.f = 1;
                            webResourceInfo.i = h5VideoInfo;
                            webResourceInfo.h = h5VideoInfo.mDuration;
                            boolean a4 = WebResourceCollector.a().a(key, webResourceInfo);
                            if (i != 3) {
                                if (a4) {
                                }
                            }
                        }
                    }
                }
            }
        }
        Logs.c("WebResourceSnifferEngine", "[ID856487549] [DEVv_linhxie] analysisResourceList exit isChange=" + i);
        return i;
    }

    public void a() {
        QBTask.b((Callable) new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                WebResourceSnifferEngine.this.f = false;
                String v = WindowManager.a().v();
                ArrayList<WebResourceInfo> a2 = WebResourceCollector.a().a(v);
                if (a2 != null && a2.size() > 0) {
                    WebResourceSnifferEngine.this.b();
                    return null;
                }
                PageToolBoxGuideBean pageToolBoxGuideBean = new PageToolBoxGuideBean();
                pageToolBoxGuideBean.f56138c = "-1";
                pageToolBoxGuideBean.f56137b = v;
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        WebResourceSnifferEngine.this.showSniffResultList();
                    }
                };
                pageToolBoxGuideBean.e = runnable;
                pageToolBoxGuideBean.g = runnable;
                EventEmiter.getDefault().emit(new EventMessage(IPageToolBoxGuideService.EVENT_TOOL_SNIFF, pageToolBoxGuideBean));
                return null;
            }
        });
    }

    public void a(QBWebView qBWebView, String str) {
        if (e(str)) {
            b(qBWebView, str);
        }
    }

    public void a(String str) {
        WebSniffStatUtil.a();
    }

    public void a(final String str, final boolean z, final ValueCallback<MenuTipsShowRes> valueCallback) {
        if (ThreadUtils.isMainThread()) {
            b(str, z, valueCallback);
        } else {
            BrowserExecutorSupplier.forMainThreadTasks().execute(new Runnable() {
                @Override
                public void run() {
                    WebResourceSnifferEngine.this.b(str, z, valueCallback);
                }
            });
        }
    }

    public boolean a(ArrayList<String> arrayList, Map<String, Integer> map) {
        Iterator<String> it = arrayList.iterator();
        while (it.hasNext()) {
            String next = it.next();
            if (next.startsWith("*.")) {
                String substring = next.substring(2);
                if (!TextUtils.isEmpty(substring) && map.containsKey(substring.toLowerCase())) {
                    return true;
                }
            }
        }
        return false;
    }

    public void b(String str, boolean z, ValueCallback<MenuTipsShowRes> valueCallback) {
        ArrayList<WebResourceInfo> a2;
        if (TextUtils.isEmpty(str)) {
            str = WindowManager.a().v();
        }
        boolean z2 = false;
        if (!TextUtils.isEmpty(str) && UrlUtils.isWebUrl(str) && b(str) && WebResourceConfigManager.getInstance().b() && !this.f59231b && (a2 = WebResourceCollector.a().a(str)) != null && a2.size() > 0 && z) {
            MediaFileType.a();
            WebResourceCollector.a().a(str, true);
            Bitmap p = MttResources.p(WebResourceUtils.a(WebResourceUtils.b(a2)));
            final PageToolBoxGuideBean pageToolBoxGuideBean = new PageToolBoxGuideBean();
            pageToolBoxGuideBean.f56136a = IPluginService.PLUGIN_RESOURCE_SNIFFER;
            pageToolBoxGuideBean.f56137b = str;
            pageToolBoxGuideBean.f56138c = "发现" + a2.size() + "个可下载资源";
            pageToolBoxGuideBean.f = "下载";
            pageToolBoxGuideBean.f56139d = p;
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    WebResourceSnifferEngine.this.showSniffResultList();
                }
            };
            pageToolBoxGuideBean.e = runnable;
            pageToolBoxGuideBean.g = runnable;
            pageToolBoxGuideBean.h = new PageToolBoxGuideBean.StatCallBack() {
                @Override
                public void a(int i) {
                    String str2;
                    String str3 = "sniff_003";
                    if (i == 1) {
                        StatManager.b().c("BZXT002");
                    } else if (i != 2) {
                        if (i == 3) {
                            str2 = pageToolBoxGuideBean.f56137b;
                            str3 = "sniff_023";
                        } else {
                            if (i != 4) {
                                return;
                            }
                            str2 = pageToolBoxGuideBean.f56137b;
                            str3 = "sniff_002";
                        }
                        WebSniffStatUtil.a(str3, str2, 1);
                    }
                    str2 = pageToolBoxGuideBean.f56137b;
                    WebSniffStatUtil.a(str3, str2, 1);
                }
            };
            pageToolBoxGuideBean.a("https://static.res.qq.com/nav/file/sniffer_guide_2021_0519.json", "https://static.res.qq.com/nav/file/sniffer_guide_2021_0519_night.json", "https://static.res.qq.com/nav/file/sniffer_guide_2021_0519_night.json");
            EventEmiter.getDefault().emit(new EventMessage(IPageToolBoxGuideService.EVENT_TOOL_GUIDE, pageToolBoxGuideBean));
            z2 = true;
        }
        if (valueCallback != null) {
            MenuTipsShowRes menuTipsShowRes = new MenuTipsShowRes();
            menuTipsShowRes.f59251a = z2;
            menuTipsShowRes.f59252b = str;
            valueCallback.onReceiveValue(menuTipsShowRes);
        }
    }

    public boolean b(String str) {
        return WebResourceConfigManager.getInstance().a(str);
    }

    @Override
    public void backgroundSniff(String str) {
        WebResourceBkgController.a().a(str);
    }

    public void c(String str) {
        ArrayList<WebResourceInfo> a2 = WebResourceCollector.a().a(str);
        if (a2 == null || a2.size() <= 0) {
            d("-1", str);
        }
    }

    public void d(String str) {
        ArrayList<WebResourceInfo> a2 = WebResourceCollector.a().a(str);
        if (a2 == null || a2.size() <= 0 || !f(str)) {
            return;
        }
        d(String.valueOf(a2.size()), str);
    }

    @Override
    public void f() {
        this.f59231b = true;
        b();
    }

    @Override
    public void g() {
        this.f59231b = false;
        a((String) null, false, (ValueCallback<MenuTipsShowRes>) null);
        b();
    }

    @Override
    public String getPluginItemTips() {
        WebResourcesData b2;
        String v = WindowManager.a().v();
        return ((UrlUtils.isHttpsUrl(v) || UrlUtils.isHttpUrl(v)) && b(v) && isHoverBtnEnable() && (b2 = WebResourceCollector.a().b(v)) != null && b2.f59290a && b2.f59292c.size() > 0) ? String.valueOf(b2.f59292c.size()) : "";
    }

    @Override
    public boolean handleMessage(Message message) {
        return message.what == 1;
    }

    @Override
    public boolean isHoverBtnEnable() {
        return WebResourceConfigManager.getInstance().b();
    }

    @Override
    public boolean isPluginToolsEnable() {
        String v = WindowManager.a().v();
        Logs.c("WebResourceSnifferEngine", "[ID856487549] [DEVv_linhxie] isPluginToolsEnable if-else check UrlUtils.isHttpsUrl(url)= " + UrlUtils.isHttpsUrl(v) + ";UrlUtils.isHttpUrl(url)= " + UrlUtils.isHttpUrl(v));
        if (UrlUtils.isHttpsUrl(v) || UrlUtils.isHttpUrl(v)) {
            Logs.c("WebResourceSnifferEngine", "[ID856487549] [DEVv_linhxie] isPluginToolsEnable exit true=true");
            return true;
        }
        Logs.c("WebResourceSnifferEngine", "[ID856487549] [DEVv_linhxie] isPluginToolsEnable exit false=false");
        return false;
    }

    @Override
    public boolean isShowBackgroundSniff(String str) {
        return b(str);
    }

    @EventReceiver(createMethod = CreateMethod.GET, eventName = "browser.business.sniffer.js.sniff.call.back")
    public void onJsSniffCallBack(EventMessage eventMessage) {
        a((String) eventMessage.args[0], (String) eventMessage.args[1]);
    }

    @Override
    public void onMenuPluginStat(int i) {
        StatManager b2;
        String str;
        String v = WindowManager.a().v();
        if (UrlUtils.isHttpsUrl(v) || UrlUtils.isHttpUrl(v)) {
            if (b(v)) {
                boolean c2 = WebResourceConfigManager.getInstance().c(v);
                boolean b3 = WebResourceConfigManager.getInstance().b();
                if (c2 && b3) {
                    if (i == 1) {
                        b2 = StatManager.b();
                        str = "BZXT003";
                    } else {
                        if (i != 2) {
                            return;
                        }
                        b2 = StatManager.b();
                        str = "BZXT004";
                    }
                } else if (i == 1) {
                    b2 = StatManager.b();
                    str = "BZXT102";
                } else {
                    if (i != 2) {
                        return;
                    }
                    b2 = StatManager.b();
                    str = "BZXT103";
                }
            } else if (i == 1) {
                b2 = StatManager.b();
                str = "BZXT203";
            } else {
                if (i != 2) {
                    return;
                }
                b2 = StatManager.b();
                str = "BZXT204";
            }
            b2.c(str);
        }
    }

    @EventReceiver(createMethod = CreateMethod.GET, eventName = "event_bussiness_should_intercept_request", threadMode = EventThreadMode.ASYNCTHREAD)
    public void onShouldInterceptRequest(EventMessage eventMessage) {
        System.currentTimeMillis();
        HashMap<String, ArrayList<Object>> hashMap = (HashMap) eventMessage.arg;
        if (this.g) {
            a();
        } else {
            this.f = true;
        }
        final int a2 = a(hashMap);
        if (this.f) {
            if (a2 == 2 || a2 == 3) {
                a((String) null, true, new ValueCallback<MenuTipsShowRes>() {
                    @Override
                    public void onReceiveValue(MenuTipsShowRes menuTipsShowRes) {
                        if (menuTipsShowRes == null || a2 != 3) {
                            return;
                        }
                        WebResourceSnifferEngine.this.f59233d.a(menuTipsShowRes.f59252b, menuTipsShowRes.f59251a);
                    }
                });
            }
        }
    }

    @Override
    public void setHoverBtnEnable(boolean z) {
        WebResourceConfigManager.getInstance().a(z);
        a((String) null, false, (ValueCallback<MenuTipsShowRes>) null);
    }

    @Override
    public void showSniffResultList() {
        WebResourceController.a().b();
        WebResourceCollector.a().a(WindowManager.a().v(), false);
    }
}