Commit 64d522c2 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Native Android payment app factory.

This patch adds a payment app factory for 3rd party native Android
payment apps in accordance with the design at:
https://bit.ly/cross-platform-pay-app-factory

The factory is responsible for finding the payment apps
(AndroidPaymentApp), filtering out apps that don't support the requested
methods, verifying ability to use the method names, and querying the
IS_READY_TO_PAY service when necessary.

Bug: 1022512
Change-Id: Id3862e8a7e1aa6ace6ce70adde56cd90c20c23fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025229Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739031}
parent 9457a610
...@@ -10,26 +10,23 @@ import android.graphics.drawable.Drawable; ...@@ -10,26 +10,23 @@ import android.graphics.drawable.Drawable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppCreatedCallback;
import org.chromium.chrome.browser.payments.PaymentAppFactory.PaymentAppFactoryAddition;
import org.chromium.components.payments.PaymentManifestDownloader; import org.chromium.components.payments.PaymentManifestDownloader;
import org.chromium.components.payments.PaymentManifestParser; import org.chromium.components.payments.PaymentManifestParser;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentMethodData;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/** Builds instances of payment apps based on installed third party Android payment apps. */ /** Looks up installed third party Android payment apps. */
public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition { public class AndroidPaymentAppFactory implements PaymentAppFactoryInterface {
// PaymentAppFactoryInterface implementation.
@Override @Override
public void create(WebContents webContents, Map<String, PaymentMethodData> methodData, public void create(PaymentAppFactoryDelegate delegate) {
boolean mayCrawlUnused, PaymentAppCreatedCallback callback) { AndroidPaymentAppFinder finder =
AndroidPaymentAppFinder.find(webContents, methodData.keySet(), new AndroidPaymentAppFinder(new PaymentManifestWebDataService(),
new PaymentManifestWebDataService(), new PaymentManifestDownloader(), new PaymentManifestDownloader(), new PaymentManifestParser(),
new PaymentManifestParser(), new PackageManagerDelegate(), callback); new PackageManagerDelegate(), delegate, /*factory=*/this);
finder.findAndroidPaymentApps();
} }
/** /**
...@@ -38,8 +35,6 @@ public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition { ...@@ -38,8 +35,6 @@ public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition {
* @return True if there are Android payment apps on device. * @return True if there are Android payment apps on device.
*/ */
public static boolean hasAndroidPaymentApps() { public static boolean hasAndroidPaymentApps() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) return false;
PackageManagerDelegate packageManagerDelegate = new PackageManagerDelegate(); PackageManagerDelegate packageManagerDelegate = new PackageManagerDelegate();
// Note that all Android payment apps must support org.chromium.intent.action.PAY action // Note that all Android payment apps must support org.chromium.intent.action.PAY action
// without additional data to be detected. // without additional data to be detected.
...@@ -56,10 +51,6 @@ public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition { ...@@ -56,10 +51,6 @@ public class AndroidPaymentAppFactory implements PaymentAppFactoryAddition {
public static Map<String, Pair<String, Drawable>> getAndroidPaymentAppsInfo() { public static Map<String, Pair<String, Drawable>> getAndroidPaymentAppsInfo() {
Map<String, Pair<String, Drawable>> paymentAppsInfo = new HashMap<>(); Map<String, Pair<String, Drawable>> paymentAppsInfo = new HashMap<>();
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
return paymentAppsInfo;
}
PackageManagerDelegate packageManagerDelegate = new PackageManagerDelegate(); PackageManagerDelegate packageManagerDelegate = new PackageManagerDelegate();
Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY); Intent payIntent = new Intent(AndroidPaymentApp.ACTION_PAY);
List<ResolveInfo> matches = List<ResolveInfo> matches =
......
...@@ -8,7 +8,6 @@ import android.support.v4.util.ArrayMap; ...@@ -8,7 +8,6 @@ import android.support.v4.util.ArrayMap;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.payments.PaymentApp.InstrumentsCallback; import org.chromium.chrome.browser.payments.PaymentApp.InstrumentsCallback;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentMethodData; import org.chromium.payments.mojom.PaymentMethodData;
...@@ -73,10 +72,6 @@ public class PaymentAppFactory implements PaymentAppFactoryInterface { ...@@ -73,10 +72,6 @@ public class PaymentAppFactory implements PaymentAppFactoryInterface {
private PaymentAppFactory() { private PaymentAppFactory() {
mAdditionalFactories = new ArrayList<>(); mAdditionalFactories = new ArrayList<>();
if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
mAdditionalFactories.add(new AndroidPaymentAppFactory());
}
} }
/** /**
......
...@@ -31,6 +31,7 @@ public class PaymentAppService implements PaymentAppFactoryInterface { ...@@ -31,6 +31,7 @@ public class PaymentAppService implements PaymentAppFactoryInterface {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) { if (ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) {
mFactories.add(new ServiceWorkerPaymentAppBridge()); mFactories.add(new ServiceWorkerPaymentAppBridge());
} }
mFactories.add(new AndroidPaymentAppFactory());
} }
/** @param factory The factory to add. */ /** @param factory The factory to add. */
......
...@@ -17,7 +17,6 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -17,7 +17,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.payments.AndroidPaymentAppFactory; import org.chromium.chrome.browser.payments.AndroidPaymentAppFactory;
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge; import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference; import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
...@@ -130,16 +129,13 @@ public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat ...@@ -130,16 +129,13 @@ public class AutofillPaymentMethodsFragment extends PreferenceFragmentCompat
} }
// Add the link to payment apps only after the credit card list is rebuilt. // Add the link to payment apps only after the credit card list is rebuilt.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS) Preference payment_apps_pref = new Preference(getStyledContext());
|| ChromeFeatureList.isEnabled(ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS)) { payment_apps_pref.setTitle(R.string.payment_apps_title);
Preference payment_apps_pref = new Preference(getStyledContext()); payment_apps_pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
payment_apps_pref.setTitle(R.string.payment_apps_title); payment_apps_pref.setShouldDisableView(true);
payment_apps_pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName()); payment_apps_pref.setKey(PREF_PAYMENT_APPS);
payment_apps_pref.setShouldDisableView(true); getPreferenceScreen().addPreference(payment_apps_pref);
payment_apps_pref.setKey(PREF_PAYMENT_APPS); refreshPaymentAppsPrefForAndroidPaymentApps(payment_apps_pref);
getPreferenceScreen().addPreference(payment_apps_pref);
refreshPaymentAppsPrefForAndroidPaymentApps(payment_apps_pref);
}
} }
private Context getStyledContext() { private Context getStyledContext() {
......
...@@ -39,7 +39,6 @@ import java.util.concurrent.TimeoutException; ...@@ -39,7 +39,6 @@ import java.util.concurrent.TimeoutException;
@CommandLineFlags.Add({ @CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
// Speed up the test by not looking up actual apps installed on the device. // Speed up the test by not looking up actual apps installed on the device.
"disable-features=" + ChromeFeatureList.ANDROID_PAYMENT_APPS,
"disable-features=" + ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS, "disable-features=" + ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS,
}) })
public class PaymentRequestPaymentAppUiSkipPreloadTest { public class PaymentRequestPaymentAppUiSkipPreloadTest {
......
...@@ -36,7 +36,6 @@ import java.util.concurrent.TimeoutException; ...@@ -36,7 +36,6 @@ import java.util.concurrent.TimeoutException;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
// Speed up the test by not looking up actual apps installed on the device. // Speed up the test by not looking up actual apps installed on the device.
"disable-features=" + ChromeFeatureList.ANDROID_PAYMENT_APPS,
"disable-features=" + ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS}) "disable-features=" + ChromeFeatureList.SERVICE_WORKER_PAYMENT_APPS})
public class PaymentRequestPaymentAppUiSkipTest { public class PaymentRequestPaymentAppUiSkipTest {
// Disable animations to reduce flakiness. // Disable animations to reduce flakiness.
......
file://components/payments/OWNERS
# COMPONENT: UI>Browser>Payments
...@@ -103,7 +103,6 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -103,7 +103,6 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kAndroidNightModeTabReparenting, &kAndroidNightModeTabReparenting,
&kAndroidPayIntegrationV1, &kAndroidPayIntegrationV1,
&kAndroidPayIntegrationV2, &kAndroidPayIntegrationV2,
&kAndroidPaymentApps,
&kAndroidSearchEngineChoiceNotification, &kAndroidSearchEngineChoiceNotification,
&kAndroidSetupSearchEngine, &kAndroidSetupSearchEngine,
&kAndroidSiteSettingsUIRefresh, &kAndroidSiteSettingsUIRefresh,
...@@ -299,10 +298,6 @@ const base::Feature kAllowRemoteContextForNotifications{ ...@@ -299,10 +298,6 @@ const base::Feature kAllowRemoteContextForNotifications{
const base::Feature kAndroidPayIntegrationV2{"AndroidPayIntegrationV2", const base::Feature kAndroidPayIntegrationV2{"AndroidPayIntegrationV2",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
// TODO(rouslan): Remove this.
const base::Feature kAndroidPaymentApps{"AndroidPaymentApps",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kAndroidSearchEngineChoiceNotification{ const base::Feature kAndroidSearchEngineChoiceNotification{
"AndroidSearchEngineChoiceNotification", base::FEATURE_ENABLED_BY_DEFAULT}; "AndroidSearchEngineChoiceNotification", base::FEATURE_ENABLED_BY_DEFAULT};
......
...@@ -173,7 +173,6 @@ public abstract class ChromeFeatureList { ...@@ -173,7 +173,6 @@ public abstract class ChromeFeatureList {
"AndroidNightModeTabReparenting"; "AndroidNightModeTabReparenting";
public static final String ANDROID_PAY_INTEGRATION_V1 = "AndroidPayIntegrationV1"; public static final String ANDROID_PAY_INTEGRATION_V1 = "AndroidPayIntegrationV1";
public static final String ANDROID_PAY_INTEGRATION_V2 = "AndroidPayIntegrationV2"; public static final String ANDROID_PAY_INTEGRATION_V2 = "AndroidPayIntegrationV2";
public static final String ANDROID_PAYMENT_APPS = "AndroidPaymentApps";
public static final String ANDROID_SEARCH_ENGINE_CHOICE_NOTIFICATION = public static final String ANDROID_SEARCH_ENGINE_CHOICE_NOTIFICATION =
"AndroidSearchEngineChoiceNotification"; "AndroidSearchEngineChoiceNotification";
public static final String ANDROID_SETUP_SEARCH_ENGINE = "AndroidSetupSearchEngine"; public static final String ANDROID_SETUP_SEARCH_ENGINE = "AndroidSetupSearchEngine";
......
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