jimu-decompiled/sources/com/facebook/internal/WebDialog.java
2025-05-13 19:24:51 +02:00

648 lines
25 KiB
Java

package com.facebook.internal;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.facebook.AccessToken;
import com.facebook.FacebookDialogException;
import com.facebook.FacebookException;
import com.facebook.FacebookGraphResponseException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.FacebookRequestError;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.R$drawable;
import com.facebook.R$string;
import com.facebook.share.internal.ShareInternalUtility;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import org.json.JSONArray;
import org.json.JSONObject;
/* loaded from: classes.dex */
public class WebDialog extends Dialog {
private String a;
private String b;
private OnCompleteListener c;
private WebView d;
private ProgressDialog e;
private ImageView f;
private FrameLayout g;
private UploadStagingResourcesTask h;
private boolean i;
private boolean j;
private boolean k;
public static class Builder {
private Context a;
private String b;
private String c;
private int d;
private OnCompleteListener e;
private Bundle f;
private AccessToken g;
public Builder(Context context, String str, Bundle bundle) {
this.g = AccessToken.getCurrentAccessToken();
if (this.g == null) {
String c = Utility.c(context);
if (c == null) {
throw new FacebookException("Attempted to create a builder without a valid access token or a valid default Application ID.");
}
this.b = c;
}
a(context, str, bundle);
}
public Builder a(OnCompleteListener onCompleteListener) {
this.e = onCompleteListener;
return this;
}
public String b() {
return this.b;
}
public Context c() {
return this.a;
}
public OnCompleteListener d() {
return this.e;
}
public Bundle e() {
return this.f;
}
public int f() {
return this.d;
}
public WebDialog a() {
AccessToken accessToken = this.g;
if (accessToken != null) {
this.f.putString("app_id", accessToken.getApplicationId());
this.f.putString(AccessToken.ACCESS_TOKEN_KEY, this.g.getToken());
} else {
this.f.putString("app_id", this.b);
}
return new WebDialog(this.a, this.c, this.f, this.d, this.e);
}
public Builder(Context context, String str, String str2, Bundle bundle) {
str = str == null ? Utility.c(context) : str;
Validate.a(str, "applicationId");
this.b = str;
a(context, str2, bundle);
}
private void a(Context context, String str, Bundle bundle) {
this.a = context;
this.c = str;
if (bundle != null) {
this.f = bundle;
} else {
this.f = new Bundle();
}
}
}
private class DialogWebViewClient extends WebViewClient {
private DialogWebViewClient() {
}
@Override // android.webkit.WebViewClient
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
if (!WebDialog.this.j) {
WebDialog.this.e.dismiss();
}
WebDialog.this.g.setBackgroundColor(0);
WebDialog.this.d.setVisibility(0);
WebDialog.this.f.setVisibility(0);
WebDialog.this.k = true;
}
@Override // android.webkit.WebViewClient
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
Utility.a("FacebookSDK.WebDialog", "Webview loading URL: " + str);
super.onPageStarted(webView, str, bitmap);
if (WebDialog.this.j) {
return;
}
WebDialog.this.e.show();
}
@Override // android.webkit.WebViewClient
public void onReceivedError(WebView webView, int i, String str, String str2) {
super.onReceivedError(webView, i, str, str2);
WebDialog.this.a(new FacebookDialogException(str, i, str2));
}
@Override // android.webkit.WebViewClient
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
super.onReceivedSslError(webView, sslErrorHandler, sslError);
sslErrorHandler.cancel();
WebDialog.this.a(new FacebookDialogException(null, -11, null));
}
/* JADX WARN: Removed duplicated region for block: B:30:0x0090 */
/* JADX WARN: Removed duplicated region for block: B:31:0x0096 */
@Override // android.webkit.WebViewClient
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public boolean shouldOverrideUrlLoading(android.webkit.WebView r6, java.lang.String r7) {
/*
r5 = this;
java.lang.StringBuilder r6 = new java.lang.StringBuilder
r6.<init>()
java.lang.String r0 = "Redirect URL: "
r6.append(r0)
r6.append(r7)
java.lang.String r6 = r6.toString()
java.lang.String r0 = "FacebookSDK.WebDialog"
com.facebook.internal.Utility.a(r0, r6)
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this
java.lang.String r6 = com.facebook.internal.WebDialog.a(r6)
boolean r6 = r7.startsWith(r6)
r0 = 1
if (r6 == 0) goto La6
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this
android.os.Bundle r6 = r6.a(r7)
java.lang.String r7 = "error"
java.lang.String r7 = r6.getString(r7)
if (r7 != 0) goto L37
java.lang.String r7 = "error_type"
java.lang.String r7 = r6.getString(r7)
L37:
java.lang.String r1 = "error_msg"
java.lang.String r1 = r6.getString(r1)
if (r1 != 0) goto L45
java.lang.String r1 = "error_message"
java.lang.String r1 = r6.getString(r1)
L45:
if (r1 != 0) goto L4d
java.lang.String r1 = "error_description"
java.lang.String r1 = r6.getString(r1)
L4d:
java.lang.String r2 = "error_code"
java.lang.String r2 = r6.getString(r2)
boolean r3 = com.facebook.internal.Utility.c(r2)
r4 = -1
if (r3 != 0) goto L5f
int r2 = java.lang.Integer.parseInt(r2) // Catch: java.lang.NumberFormatException -> L5f
goto L60
L5f:
r2 = -1
L60:
boolean r3 = com.facebook.internal.Utility.c(r7)
if (r3 == 0) goto L74
boolean r3 = com.facebook.internal.Utility.c(r1)
if (r3 == 0) goto L74
if (r2 != r4) goto L74
com.facebook.internal.WebDialog r7 = com.facebook.internal.WebDialog.this
r7.a(r6)
goto La5
L74:
if (r7 == 0) goto L8c
java.lang.String r6 = "access_denied"
boolean r6 = r7.equals(r6)
if (r6 != 0) goto L86
java.lang.String r6 = "OAuthAccessDeniedException"
boolean r6 = r7.equals(r6)
if (r6 == 0) goto L8c
L86:
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this
r6.cancel()
goto La5
L8c:
r6 = 4201(0x1069, float:5.887E-42)
if (r2 != r6) goto L96
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this
r6.cancel()
goto La5
L96:
com.facebook.FacebookRequestError r6 = new com.facebook.FacebookRequestError
r6.<init>(r2, r7, r1)
com.facebook.internal.WebDialog r7 = com.facebook.internal.WebDialog.this
com.facebook.FacebookServiceException r2 = new com.facebook.FacebookServiceException
r2.<init>(r6, r1)
r7.a(r2)
La5:
return r0
La6:
java.lang.String r6 = "fbconnect://cancel"
boolean r6 = r7.startsWith(r6)
if (r6 == 0) goto Lb4
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this
r6.cancel()
return r0
Lb4:
java.lang.String r6 = "touch"
boolean r6 = r7.contains(r6)
r1 = 0
if (r6 == 0) goto Lbe
return r1
Lbe:
com.facebook.internal.WebDialog r6 = com.facebook.internal.WebDialog.this // Catch: android.content.ActivityNotFoundException -> Ld3
android.content.Context r6 = r6.getContext() // Catch: android.content.ActivityNotFoundException -> Ld3
android.content.Intent r2 = new android.content.Intent // Catch: android.content.ActivityNotFoundException -> Ld3
java.lang.String r3 = "android.intent.action.VIEW"
android.net.Uri r7 = android.net.Uri.parse(r7) // Catch: android.content.ActivityNotFoundException -> Ld3
r2.<init>(r3, r7) // Catch: android.content.ActivityNotFoundException -> Ld3
r6.startActivity(r2) // Catch: android.content.ActivityNotFoundException -> Ld3
return r0
Ld3:
return r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.facebook.internal.WebDialog.DialogWebViewClient.shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String):boolean");
}
}
public interface OnCompleteListener {
void a(Bundle bundle, FacebookException facebookException);
}
private class UploadStagingResourcesTask extends AsyncTask<Void, Void, String[]> {
private String a;
private Bundle b;
private Exception[] c;
UploadStagingResourcesTask(String str, Bundle bundle) {
this.a = str;
this.b = bundle;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // android.os.AsyncTask
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public String[] doInBackground(Void... voidArr) {
String[] stringArray = this.b.getStringArray("media");
final String[] strArr = new String[stringArray.length];
this.c = new Exception[stringArray.length];
final CountDownLatch countDownLatch = new CountDownLatch(stringArray.length);
ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue();
AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
for (final int i = 0; i < stringArray.length; i++) {
try {
if (isCancelled()) {
Iterator it = concurrentLinkedQueue.iterator();
while (it.hasNext()) {
((AsyncTask) it.next()).cancel(true);
}
return null;
}
Uri parse = Uri.parse(stringArray[i]);
if (Utility.e(parse)) {
strArr[i] = parse.toString();
countDownLatch.countDown();
} else {
concurrentLinkedQueue.add(ShareInternalUtility.a(currentAccessToken, parse, new GraphRequest.Callback() { // from class: com.facebook.internal.WebDialog.UploadStagingResourcesTask.1
@Override // com.facebook.GraphRequest.Callback
public void a(GraphResponse graphResponse) {
FacebookRequestError a;
try {
a = graphResponse.a();
} catch (Exception e) {
UploadStagingResourcesTask.this.c[i] = e;
}
if (a != null) {
String errorMessage = a.getErrorMessage();
if (errorMessage == null) {
errorMessage = "Error staging photo.";
}
throw new FacebookGraphResponseException(graphResponse, errorMessage);
}
JSONObject b = graphResponse.b();
if (b == null) {
throw new FacebookException("Error staging photo.");
}
String optString = b.optString("uri");
if (optString == null) {
throw new FacebookException("Error staging photo.");
}
strArr[i] = optString;
countDownLatch.countDown();
}
}).b());
}
} catch (Exception unused) {
Iterator it2 = concurrentLinkedQueue.iterator();
while (it2.hasNext()) {
((AsyncTask) it2.next()).cancel(true);
}
return null;
}
}
countDownLatch.await();
return strArr;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // android.os.AsyncTask
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public void onPostExecute(String[] strArr) {
WebDialog.this.e.dismiss();
for (Exception exc : this.c) {
if (exc != null) {
WebDialog.this.a(exc);
return;
}
}
if (strArr == null) {
WebDialog.this.a(new FacebookException("Failed to stage photos for web dialog"));
return;
}
List asList = Arrays.asList(strArr);
if (asList.contains(null)) {
WebDialog.this.a(new FacebookException("Failed to stage photos for web dialog"));
return;
}
Utility.a(this.b, "media", new JSONArray((Collection) asList));
WebDialog.this.a = Utility.a(ServerProtocol.b(), FacebookSdk.j() + "/dialog/" + this.a, this.b).toString();
WebDialog.this.a((WebDialog.this.f.getDrawable().getIntrinsicWidth() / 2) + 1);
}
}
public WebDialog(Context context, String str) {
this(context, str, FacebookSdk.m());
}
private int a(int i, float f, int i2, int i3) {
int i4 = (int) (i / f);
double d = 0.5d;
if (i4 <= i2) {
d = 1.0d;
} else if (i4 < i3) {
d = 0.5d + (((i3 - i4) / (i3 - i2)) * 0.5d);
}
return (int) (i * d);
}
@Override // android.app.Dialog, android.content.DialogInterface
public void cancel() {
if (this.c == null || this.i) {
return;
}
a(new FacebookOperationCanceledException());
}
@Override // android.app.Dialog, android.content.DialogInterface
public void dismiss() {
ProgressDialog progressDialog;
WebView webView = this.d;
if (webView != null) {
webView.stopLoading();
}
if (!this.j && (progressDialog = this.e) != null && progressDialog.isShowing()) {
this.e.dismiss();
}
super.dismiss();
}
@Override // android.app.Dialog, android.view.Window.Callback
public void onAttachedToWindow() {
this.j = false;
super.onAttachedToWindow();
}
@Override // android.app.Dialog
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
this.e = new ProgressDialog(getContext());
this.e.requestWindowFeature(1);
this.e.setMessage(getContext().getString(R$string.com_facebook_loading));
this.e.setCanceledOnTouchOutside(false);
this.e.setOnCancelListener(new DialogInterface.OnCancelListener() { // from class: com.facebook.internal.WebDialog.1
@Override // android.content.DialogInterface.OnCancelListener
public void onCancel(DialogInterface dialogInterface) {
WebDialog.this.cancel();
}
});
requestWindowFeature(1);
this.g = new FrameLayout(getContext());
d();
getWindow().setGravity(17);
getWindow().setSoftInputMode(16);
e();
if (this.a != null) {
a((this.f.getDrawable().getIntrinsicWidth() / 2) + 1);
}
this.g.addView(this.f, new ViewGroup.LayoutParams(-2, -2));
setContentView(this.g);
}
@Override // android.app.Dialog, android.view.Window.Callback
public void onDetachedFromWindow() {
this.j = true;
super.onDetachedFromWindow();
}
@Override // android.app.Dialog, android.view.KeyEvent.Callback
public boolean onKeyDown(int i, KeyEvent keyEvent) {
if (i == 4) {
cancel();
}
return super.onKeyDown(i, keyEvent);
}
@Override // android.app.Dialog
protected void onStart() {
super.onStart();
UploadStagingResourcesTask uploadStagingResourcesTask = this.h;
if (uploadStagingResourcesTask == null || uploadStagingResourcesTask.getStatus() != AsyncTask.Status.PENDING) {
d();
} else {
this.h.execute(new Void[0]);
this.e.show();
}
}
@Override // android.app.Dialog
protected void onStop() {
UploadStagingResourcesTask uploadStagingResourcesTask = this.h;
if (uploadStagingResourcesTask != null) {
uploadStagingResourcesTask.cancel(true);
this.e.dismiss();
}
super.onStop();
}
public WebDialog(Context context, String str, int i) {
super(context, i == 0 ? FacebookSdk.m() : i);
this.b = "fbconnect://success";
this.i = false;
this.j = false;
this.k = false;
this.a = str;
}
private void e() {
this.f = new ImageView(getContext());
this.f.setOnClickListener(new View.OnClickListener() { // from class: com.facebook.internal.WebDialog.2
@Override // android.view.View.OnClickListener
public void onClick(View view) {
WebDialog.this.cancel();
}
});
this.f.setImageDrawable(getContext().getResources().getDrawable(R$drawable.com_facebook_close));
this.f.setVisibility(4);
}
protected void b(String str) {
this.b = str;
}
protected boolean c() {
return this.k;
}
public void d() {
Display defaultDisplay = ((WindowManager) getContext().getSystemService("window")).getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
defaultDisplay.getMetrics(displayMetrics);
int i = displayMetrics.widthPixels;
int i2 = displayMetrics.heightPixels;
if (i >= i2) {
i = i2;
}
int i3 = displayMetrics.widthPixels;
int i4 = displayMetrics.heightPixels;
if (i3 < i4) {
i3 = i4;
}
getWindow().setLayout(Math.min(a(i, displayMetrics.density, 480, 800), displayMetrics.widthPixels), Math.min(a(i3, displayMetrics.density, 800, 1280), displayMetrics.heightPixels));
}
protected boolean b() {
return this.i;
}
public void a(OnCompleteListener onCompleteListener) {
this.c = onCompleteListener;
}
protected Bundle a(String str) {
Uri parse = Uri.parse(str);
Bundle d = Utility.d(parse.getQuery());
d.putAll(Utility.d(parse.getFragment()));
return d;
}
public WebDialog(Context context, String str, Bundle bundle, int i, OnCompleteListener onCompleteListener) {
super(context, i == 0 ? FacebookSdk.m() : i);
this.b = "fbconnect://success";
this.i = false;
this.j = false;
this.k = false;
bundle = bundle == null ? new Bundle() : bundle;
bundle.putString("redirect_uri", "fbconnect://success");
bundle.putString("display", "touch");
bundle.putString("sdk", String.format(Locale.ROOT, "android-%s", FacebookSdk.l()));
this.c = onCompleteListener;
if (str.equals("share") && bundle.containsKey("media")) {
this.h = new UploadStagingResourcesTask(str, bundle);
return;
}
this.a = Utility.a(ServerProtocol.b(), FacebookSdk.j() + "/dialog/" + str, bundle).toString();
}
protected WebView a() {
return this.d;
}
protected void a(Bundle bundle) {
OnCompleteListener onCompleteListener = this.c;
if (onCompleteListener == null || this.i) {
return;
}
this.i = true;
onCompleteListener.a(bundle, null);
dismiss();
}
protected void a(Throwable th) {
FacebookException facebookException;
if (this.c == null || this.i) {
return;
}
this.i = true;
if (th instanceof FacebookException) {
facebookException = (FacebookException) th;
} else {
facebookException = new FacebookException(th);
}
this.c.a(null, facebookException);
dismiss();
}
/* JADX INFO: Access modifiers changed from: private */
@SuppressLint({"SetJavaScriptEnabled"})
public void a(int i) {
LinearLayout linearLayout = new LinearLayout(getContext());
this.d = new WebView(this, getContext().getApplicationContext()) { // from class: com.facebook.internal.WebDialog.3
@Override // android.webkit.WebView, android.view.View
public void onWindowFocusChanged(boolean z) {
try {
super.onWindowFocusChanged(z);
} catch (NullPointerException unused) {
}
}
};
this.d.setVerticalScrollBarEnabled(false);
this.d.setHorizontalScrollBarEnabled(false);
this.d.setWebViewClient(new DialogWebViewClient());
this.d.getSettings().setJavaScriptEnabled(true);
this.d.loadUrl(this.a);
this.d.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
this.d.setVisibility(4);
this.d.getSettings().setSavePassword(false);
this.d.getSettings().setSaveFormData(false);
this.d.setFocusable(true);
this.d.setFocusableInTouchMode(true);
this.d.setOnTouchListener(new View.OnTouchListener(this) { // from class: com.facebook.internal.WebDialog.4
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
if (view.hasFocus()) {
return false;
}
view.requestFocus();
return false;
}
});
linearLayout.setPadding(i, i, i, i);
linearLayout.addView(this.d);
linearLayout.setBackgroundColor(-872415232);
this.g.addView(linearLayout);
}
}