Skip to content

Commit

Permalink
fix DCHECK error & implement close()
Browse files Browse the repository at this point in the history
  • Loading branch information
MyidShin authored and javifernandez committed Dec 3, 2024
1 parent fbd6bcd commit 31e4858
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.IntentRequestTracker;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.url.GURL;
Expand Down Expand Up @@ -56,6 +58,7 @@ public class WolvicPaymentUiService {
private List<PaymentApp> mPaymentApps;

private static final String TAG = "WolvicPaymentUiService";
private Runnable mHider;

/** The delegate of this class. */
// TODO(jfernandez): Define the a complete delegate
Expand Down Expand Up @@ -246,11 +249,14 @@ public void initialize(PaymentDetails details) {
* successful; null if failed.
*/
public @Nullable WebContents showPaymentHandlerUI(GURL url) {
WindowAndroid windowAndroid = mWebContents.getTopLevelNativeWindow();
if (windowAndroid == null) return null;
Activity activity = windowAndroid.getActivity().get();
if (mWebContents.getTopLevelNativeWindow() == null) return null;

Activity activity = mWebContents.getTopLevelNativeWindow().getActivity().get();
if (activity == null) return null;

ActivityWindowAndroid windowAndroid = new ActivityWindowAndroid(activity, false,
IntentRequestTracker.createFromActivity(activity));

WebContents paymentHandlerWebContents = createWebContents(mIsOffTheRecord);
if (paymentHandlerWebContents == null)
return null;
Expand All @@ -270,6 +276,9 @@ public void initialize(PaymentDetails details) {

mWebContents.notifyOnCreateNewPaymentHandler(paymentHandlerWebContents);

mHider = () -> {
paymentHandlerWebContents.destroy();
};
return paymentHandlerWebContents;
}

Expand Down Expand Up @@ -328,7 +337,8 @@ public void close() {
assert !mHasClosed;
mHasClosed = true;

// TODO(jfernandez): Implement properly the "close" logic.

if (mHider == null) return;
mHider.run();
mHider = null;
}
}

0 comments on commit 31e4858

Please sign in to comment.