Skip to content

Commit 02ba2ac

Browse files
MyidShinjavifernandez
authored andcommitted
[WebPayments] fix DCHECK error & implement close()
The PaymentUiService should not re-use the WindowAndroid instance from the original WebContents and, instead, must create a new one for the main activity. Additionally, this change also implements the close() method, so that we can properly destroy the newly created WebContent instance for the payment handler.
1 parent ae054ed commit 02ba2ac

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Diff for: wolvic/java/org/chromium/wolvic/payments/ui/WolvicPaymentUiService.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import org.chromium.content_public.browser.LoadUrlParams;
2626
import org.chromium.content_public.browser.WebContents;
27+
import org.chromium.ui.base.ActivityWindowAndroid;
28+
import org.chromium.ui.base.IntentRequestTracker;
2729
import org.chromium.ui.base.ViewAndroidDelegate;
2830
import org.chromium.ui.base.WindowAndroid;
2931
import org.chromium.url.GURL;
@@ -60,6 +62,7 @@ public class WolvicPaymentUiService {
6062
private List<PaymentApp> mPaymentApps;
6163

6264
private static final String TAG = "WolvicPaymentUiService";
65+
private Runnable mHider;
6366

6467
/** The delegate of this class. */
6568
// TODO(jfernandez): Define the a complete delegate
@@ -250,11 +253,14 @@ public void initialize(PaymentDetails details) {
250253
* successful; null if failed.
251254
*/
252255
public @Nullable WebContents showPaymentHandlerUI(GURL url) {
253-
WindowAndroid windowAndroid = mWebContents.getTopLevelNativeWindow();
254-
if (windowAndroid == null) return null;
255-
Activity activity = windowAndroid.getActivity().get();
256+
if (mWebContents.getTopLevelNativeWindow() == null) return null;
257+
258+
Activity activity = mWebContents.getTopLevelNativeWindow().getActivity().get();
256259
if (activity == null) return null;
257260

261+
ActivityWindowAndroid windowAndroid = new ActivityWindowAndroid(activity, false,
262+
IntentRequestTracker.createFromActivity(activity));
263+
258264
WebContents paymentHandlerWebContents = createWebContents(mIsOffTheRecord);
259265
if (paymentHandlerWebContents == null)
260266
return null;
@@ -274,6 +280,9 @@ public void initialize(PaymentDetails details) {
274280

275281
mWebContents.notifyOnCreateNewPaymentHandler(paymentHandlerWebContents);
276282

283+
mHider = () -> {
284+
paymentHandlerWebContents.destroy();
285+
};
277286
return paymentHandlerWebContents;
278287
}
279288

@@ -330,7 +339,8 @@ public void close() {
330339
assert !mHasClosed;
331340
mHasClosed = true;
332341

333-
// TODO(jfernandez): Implement properly the "close" logic.
334-
342+
if (mHider == null) return;
343+
mHider.run();
344+
mHider = null;
335345
}
336346
}

0 commit comments

Comments
 (0)