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> { ...@@ -116,7 +116,8 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
} }
@Override @Override
public boolean isOffTheRecord(@Nullable ChromeActivity activity) { public boolean isOffTheRecord(WebContents webContents) {
ChromeActivity activity = ChromeActivity.fromWebContents(webContents);
return activity != null && activity.getCurrentTabModel().getProfile().isOffTheRecord(); return activity != null && activity.getCurrentTabModel().getProfile().isOffTheRecord();
} }
...@@ -186,8 +187,11 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> { ...@@ -186,8 +187,11 @@ public class PaymentRequestFactory implements InterfaceFactory<PaymentRequest> {
delegate = new PaymentRequestDelegateImpl(mRenderFrameHost); delegate = new PaymentRequestDelegateImpl(mRenderFrameHost);
} }
return new ComponentPaymentRequestImpl((componentPaymentRequest) WebContents webContents = WebContentsStatics.fromRenderFrameHost(mRenderFrameHost);
-> new PaymentRequestImpl(mRenderFrameHost, return new ComponentPaymentRequestImpl(mRenderFrameHost,
componentPaymentRequest, delegate)); delegate.isOffTheRecord(webContents),
(componentPaymentRequest, isOffTheRecord, journeyLogger)
-> new PaymentRequestImpl(mRenderFrameHost, componentPaymentRequest,
isOffTheRecord, journeyLogger, delegate));
} }
} }
...@@ -135,9 +135,9 @@ public class PaymentRequestImpl ...@@ -135,9 +135,9 @@ public class PaymentRequestImpl
*/ */
public interface Delegate { 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 * Returns a non-null string if there is an invalid SSL certificate on the currently
* loaded page. * loaded page.
...@@ -412,9 +412,14 @@ public class PaymentRequestImpl ...@@ -412,9 +412,14 @@ public class PaymentRequestImpl
* *
* @param renderFrameHost The host of the frame that has invoked the PaymentRequest API. * @param renderFrameHost The host of the frame that has invoked the PaymentRequest API.
* @param componentPaymentRequestImpl The component side of the PaymentRequest implementation. * @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, public PaymentRequestImpl(RenderFrameHost renderFrameHost,
ComponentPaymentRequestImpl componentPaymentRequestImpl, Delegate delegate) { ComponentPaymentRequestImpl componentPaymentRequestImpl, boolean isOffTheRecord,
JourneyLogger journeyLogger, Delegate delegate) {
assert renderFrameHost != null; assert renderFrameHost != null;
assert componentPaymentRequestImpl != null; assert componentPaymentRequestImpl != null;
assert delegate != null; assert delegate != null;
...@@ -422,23 +427,16 @@ public class PaymentRequestImpl ...@@ -422,23 +427,16 @@ public class PaymentRequestImpl
mRenderFrameHost = renderFrameHost; mRenderFrameHost = renderFrameHost;
mDelegate = delegate; mDelegate = delegate;
mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost); mWebContents = WebContentsStatics.fromRenderFrameHost(renderFrameHost);
mPaymentRequestOrigin = mPaymentRequestOrigin =
UrlFormatter.formatUrlForSecurityDisplay(mRenderFrameHost.getLastCommittedURL()); UrlFormatter.formatUrlForSecurityDisplay(mRenderFrameHost.getLastCommittedURL());
mPaymentRequestSecurityOrigin = mRenderFrameHost.getLastCommittedOrigin(); mPaymentRequestSecurityOrigin = mRenderFrameHost.getLastCommittedOrigin();
mTopLevelOrigin = mTopLevelOrigin =
UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl()); UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl());
mMerchantName = mWebContents.getTitle(); mMerchantName = mWebContents.getTitle();
mCertificateChain = CertificateChainHelper.getCertificateChain(mWebContents); mCertificateChain = CertificateChainHelper.getCertificateChain(mWebContents);
mIsOffTheRecord = isOffTheRecord;
mIsOffTheRecord = mDelegate.isOffTheRecord(ChromeActivity.fromWebContents(mWebContents)); mJourneyLogger = journeyLogger;
mJourneyLogger = new JourneyLogger(mIsOffTheRecord, mWebContents);
mSkipUiForNonUrlPaymentMethodIdentifiers = mDelegate.skipUiForBasicCard(); mSkipUiForNonUrlPaymentMethodIdentifiers = mDelegate.skipUiForBasicCard();
if (sObserverForTest != null) sObserverForTest.onPaymentRequestCreated(this); if (sObserverForTest != null) sObserverForTest.onPaymentRequestCreated(this);
mPaymentUIsManager = new PaymentUIsManager(/*delegate=*/this, mPaymentUIsManager = new PaymentUIsManager(/*delegate=*/this,
/*params=*/this, mWebContents, mIsOffTheRecord, mJourneyLogger); /*params=*/this, mWebContents, mIsOffTheRecord, mJourneyLogger);
......
...@@ -50,7 +50,7 @@ public class PaymentRequestTestBridge { ...@@ -50,7 +50,7 @@ public class PaymentRequestTestBridge {
} }
@Override @Override
public boolean isOffTheRecord(@Nullable ChromeActivity activity) { public boolean isOffTheRecord(WebContents webContents) {
return mIsOffTheRecord; return mIsOffTheRecord;
} }
......
...@@ -8,6 +8,8 @@ import androidx.annotation.Nullable; ...@@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.components.autofill.EditableOption; 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.mojo.system.MojoException;
import org.chromium.payments.mojom.PaymentDetails; import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentItem; import org.chromium.payments.mojom.PaymentItem;
...@@ -28,8 +30,10 @@ import java.util.List; ...@@ -28,8 +30,10 @@ import java.util.List;
public class ComponentPaymentRequestImpl implements PaymentRequest { public class ComponentPaymentRequestImpl implements PaymentRequest {
private static NativeObserverForTest sNativeObserverForTest; private static NativeObserverForTest sNativeObserverForTest;
private final BrowserPaymentRequestFactory mBrowserPaymentRequestFactory; private final BrowserPaymentRequestFactory mBrowserPaymentRequestFactory;
private final RenderFrameHost mRenderFrameHost;
private BrowserPaymentRequest mBrowserPaymentRequest; private BrowserPaymentRequest mBrowserPaymentRequest;
private PaymentRequestClient mClient; private PaymentRequestClient mClient;
private boolean mIsOffTheRecord;
private PaymentRequestLifecycleObserver mPaymentRequestLifecycleObserver; private PaymentRequestLifecycleObserver mPaymentRequestLifecycleObserver;
/** The factory that creates an instance of {@link BrowserPaymentRequest}. */ /** The factory that creates an instance of {@link BrowserPaymentRequest}. */
...@@ -39,9 +43,13 @@ public class ComponentPaymentRequestImpl implements PaymentRequest { ...@@ -39,9 +43,13 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
* instance of {@link ComponentPaymentRequestImpl}. * instance of {@link ComponentPaymentRequestImpl}.
* @param componentPaymentRequestImpl The ComponentPaymentRequestImpl to work together with * @param componentPaymentRequestImpl The ComponentPaymentRequestImpl to work together with
* the BrowserPaymentRequest instance. * 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( BrowserPaymentRequest createBrowserPaymentRequest(
ComponentPaymentRequestImpl componentPaymentRequestImpl); ComponentPaymentRequestImpl componentPaymentRequestImpl, boolean isOffTheRecord,
JourneyLogger journeyLogger);
} }
/** /**
...@@ -66,11 +74,17 @@ public class ComponentPaymentRequestImpl implements PaymentRequest { ...@@ -66,11 +74,17 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
/** /**
* Build an instance of the PaymentRequest implementation. * 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 * @param browserPaymentRequestFactory The factory that generates an instance of
* BrowserPaymentRequest to work with this ComponentPaymentRequestImpl instance. * BrowserPaymentRequest to work with this ComponentPaymentRequestImpl instance.
*/ */
public ComponentPaymentRequestImpl(BrowserPaymentRequestFactory browserPaymentRequestFactory) { public ComponentPaymentRequestImpl(RenderFrameHost renderFrameHost, boolean isOffTheRecord,
BrowserPaymentRequestFactory browserPaymentRequestFactory) {
mBrowserPaymentRequestFactory = browserPaymentRequestFactory; mBrowserPaymentRequestFactory = browserPaymentRequestFactory;
mIsOffTheRecord = isOffTheRecord;
mRenderFrameHost = renderFrameHost;
} }
/** /**
...@@ -92,7 +106,10 @@ public class ComponentPaymentRequestImpl implements PaymentRequest { ...@@ -92,7 +106,10 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
@Override @Override
public void init(PaymentRequestClient client, PaymentMethodData[] methodData, public void init(PaymentRequestClient client, PaymentMethodData[] methodData,
PaymentDetails details, PaymentOptions options, boolean googlePayBridgeEligible) { 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; assert mBrowserPaymentRequest != null;
if (mClient != null) { if (mClient != null) {
mBrowserPaymentRequest.getJourneyLogger().setAborted( mBrowserPaymentRequest.getJourneyLogger().setAborted(
...@@ -103,8 +120,7 @@ public class ComponentPaymentRequestImpl implements PaymentRequest { ...@@ -103,8 +120,7 @@ public class ComponentPaymentRequestImpl implements PaymentRequest {
} }
if (client == null) { if (client == null) {
mBrowserPaymentRequest.getJourneyLogger().setAborted( journeyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
AbortReason.INVALID_DATA_FROM_RENDERER);
mBrowserPaymentRequest.disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_STATE); mBrowserPaymentRequest.disconnectFromClientWithDebugMessage(ErrorStrings.INVALID_STATE);
return; 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