MD5 校验值:d7f913ab91d7343430e85d5ce2e5aff0
MraidBridge.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.mopub.mraid; import android.content.Context; import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.view.MotionEvent; import android.view.View; import android.webkit.ConsoleMessage; import android.webkit.JsResult; import android.webkit.RenderProcessGoneDetail; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import com.mopub.common.Constants; import com.mopub.common.Preconditions; import com.mopub.common.VisibilityTracker; import com.mopub.common.VisibleForTesting; import com.mopub.common.logging.MoPubLog; import com.mopub.mobileads.BaseWebViewViewability; import com.mopub.mobileads.MoPubErrorCode; import com.mopub.mobileads.ViewGestureDetector; import com.mopub.network.MoPubNetworkUtils; import com.mopub.network.Networking; import com.ottplay.ottplay.epg.EpgSource; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import org.json.JSONObject; public class MraidBridge { public final PlacementType f19455a; public MraidBridgeListener f19456b; public MraidWebView f19457c; public ViewGestureDetector f19458d; public boolean f19459e; public final WebViewClient f19460f; public interface MraidBridgeListener { void onClose(); boolean onConsoleMessage(ConsoleMessage consoleMessage); void onExpand(URI uri); boolean onJsAlert(String str, JsResult jsResult); void onOpen(URI uri); void onPageFailedToLoad(); void onPageLoaded(); void onRenderProcessGone(MoPubErrorCode moPubErrorCode); void onResize(int i10, int i11, int i12, int i13, boolean z10); void onSetOrientationProperties(boolean z10, com.mopub.mraid.a aVar); void onVisibilityChanged(boolean z10); } public static class MraidWebView extends BaseWebViewViewability { public OnVisibilityChangedListener f19461k; public VisibilityTracker f19462l; public boolean f19463m; public interface OnVisibilityChangedListener { void onVisibilityChanged(boolean z10); } public class a implements VisibilityTracker.VisibilityTrackerListener { public a() { } @Override public void onVisibilityChanged(List<View> list, List<View> list2) { Preconditions.checkNotNull(list); Preconditions.checkNotNull(list2); MraidWebView mraidWebView = MraidWebView.this; mraidWebView.setMraidViewable(list.contains(mraidWebView)); } } public MraidWebView(Context context) { super(context); if (Build.VERSION.SDK_INT <= 22) { this.f19463m = getVisibility() == 0; return; } VisibilityTracker visibilityTracker = new VisibilityTracker(context); this.f19462l = visibilityTracker; visibilityTracker.setVisibilityTrackerListener(new a()); } public void setMraidViewable(boolean z10) { if (this.f19463m == z10) { return; } this.f19463m = z10; OnVisibilityChangedListener onVisibilityChangedListener = this.f19461k; if (onVisibilityChangedListener != null) { onVisibilityChangedListener.onVisibilityChanged(z10); } } @Override public void destroy() { super.destroy(); this.f19462l = null; this.f19461k = null; } public boolean isMraidViewable() { return this.f19463m; } @Override public void onVisibilityChanged(View view, int i10) { super.onVisibilityChanged(view, i10); VisibilityTracker visibilityTracker = this.f19462l; if (visibilityTracker == null) { setMraidViewable(i10 == 0); } else if (i10 == 0) { visibilityTracker.clear(); this.f19462l.addView(view, this, 0, 0, 1); } else { visibilityTracker.removeView(this); setMraidViewable(false); } } public void setVisibilityChangedListener(OnVisibilityChangedListener onVisibilityChangedListener) { this.f19461k = onVisibilityChangedListener; } } public class a extends WebChromeClient { public a() { } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { MraidBridgeListener mraidBridgeListener = MraidBridge.this.f19456b; return mraidBridgeListener != null ? mraidBridgeListener.onConsoleMessage(consoleMessage) : super.onConsoleMessage(consoleMessage); } @Override public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) { MraidBridgeListener mraidBridgeListener = MraidBridge.this.f19456b; return mraidBridgeListener != null ? mraidBridgeListener.onJsAlert(str2, jsResult) : super.onJsAlert(webView, str, str2, jsResult); } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) { super.onShowCustomView(view, customViewCallback); } } public class b implements View.OnTouchListener { public b() { } @Override public boolean onTouch(View view, MotionEvent motionEvent) { MraidBridge.this.f19458d.onTouchEvent(motionEvent); int action = motionEvent.getAction(); if ((action != 0 && action != 1) || view.hasFocus()) { return false; } view.requestFocus(); return false; } } public class c implements MraidWebView.OnVisibilityChangedListener { public c() { } @Override public void onVisibilityChanged(boolean z10) { MraidBridgeListener mraidBridgeListener = MraidBridge.this.f19456b; if (mraidBridgeListener != null) { mraidBridgeListener.onVisibilityChanged(z10); } } } public class d extends MraidWebViewClient { public d() { } @Override public void onPageFinished(WebView webView, String str) { if (webView instanceof BaseWebViewViewability) { ((BaseWebViewViewability) webView).setPageLoaded(); } MraidBridge mraidBridge = MraidBridge.this; if (mraidBridge.f19459e) { return; } mraidBridge.f19459e = true; MraidBridgeListener mraidBridgeListener = mraidBridge.f19456b; if (mraidBridgeListener != null) { mraidBridgeListener.onPageLoaded(); } } @Override public void onReceivedError(WebView webView, int i10, String str, String str2) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, i.c.a("Error: ", str)); super.onReceivedError(webView, i10, str, str2); } @Override public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) { MraidBridge mraidBridge = MraidBridge.this; Objects.requireNonNull(mraidBridge); MoPubErrorCode moPubErrorCode = (renderProcessGoneDetail == null || !renderProcessGoneDetail.didCrash()) ? MoPubErrorCode.RENDER_PROCESS_GONE_UNSPECIFIED : MoPubErrorCode.RENDER_PROCESS_GONE_WITH_CRASH; MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, moPubErrorCode); mraidBridge.c(); MraidBridgeListener mraidBridgeListener = mraidBridge.f19456b; if (mraidBridgeListener != null) { mraidBridgeListener.onRenderProcessGone(moPubErrorCode); } return true; } @Override public boolean shouldOverrideUrlLoading(WebView webView, String str) { MraidBridgeListener mraidBridgeListener; MraidBridge mraidBridge = MraidBridge.this; Objects.requireNonNull(mraidBridge); try { new URI(str); Uri parse = Uri.parse(str); String scheme = parse.getScheme(); String host = parse.getHost(); if (!"mopub".equals(scheme)) { ViewGestureDetector viewGestureDetector = mraidBridge.f19458d; if ((viewGestureDetector != null && viewGestureDetector.isClicked()) && !"mraid".equals(scheme)) { try { parse = Uri.parse("mraid://open?url=" + URLEncoder.encode(str, "UTF-8")); host = parse.getHost(); scheme = parse.getScheme(); } catch (UnsupportedEncodingException unused) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, i.c.a("Invalid MRAID URL encoding: ", str)); mraidBridge.d(MraidJavascriptCommand.OPEN, "Non-mraid URL is invalid"); return false; } } if (!"mraid".equals(scheme)) { return false; } try { for (MraidJavascriptCommand mraidJavascriptCommand : MraidJavascriptCommand.values()) { if (!mraidJavascriptCommand.f19497a.equals(host)) { } break; } break; mraidBridge.n(mraidJavascriptCommand, MoPubNetworkUtils.getQueryParamMap(parse)); } catch (IllegalArgumentException | se.a e10) { mraidBridge.d(mraidJavascriptCommand, e10.getMessage()); } mraidJavascriptCommand = MraidJavascriptCommand.UNSPECIFIED; StringBuilder a10 = android.support.v4.media.b.a("window.mraidbridge.nativeCallComplete("); a10.append(JSONObject.quote(mraidJavascriptCommand.f19497a)); a10.append(")"); mraidBridge.e(a10.toString()); } else if ("failLoad".equals(host) && mraidBridge.f19455a == PlacementType.INLINE && (mraidBridgeListener = mraidBridge.f19456b) != null) { mraidBridgeListener.onPageFailedToLoad(); } } catch (URISyntaxException unused2) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, i.c.a("Invalid MRAID URL: ", str)); mraidBridge.d(MraidJavascriptCommand.UNSPECIFIED, "Mraid command sent an invalid URL"); } return true; } } public static class e { public static final int[] f19469a; static { int[] iArr = new int[MraidJavascriptCommand.values().length]; f19469a = iArr; try { iArr[MraidJavascriptCommand.CLOSE.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { f19469a[MraidJavascriptCommand.RESIZE.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { f19469a[MraidJavascriptCommand.EXPAND.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { f19469a[MraidJavascriptCommand.OPEN.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } try { f19469a[MraidJavascriptCommand.SET_ORIENTATION_PROPERTIES.ordinal()] = 5; } catch (NoSuchFieldError unused5) { } try { f19469a[MraidJavascriptCommand.PLAY_VIDEO.ordinal()] = 6; } catch (NoSuchFieldError unused6) { } try { f19469a[MraidJavascriptCommand.STORE_PICTURE.ordinal()] = 7; } catch (NoSuchFieldError unused7) { } try { f19469a[MraidJavascriptCommand.CREATE_CALENDAR_EVENT.ordinal()] = 8; } catch (NoSuchFieldError unused8) { } try { f19469a[MraidJavascriptCommand.UNSPECIFIED.ordinal()] = 9; } catch (NoSuchFieldError unused9) { } } } public MraidBridge(PlacementType placementType) { new MraidNativeCommandHandler(); this.f19460f = new d(); this.f19455a = placementType; } public static boolean k(String str) { if ("true".equals(str)) { return true; } if ("false".equals(str)) { return false; } throw new se.a(i.c.a("Invalid boolean parameter: ", str)); } public void a(MraidWebView mraidWebView) { this.f19457c = mraidWebView; mraidWebView.getSettings().setJavaScriptEnabled(true); if (this.f19455a == PlacementType.INTERSTITIAL) { mraidWebView.getSettings().setMediaPlaybackRequiresUserGesture(false); } this.f19457c.setScrollContainer(false); this.f19457c.setVerticalScrollBarEnabled(false); this.f19457c.setHorizontalScrollBarEnabled(false); this.f19457c.setBackgroundColor(0); this.f19457c.setWebViewClient(this.f19460f); this.f19457c.setWebChromeClient(new a()); this.f19458d = new ViewGestureDetector(this.f19457c.getContext()); this.f19457c.setOnTouchListener(new b()); this.f19457c.setVisibilityChangedListener(new c()); } public final int b(int i10, int i11, int i12) { if (i10 < i11 || i10 > i12) { throw new se.a(android.support.v4.media.a.a("Integer parameter out of range: ", i10)); } return i10; } public void c() { MraidWebView mraidWebView = this.f19457c; if (mraidWebView != null) { mraidWebView.destroy(); this.f19457c = null; } } public final void d(MraidJavascriptCommand mraidJavascriptCommand, String str) { StringBuilder a10 = android.support.v4.media.b.a("window.mraidbridge.notifyErrorEvent("); a10.append(JSONObject.quote(mraidJavascriptCommand.f19497a)); a10.append(", "); a10.append(JSONObject.quote(str)); a10.append(")"); e(a10.toString()); } public void e(String str) { if (this.f19457c == null) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, i.c.a("Attempted to inject Javascript into MRAID WebView while was not attached:\n\t", str)); return; } MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, i.c.a("Injecting Javascript into MRAID WebView:\n\t", str)); this.f19457c.loadUrl("javascript:" + str); } public boolean f() { return this.f19457c != null; } public void g(PlacementType placementType) { StringBuilder a10 = android.support.v4.media.b.a("mraidbridge.setPlacementType("); a10.append(JSONObject.quote(placementType.toString().toLowerCase(Locale.US))); a10.append(")"); e(a10.toString()); } public void h(boolean z10, boolean z11, boolean z12, boolean z13, boolean z14) { e("mraidbridge.setSupports(" + z10 + "," + z11 + "," + z12 + "," + z13 + "," + z14 + ")"); } public void i(ViewState viewState) { StringBuilder a10 = android.support.v4.media.b.a("mraidbridge.setState("); a10.append(JSONObject.quote(viewState.toJavascriptString())); a10.append(")"); e(a10.toString()); } public void j(boolean z10) { e("mraidbridge.setIsViewable(" + z10 + ")"); } public final int l(String str) { try { return Integer.parseInt(str, 10); } catch (NumberFormatException unused) { throw new se.a(i.c.a("Invalid numeric parameter: ", str)); } } public final URI m(String str) { if (str == null) { throw new se.a("Parameter cannot be null"); } try { return new URI(str); } catch (URISyntaxException unused) { throw new se.a(i.c.a("Invalid URL parameter: ", str)); } } @VisibleForTesting public void n(MraidJavascriptCommand mraidJavascriptCommand, Map<String, String> map) { com.mopub.mraid.a aVar; if (mraidJavascriptCommand.a(this.f19455a)) { ViewGestureDetector viewGestureDetector = this.f19458d; if (!(viewGestureDetector != null && viewGestureDetector.isClicked())) { throw new se.a("Cannot execute this command unless the user clicks"); } } if (this.f19456b == null) { throw new se.a("Invalid state to execute this command"); } if (this.f19457c == null) { throw new se.a("The current WebView is being destroyed"); } switch (e.f19469a[mraidJavascriptCommand.ordinal()]) { case 1: this.f19456b.onClose(); return; case 2: int l10 = l(map.get("width")); b(l10, 0, 100000); int l11 = l(map.get("height")); b(l11, 0, 100000); int l12 = l(map.get("offsetX")); b(l12, -100000, 100000); int l13 = l(map.get("offsetY")); b(l13, -100000, 100000); String str = map.get("allowOffscreen"); this.f19456b.onResize(l10, l11, l12, l13, str == null ? true : k(str)); return; case 3: String str2 = map.get(EpgSource.EPG_URL); this.f19456b.onExpand(str2 != null ? m(str2) : null); return; case 4: this.f19456b.onOpen(m(map.get(EpgSource.EPG_URL))); return; case 5: boolean k10 = k(map.get("allowOrientationChange")); String str3 = map.get("forceOrientation"); if ("portrait".equals(str3)) { aVar = com.mopub.mraid.a.PORTRAIT; } else if ("landscape".equals(str3)) { aVar = com.mopub.mraid.a.LANDSCAPE; } else { if (!"none".equals(str3)) { throw new se.a(i.c.a("Invalid orientation: ", str3)); } aVar = com.mopub.mraid.a.NONE; } this.f19456b.onSetOrientationProperties(k10, aVar); return; case 6: case 7: case 8: throw new se.a("Unsupported MRAID Javascript command"); case 9: throw new se.a("Unspecified MRAID Javascript command"); default: return; } } public void notifyScreenMetrics(se.e eVar) { StringBuilder a10 = android.support.v4.media.b.a("mraidbridge.setScreenSize("); a10.append(p(eVar.f40465c)); a10.append(");mraidbridge.setMaxSize("); a10.append(p(eVar.f40467e)); a10.append(");mraidbridge.setCurrentPosition("); a10.append(o(eVar.f40469g)); a10.append(");mraidbridge.setDefaultPosition("); a10.append(o(eVar.f40471i)); a10.append(")"); e(a10.toString()); e("mraidbridge.notifySizeChangeEvent(" + p(eVar.f40469g) + ")"); } public final String o(Rect rect) { return rect.left + "," + rect.top + "," + rect.width() + "," + rect.height(); } public final String p(Rect rect) { return rect.width() + "," + rect.height(); } public void setContentHtml(String str) { MraidWebView mraidWebView = this.f19457c; if (mraidWebView == null) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, "MRAID bridge called setContentHtml before WebView was attached"); return; } this.f19459e = false; StringBuilder sb2 = new StringBuilder(); sb2.append(Networking.getScheme()); sb2.append("://"); mraidWebView.loadDataWithBaseURL(w.a.a(sb2, Constants.HOST, "/"), str, "text/html", "UTF-8", null); } public void setContentUrl(String str) { MraidWebView mraidWebView = this.f19457c; if (mraidWebView == null) { MoPubLog.log(MoPubLog.SdkLogEvent.CUSTOM, "MRAID bridge called setContentHtml while WebView was not attached"); } else { this.f19459e = false; mraidWebView.loadUrl(str); } } }