/*
- * Copyright © 2018-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2018-2019,2021 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
package com.stoutner.privacybrowser.helpers;
+import android.app.Activity;
import android.net.http.SslCertificate;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
+import com.stoutner.privacybrowser.R;
+import com.stoutner.privacybrowser.activities.MainWebViewActivity;
+import com.stoutner.privacybrowser.definitions.PendingDialog;
import com.stoutner.privacybrowser.dialogs.PinnedMismatchDialog;
import com.stoutner.privacybrowser.views.NestedScrollWebView;
import java.util.Date;
public class CheckPinnedMismatchHelper {
- public static void checkPinnedMismatch(FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) {
+ public static void checkPinnedMismatch(Activity activity, FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) {
// Initialize the current SSL certificate variables.
String currentWebsiteIssuedToCName = "";
String currentWebsiteIssuedToOName = "";
// Get a handle for the pinned mismatch alert dialog.
DialogFragment pinnedMismatchDialogFragment = PinnedMismatchDialog.displayDialog(nestedScrollWebView.getWebViewFragmentId());
- // Show the pinned mismatch alert dialog.
- pinnedMismatchDialogFragment.show(fragmentManager, "Pinned Mismatch");
+ // Try to show the dialog. Sometimes the window is not active.
+ try {
+ // Show the pinned mismatch alert dialog.
+ pinnedMismatchDialogFragment.show(fragmentManager, activity.getString(R.string.pinned_mismatch));
+ } catch (Exception exception) {
+ // Add the dialog to the pending dialog array list. It will be displayed in `onStart()`.
+ MainWebViewActivity.pendingDialogsArrayList.add(new PendingDialog(pinnedMismatchDialogFragment, activity.getString(R.string.pinned_mismatch)));
+ }
}
}
}
\ No newline at end of file