QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 ImageReaderProxy.java 源代码,内容仅作参考
package com.tencent.mtt.external.reader.image.inhost;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.webkit.ValueCallback;
import com.tencent.common.data.FSFileInfo;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.http.MttResponse;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.Md5Utils;
import com.tencent.mtt.base.task.NetworkTask;
import com.tencent.mtt.base.utils.QBUrlUtils;
import com.tencent.mtt.base.webview.QBWebView;
import com.tencent.mtt.browser.window.IWebView;
import com.tencent.mtt.browser.window.IWebViewClient;
import com.tencent.mtt.browser.window.UrlParams;
import com.tencent.mtt.browser.window.WindowManager;
import com.tencent.mtt.dex.Module;
import com.tencent.mtt.external.archiver.IMttArchiver;
import com.tencent.mtt.external.reader.image.ImageReaderController;
import com.tencent.mtt.external.reader.image.ImageReaderWebSniffUtils;
import com.tencent.mtt.external.reader.image.facade.IImageReaderOpen;
import com.tencent.mtt.external.reader.image.facade.ImageDataObject;
import com.tencent.mtt.external.reader.image.facade.ImgExportPDFListener;
import com.tencent.mtt.external.reader.image.facade.MergeMultiImgParam;
import com.tencent.mtt.external.reader.image.facade.ReadImageParam;
import com.tencent.mtt.external.reader.image.refactor.ImageReaderDataNewDelivery;
import com.tencent.mtt.external.reader.image.ui.ImageReaderSaveDialog;
import com.tencent.mtt.external.reader.image.ui.ImageReaderSaveDialogNoPDF;
import com.tencent.mtt.external.reader.pdf.PDFCreator;
import com.tencent.mtt.file.page.statistics.ToolStatHelper;
import com.tencent.mtt.log.utils.StringUtil;
import com.tencent.mtt.setting.PublicSettingManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ImageReaderProxy implements IImageReaderOpen {
public static boolean GET_JS = false;
public static final int IMG_TYPE_BARCODE = 4;
public static final int IMG_TYPE_FILES = 6;
public static final int IMG_TYPE_URL = 1;
public static final int IMG_TYPE_URLS = 2;
public static final int IMG_TYPE_URLS_THUMP = 14;
public static final int IMG_TYPE_WEIYUN = 5;
public static final int IMG_TYPE_ZIP = 9;
public static final int IMG_TYPE_ZIP_LIST = 10;
public static final String KEY_IMG_BARCODE = "key_img_barcode";
public static final String KEY_IMG_DESCRIPT = "key_img_descript";
public static final String KEY_IMG_FILE = "key_img_file";
public static final String KEY_IMG_FILES = "key_img_files";
public static final String KEY_IMG_INDEX = "key_img_index";
public static final String KEY_IMG_PATH = "key_img_path";
public static final String KEY_IMG_REFER = "key_img_refer";
public static final String KEY_IMG_SHOWMENU = "key_img_showmenu";
public static final String KEY_IMG_SHOW_DETAIL = "key_img_show_detail";
public static final String KEY_IMG_SHOW_DETAILSDCARD = "key_img_show_detail_sdcard";
public static final String KEY_IMG_SHOW_PARAM = "key_img_show_param";
public static final String KEY_IMG_TYPE = "key_img_type";
public static final String KEY_IMG_URL = "key_img_url";
public static final String KEY_MOIVE_PALY_SECRTE_SHOW = "key_moive_paly_secrte_show";
private static final String KEY_SCRIPT_LAST_MODIFIED = "pic_sniff_last_modified_time";
private static final String SNIFFER_PIC_CDN_URL = "https://res.imtt.qq.com/res_mtt/picture_viewer/pictureGetJs.js";
private static final String SNIFFER_PIC_DIR = "pic_sniff";
private static final String SNIFFER_PIC_FILE = "pic_sniff_file";
public static final String STR_DEX_NAME = "com.tencent.mtt.imagereader.jar";
public static final String STR_IMAGE_READER_CONTROLLER_CLASS = "com.tencent.mtt.external.reader.image.ImageReaderController";
public static final String TAG = "ImageReaderProxy";
private static ImageReaderProxy instance;
private Module mModule;
public boolean isOpeningImageReader = false;
private Class imageReaderControllerClass = null;
private Object mLock = new Object();
private Handler mHandler = new Handler(Looper.getMainLooper());
private String mDefaultJavaScript = "javascript:(function(){var a=57;var b=200;var c=document.getElementsByTagName('img');var d=[],noNeedsDownloadImageArr=[],invalidImageArr=[],dataOriginalArr=[];for(var i=0;i<c.length;i++){var e=true;var f=false;var g=false;var h=false;var j=false;var k=false;if(parseInt(window.getComputedStyle(c[i]).width)>=a&&parseInt(window.getComputedStyle(c[i]).height)>=a){g=true}if(parseInt(window.getComputedStyle(c[i]).width)===0&&parseInt(window.getComputedStyle(c[i]).height)===0){h=true}if(c[i].naturalWidth>=b&&c[i].naturalHeight>=b){j=true}if(c[i].naturalWidth===0&&c[i].naturalHeight===0){k=true}if(g&&j){e=false}if(h||k){f=true}var l=c[i].src;console.log(l);if(c[i].getAttribute('src')===null||c[i].getAttribute('src').startsWith('data:image')||c[i].getAttribute('src')===\"\"||c[i].getAttribute('src').startsWith('/')){if(c[i].hasAttribute('data-original')&&c[i].getAttribute('data-original')!==\"\"){l=encodeURI(c[i].getAttribute('data-original'));dataOriginalArr.push(l)}if(c[i].hasAttribute('data-src')&&c[i].getAttribute('data-src')!==\"\"){l=encodeURI(c[i].getAttribute('data-src'));dataOriginalArr.push(l)}if(c[i].hasAttribute('original')&&c[i].getAttribute('original')!==\"\"){l=encodeURI(c[i].getAttribute('original'));dataOriginalArr.push(l)}}if(l.startsWith('http')===false)e=true;if(e){if(f){d.push(l)}else{invalidImageArr.push(l)}}else{noNeedsDownloadImageArr.push(l)}}const retJsonMapObj={};retJsonMapObj.imgs_count=c.length;retJsonMapObj.downloadImageArr_count=d.length;retJsonMapObj.noNeedsDownloadImageArr_count=noNeedsDownloadImageArr.length;retJsonMapObj.invalidImageArr_count=invalidImageArr.length;retJsonMapObj.dataOriginalArr_count=dataOriginalArr.length;retJsonMapObj.downloadImageArr=d;retJsonMapObj.noNeedsDownloadImageArr=noNeedsDownloadImageArr;retJsonMapObj.invalidImageArr=invalidImageArr;retJsonMapObj.dataOriginalArr=dataOriginalArr;const retJsonObj={};retJsonObj.map=retJsonMapObj;return JSON.stringify(retJsonObj)})();";
public ImageReaderProxy() {
this.mModule = null;
this.mModule = new Module(STR_DEX_NAME, STR_IMAGE_READER_CONTROLLER_CLASS);
}
public static String getCurrentWebUrl() {
IWebView u = WindowManager.a().u();
if (u != null) {
return u.getUrl();
}
return null;
}
public static ImageReaderProxy getInstance() {
if (instance == null) {
synchronized (ImageReaderProxy.class) {
if (instance == null) {
instance = new ImageReaderProxy();
}
}
}
return instance;
}
public static String getParsedLocalPath(String str) {
try {
return new URL(str).getPath();
} catch (Exception unused) {
return null;
}
}
@Override
public void exportPDF(Context context, List<String> list, String str, String str2, boolean z, ImgExportPDFListener imgExportPDFListener) {
exportPDFv2(context, list, str, str2, z, null, imgExportPDFListener);
}
@Override
public void exportPDFv2(Context context, List<String> list, String str, String str2, boolean z, Bundle bundle, final ImgExportPDFListener imgExportPDFListener) {
if (Build.VERSION.SDK_INT <= 23 || Build.VERSION.SDK_INT >= 28) {
PDFCreator.a().a(new ArrayList<>(list), str, str2, z, imgExportPDFListener, bundle);
return;
}
ImageReaderSaveDialog imageReaderSaveDialog = new ImageReaderSaveDialog(context);
imageReaderSaveDialog.b(list);
imageReaderSaveDialog.a((Bitmap) null);
imageReaderSaveDialog.a(1);
imageReaderSaveDialog.a(new MergeMultiImgParam.Callback() {
@Override
public void stitchSuccess() {
}
@Override
public void toPDFSuccess(String str3) {
ImgExportPDFListener imgExportPDFListener2 = imgExportPDFListener;
if (imgExportPDFListener2 != null) {
imgExportPDFListener2.a(str3);
}
}
});
imageReaderSaveDialog.b(false);
imageReaderSaveDialog.show();
}
public String getFileName(String str) {
return SNIFFER_PIC_FILE + Md5Utils.a(str);
}
@Override
public IWebView getImageContainer(Context context, IWebViewClient iWebViewClient, UrlParams urlParams) {
return new ImageContainer(context, iWebViewClient).buildEntryPage(urlParams);
}
@Override
public String getJavaScriptString() {
String loadLocalScript = loadLocalScript(SNIFFER_PIC_CDN_URL);
if (StringUtil.a(loadLocalScript)) {
loadLocalScript = this.mDefaultJavaScript;
}
if (!GET_JS) {
GET_JS = true;
remoteFetch(null, SNIFFER_PIC_CDN_URL, true);
}
return loadLocalScript;
}
@Override
public Bundle getLocalImageBundle(String str, int i, String str2) {
if (StringUtil.a(str)) {
return null;
}
ArrayList arrayList = new ArrayList();
FSFileInfo fSFileInfo = new FSFileInfo();
fSFileInfo.q = 2;
fSFileInfo.f9373b = str;
arrayList.add(fSFileInfo);
ReadImageParam readImageParam = new ReadImageParam();
readImageParam.deleteInterface = null;
readImageParam.initIndex = 0;
readImageParam.datas = arrayList;
readImageParam.from = i;
readImageParam.isNeedShareButon = true;
readImageParam.isNeedEncyrptSaveButton = true;
readImageParam.isNeedDeleteButton = true;
readImageParam.unit = "file_image";
readImageParam.scene = ToolStatHelper.c(str2);
readImageParam.unitTitle = str;
if (readImageParam.userBehaviorData != null && readImageParam.userBehaviorData.getString("fromMethod", "").equals("")) {
readImageParam.userBehaviorData.putString("fromMethod", "getLocalImageBundle");
}
int a2 = ImageReaderDataNewDelivery.a().a(readImageParam);
Bundle bundle = new Bundle();
bundle.putInt("key_img_show_param", a2);
return bundle;
}
public File getScriptFile(String str) {
return new File(FileUtils.f(SNIFFER_PIC_DIR), getFileName(str));
}
@Override
public Bundle getWebImageBundle(String str, String str2, boolean z, int i) {
if (StringUtil.a(str)) {
return null;
}
if (QBUrlUtils.G(str)) {
return getLocalImageBundle(getParsedLocalPath(str), i, "");
}
ArrayList arrayList = new ArrayList();
arrayList.add(new ImageDataObject(str, null));
ReadImageParam readImageParam = new ReadImageParam();
readImageParam.deleteInterface = null;
readImageParam.initIndex = 0;
readImageParam.datas = arrayList;
readImageParam.from = i;
readImageParam.isNeedShareButon = true;
readImageParam.isNeedEncyrptSaveButton = true;
readImageParam.isNeedSaveButton = true;
readImageParam.isNeedDetailButon = false;
if (readImageParam.userBehaviorData != null && readImageParam.userBehaviorData.getString("fromMethod", "").equals("")) {
readImageParam.userBehaviorData.putString("fromMethod", "getWebImageBundle");
}
int a2 = ImageReaderDataNewDelivery.a().a(readImageParam);
Bundle bundle = new Bundle();
bundle.putInt("key_img_show_param", a2);
return bundle;
}
public String loadLocalScript(String str) {
FileInputStream fileInputStream;
InputStreamReader inputStreamReader;
BufferedReader bufferedReader;
if (TextUtils.isEmpty(str)) {
return "";
}
BufferedReader bufferedReader2 = null;
try {
if (!getScriptFile(str).exists()) {
return "";
}
fileInputStream = FileUtils.i(getScriptFile(str));
try {
inputStreamReader = new InputStreamReader(fileInputStream);
try {
bufferedReader = new BufferedReader(inputStreamReader);
} catch (Throwable unused) {
}
try {
StringBuffer stringBuffer = new StringBuffer();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
stringBuffer.append(readLine);
stringBuffer.append("\n");
}
String stringBuffer2 = stringBuffer.toString();
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (Throwable unused2) {
}
}
inputStreamReader.close();
bufferedReader.close();
return stringBuffer2;
} catch (Throwable unused3) {
bufferedReader2 = bufferedReader;
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (Throwable unused4) {
return "";
}
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (bufferedReader2 != null) {
bufferedReader2.close();
}
return "";
}
} catch (Throwable unused5) {
inputStreamReader = null;
}
} catch (Throwable unused6) {
fileInputStream = null;
inputStreamReader = null;
}
}
@Override
public void openPicByJsSniff(QBWebView qBWebView, boolean z, String str, boolean z2) {
ImageReaderWebSniffUtils.a(qBWebView, z, str, z2);
}
public void remoteFetch(final ValueCallback<String> valueCallback, final String str, final boolean z) {
BrowserExecutorSupplier.forBackgroundTasks().execute(new Runnable() {
@Override
public void run() {
new NetworkTask(str, new NetworkTask.NetworkTaskCallback() {
@Override
public void onTaskFailed(MttRequestBase mttRequestBase, int i) {
}
@Override
public void onTaskSuccess(MttRequestBase mttRequestBase, MttResponse mttResponse) {
try {
int intValue = mttResponse.getStatusCode().intValue();
if (intValue != 200) {
if (intValue != 304) {
throw new Exception("Request Failed. HTTP Error Code: " + mttResponse.getStatusCode());
}
if (valueCallback == null || z) {
return;
}
valueCallback.onReceiveValue(ImageReaderProxy.this.loadLocalScript(str));
return;
}
String headerField = mttResponse.getHeaderField("Last-Modified");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mttResponse.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
stringBuffer.append(readLine);
stringBuffer.append("\n");
}
String stringBuffer2 = stringBuffer.toString();
if (valueCallback != null) {
valueCallback.onReceiveValue(stringBuffer2);
}
PublicSettingManager.a().setString(ImageReaderProxy.KEY_SCRIPT_LAST_MODIFIED + Md5Utils.a(str), headerField);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = FileUtils.j(ImageReaderProxy.this.getScriptFile(str));
FileUtils.a(stringBuffer.toString(), fileOutputStream);
} catch (Throwable unused) {
if (fileOutputStream != null) {
fileOutputStream.close();
}
bufferedReader.close();
}
} catch (Throwable unused2) {
if (valueCallback != null) {
valueCallback.onReceiveValue("");
}
}
}
}).b("If-Modified-Since", PublicSettingManager.a().getString(ImageReaderProxy.KEY_SCRIPT_LAST_MODIFIED + Md5Utils.a(str), "")).a(3000).d();
}
});
}
@Override
public void showImage(String str) {
ArrayList<FSFileInfo> arrayList = new ArrayList<>();
FSFileInfo fSFileInfo = new FSFileInfo();
fSFileInfo.f9373b = str;
arrayList.add(fSFileInfo);
showImageList(arrayList, 0, false, false, null);
}
@Override
public Object showImageList(ArrayList<FSFileInfo> arrayList, int i, boolean z, boolean z2, ReadImageParam readImageParam) {
ImageReaderController.showImageList(arrayList, i, z, z2, readImageParam);
return null;
}
@Override
public void showImageListNativePage(ArrayList<FSFileInfo> arrayList, int i, boolean z, boolean z2, ReadImageParam readImageParam) {
ImageReaderController.showImageListNative(arrayList, i, z, z2, readImageParam);
}
@Override
public void showImageListOld(ArrayList<FSFileInfo> arrayList, int i, boolean z, boolean z2, ReadImageParam readImageParam) {
ImageReaderController.showImageListOld(arrayList, i, z, z2, readImageParam);
}
@Override
@Deprecated
public void showImageUrl(String str) {
if (QBUrlUtils.G(str)) {
showImage(getParsedLocalPath(str));
} else {
showImageUrl(str, getCurrentWebUrl());
}
}
@Override
@Deprecated
public void showImageUrl(String str, String str2) {
showImageUrl(str, str2, true);
}
@Override
@Deprecated
public void showImageUrl(String str, String str2, boolean z) {
ImageReaderController.showImageUrl(str, str2, z);
}
@Override
@Deprecated
public void showImageUrls(LinkedList<String> linkedList, int i) {
showImageUrls(linkedList, i, getCurrentWebUrl());
}
@Override
@Deprecated
public void showImageUrls(LinkedList<String> linkedList, int i, String str) {
ImageReaderController.showImageUrls(linkedList, i, str);
}
@Override
public Object showImgUrlsWithThumpImgs(LinkedList<ImageDataObject> linkedList, int i, ReadImageParam readImageParam, String str) {
return showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str, null, false);
}
@Override
public Object showImgUrlsWithThumpImgs(LinkedList<ImageDataObject> linkedList, int i, ReadImageParam readImageParam, String str, View view, boolean z) {
ImageReaderController.showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str);
return null;
}
@Override
public Object showImgUrlsWithThumpImgs(LinkedList<ImageDataObject> linkedList, int i, ReadImageParam readImageParam, String str, boolean z) {
return showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str, null, z);
}
@Override
public Object showImgUrlsWithThumpImgs(Map<String, Bitmap> map, int i, ReadImageParam readImageParam, String str) {
LinkedList<ImageDataObject> linkedList = new LinkedList<>();
for (String str2 : map.keySet()) {
linkedList.add(new ImageDataObject(str2, map.get(str2)));
}
return showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str, null, false);
}
@Override
public Object showImgUrlsWithThumpImgs(Map<String, Bitmap> map, int i, ReadImageParam readImageParam, String str, boolean z) {
LinkedList<ImageDataObject> linkedList = new LinkedList<>();
for (String str2 : map.keySet()) {
linkedList.add(new ImageDataObject(str2, map.get(str2)));
}
return showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str, null, z);
}
@Override
public Object showImgUrlsWithThumpImgsWithDefault(Bitmap bitmap) {
LinkedHashMap linkedHashMap = new LinkedHashMap();
linkedHashMap.put(null, bitmap);
return showImgUrlsWithThumpImgsWithDefault(linkedHashMap, 0, (String) null);
}
@Override
public Object showImgUrlsWithThumpImgsWithDefault(String str, String str2) {
LinkedHashMap linkedHashMap = new LinkedHashMap();
linkedHashMap.put(str, null);
return showImgUrlsWithThumpImgsWithDefault(linkedHashMap, 0, str2);
}
@Override
public Object showImgUrlsWithThumpImgsWithDefault(Map<String, Bitmap> map, int i, String str) {
ReadImageParam readImageParam = new ReadImageParam();
readImageParam.isNeedBack = false;
readImageParam.mBackStr = null;
if (readImageParam.userBehaviorData != null && readImageParam.userBehaviorData.getString("fromMethod", "").equals("")) {
readImageParam.userBehaviorData.putString("fromMethod", "showImgUrlsWithThumpImgsWithDefault1");
}
return showImgUrlsWithThumpImgs(map, i, readImageParam, str);
}
@Override
public Object showImgUrlsWithThumpImgsWithDefault(Map<String, Bitmap> map, int i, String str, View view) {
ReadImageParam readImageParam = new ReadImageParam();
readImageParam.isNeedBack = false;
readImageParam.mBackStr = null;
if (readImageParam.userBehaviorData != null && readImageParam.userBehaviorData.getString("fromMethod", "").equals("")) {
readImageParam.userBehaviorData.putString("fromMethod", "showImgUrlsWithThumpImgsWithDefault");
}
if (view != null) {
Rect rect = new Rect();
Rect rect2 = new Rect();
int[] iArr = new int[2];
view.getLocationOnScreen(iArr);
rect2.top = iArr[1];
rect2.left = iArr[0];
rect2.right = rect2.left + view.getWidth();
rect2.bottom = rect2.top + view.getHeight();
view.getGlobalVisibleRect(rect);
readImageParam.setVisiableRect(rect);
readImageParam.setRect(rect2);
}
return showImgUrlsWithThumpImgs(map, i, readImageParam, str);
}
@Override
public Object showImgUrlsWithThumpImgsWithDefault(Map<String, Bitmap> map, int i, boolean z) {
ReadImageParam readImageParam = new ReadImageParam();
readImageParam.isNeedBack = false;
readImageParam.mBackStr = null;
if (readImageParam.userBehaviorData != null && readImageParam.userBehaviorData.getString("fromMethod", "").equals("")) {
readImageParam.userBehaviorData.putString("fromMethod", "showImgUrlsWithThumpImgsWithDefault2");
}
return showImgUrlsWithThumpImgs(map, i, readImageParam, (String) null, z);
}
@Override
public Object showImgUrlsWithThumpImgsWithParam(LinkedList<ImageDataObject> linkedList, int i, ReadImageParam readImageParam, String str) {
ImageReaderController.showImgUrlsWithThumpImgs(linkedList, i, readImageParam, str, false);
return null;
}
@Override
public void showMergeView(Context context, MergeMultiImgParam mergeMultiImgParam) {
ImageReaderSaveDialogNoPDF imageReaderSaveDialogNoPDF = new ImageReaderSaveDialogNoPDF(context);
imageReaderSaveDialogNoPDF.a(mergeMultiImgParam.f57887a);
imageReaderSaveDialogNoPDF.a(mergeMultiImgParam.f57888b);
imageReaderSaveDialogNoPDF.a(mergeMultiImgParam.f57890d);
imageReaderSaveDialogNoPDF.show();
}
@Override
public void showZipImageList(ArrayList<IMttArchiver> arrayList, int i, String str, String str2) {
ImageReaderController.showZipImageList(arrayList, i, str, str2);
}
}