Commit 892829de authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[WebLayer] Pass only need-to-know info through parameters.

Before the CL, for the BPRService implementation methods in CPRService,
they often called PRService's getters for certain values.

This CL simplified this as BPRService passing the getter values to
CPRService.

This would make CPRService depend less on the
concrete object PRService, and more on the BPRService interface.

Bug: 1025619
Change-Id: I2b819fd3c31d992cbcd309fcaf23aaf7c490d1eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543835
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828399}
parent 685f5048
......@@ -26,6 +26,7 @@ import org.chromium.components.payments.JourneyLogger;
import org.chromium.components.payments.MethodStrings;
import org.chromium.components.payments.PackageManagerDelegate;
import org.chromium.components.payments.PaymentApp;
import org.chromium.components.payments.PaymentAppFactoryDelegate;
import org.chromium.components.payments.PaymentAppService;
import org.chromium.components.payments.PaymentAppType;
import org.chromium.components.payments.PaymentDetailsUpdateServiceHelper;
......@@ -187,7 +188,8 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
public void addPaymentAppFactories(PaymentAppService service) {
public void addPaymentAppFactories(
PaymentAppService service, PaymentAppFactoryDelegate delegate) {
String androidFactoryId = AndroidPaymentAppFactory.class.getName();
if (!service.containsFactory(androidFactoryId)) {
service.addUniqueFactory(new AndroidPaymentAppFactory(), androidFactoryId);
......@@ -204,7 +206,7 @@ public class ChromePaymentRequestService
if (AutofillPaymentAppFactory.canMakePayments(mSpec.getMethodData())) {
mPaymentUiService.setAutofillPaymentAppCreator(
AutofillPaymentAppFactory.createAppCreator(
/*delegate=*/mPaymentRequestService));
/*delegate=*/delegate));
}
}
......@@ -216,7 +218,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
public String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
PaymentOptions paymentOptions, boolean isUserGestureShow) {
assert mPaymentRequestService
!= null : "This method is only supposed to be called by mPaymentRequestService.";
// Send AppListReady signal when all apps are created and request.show() is called.
......@@ -226,9 +228,9 @@ public class ChromePaymentRequestService
}
// Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called.
mPaymentUiService.calculateWhetherShouldSkipShowingPaymentRequestUi(
mPaymentRequestService.isUserGestureShow(), mDelegate.skipUiForBasicCard(),
mSpec.getPaymentOptions(), mSpec.getMethodData().keySet());
mPaymentUiService.calculateWhetherShouldSkipShowingPaymentRequestUi(isUserGestureShow,
mDelegate.skipUiForBasicCard(), mSpec.getPaymentOptions(),
mSpec.getMethodData().keySet());
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
String error = mPaymentUiService.buildPaymentRequestUI(chromeActivity,
......@@ -260,7 +262,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
public String triggerPaymentAppUiSkipIfApplicable() {
public String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) {
// If we are skipping showing the Payment Request UI, we should call into the payment app
// immediately after we determine the apps are ready and UI is shown.
if ((mPaymentUiService.shouldSkipShowingPaymentRequestUi() || mSkipToGPayHelper != null)
......@@ -270,7 +272,7 @@ public class ChromePaymentRequestService
assert !mPaymentUiService.getPaymentMethodsSection().isEmpty();
assert mPaymentUiService.getPaymentRequestUI() != null;
if (isMinimalUiApplicable()) {
if (isMinimalUiApplicable(isUserGestureShow)) {
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
if (mPaymentUiService.triggerMinimalUI(chromeActivity, mSpec.getRawTotal(),
......@@ -305,10 +307,12 @@ public class ChromePaymentRequestService
return null;
}
/** @return Whether the minimal UI should be shown. */
private boolean isMinimalUiApplicable() {
if (!mPaymentRequestService.isUserGestureShow()
|| mPaymentUiService.getPaymentMethodsSection() == null
/**
* @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture.
* @return Whether the minimal UI should be shown.
*/
private boolean isMinimalUiApplicable(boolean isUserGestureShow) {
if (!isUserGestureShow || mPaymentUiService.getPaymentMethodsSection() == null
|| mPaymentUiService.getPaymentMethodsSection().getSize() != 1) {
return false;
}
......@@ -361,15 +365,11 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
@Nullable
public WebContents openPaymentHandlerWindow(GURL url) {
if (mPaymentRequestService == null) return null;
PaymentApp invokedPaymentApp = mPaymentRequestService.getInvokedPaymentApp();
assert invokedPaymentApp != null;
assert invokedPaymentApp.getPaymentAppType() == PaymentAppType.SERVICE_WORKER_APP;
public WebContents openPaymentHandlerWindow(
GURL url, boolean isOffTheRecord, long ukmSourceId) {
@Nullable
WebContents paymentHandlerWebContents = mPaymentUiService.showPaymentHandlerUI(
url, mPaymentRequestService.isOffTheRecord());
WebContents paymentHandlerWebContents =
mPaymentUiService.showPaymentHandlerUI(url, isOffTheRecord);
if (paymentHandlerWebContents != null) {
ServiceWorkerPaymentAppBridge.onOpeningPaymentAppWindow(
/*paymentRequestWebContents=*/mWebContents,
......@@ -377,7 +377,7 @@ public class ChromePaymentRequestService
// UKM for payment app origin should get recorded only when the origin of the invoked
// payment app is shown to the user.
mJourneyLogger.setPaymentAppUkmSourceId(invokedPaymentApp.getUkmSourceId());
mJourneyLogger.setPaymentAppUkmSourceId(ukmSourceId);
}
return paymentHandlerWebContents;
}
......@@ -410,7 +410,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
public String continueShow() {
public String continueShow(boolean isFinishedQueryingPaymentApps, boolean isUserGestureShow) {
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
......@@ -435,10 +435,10 @@ public class ChromePaymentRequestService
mSpec.getRawTotal().amount.value, false /*completed*/);
}
String error = triggerPaymentAppUiSkipIfApplicable();
String error = triggerPaymentAppUiSkipIfApplicable(isUserGestureShow);
if (error != null) return error;
if (mPaymentRequestService.isFinishedQueryingPaymentApps()
if (isFinishedQueryingPaymentApps
&& !mPaymentUiService.shouldSkipShowingPaymentRequestUi()) {
boolean providedInformationToPaymentRequestUI =
mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo();
......
......@@ -110,8 +110,9 @@ public interface BrowserPaymentRequest {
/**
* Adds the PaymentAppFactory(s) specified by the implementers to the given PaymentAppService.
* @param service The PaymentAppService to be added with the factories.
* @param delegate The delegate of payment app factory.
*/
void addPaymentAppFactories(PaymentAppService service);
void addPaymentAppFactories(PaymentAppService service, PaymentAppFactoryDelegate delegate);
default void onWhetherGooglePayBridgeEligible(boolean googlePayBridgeEligible,
WebContents webContents, PaymentMethodData[] rawMethodData) {}
......@@ -130,11 +131,12 @@ public interface BrowserPaymentRequest {
* updated details.
* @param total The total amount specified in the payment request.
* @param paymentOptions The payment options specified in the payment request.
* @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture.
* @return The error of the showing if any; null if success.
*/
@Nullable
default String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
PaymentOptions paymentOptions, boolean isUserGestureShow) {
return null;
}
......@@ -148,9 +150,10 @@ public interface BrowserPaymentRequest {
* Skips the app selector UI whether it is currently opened or not, and if applicable, invokes a
* payment app.
* @return The error if it fails; null otherwise.
* @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture.
*/
@Nullable
default String triggerPaymentAppUiSkipIfApplicable() {
default String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) {
return null;
}
......@@ -199,9 +202,12 @@ public interface BrowserPaymentRequest {
/**
* Opens a payment handler window and creates a WebContents with the given url to display in it.
* @param url The url of the page to be opened in the window.
* @param isOffTheRecord Whether the profile is off the record.
* @param ukmSourceId The ukm source id assigned to the payment app.
* @return The created WebContents.
*/
default WebContents openPaymentHandlerWindow(GURL url) {
default WebContents openPaymentHandlerWindow(
GURL url, boolean isOffTheRecord, long ukmSourceId) {
return null;
}
......@@ -214,9 +220,12 @@ public interface BrowserPaymentRequest {
* Continues the unfinished part of show() that was blocked for the payment details that was
* pending to be updated.
* @return The error if it fails; null otherwise.
* @param isFinishedQueryingPaymentApps Whether all payment app factories have been queried for
* their payment apps.
* @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture.
*/
@Nullable
default String continueShow() {
default String continueShow(boolean isFinishedQueryingPaymentApps, boolean isUserGestureShow) {
return null;
}
......
......@@ -356,7 +356,7 @@ public class PaymentRequestService
private void startPaymentAppService() {
PaymentAppService service = PaymentAppService.getInstance();
mBrowserPaymentRequest.addPaymentAppFactories(service);
mBrowserPaymentRequest.addPaymentAppFactories(service, /*delegate=*/this);
service.create(/*delegate=*/this);
}
......@@ -377,7 +377,11 @@ public class PaymentRequestService
@Nullable
public static WebContents openPaymentHandlerWindow(GURL url) {
if (sShowingPaymentRequest == null) return null;
return sShowingPaymentRequest.mBrowserPaymentRequest.openPaymentHandlerWindow(url);
PaymentApp invokedPaymentApp = sShowingPaymentRequest.mInvokedPaymentApp;
assert invokedPaymentApp != null;
assert invokedPaymentApp.getPaymentAppType() == PaymentAppType.SERVICE_WORKER_APP;
return sShowingPaymentRequest.mBrowserPaymentRequest.openPaymentHandlerWindow(
url, sShowingPaymentRequest.mIsOffTheRecord, invokedPaymentApp.getUkmSourceId());
}
/**
......@@ -668,14 +672,15 @@ public class PaymentRequestService
mPendingApps.clear();
if (isCurrentPaymentRequestShowing()) {
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions());
mSpec.getRawTotal(), mSpec.getPaymentOptions(), mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
}
}
String error = mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable();
String error =
mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable(mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
......@@ -948,14 +953,15 @@ public class PaymentRequestService
}
if (isFinishedQueryingPaymentApps()) {
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions());
mSpec.getRawTotal(), mSpec.getPaymentOptions(), mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
}
}
String error = mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable();
String error =
mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable(mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
......@@ -986,7 +992,8 @@ public class PaymentRequestService
mSpec.updateWith(details);
mIsShowWaitingForUpdatedDetails = false;
String error = mBrowserPaymentRequest.continueShow();
String error = mBrowserPaymentRequest.continueShow(
mIsFinishedQueryingPaymentApps, mIsUserGestureShow);
if (error != null) return error;
return null;
}
......
......@@ -5,6 +5,7 @@
package org.chromium.weblayer_private.payments;
import org.chromium.components.payments.BrowserPaymentRequest;
import org.chromium.components.payments.PaymentAppFactoryDelegate;
import org.chromium.components.payments.PaymentAppService;
import org.chromium.components.payments.PaymentRequestService;
import org.chromium.components.payments.PaymentRequestService.Delegate;
......@@ -50,8 +51,8 @@ public class WebLayerPaymentRequestService implements BrowserPaymentRequest {
}
@Override
public void addPaymentAppFactories(PaymentAppService service) {
public void addPaymentAppFactories(
PaymentAppService service, PaymentAppFactoryDelegate delegate) {
assert false : "Not implemented yet";
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment