package com.helpshift.chat; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; import android.os.Message; import android.webkit.ConsoleMessage; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebView; import com.helpshift.log.HSLogger; import com.helpshift.log.WebviewConsoleLogger; import com.helpshift.util.Utils; /* loaded from: classes3.dex */ public class HSChatWebChromeClient extends WebChromeClient { public final HSChatEventsHandler eventsHandler; public ValueCallback filePathCallback; public void setFilePathCallback(ValueCallback valueCallback) { this.filePathCallback = valueCallback; } public HSChatWebChromeClient(HSChatEventsHandler hSChatEventsHandler) { this.eventsHandler = hSChatEventsHandler; } @Override // android.webkit.WebChromeClient public boolean onConsoleMessage(ConsoleMessage consoleMessage) { WebviewConsoleLogger.log(consoleMessage.messageLevel(), "chatWVClient", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId()); return super.onConsoleMessage(consoleMessage); } @Override // android.webkit.WebChromeClient public boolean onCreateWindow(WebView webView, boolean z, boolean z2, Message message) { if (!z2) { return false; } WebView.HitTestResult hitTestResult = webView.getHitTestResult(); String createUriForSystemAppLaunch = createUriForSystemAppLaunch(hitTestResult.getType(), hitTestResult.getExtra()); if (Utils.isNotEmpty(createUriForSystemAppLaunch)) { this.eventsHandler.sendIntentToSystemApp(new Intent("android.intent.action.VIEW", Uri.parse(createUriForSystemAppLaunch))); return true; } WebView webView2 = new WebView(webView.getContext()); this.eventsHandler.addWebviewToCurrentUI(webView2); ((WebView.WebViewTransport) message.obj).setWebView(webView2); message.sendToTarget(); return true; } public final String createUriForSystemAppLaunch(int i, String str) { if (i != 2) { return i != 7 ? "" : str; } return "tel:" + str; } @Override // android.webkit.WebChromeClient public boolean onShowFileChooser(WebView webView, ValueCallback valueCallback, WebChromeClient.FileChooserParams fileChooserParams) { if (this.filePathCallback != null) { HSLogger.d("chatWVClient", "filePathCallback is not null, returning false."); this.filePathCallback.onReceiveValue(null); this.filePathCallback = null; return false; } this.filePathCallback = valueCallback; this.eventsHandler.setAttachmentFilePathCallback(valueCallback); try { Intent createIntent = fileChooserParams.createIntent(); createIntent.setType("*/*"); String[] acceptTypes = fileChooserParams.getAcceptTypes(); if (acceptTypes.length != 0) { createIntent.putExtra("android.intent.extra.MIME_TYPES", acceptTypes); } createIntent.setAction("android.intent.action.OPEN_DOCUMENT"); createIntent.addCategory("android.intent.category.OPENABLE"); HSLogger.d("chatWVClient", "Starting open file chooser request."); this.eventsHandler.openFileChooser(createIntent, 1001); HSLogger.d("chatWVClient", "onShowFileChooser success, returning true"); return true; } catch (ActivityNotFoundException e) { HSLogger.e("chatWVClient", "ActivityNotFoundException error in opening the attachment file chooser.", e); this.filePathCallback = null; return true; } catch (Exception e2) { HSLogger.e("chatWVClient", "error in opening the attachment in browser window, returning false", e2); this.filePathCallback = null; return false; } } }