Commit 91dc1b58 authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

PaymentHandler: Replace 'enabledMethods' array with 'method' string

The related spec change:
  https://github.com/w3c/payment-handler/pull/276

Payment Handler feature is behind a flag:
  chrome://flags/#service-worker-payment-apps

FYI, the original field type was `repeated string`, and the changed
field type is `optional string`. So, if `enabledMethods` data is
stored in a previous version, when reading the `method` field in a new
version, the protobuf will read the first element of `enabledMethods`.
Therefore, DB migration is not required.

Bug: 828894
Change-Id: Ic5775768eaff9584517956f2984473e8b6a0a411
Reviewed-on: https://chromium-review.googlesource.com/986121Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#548750}
parent f1ba9bd1
...@@ -328,7 +328,7 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen ...@@ -328,7 +328,7 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen
iframeOrigin, id, new HashSet<>(methodData.values()), total, iframeOrigin, id, new HashSet<>(methodData.values()), total,
new HashSet<>(modifiers.values()), callback, mAppName, new HashSet<>(modifiers.values()), callback, mAppName,
icon == null ? null : icon.getBitmap(), mSwUri, mScope, mUseCache, icon == null ? null : icon.getBitmap(), mSwUri, mScope, mUseCache,
mMethodNames); mMethodNames.toArray(new String[0])[0]);
} else { } else {
ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mRegistrationId, origin, ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mRegistrationId, origin,
iframeOrigin, id, new HashSet<>(methodData.values()), total, iframeOrigin, id, new HashSet<>(methodData.values()), total,
......
...@@ -207,20 +207,19 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ...@@ -207,20 +207,19 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
* @param swUri The URI to get the app's service worker js script. * @param swUri The URI to get the app's service worker js script.
* @param scope The scope of the service worker that should be registered. * @param scope The scope of the service worker that should be registered.
* @param useCache Whether to use cache when registering the service worker. * @param useCache Whether to use cache when registering the service worker.
* @param methodNames Supported method names of the app. * @param method Supported method name of the app.
*/ */
public static void installAndInvokePaymentApp(WebContents webContents, String origin, public static void installAndInvokePaymentApp(WebContents webContents, String origin,
String iframeOrigin, String paymentRequestId, Set<PaymentMethodData> methodData, String iframeOrigin, String paymentRequestId, Set<PaymentMethodData> methodData,
PaymentItem total, Set<PaymentDetailsModifier> modifiers, PaymentItem total, Set<PaymentDetailsModifier> modifiers,
PaymentInstrument.InstrumentDetailsCallback callback, String appName, PaymentInstrument.InstrumentDetailsCallback callback, String appName,
@Nullable Bitmap icon, URI swUri, URI scope, boolean useCache, @Nullable Bitmap icon, URI swUri, URI scope, boolean useCache, String method) {
Set<String> methodNames) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
nativeInstallAndInvokePaymentApp(webContents, origin, iframeOrigin, paymentRequestId, nativeInstallAndInvokePaymentApp(webContents, origin, iframeOrigin, paymentRequestId,
methodData.toArray(new PaymentMethodData[0]), total, methodData.toArray(new PaymentMethodData[0]), total,
modifiers.toArray(new PaymentDetailsModifier[0]), callback, appName, icon, modifiers.toArray(new PaymentDetailsModifier[0]), callback, appName, icon,
swUri.toString(), scope.toString(), useCache, methodNames.toArray(new String[0])); swUri.toString(), scope.toString(), useCache, method);
} }
/** /**
...@@ -427,8 +426,7 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ...@@ -427,8 +426,7 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
String topLevelOrigin, String paymentRequestOrigin, String paymentRequestId, String topLevelOrigin, String paymentRequestOrigin, String paymentRequestId,
PaymentMethodData[] methodData, PaymentItem total, PaymentDetailsModifier[] modifiers, PaymentMethodData[] methodData, PaymentItem total, PaymentDetailsModifier[] modifiers,
PaymentInstrument.InstrumentDetailsCallback callback, String appName, PaymentInstrument.InstrumentDetailsCallback callback, String appName,
@Nullable Bitmap icon, String swUrl, String scope, boolean useCache, @Nullable Bitmap icon, String swUrl, String scope, boolean useCache, String method);
String[] methodNames);
private static native void nativeAbortPaymentApp( private static native void nativeAbortPaymentApp(
WebContents webContents, long registrationId, PaymentInstrument.AbortCallback callback); WebContents webContents, long registrationId, PaymentInstrument.AbortCallback callback);
......
...@@ -467,7 +467,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -467,7 +467,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
const JavaParamRef<jstring>& jsw_js_url, const JavaParamRef<jstring>& jsw_js_url,
const JavaParamRef<jstring>& jsw_scope, const JavaParamRef<jstring>& jsw_scope,
jboolean juse_cache, jboolean juse_cache,
const JavaParamRef<jobjectArray>& jmethod_names) { const JavaParamRef<jstring>& jmethod) {
content::WebContents* web_contents = content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents); content::WebContents::FromJavaWebContents(jweb_contents);
...@@ -476,9 +476,6 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -476,9 +476,6 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(jicon)); icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(jicon));
} }
std::vector<std::string> enabled_methods;
base::android::AppendJavaStringArrayToStringVector(env, jmethod_names,
&enabled_methods);
content::PaymentAppProvider::GetInstance()->InstallAndInvokePaymentApp( content::PaymentAppProvider::GetInstance()->InstallAndInvokePaymentApp(
web_contents, web_contents,
ConvertPaymentRequestEventDataFromJavaToNative( ConvertPaymentRequestEventDataFromJavaToNative(
...@@ -486,7 +483,8 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -486,7 +483,8 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
jmethod_data, jtotal, jmodifiers), jmethod_data, jtotal, jmodifiers),
ConvertJavaStringToUTF8(env, japp_name), icon_bitmap, ConvertJavaStringToUTF8(env, japp_name), icon_bitmap,
ConvertJavaStringToUTF8(env, jsw_js_url), ConvertJavaStringToUTF8(env, jsw_js_url),
ConvertJavaStringToUTF8(env, jsw_scope), juse_cache, enabled_methods, ConvertJavaStringToUTF8(env, jsw_scope), juse_cache,
ConvertJavaStringToUTF8(env, jmethod),
base::BindOnce(&OnPaymentAppInvoked, base::BindOnce(&OnPaymentAppInvoked,
ScopedJavaGlobalRef<jobject>(env, jweb_contents), ScopedJavaGlobalRef<jobject>(env, jweb_contents),
ScopedJavaGlobalRef<jobject>(env, jcallback))); ScopedJavaGlobalRef<jobject>(env, jcallback)));
......
...@@ -202,8 +202,7 @@ void ServiceWorkerPaymentInstrument::InvokePaymentApp(Delegate* delegate) { ...@@ -202,8 +202,7 @@ void ServiceWorkerPaymentInstrument::InvokePaymentApp(Delegate* delegate) {
: *(installable_web_app_info_->icon), : *(installable_web_app_info_->icon),
installable_web_app_info_->sw_js_url, installable_web_app_info_->sw_js_url,
installable_web_app_info_->sw_scope, installable_web_app_info_->sw_scope,
installable_web_app_info_->sw_use_cache, installable_web_app_info_->sw_use_cache, installable_enabled_method_,
std::vector<std::string>(1, installable_enabled_method_),
base::BindOnce(&ServiceWorkerPaymentInstrument::OnPaymentAppInvoked, base::BindOnce(&ServiceWorkerPaymentInstrument::OnPaymentAppInvoked,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} else { } else {
......
...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars ...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars
} }
registration.paymentManager.instruments registration.paymentManager.instruments
.set('123456', {name: 'Alice Pay', enabledMethods: [method]}) .set('123456', {name: 'Alice Pay', method: method})
.then(() => { .then(() => {
output( output(
'instruments.set()', 'instruments.set()',
......
...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars ...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars
} }
registration.paymentManager.instruments registration.paymentManager.instruments
.set('123456', {name: 'Alice Pay', enabledMethods: [method]}) .set('123456', {name: 'Alice Pay', method: method})
.then(() => { .then(() => {
output( output(
'instruments.set()', 'instruments.set()',
......
...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars ...@@ -54,7 +54,7 @@ function install(method) { // eslint-disable-line no-unused-vars
} }
registration.paymentManager.instruments registration.paymentManager.instruments
.set('123456', {name: 'Bob Pay', enabledMethods: [method]}) .set('123456', {name: 'Bob Pay', method: method})
.then(() => { .then(() => {
output( output(
'instruments.set()', 'instruments.set()',
......
...@@ -28,7 +28,7 @@ message StoredPaymentInstrumentProto { ...@@ -28,7 +28,7 @@ message StoredPaymentInstrumentProto {
optional int64 registration_id = 1; optional int64 registration_id = 1;
optional string instrument_key = 2; optional string instrument_key = 2;
optional string name = 3; optional string name = 3;
repeated string enabled_methods = 4; optional string method = 4;
optional string stringified_capabilities = 5; optional string stringified_capabilities = 5;
repeated StoredPaymentInstrumentImageObject icons = 6; repeated StoredPaymentInstrumentImageObject icons = 6;
optional string decoded_instrument_icon = 7; optional string decoded_instrument_icon = 7;
......
...@@ -80,8 +80,7 @@ PaymentInstrumentPtr ToPaymentInstrumentForMojo(const std::string& input) { ...@@ -80,8 +80,7 @@ PaymentInstrumentPtr ToPaymentInstrumentForMojo(const std::string& input) {
} }
instrument->icons.emplace_back(icon); instrument->icons.emplace_back(icon);
} }
for (const auto& method : instrument_proto.enabled_methods()) instrument->method = instrument_proto.method();
instrument->enabled_methods.push_back(method);
instrument->stringified_capabilities = instrument->stringified_capabilities =
instrument_proto.stringified_capabilities(); instrument_proto.stringified_capabilities();
...@@ -431,7 +430,7 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker( ...@@ -431,7 +430,7 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker(
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon, const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback) { SetPaymentAppInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -439,14 +438,14 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker( ...@@ -439,14 +438,14 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker(
registration_id, registration_id,
base::BindOnce(&PaymentAppDatabase::DidFindRegistrationToSetPaymentApp, base::BindOnce(&PaymentAppDatabase::DidFindRegistrationToSetPaymentApp,
weak_ptr_factory_.GetWeakPtr(), instrument_key, name, icon, weak_ptr_factory_.GetWeakPtr(), instrument_key, name, icon,
enabled_methods, std::move(callback))); method, std::move(callback)));
} }
void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp( void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp(
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon, const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) { scoped_refptr<ServiceWorkerRegistration> registration) {
...@@ -472,16 +471,15 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp( ...@@ -472,16 +471,15 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp(
{{CreatePaymentAppKey(registration->pattern().spec()), {{CreatePaymentAppKey(registration->pattern().spec()),
serialized_payment_app}}, serialized_payment_app}},
base::Bind(&PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp, base::Bind(&PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp,
weak_ptr_factory_.GetWeakPtr(), instrument_key, weak_ptr_factory_.GetWeakPtr(), instrument_key, method,
enabled_methods, base::Passed(std::move(callback)), base::Passed(std::move(callback)), std::move(registration)));
std::move(registration)));
return; return;
} }
void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp( void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp(
const std::string& instrument_key, const std::string& instrument_key,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
scoped_refptr<ServiceWorkerRegistration> registration, scoped_refptr<ServiceWorkerRegistration> registration,
ServiceWorkerStatusCode status) { ServiceWorkerStatusCode status) {
...@@ -495,9 +493,7 @@ void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp( ...@@ -495,9 +493,7 @@ void PaymentAppDatabase::DidWritePaymentAppForSetPaymentApp(
StoredPaymentInstrumentProto instrument_proto; StoredPaymentInstrumentProto instrument_proto;
instrument_proto.set_registration_id(registration->id()); instrument_proto.set_registration_id(registration->id());
instrument_proto.set_instrument_key(instrument_key); instrument_proto.set_instrument_key(instrument_key);
for (const auto& method : enabled_methods) { instrument_proto.set_method(method);
instrument_proto.add_enabled_methods(method);
}
std::string serialized_instrument; std::string serialized_instrument;
bool success = instrument_proto.SerializeToString(&serialized_instrument); bool success = instrument_proto.SerializeToString(&serialized_instrument);
...@@ -582,10 +578,7 @@ void PaymentAppDatabase::DidReadAllPaymentInstruments( ...@@ -582,10 +578,7 @@ void PaymentAppDatabase::DidReadAllPaymentInstruments(
if (!base::ContainsKey(apps, id)) if (!base::ContainsKey(apps, id))
continue; continue;
for (const auto& method : instrument_proto.enabled_methods()) { apps[id]->enabled_methods.emplace_back(instrument_proto.method());
apps[id]->enabled_methods.push_back(method);
}
apps[id]->capabilities.emplace_back(StoredCapabilities()); apps[id]->capabilities.emplace_back(StoredCapabilities());
for (const auto& network : instrument_proto.supported_card_networks()) { for (const auto& network : instrument_proto.supported_card_networks()) {
apps[id]->capabilities.back().supported_card_networks.emplace_back( apps[id]->capabilities.back().supported_card_networks.emplace_back(
...@@ -773,9 +766,7 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument( ...@@ -773,9 +766,7 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument(
instrument_proto.set_decoded_instrument_icon(decoded_instrument_icon); instrument_proto.set_decoded_instrument_icon(decoded_instrument_icon);
instrument_proto.set_instrument_key(instrument_key); instrument_proto.set_instrument_key(instrument_key);
instrument_proto.set_name(instrument->name); instrument_proto.set_name(instrument->name);
for (const auto& method : instrument->enabled_methods) { instrument_proto.set_method(instrument->method);
instrument_proto.add_enabled_methods(method);
}
for (const auto& icon : instrument->icons) { for (const auto& icon : instrument->icons) {
StoredPaymentInstrumentImageObject* image_object_proto = StoredPaymentInstrumentImageObject* image_object_proto =
instrument_proto.add_icons(); instrument_proto.add_icons();
......
...@@ -82,7 +82,7 @@ class CONTENT_EXPORT PaymentAppDatabase { ...@@ -82,7 +82,7 @@ class CONTENT_EXPORT PaymentAppDatabase {
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon, const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback); SetPaymentAppInfoCallback callback);
private: private:
...@@ -210,13 +210,13 @@ class CONTENT_EXPORT PaymentAppDatabase { ...@@ -210,13 +210,13 @@ class CONTENT_EXPORT PaymentAppDatabase {
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon, const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration); scoped_refptr<ServiceWorkerRegistration> registration);
void DidWritePaymentAppForSetPaymentApp( void DidWritePaymentAppForSetPaymentApp(
const std::string& instrument_key, const std::string& instrument_key,
const std::vector<std::string>& enabled_methods, const std::string& method,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
scoped_refptr<ServiceWorkerRegistration> registration, scoped_refptr<ServiceWorkerRegistration> registration,
ServiceWorkerStatusCode status); ServiceWorkerStatusCode status);
......
...@@ -32,12 +32,13 @@ class SelfDeleteInstaller ...@@ -32,12 +32,13 @@ class SelfDeleteInstaller
const GURL& sw_url, const GURL& sw_url,
const GURL& scope, const GURL& scope,
bool use_cache, bool use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
PaymentAppInstaller::InstallPaymentAppCallback callback) PaymentAppInstaller::InstallPaymentAppCallback callback)
: app_name_(app_name), : app_name_(app_name),
app_icon_(app_icon), app_icon_(app_icon),
sw_url_(sw_url), sw_url_(sw_url),
scope_(scope), scope_(scope),
method_(method),
callback_(std::move(callback)) { callback_(std::move(callback)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -45,9 +46,6 @@ class SelfDeleteInstaller ...@@ -45,9 +46,6 @@ class SelfDeleteInstaller
// installation early. // installation early.
Observe(web_contents); Observe(web_contents);
std::copy(enabled_methods.begin(), enabled_methods.end(),
std::back_inserter(enabled_methods_));
content::BrowserContext* browser_context = content::BrowserContext* browser_context =
web_contents->GetBrowserContext(); web_contents->GetBrowserContext();
ServiceWorkerContextWrapper* service_worker_context = ServiceWorkerContextWrapper* service_worker_context =
...@@ -137,7 +135,7 @@ class SelfDeleteInstaller ...@@ -137,7 +135,7 @@ class SelfDeleteInstaller
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce(&SelfDeleteInstaller::SetPaymentAppInfoOnIO, this, base::BindOnce(&SelfDeleteInstaller::SetPaymentAppInfoOnIO, this,
payment_app_context, registration_id_, scope_.spec(), payment_app_context, registration_id_, scope_.spec(),
app_name_, app_icon_, enabled_methods_)); app_name_, app_icon_, method_));
} }
void SetPaymentAppInfoOnIO( void SetPaymentAppInfoOnIO(
...@@ -146,12 +144,12 @@ class SelfDeleteInstaller ...@@ -146,12 +144,12 @@ class SelfDeleteInstaller
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& app_icon, const std::string& app_icon,
const std::vector<std::string>& enabled_methods) { const std::string& method) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context->payment_app_database() payment_app_context->payment_app_database()
->SetPaymentAppInfoForRegisteredServiceWorker( ->SetPaymentAppInfoForRegisteredServiceWorker(
registration_id, instrument_key, name, app_icon, enabled_methods, registration_id, instrument_key, name, app_icon, method,
base::BindOnce(&SelfDeleteInstaller::OnSetPaymentAppInfo, this)); base::BindOnce(&SelfDeleteInstaller::OnSetPaymentAppInfo, this));
} }
...@@ -192,7 +190,7 @@ class SelfDeleteInstaller ...@@ -192,7 +190,7 @@ class SelfDeleteInstaller
std::string app_icon_; std::string app_icon_;
GURL sw_url_; GURL sw_url_;
GURL scope_; GURL scope_;
std::vector<std::string> enabled_methods_; std::string method_;
PaymentAppInstaller::InstallPaymentAppCallback callback_; PaymentAppInstaller::InstallPaymentAppCallback callback_;
int64_t registration_id_ = -1; // Take -1 as an invalid registration Id. int64_t registration_id_ = -1; // Take -1 as an invalid registration Id.
...@@ -204,19 +202,18 @@ class SelfDeleteInstaller ...@@ -204,19 +202,18 @@ class SelfDeleteInstaller
} // namespace. } // namespace.
// Static // Static
void PaymentAppInstaller::Install( void PaymentAppInstaller::Install(WebContents* web_contents,
WebContents* web_contents,
const std::string& app_name, const std::string& app_name,
const std::string& app_icon, const std::string& app_icon,
const GURL& sw_url, const GURL& sw_url,
const GURL& scope, const GURL& scope,
bool use_cache, bool use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
InstallPaymentAppCallback callback) { InstallPaymentAppCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
new SelfDeleteInstaller(web_contents, app_name, app_icon, sw_url, scope, new SelfDeleteInstaller(web_contents, app_name, app_icon, sw_url, scope,
use_cache, enabled_methods, std::move(callback)); use_cache, method, std::move(callback));
} }
} // namespace content } // namespace content
...@@ -39,7 +39,7 @@ class PaymentAppInstaller { ...@@ -39,7 +39,7 @@ class PaymentAppInstaller {
const GURL& sw_url, const GURL& sw_url,
const GURL& scope, const GURL& scope,
bool use_cache, bool use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
InstallPaymentAppCallback callback); InstallPaymentAppCallback callback);
private: private:
......
...@@ -410,7 +410,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp( ...@@ -410,7 +410,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp(
const std::string& sw_js_url, const std::string& sw_js_url,
const std::string& sw_scope, const std::string& sw_scope,
bool sw_use_cache, bool sw_use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
InvokePaymentAppCallback callback) { InvokePaymentAppCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -418,7 +418,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp( ...@@ -418,7 +418,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp(
GURL url = GURL(sw_js_url); GURL url = GURL(sw_js_url);
DCHECK(base::IsStringUTF8(sw_scope)); DCHECK(base::IsStringUTF8(sw_scope));
GURL scope = GURL(sw_scope); GURL scope = GURL(sw_scope);
if (!url.is_valid() || !scope.is_valid() || enabled_methods.size() == 0) { if (!url.is_valid() || !scope.is_valid() || method.empty()) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(std::move(callback), base::BindOnce(std::move(callback),
...@@ -438,7 +438,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp( ...@@ -438,7 +438,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp(
PaymentAppInstaller::Install( PaymentAppInstaller::Install(
web_contents, app_name, string_encoded_icon, url, scope, sw_use_cache, web_contents, app_name, string_encoded_icon, url, scope, sw_use_cache,
enabled_methods, method,
base::BindOnce(&OnInstallPaymentApp, std::move(event_data), base::BindOnce(&OnInstallPaymentApp, std::move(event_data),
std::move(callback))); std::move(callback)));
} }
......
...@@ -33,7 +33,7 @@ class CONTENT_EXPORT PaymentAppProviderImpl : public PaymentAppProvider { ...@@ -33,7 +33,7 @@ class CONTENT_EXPORT PaymentAppProviderImpl : public PaymentAppProvider {
const std::string& sw_js_url, const std::string& sw_js_url,
const std::string& sw_scope, const std::string& sw_scope,
bool sw_use_cache, bool sw_use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
InvokePaymentAppCallback callback) override; InvokePaymentAppCallback callback) override;
void CanMakePayment(BrowserContext* browser_context, void CanMakePayment(BrowserContext* browser_context,
int64_t registration_id, int64_t registration_id,
......
...@@ -211,17 +211,17 @@ TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) { ...@@ -211,17 +211,17 @@ TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) {
PaymentHandlerStatus status; PaymentHandlerStatus status;
PaymentInstrumentPtr instrument_1 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_1 = PaymentInstrument::New();
instrument_1->enabled_methods.push_back("hellopay"); instrument_1->method = "hellopay";
SetPaymentInstrument(manager1, "test_key1", std::move(instrument_1), SetPaymentInstrument(manager1, "test_key1", std::move(instrument_1),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
PaymentInstrumentPtr instrument_2 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_2 = PaymentInstrument::New();
instrument_2->enabled_methods.push_back("hellopay"); instrument_2->method = "hellopay";
SetPaymentInstrument(manager2, "test_key2", std::move(instrument_2), SetPaymentInstrument(manager2, "test_key2", std::move(instrument_2),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
PaymentInstrumentPtr instrument_3 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_3 = PaymentInstrument::New();
instrument_3->enabled_methods.push_back("bobpay"); instrument_3->method = "bobpay";
SetPaymentInstrument(manager2, "test_key3", std::move(instrument_3), SetPaymentInstrument(manager2, "test_key3", std::move(instrument_3),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
...@@ -244,17 +244,17 @@ TEST_F(PaymentAppProviderTest, GetAllPaymentAppsFromTheSameOriginTest) { ...@@ -244,17 +244,17 @@ TEST_F(PaymentAppProviderTest, GetAllPaymentAppsFromTheSameOriginTest) {
PaymentHandlerStatus status; PaymentHandlerStatus status;
PaymentInstrumentPtr instrument_1 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_1 = PaymentInstrument::New();
instrument_1->enabled_methods.push_back("hellopay"); instrument_1->method = "hellopay";
SetPaymentInstrument(manager1, "test_key1", std::move(instrument_1), SetPaymentInstrument(manager1, "test_key1", std::move(instrument_1),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
PaymentInstrumentPtr instrument_2 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_2 = PaymentInstrument::New();
instrument_2->enabled_methods.push_back("hellopay"); instrument_2->method = "hellopay";
SetPaymentInstrument(manager2, "test_key2", std::move(instrument_2), SetPaymentInstrument(manager2, "test_key2", std::move(instrument_2),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
PaymentInstrumentPtr instrument_3 = PaymentInstrument::New(); PaymentInstrumentPtr instrument_3 = PaymentInstrument::New();
instrument_3->enabled_methods.push_back("bobpay"); instrument_3->method = "bobpay";
SetPaymentInstrument(manager2, "test_key3", std::move(instrument_3), SetPaymentInstrument(manager2, "test_key3", std::move(instrument_3),
base::BindOnce(&SetPaymentInstrumentCallback, &status)); base::BindOnce(&SetPaymentInstrumentCallback, &status));
......
...@@ -126,8 +126,8 @@ class PaymentManagerTest : public PaymentAppContentUnitTestBase { ...@@ -126,8 +126,8 @@ class PaymentManagerTest : public PaymentAppContentUnitTestBase {
TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) {
PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND;
PaymentInstrumentPtr write_details = PaymentInstrument::New(); PaymentInstrumentPtr write_details = PaymentInstrument::New();
write_details->name = "Visa ending ****4756", write_details->name = "Visa ending ****4756";
write_details->enabled_methods.push_back("visa"); write_details->method = "visa";
write_details->stringified_capabilities = "{}"; write_details->stringified_capabilities = "{}";
SetPaymentInstrument("test_key", std::move(write_details), &write_status); SetPaymentInstrument("test_key", std::move(write_details), &write_status);
// Write the first instrument of a web payment app will return // Write the first instrument of a web payment app will return
...@@ -141,8 +141,7 @@ TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { ...@@ -141,8 +141,7 @@ TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) {
GetPaymentInstrument("test_key", &read_details, &read_status); GetPaymentInstrument("test_key", &read_details, &read_status);
ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status);
EXPECT_EQ("Visa ending ****4756", read_details->name); EXPECT_EQ("Visa ending ****4756", read_details->name);
ASSERT_EQ(1U, read_details->enabled_methods.size()); EXPECT_EQ("visa", read_details->method);
EXPECT_EQ("visa", read_details->enabled_methods[0]);
EXPECT_EQ("{}", read_details->stringified_capabilities); EXPECT_EQ("{}", read_details->stringified_capabilities);
} }
...@@ -156,8 +155,8 @@ TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) { ...@@ -156,8 +155,8 @@ TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) {
TEST_F(PaymentManagerTest, DeletePaymentInstrument) { TEST_F(PaymentManagerTest, DeletePaymentInstrument) {
PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND;
PaymentInstrumentPtr write_details = PaymentInstrument::New(); PaymentInstrumentPtr write_details = PaymentInstrument::New();
write_details->name = "Visa ending ****4756", write_details->name = "Visa ending ****4756";
write_details->enabled_methods.push_back("visa"); write_details->method = "visa";
write_details->stringified_capabilities = "{}"; write_details->stringified_capabilities = "{}";
SetPaymentInstrument("test_key", std::move(write_details), &write_status); SetPaymentInstrument("test_key", std::move(write_details), &write_status);
// Write the first instrument of a web payment app will return // Write the first instrument of a web payment app will return
...@@ -183,8 +182,8 @@ TEST_F(PaymentManagerTest, DeletePaymentInstrument) { ...@@ -183,8 +182,8 @@ TEST_F(PaymentManagerTest, DeletePaymentInstrument) {
TEST_F(PaymentManagerTest, HasPaymentInstrument) { TEST_F(PaymentManagerTest, HasPaymentInstrument) {
PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND;
PaymentInstrumentPtr write_details = PaymentInstrument::New(); PaymentInstrumentPtr write_details = PaymentInstrument::New();
write_details->name = "Visa ending ****4756", write_details->name = "Visa ending ****4756";
write_details->enabled_methods.push_back("visa"); write_details->method = "visa";
write_details->stringified_capabilities = "{}"; write_details->stringified_capabilities = "{}";
SetPaymentInstrument("test_key", std::move(write_details), &write_status); SetPaymentInstrument("test_key", std::move(write_details), &write_status);
// Write the first instrument of a web payment app will return // Write the first instrument of a web payment app will return
......
...@@ -57,7 +57,7 @@ class CONTENT_EXPORT PaymentAppProvider { ...@@ -57,7 +57,7 @@ class CONTENT_EXPORT PaymentAppProvider {
const std::string& sw_js_url, const std::string& sw_js_url,
const std::string& sw_scope, const std::string& sw_scope,
bool sw_use_cache, bool sw_use_cache,
const std::vector<std::string>& enabled_methods, const std::string& method,
InvokePaymentAppCallback callback) = 0; InvokePaymentAppCallback callback) = 0;
virtual void CanMakePayment( virtual void CanMakePayment(
BrowserContext* browser_context, BrowserContext* browser_context,
......
...@@ -17,7 +17,7 @@ function registerPaymentApp() { ...@@ -17,7 +17,7 @@ function registerPaymentApp() {
'basic-card-payment-app-id', 'basic-card-payment-app-id',
{ {
name: 'Visa ****', name: 'Visa ****',
enabledMethods: ['basic-card'], method: 'basic-card',
icons: [ icons: [
{ {
'src': 'icon-1x.png', 'src': 'icon-1x.png',
...@@ -42,7 +42,7 @@ function registerPaymentApp() { ...@@ -42,7 +42,7 @@ function registerPaymentApp() {
'bobpay-payment-app-id', 'bobpay-payment-app-id',
{ {
name: 'Bob Pay', name: 'Bob Pay',
enabledMethods: ['https://bobpay.com'], method: 'https://bobpay.com',
icons: [ icons: [
{ {
'src': 'icon-1x.png', 'src': 'icon-1x.png',
......
...@@ -40,7 +40,7 @@ promise_test(test => { ...@@ -40,7 +40,7 @@ promise_test(test => {
'purpose': 'any badge' 'purpose': 'any badge'
} }
], ],
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
...@@ -53,7 +53,7 @@ promise_test(test => { ...@@ -53,7 +53,7 @@ promise_test(test => {
}) })
.then(stored_instrument => { .then(stored_instrument => {
assert_equals(stored_instrument.name, 'Visa ending ****4756'); assert_equals(stored_instrument.name, 'Visa ending ****4756');
assert_array_equals(stored_instrument.enabledMethods, ['basic-card']); assert_equals(stored_instrument.method, 'basic-card');
assert_equals(stored_instrument.icons.length, 2); assert_equals(stored_instrument.icons.length, 2);
assert_object_equals(stored_instrument.icons[0], { assert_object_equals(stored_instrument.icons[0], {
src: location.origin + '/payments/resources/icon-1x.png', src: location.origin + '/payments/resources/icon-1x.png',
...@@ -112,7 +112,7 @@ promise_test(test => { ...@@ -112,7 +112,7 @@ promise_test(test => {
'test_key', 'test_key',
{ {
name: 'Visa ending ****4756', name: 'Visa ending ****4756',
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
...@@ -152,7 +152,7 @@ promise_test(test => { ...@@ -152,7 +152,7 @@ promise_test(test => {
'test_key', 'test_key',
{ {
name: 'Visa ending ****4756', name: 'Visa ending ****4756',
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
...@@ -193,7 +193,7 @@ promise_test(test => { ...@@ -193,7 +193,7 @@ promise_test(test => {
'test_key1', 'test_key1',
{ {
name: 'Visa ending ****4756', name: 'Visa ending ****4756',
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
...@@ -203,7 +203,7 @@ promise_test(test => { ...@@ -203,7 +203,7 @@ promise_test(test => {
'test_key2', 'test_key2',
{ {
name: "My Bob Pay Account: john@example.com", name: "My Bob Pay Account: john@example.com",
enabledMethods: ["https://bobpay.com/"] method: "https://bobpay.com/"
}) })
]; ];
return Promise.all(instruments); return Promise.all(instruments);
...@@ -238,7 +238,7 @@ promise_test(test => { ...@@ -238,7 +238,7 @@ promise_test(test => {
'test_key1', 'test_key1',
{ {
name: 'Visa ending ****4756', name: 'Visa ending ****4756',
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
...@@ -248,7 +248,7 @@ promise_test(test => { ...@@ -248,7 +248,7 @@ promise_test(test => {
'test_key2', 'test_key2',
{ {
name: "My Bob Pay Account: john@example.com", name: "My Bob Pay Account: john@example.com",
enabledMethods: ["https://bobpay.com/"] method: "https://bobpay.com/"
}) })
]; ];
return Promise.all(instruments); return Promise.all(instruments);
...@@ -303,7 +303,7 @@ promise_test(test => { ...@@ -303,7 +303,7 @@ promise_test(test => {
'purpose': 'any badge' 'purpose': 'any badge'
} }
], ],
enabledMethods: ['basic-card'], method: 'basic-card',
capabilities: { capabilities: {
supportedNetworks: ['visa'], supportedNetworks: ['visa'],
supportedTypes: ['credit'] supportedTypes: ['credit']
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
dictionary PaymentInstrument { dictionary PaymentInstrument {
required DOMString name; required DOMString name;
sequence<ImageObject> icons; sequence<ImageObject> icons;
sequence<DOMString> enabledMethods; DOMString method;
object capabilities; object capabilities;
}; };
...@@ -249,9 +249,8 @@ void PaymentInstruments::OnRequestPermission( ...@@ -249,9 +249,8 @@ void PaymentInstruments::OnRequestPermission(
} }
} }
if (details.hasEnabledMethods()) { instrument->method =
instrument->enabled_methods = details.enabledMethods(); details.hasMethod() ? details.method() : WTF::g_empty_string;
}
if (details.hasCapabilities()) { if (details.hasCapabilities()) {
v8::Local<v8::String> value; v8::Local<v8::String> value;
...@@ -264,7 +263,7 @@ void PaymentInstruments::OnRequestPermission( ...@@ -264,7 +263,7 @@ void PaymentInstruments::OnRequestPermission(
return; return;
} }
instrument->stringified_capabilities = ToCoreString(value); instrument->stringified_capabilities = ToCoreString(value);
if (instrument->enabled_methods.Contains("basic-card")) { if (instrument->method == "basic-card") {
ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(),
ExceptionState::kSetterContext, ExceptionState::kSetterContext,
"PaymentInstruments", "set"); "PaymentInstruments", "set");
...@@ -326,13 +325,7 @@ void PaymentInstruments::onGetPaymentInstrument( ...@@ -326,13 +325,7 @@ void PaymentInstruments::onGetPaymentInstrument(
icons.emplace_back(image_object); icons.emplace_back(image_object);
} }
instrument.setIcons(icons); instrument.setIcons(icons);
instrument.setMethod(stored_instrument->method);
Vector<String> enabled_methods;
for (const auto& method : stored_instrument->enabled_methods) {
enabled_methods.push_back(method);
}
instrument.setEnabledMethods(enabled_methods);
if (!stored_instrument->stringified_capabilities.IsEmpty()) { if (!stored_instrument->stringified_capabilities.IsEmpty()) {
ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(),
ExceptionState::kGetterContext, ExceptionState::kGetterContext,
......
...@@ -25,7 +25,7 @@ enum PaymentHandlerStatus { ...@@ -25,7 +25,7 @@ enum PaymentHandlerStatus {
struct PaymentInstrument { struct PaymentInstrument {
string name; string name;
array<blink.mojom.ManifestIcon> icons; array<blink.mojom.ManifestIcon> icons;
array<string> enabled_methods; string method;
string stringified_capabilities; string stringified_capabilities;
// Parsed basic-card specific capabilities. // Parsed basic-card specific capabilities.
......
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