Commit 5d862c79 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PRImpl] Move JourneyLogger into ComponentPRImpl

Change:
* Move JourneyLogger into ComponentPRImpl to facilitate the moving of
PRImpl#close() into ComponentPRImpl.
* Move the PRImpl.Delegate.isOffTheRecord interface method into
PRFactory. The value of isOffTheRecord will be set according to the
merchant page's state at PRFactory#createImpl().

Bug: 1102522

Change-Id: I46de04bdde95e48d8ecdf1c31cf2685fef213001
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341948
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796473}
parent 17506715
......@@ -116,7 +116,8 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
}
@Override
public boolean isOffTheRecord(@Nullable ChromeActivity activity) {
public boolean isOffTheRecord(WebContents webContents) {
ChromeActivity activity = ChromeActivity.fromWebContents(webContents);
return activity != null && activity.getCurrentTabModel().getProfile().isOffTheRecord();
}
......@@ -186,8 +187,11 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
delegate = new PaymentRequestDelegateImpl(mRenderFrameHost);
}
return new ComponentPaymentRequestImpl((componentPaymentRequest)
-> new PaymentRequestImpl(mRenderFrameHost,
componentPaymentRequest, delegate));
WebContents webContents = WebContentsStatics.fromRenderFrameHost(mRenderFrameHost);
return new ComponentPaymentRequestImpl(mRenderFrameHost,
delegate.isOffTheRecord(webContents),
(componentPaymentRequest, isOffTheRecord, journeyLogger)
-> new PaymentRequestImpl(mRenderFrameHost, componentPaymentRequest,
isOffTheRecord, journeyLogger, delegate));
}
}
......@@ -135,9 +135,9 @@ public class PaymentRequestImpl
*/
public interface Delegate {
/**
* Returns whether the ChromeActivity is currently showing an OffTheRecord tab.
* Returns whether the WebContents is currently showing an off-the-record tab.
*/
boolean isOffTheRecord(ChromeActivity activity);
boolean isOffTheRecord(WebContents webContents);
/**
* Returns a non-null string if there is an invalid SSL certificate on the currently
* loaded page.
......@@ -412,9 +412,14 @@ public class PaymentRequestImpl
*
* @param renderFrameHost The host of the frame that has invoked the PaymentRequest API.
* @param componentPaymentRequestImpl The component side of the PaymentRequest implementation.
* @param isOffTheRecord Whether the merchant page is shown in an off-the-record tab.
* @param journeyLogger The JourneyLogger that records the user journey of using the
* PaymentRequest service.
* @param delegate The delegate of this class.
*/
public PaymentRequestImpl(RenderFrameHost renderFrameHost,
ComponentPaymentRequestImpl componentPaymentRequestImpl, Delegate delegate) {
ComponentPaymentRequestImpl componentPaymentRequestImpl, boolean isOffTheRecord,
JourneyLogger journeyLogger, Delegate delegate) {
assert renderFrameHost != null;
assert componentPaymentRequestImpl != null;
assert delegate != null;
......@@ -422,23 +427,16 @@ public class PaymentRequestImpl
mRenderFrameHost = renderFrameHost;
mDelegate = delegate;
mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost);
mPaymentRequestOrigin =
UrlFormatter.formatUrlForSecurityDisplay(mRenderFrameHost.getLastCommittedURL());
mPaymentRequestSecurityOrigin = mRenderFrameHost.getLastCommittedOrigin();
mTopLevelOrigin =
UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl());
mMerchantName = mWebContents.getTitle();
mCertificateChain = CertificateChainHelper.getCertificateChain(mWebContents);
mIsOffTheRecord = mDelegate.isOffTheRecord(ChromeActivity.fromWebContents(mWebContents));
mJourneyLogger = new JourneyLogger(mIsOffTheRecord, mWebContents);
mIsOffTheRecord = isOffTheRecord;
mJourneyLogger = journeyLogger;
mSkipUiForNonUrlPaymentMethodIdentifiers = mDelegate.skipUiForBasicCard();
if (sObserverForTest != null) sObserverForTest.onPaymentRequestCreated(this);
mPaymentUIsManager = new PaymentUIsManager(/*delegate=*/this,
/*params=*/this, mWebContents, mIsOffTheRecord, mJourneyLogger);
......
......@@ -50,7 +50,7 @@ public class PaymentRequestTestBridge {
}
@Override
public boolean isOffTheRecord(@Nullable ChromeActivity activity) {
public boolean isOffTheRecord(WebContents webContents) {
return mIsOffTheRecord;
}
......
......@@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import org.chromium.components.autofill.EditableOption;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.WebContentsStatics;
import org.chromium.mojo.system.MojoException;
import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentItem;
......@@ -28,8 +30,10 @@ import java.util.List;
public class ComponentPaymentRequestImpl implements PaymentRequest {
private static NativeObserverForTest sNativeObserverForTest;
private final BrowserPaymentRequestFactory mBrowserPaymentRequestFactory;
private final RenderFrameHost mRenderFrameHost;
private BrowserPaymentRequest mBrowserPaymentRequest;
private PaymentRequestClient mClient;
private boolean mIsOffTheRecord;
private PaymentRequestLifecycleObserver mPaymentRequestLifecycleObserver;
/** The factory that creates an instance of {@link BrowserPaymentRequest}. */
......@@ -39,9 +43,13 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
* instance of {@link ComponentPaymentRequestImpl}.
* @param componentPaymentRequestImpl The ComponentPaymentRequestImpl to work together with
* the BrowserPaymentRequest instance.
* @param isOffTheRecord Whether the merchant page is in a OffTheRecord (e.g., incognito,
* guest mode) Tab.
* @param journeyLogger The logger that records the user journey of PaymentRequest.
*/
BrowserPaymentRequest createBrowserPaymentRequest(
ComponentPaymentRequestImpl componentPaymentRequestImpl);
ComponentPaymentRequestImpl componentPaymentRequestImpl, boolean isOffTheRecord,
JourneyLogger journeyLogger);
}
/**
......@@ -66,11 +74,17 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
/**
* Build an instance of the PaymentRequest implementation.
* @param renderFrameHost The RenderFrameHost of the merchant page.
* @param isOffTheRecord Whether the merchant page is in a OffTheRecord (e.g., incognito, guest
* mode) Tab.
* @param browserPaymentRequestFactory The factory that generates an instance of
* BrowserPaymentRequest to work with this ComponentPaymentRequestImpl instance.
*/
public ComponentPaymentRequestImpl(BrowserPaymentRequestFactory browserPaymentRequestFactory) {
public ComponentPaymentRequestImpl(RenderFrameHost renderFrameHost, boolean isOffTheRecord,
BrowserPaymentRequestFactory browserPaymentRequestFactory) {
mBrowserPaymentRequestFactory = browserPaymentRequestFactory;
mIsOffTheRecord = isOffTheRecord;
mRenderFrameHost = renderFrameHost;
}
/**
......@@ -92,7 +106,10 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
@Override
public void init(PaymentRequestClient client, PaymentMethodData[] methodData,
PaymentDetails details, PaymentOptions options, boolean googlePayBridgeEligible) {
mBrowserPaymentRequest = mBrowserPaymentRequestFactory.createBrowserPaymentRequest(this);
JourneyLogger journeyLogger = new JourneyLogger(
mIsOffTheRecord, WebContentsStatics.fromRenderFrameHost(mRenderFrameHost));
mBrowserPaymentRequest = mBrowserPaymentRequestFactory.createBrowserPaymentRequest(
this, mIsOffTheRecord, journeyLogger);
assert mBrowserPaymentRequest != null;
if (mClient != null) {
mBrowserPaymentRequest.getJourneyLogger().setAborted(
......@@ -103,8 +120,7 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
}
if (client == null) {
mBrowserPaymentRequest.getJourneyLogger().setAborted(
AbortReason.INVALID_DATA_FROM_RENDERER);
journeyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
mBrowserPaymentRequest.disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_STATE);
return;
}
......
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