TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c

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


package com.tencent.biz.webviewplugin;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.text.TextUtils;
import com.tencent.biz.AuthorizeConfig;
import com.tencent.biz.ProtoServlet;
import com.tencent.biz.common.offline.HtmlOffline;
import com.tencent.biz.common.util.HttpUtil;
import com.tencent.biz.common.util.Util;
import com.tencent.biz.pubaccount.CustomWebView;
import com.tencent.mobileqq.dating.HotChatFlashPicActivity;
import com.tencent.mobileqq.statistics.ReportController;
import com.tencent.mobileqq.transfile.SosoSrvAddrProvider;
import com.tencent.mobileqq.utils.FileUtils;
import com.tencent.mobileqq.webview.swift.WebViewPlugin;
import com.tencent.mobileqq.webview.swift.WebviewPluginEventConfig;
import com.tencent.pb.websafe.WebSafe;
import com.tencent.qphone.base.util.QLog;
import com.tencent.smtt.sdk.WebView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import mqq.app.NewIntent;
public class SosoPlugin extends WebViewPlugin {
    public static final int f83431a = 0;
    public static final int f83432b = 1;
    public static final String f6851b = "key_isReadModeEnabled";
    private static boolean f6852b = false;
    private static boolean f6853c = false;
    public static final String e = "/cgi-bin/httpconn?htcmd=0x6ff0080";
    public static final String f = "#__SOSO_RAW_URL___";
    private static final String g = "1004";
    private static final String h = "domain_white_list.txt";
    private static final String i = "http://pub.idqqimg.com/qqmobile/client/android/forbidden.html";
    private BroadcastReceiver f6854a;
    SosoSrvAddrProvider f6855a;
    public WebView f6856a;
    private ArrayList f6857a;
    private boolean f6861d;
    public static final String f6849a = SosoPlugin.class.getSimpleName();
    public static final String f83433c = "http://htdata.qq.com/cgi-bin/httpconn?htcmd=0x6ff0080";
    public static final String d = "http://htdata2.qq.com/cgi-bin/httpconn?htcmd=0x6ff0080";
    public static String[] f6850a = {f83433c, d};
    private int f6859c = 1;
    private int f6860d = this.f6859c;
    boolean f6858a = true;
    private int f6862e = -1;

    public SosoPlugin() {
        this.mPluginNameSpace = f6849a;
    }

    @Override
    public void onCreate() {
        SosoSrvAddrProvider.a().c();
        f6853c = AuthorizeConfig.a().a("enable_check_url_old", (Boolean) false).booleanValue();
        if (QLog.isColorLevel()) {
            QLog.d(this.TAG, 2, "enable_check_url_old : " + f6853c);
        }
    }

    @Override
    public void onActivityReady() {
        a();
    }

    @Override
    public void onWebViewCreated(CustomWebView customWebView) {
        super.onWebViewCreated(customWebView);
        this.f6856a = customWebView;
    }

    private void a() {
        if (this.f6854a == null) {
            this.f6854a = new hyn(this);
        }
        try {
            if (QLog.isColorLevel()) {
                QLog.d(this.TAG, 2, "registerReceiver soso receiver");
            }
            this.mRuntime.a().registerReceiver(this.f6854a, new IntentFilter(SosoSrvAddrProvider.f31116b));
        } catch (Exception e2) {
            if (QLog.isColorLevel()) {
                QLog.e(this.TAG, 2, "registerReceiver soso receiver error", e2);
            }
        }
    }

    @Override
    public boolean handleSchemaRequest(String str, String str2) {
        boolean z;
        Intent intent;
        boolean z2;
        if ("http".equals(str2) || "https".equals(str2)) {
            if (str.contains(URLEncoder.encode("/cgi-bin/httpconn?htcmd=0x6ff0080")) || str.contains("/cgi-bin/httpconn?htcmd=0x6ff0080") || !m1844a()) {
                return false;
            }
            if (f6853c) {
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "check url safety with old solution (<5.3)");
                }
                String m1845a = m1845a(str);
                if (!str.equalsIgnoreCase(m1845a)) {
                    this.f6856a.loadUrl(m1845a);
                    return true;
                }
            } else {
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "check url safety with new solution (>= 5.3)");
                }
                if (!f6852b) {
                    if (HtmlOffline.m917f("1004")) {
                        boolean m912a = HtmlOffline.m912a("1004", "http://domain_white_list.txt");
                        if (QLog.isColorLevel()) {
                            QLog.d(this.TAG, 2, "verify offline file " + m912a);
                        }
                    }
                    if (HttpUtil.a() == 1) {
                        HtmlOffline.b("1004", this.mRuntime.m9632a(), true, new hyo(this));
                    }
                    f6852b = true;
                }
                if (this.f6857a == null || this.f6857a.size() == 0) {
                    String str3 = HtmlOffline.a("1004") + "1004" + File.separator + h;
                    if (FileUtils.m9176a(str3)) {
                        a(str3);
                    }
                }
                if (this.f6857a != null) {
                    String host = Uri.parse(str).getHost();
                    Iterator it = this.f6857a.iterator();
                    z = false;
                    while (it.hasNext()) {
                        if (AuthorizeConfig.m836b((String) it.next(), host)) {
                            String m1845a2 = m1845a(str);
                            if (!str.equalsIgnoreCase(m1845a2)) {
                                if (QLog.isColorLevel()) {
                                    QLog.d(this.TAG, 2, "current url is in the format white list, check it with the old solution");
                                }
                                this.f6856a.loadUrl(m1845a2);
                                return true;
                            }
                            z2 = true;
                        } else {
                            z2 = z;
                        }
                        z = z2;
                    }
                } else {
                    if (QLog.isColorLevel()) {
                        QLog.d(this.TAG, 2, "after trying to read the offline format white list into the memory, mFormatWhiteList is still null, so check current url with new solution");
                    }
                    f6852b = false;
                    z = false;
                }
                if (this.mRuntime != null && !z) {
                    WebSafe.CheckURLReq checkURLReq = new WebSafe.CheckURLReq();
                    checkURLReq.url.set(str);
                    if (this.mRuntime.a() != null && (intent = this.mRuntime.a().getIntent()) != null) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("wap=3");
                        switch (intent.getExtras().getInt(HotChatFlashPicActivity.f21720g)) {
                            case 0:
                                sb.append("&qq-pf-to=mqq.c2c");
                                break;
                            case 1:
                                sb.append("&qq-pf-to=mqq.group");
                                break;
                            case 3000:
                                sb.append("&qq-pf-to=mqq.discussion");
                                break;
                            default:
                                sb.append("&qq-pf-to=mqq.temporaryc2c");
                                break;
                        }
                        String stringExtra = intent.getStringExtra("uin");
                        if (!TextUtils.isEmpty(stringExtra)) {
                            sb.append("&uin=").append(stringExtra);
                        }
                        String stringExtra2 = intent.getStringExtra("friendUin");
                        if (!TextUtils.isEmpty(stringExtra2)) {
                            sb.append("&originuin=").append(stringExtra2);
                        }
                        checkURLReq.gdt_data.set(sb.toString());
                    }
                    NewIntent newIntent = new NewIntent(this.mRuntime.a(), ProtoServlet.class);
                    newIntent.setWithouLogin(true);
                    newIntent.putExtra("cmd", "SafeSvr.check_url");
                    newIntent.putExtra("data", checkURLReq.toByteArray());
                    newIntent.setObserver(new hyp(this, str));
                    if (this.mRuntime.m9632a() != null) {
                        if (QLog.isColorLevel()) {
                            QLog.d(this.TAG, 2, "sending SSO request, SafeSvr.check_url, url : " + Util.a(str, new String[0]));
                        }
                        this.mRuntime.m9632a().startServlet(newIntent);
                        this.f6861d = false;
                    }
                }
            }
        }
        return false;
    }

    String a(Intent intent, String str, SosoSrvAddrProvider sosoSrvAddrProvider) {
        if (!str.contains(URLEncoder.encode("/cgi-bin/httpconn?htcmd=0x6ff0080")) && !str.contains("/cgi-bin/httpconn?htcmd=0x6ff0080")) {
            try {
                String str2 = f6850a[new Random().nextInt(2)];
                StringBuilder sb = new StringBuilder();
                sb.append(str2);
                sb.append("&u=");
                sb.append(URLEncoder.encode(str, "UTF-8"));
                sb.append("&wap=3");
                switch (intent.getExtras().getInt(HotChatFlashPicActivity.f21720g)) {
                    case 0:
                        sb.append("&qq-pf-to=mqq.c2c");
                        break;
                    case 1:
                        sb.append("&qq-pf-to=mqq.group");
                        break;
                    case 3000:
                        sb.append("&qq-pf-to=mqq.discussion");
                        break;
                    default:
                        sb.append("&qq-pf-to=mqq.temporaryc2c");
                        break;
                }
                String stringExtra = intent.getStringExtra("uin");
                if (!TextUtils.isEmpty(stringExtra)) {
                    sb.append("&uin=").append(stringExtra);
                }
                String stringExtra2 = intent.getStringExtra("friendUin");
                if (!TextUtils.isEmpty(stringExtra2)) {
                    sb.append("&originuin=").append(stringExtra2);
                }
                str = sb.toString();
                return str;
            } catch (UnsupportedEncodingException e2) {
                e2.printStackTrace();
                return str;
            }
        }
        return str;
    }

    private String b(String str) {
        if (this.f6859c == 1) {
            if (AuthorizeConfig.a().m848b(str)) {
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "Url is on cig skip white list,the url:" + Util.b(str, new String[0]));
                    return str;
                }
                return str;
            } else if (this.f6858a) {
                return a(this.mRuntime.a().getIntent(), str, SosoSrvAddrProvider.a());
            } else {
                return str;
            }
        } else if (str.contains("/cgi-bin/httpconn?htcmd=0x6ff0080") && QLog.isColorLevel()) {
            QLog.e(this.TAG, 2, "VIEW_MODE_SYSTEM_BROWSER_MODE! url is not original!");
            return str;
        } else {
            return str;
        }
    }

    String m1845a(String str) {
        if (m1844a()) {
            if (this.f6859c == 1) {
                if (str.indexOf(f) == -1) {
                    str = b(str);
                } else {
                    this.f6860d = this.f6859c;
                    this.f6859c = 0;
                    this.f6862e = this.f6856a.copyBackForwardList().getCurrentIndex();
                    if (QLog.isColorLevel()) {
                        QLog.d(this.TAG, 2, "anchorIndex org " + this.f6862e);
                    }
                }
                if (this.f6860d == 0) {
                    this.f6862e = -1;
                }
            } else {
                this.f6860d = this.f6859c;
                this.f6859c = 0;
            }
        }
        return str;
    }

    private void b() {
        if (this.f6859c == 1) {
            this.f6860d = this.f6859c;
            this.f6859c = 0;
            return;
        }
        this.f6860d = this.f6859c;
        this.f6859c = 1;
    }

    @Override
    public boolean handleEvent(String str, long j, Map map) {
        if (j == WebviewPluginEventConfig.u) {
            int currentIndex = this.f6856a.copyBackForwardList().getCurrentIndex();
            if (this.f6862e == currentIndex - 1) {
                b();
                this.f6862e = currentIndex;
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "anchorIndex back " + this.f6862e);
                    return false;
                }
                return false;
            }
            return false;
        } else if (j == WebviewPluginEventConfig.n) {
            this.f6858a = true;
            if (str.contains(i)) {
                this.f6856a.clearHistory();
                return false;
            } else if (!TextUtils.isEmpty(str) && str.startsWith("http")) {
                ReportController.b(null, "dc01332", "BizTechReport", "", "web_safe", "url_safe_check", 0, this.f6861d ? 1 : 0, "", "", "", "");
                return false;
            } else {
                return false;
            }
        } else if (j == WebviewPluginEventConfig.o) {
            this.f6858a = true;
            SosoSrvAddrProvider.a().a(SosoSrvAddrProvider.SosoSrvAddrType.URL_ENCODE_SRV, str);
            return false;
        } else if (j == WebviewPluginEventConfig.m) {
            this.f6858a = false;
            return false;
        } else if (j == WebviewPluginEventConfig.v) {
            int currentIndex2 = this.f6856a.copyBackForwardList().getCurrentIndex();
            if (this.f6862e == currentIndex2 + 1) {
                b();
                this.f6862e = currentIndex2;
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "anchorIndex forward " + this.f6862e);
                    return false;
                }
                return false;
            }
            return false;
        } else {
            return false;
        }
    }

    @Override
    public void onDestroy() {
        if (this.f6854a != null) {
            try {
                if (QLog.isColorLevel()) {
                    QLog.d(this.TAG, 2, "unregisterReceiver sosoReceiver");
                }
                this.mRuntime.a().unregisterReceiver(this.f6854a);
            } catch (Exception e2) {
            }
        }
    }

    private void a(String str) {
        BufferedReader bufferedReader;
        FileInputStream fileInputStream;
        FileInputStream fileInputStream2 = null;
        if (QLog.isColorLevel()) {
            QLog.d(this.TAG, 2, "try to read the offline format white list into the memory");
        }
        this.f6857a = new ArrayList();
        try {
            fileInputStream = new FileInputStream(new File(str));
            try {
                bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
                while (true) {
                    try {
                        String readLine = bufferedReader.readLine();
                        if (readLine == null) {
                            break;
                        }
                        this.f6857a.add(readLine);
                    } catch (IOException e2) {
                        e = e2;
                        fileInputStream2 = fileInputStream;
                        try {
                            if (QLog.isDevelopLevel()) {
                                QLog.d(this.TAG, 4, QLog.getStackTraceString(e));
                            }
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (IOException e3) {
                                    e3.printStackTrace();
                                }
                            }
                            if (fileInputStream2 != null) {
                                try {
                                    fileInputStream2.close();
                                    return;
                                } catch (IOException e4) {
                                    e4.printStackTrace();
                                    return;
                                }
                            }
                            return;
                        } catch (Throwable th) {
                            th = th;
                            fileInputStream = fileInputStream2;
                            if (bufferedReader != null) {
                                try {
                                    bufferedReader.close();
                                } catch (IOException e5) {
                                    e5.printStackTrace();
                                }
                            }
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e6) {
                                    e6.printStackTrace();
                                }
                            }
                            throw th;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        if (bufferedReader != null) {
                        }
                        if (fileInputStream != null) {
                        }
                        throw th;
                    }
                }
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e7) {
                        e7.printStackTrace();
                    }
                }
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e8) {
                        e8.printStackTrace();
                    }
                }
            } catch (IOException e9) {
                e = e9;
                bufferedReader = null;
                fileInputStream2 = fileInputStream;
            } catch (Throwable th3) {
                th = th3;
                bufferedReader = null;
            }
        } catch (IOException e10) {
            e = e10;
            bufferedReader = null;
        } catch (Throwable th4) {
            th = th4;
            bufferedReader = null;
            fileInputStream = null;
        }
    }

    private boolean m1844a() {
        if (this.mRuntime == null || this.mRuntime.a() == null) {
            return false;
        }
        return this.mRuntime.a().getIntent().getBooleanExtra("key_isReadModeEnabled", false);
    }
}