Commit e21a1979 authored by gogerald's avatar gogerald Committed by Commit Bot

[Payments] Persist payment handler's icon for JIT PH

Test video:
https://drive.google.com/file/d/1XJjWyN1hMDKoZsAkLF66Yp-Rn3pyDXv3/view?usp=sharing

Bug: 782270

Change-Id: Ief93be66fb740feb439f92d2a55c41e6c9ed4f44
Reviewed-on: https://chromium-review.googlesource.com/943676Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541000}
parent 6fef1dd8
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.payments; package org.chromium.chrome.browser.payments;
import android.graphics.drawable.Drawable; import android.graphics.drawable.BitmapDrawable;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -114,7 +114,7 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen ...@@ -114,7 +114,7 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen
*/ */
public ServiceWorkerPaymentApp(WebContents webContents, long registrationId, URI scope, public ServiceWorkerPaymentApp(WebContents webContents, long registrationId, URI scope,
@Nullable String name, @Nullable String userHint, String origin, @Nullable String name, @Nullable String userHint, String origin,
@Nullable Drawable icon, String[] methodNames, Capabilities[] capabilities, @Nullable BitmapDrawable icon, String[] methodNames, Capabilities[] capabilities,
String[] preferredRelatedApplicationIds) { String[] preferredRelatedApplicationIds) {
// Do not display duplicate information. // Do not display duplicate information.
super(scope.toString(), TextUtils.isEmpty(name) ? origin : name, userHint, super(scope.toString(), TextUtils.isEmpty(name) ? origin : name, userHint,
...@@ -161,7 +161,8 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen ...@@ -161,7 +161,8 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen
* @param methodName The supported method name. * @param methodName The supported method name.
*/ */
public ServiceWorkerPaymentApp(WebContents webContents, @Nullable String name, String origin, public ServiceWorkerPaymentApp(WebContents webContents, @Nullable String name, String origin,
URI swUri, URI scope, boolean useCache, @Nullable Drawable icon, String methodName) { URI swUri, URI scope, boolean useCache, @Nullable BitmapDrawable icon,
String methodName) {
// Do not display duplicate information. // Do not display duplicate information.
super(scope.toString(), TextUtils.isEmpty(name) ? origin : name, null, super(scope.toString(), TextUtils.isEmpty(name) ? origin : name, null,
TextUtils.isEmpty(name) ? null : origin, icon); TextUtils.isEmpty(name) ? null : origin, icon);
...@@ -322,10 +323,12 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen ...@@ -322,10 +323,12 @@ public class ServiceWorkerPaymentApp extends PaymentInstrument implements Paymen
PaymentItem total, List<PaymentItem> displayItems, PaymentItem total, List<PaymentItem> displayItems,
Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCallback callback) { Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCallback callback) {
if (mNeedsInstallation) { if (mNeedsInstallation) {
BitmapDrawable icon = (BitmapDrawable) getDrawableIcon();
ServiceWorkerPaymentAppBridge.installAndInvokePaymentApp(mWebContents, origin, ServiceWorkerPaymentAppBridge.installAndInvokePaymentApp(mWebContents, origin,
iframeOrigin, id, new HashSet<>(methodData.values()), total, iframeOrigin, id, new HashSet<>(methodData.values()), total,
new HashSet<>(modifiers.values()), callback, mAppName, mSwUri, mScope, new HashSet<>(modifiers.values()), callback, mAppName,
mUseCache, mMethodNames); icon == null ? null : icon.getBitmap(), mSwUri, mScope, mUseCache,
mMethodNames);
} 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,
......
...@@ -202,6 +202,7 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ...@@ -202,6 +202,7 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
* @param modifiers Payment method specific modifiers to the payment items and the total. * @param modifiers Payment method specific modifiers to the payment items and the total.
* @param callback Called after the payment app is finished running. * @param callback Called after the payment app is finished running.
* @param appName The installable app name. * @param appName The installable app name.
* @param appIcon The installable app icon.
* @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.
...@@ -210,13 +211,14 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ...@@ -210,13 +211,14 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
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, URI swUri, PaymentInstrument.InstrumentDetailsCallback callback, String appName,
URI scope, boolean useCache, Set<String> methodNames) { @Nullable Bitmap icon, URI swUri, URI scope, boolean useCache,
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, modifiers.toArray(new PaymentDetailsModifier[0]), callback, appName, icon,
swUri.toString(), scope.toString(), useCache, methodNames.toArray(new String[0])); swUri.toString(), scope.toString(), useCache, methodNames.toArray(new String[0]));
} }
...@@ -422,8 +424,9 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA ...@@ -422,8 +424,9 @@ public class ServiceWorkerPaymentAppBridge implements PaymentAppFactory.PaymentA
private static native void nativeInstallAndInvokePaymentApp(WebContents webContents, private static native void nativeInstallAndInvokePaymentApp(WebContents webContents,
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, String swUrl, PaymentInstrument.InstrumentDetailsCallback callback, String appName,
String scope, boolean useCache, String[] methodNames); @Nullable Bitmap icon, String swUrl, String scope, boolean useCache,
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);
......
...@@ -14,7 +14,9 @@ import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.ENABLE ...@@ -14,7 +14,9 @@ import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.ENABLE
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.HAVE_INSTRUMENTS; import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.HAVE_INSTRUMENTS;
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.IMMEDIATE_RESPONSE; import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.IMMEDIATE_RESPONSE;
import android.graphics.drawable.ColorDrawable; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import org.junit.Before; import org.junit.Before;
...@@ -25,6 +27,7 @@ import org.junit.runner.RunWith; ...@@ -25,6 +27,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill.AutofillTestHelper; import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.autofill.CardType; import org.chromium.chrome.browser.autofill.CardType;
...@@ -322,19 +325,24 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest { ...@@ -322,19 +325,24 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest {
PaymentAppFactory.getInstance().addAdditionalFactory((webContents, methodNames, PaymentAppFactory.getInstance().addAdditionalFactory((webContents, methodNames,
callback) -> { callback) -> {
ChromeActivity activity = ChromeActivity.fromWebContents(webContents);
BitmapDrawable icon = new BitmapDrawable(activity.getResources(),
Bitmap.createBitmap(new int[] {Color.RED}, 1 /* width */, 1 /* height */,
Bitmap.Config.ARGB_8888));
ServiceWorkerPaymentAppBridge.setCanMakePaymentForTesting(true); ServiceWorkerPaymentAppBridge.setCanMakePaymentForTesting(true);
callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents,
0 /* registrationId */, 0 /* registrationId */,
UriUtils.parseUriFromString("https://bobpay.com") /* scope */, UriUtils.parseUriFromString("https://bobpay.com") /* scope */,
"BobPay" /* label */, "https://bobpay.com" /* sublabel*/, "BobPay" /* label */, "https://bobpay.com" /* sublabel*/,
"https://bobpay.com" /* tertiarylabel */, new ColorDrawable() /* icon */, "https://bobpay.com" /* tertiarylabel */, icon /* icon */,
bobpayMethodNames /* methodNames */, bobpayCapabilities /* capabilities */, bobpayMethodNames /* methodNames */, bobpayCapabilities /* capabilities */,
new String[0] /* preferredRelatedApplicationIds */)); new String[0] /* preferredRelatedApplicationIds */));
callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents, callback.onPaymentAppCreated(new ServiceWorkerPaymentApp(webContents,
0 /* registrationId */, 0 /* registrationId */,
UriUtils.parseUriFromString("https://alicepay.com") /* scope */, UriUtils.parseUriFromString("https://alicepay.com") /* scope */,
"AlicePay" /* label */, "https://bobpay.com" /* sublabel*/, "AlicePay" /* label */, "https://bobpay.com" /* sublabel*/,
"https://alicepay.com" /* tertiarylabel */, new ColorDrawable() /* icon */, "https://alicepay.com" /* tertiarylabel */, icon /* icon */,
alicepayMethodNames /* methodNames */, alicepayCapabilities /* capabilities */, alicepayMethodNames /* methodNames */, alicepayCapabilities /* capabilities */,
new String[0] /* preferredRelatedApplicationIds */)); new String[0] /* preferredRelatedApplicationIds */));
callback.onAllPaymentAppsCreated(); callback.onAllPaymentAppsCreated();
......
...@@ -461,6 +461,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -461,6 +461,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
const JavaParamRef<jobjectArray>& jmodifiers, const JavaParamRef<jobjectArray>& jmodifiers,
const JavaParamRef<jobject>& jcallback, const JavaParamRef<jobject>& jcallback,
const JavaParamRef<jstring>& japp_name, const JavaParamRef<jstring>& japp_name,
const JavaParamRef<jobject>& jicon,
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,
...@@ -468,6 +469,11 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -468,6 +469,11 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
content::WebContents* web_contents = content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents); content::WebContents::FromJavaWebContents(jweb_contents);
SkBitmap icon_bitmap;
if (jicon) {
icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(jicon));
}
std::vector<std::string> enabled_methods; std::vector<std::string> enabled_methods;
base::android::AppendJavaStringArrayToStringVector(env, jmethod_names, base::android::AppendJavaStringArrayToStringVector(env, jmethod_names,
&enabled_methods); &enabled_methods);
...@@ -476,7 +482,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp( ...@@ -476,7 +482,7 @@ static void JNI_ServiceWorkerPaymentAppBridge_InstallAndInvokePaymentApp(
ConvertPaymentRequestEventDataFromJavaToNative( ConvertPaymentRequestEventDataFromJavaToNative(
env, jtop_level_origin, jpayment_request_origin, jpayment_request_id, env, jtop_level_origin, jpayment_request_origin, jpayment_request_id,
jmethod_data, jtotal, jmodifiers), jmethod_data, jtotal, jmodifiers),
ConvertJavaStringToUTF8(env, japp_name), 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, enabled_methods,
base::BindOnce(&OnPaymentAppInvoked, base::BindOnce(&OnPaymentAppInvoked,
......
...@@ -196,7 +196,11 @@ void ServiceWorkerPaymentInstrument::InvokePaymentApp(Delegate* delegate) { ...@@ -196,7 +196,11 @@ void ServiceWorkerPaymentInstrument::InvokePaymentApp(Delegate* delegate) {
if (needs_installation_) { if (needs_installation_) {
content::PaymentAppProvider::GetInstance()->InstallAndInvokePaymentApp( content::PaymentAppProvider::GetInstance()->InstallAndInvokePaymentApp(
web_contents_, CreatePaymentRequestEventData(), web_contents_, CreatePaymentRequestEventData(),
installable_web_app_info_->name, installable_web_app_info_->sw_js_url, installable_web_app_info_->name,
installable_web_app_info_->icon == nullptr
? SkBitmap()
: *(installable_web_app_info_->icon),
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,
std::vector<std::string>(1, installable_enabled_method_), std::vector<std::string>(1, installable_enabled_method_),
......
...@@ -405,6 +405,7 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker( ...@@ -405,6 +405,7 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker(
int64_t registration_id, int64_t registration_id,
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::vector<std::string>& enabled_methods,
SetPaymentAppInfoCallback callback) { SetPaymentAppInfoCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -412,13 +413,14 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker( ...@@ -412,13 +413,14 @@ void PaymentAppDatabase::SetPaymentAppInfoForRegisteredServiceWorker(
service_worker_context_->FindReadyRegistrationForIdOnly( service_worker_context_->FindReadyRegistrationForIdOnly(
registration_id, registration_id,
base::BindOnce(&PaymentAppDatabase::DidFindRegistrationToSetPaymentApp, base::BindOnce(&PaymentAppDatabase::DidFindRegistrationToSetPaymentApp,
weak_ptr_factory_.GetWeakPtr(), instrument_key, name, weak_ptr_factory_.GetWeakPtr(), instrument_key, name, icon,
enabled_methods, std::move(callback))); enabled_methods, 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::vector<std::string>& enabled_methods, const std::vector<std::string>& enabled_methods,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
...@@ -434,6 +436,7 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp( ...@@ -434,6 +436,7 @@ void PaymentAppDatabase::DidFindRegistrationToSetPaymentApp(
payment_app_proto.set_registration_id(registration->id()); payment_app_proto.set_registration_id(registration->id());
payment_app_proto.set_scope(registration->pattern().spec()); payment_app_proto.set_scope(registration->pattern().spec());
payment_app_proto.set_name(name); payment_app_proto.set_name(name);
payment_app_proto.set_icon(icon);
std::string serialized_payment_app; std::string serialized_payment_app;
bool success = payment_app_proto.SerializeToString(&serialized_payment_app); bool success = payment_app_proto.SerializeToString(&serialized_payment_app);
......
...@@ -82,6 +82,7 @@ class CONTENT_EXPORT PaymentAppDatabase { ...@@ -82,6 +82,7 @@ class CONTENT_EXPORT PaymentAppDatabase {
int64_t registration_id, int64_t registration_id,
const std::string& instrument_key, const std::string& instrument_key,
const std::string& name, const std::string& name,
const std::string& icon,
const std::vector<std::string>& enabled_methods, const std::vector<std::string>& enabled_methods,
SetPaymentAppInfoCallback callback); SetPaymentAppInfoCallback callback);
...@@ -205,6 +206,7 @@ class CONTENT_EXPORT PaymentAppDatabase { ...@@ -205,6 +206,7 @@ class CONTENT_EXPORT PaymentAppDatabase {
void DidFindRegistrationToSetPaymentApp( void 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::vector<std::string>& enabled_methods, const std::vector<std::string>& enabled_methods,
SetPaymentAppInfoCallback callback, SetPaymentAppInfoCallback callback,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
......
...@@ -28,12 +28,14 @@ class SelfDeleteInstaller ...@@ -28,12 +28,14 @@ class SelfDeleteInstaller
public: public:
SelfDeleteInstaller(WebContents* web_contents, SelfDeleteInstaller(WebContents* web_contents,
const std::string& app_name, const std::string& app_name,
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::vector<std::string>& enabled_methods,
PaymentAppInstaller::InstallPaymentAppCallback callback) PaymentAppInstaller::InstallPaymentAppCallback callback)
: app_name_(app_name), : app_name_(app_name),
app_icon_(app_icon),
sw_url_(sw_url), sw_url_(sw_url),
scope_(scope), scope_(scope),
callback_(std::move(callback)) { callback_(std::move(callback)) {
...@@ -135,7 +137,7 @@ class SelfDeleteInstaller ...@@ -135,7 +137,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_, enabled_methods_)); app_name_, app_icon_, enabled_methods_));
} }
void SetPaymentAppInfoOnIO( void SetPaymentAppInfoOnIO(
...@@ -143,12 +145,13 @@ class SelfDeleteInstaller ...@@ -143,12 +145,13 @@ class SelfDeleteInstaller
int64_t registration_id, int64_t registration_id,
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::vector<std::string>& enabled_methods) { const std::vector<std::string>& enabled_methods) {
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, enabled_methods, registration_id, instrument_key, name, app_icon, enabled_methods,
base::BindOnce(&SelfDeleteInstaller::OnSetPaymentAppInfo, this)); base::BindOnce(&SelfDeleteInstaller::OnSetPaymentAppInfo, this));
} }
...@@ -186,6 +189,7 @@ class SelfDeleteInstaller ...@@ -186,6 +189,7 @@ class SelfDeleteInstaller
} }
std::string app_name_; std::string app_name_;
std::string app_icon_;
GURL sw_url_; GURL sw_url_;
GURL scope_; GURL scope_;
std::vector<std::string> enabled_methods_; std::vector<std::string> enabled_methods_;
...@@ -203,6 +207,7 @@ class SelfDeleteInstaller ...@@ -203,6 +207,7 @@ class SelfDeleteInstaller
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 GURL& sw_url, const GURL& sw_url,
const GURL& scope, const GURL& scope,
bool use_cache, bool use_cache,
...@@ -210,8 +215,8 @@ void PaymentAppInstaller::Install( ...@@ -210,8 +215,8 @@ void PaymentAppInstaller::Install(
InstallPaymentAppCallback callback) { InstallPaymentAppCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
new SelfDeleteInstaller(web_contents, app_name, sw_url, scope, use_cache, new SelfDeleteInstaller(web_contents, app_name, app_icon, sw_url, scope,
enabled_methods, std::move(callback)); use_cache, enabled_methods, std::move(callback));
} }
} // namespace content } // namespace content
\ No newline at end of file
...@@ -27,6 +27,7 @@ class PaymentAppInstaller { ...@@ -27,6 +27,7 @@ class PaymentAppInstaller {
// Installs the payment app. // Installs the payment app.
// |app_name| is the name of the payment app. // |app_name| is the name of the payment app.
// |app_icon| is the icon of the payment app.
// |sw_url| is the url to get the service worker js script. // |sw_url| is the url to get the service worker js script.
// |scope| is the registration scope. // |scope| is the registration scope.
// |use_cache| indicates whether to use cache. // |use_cache| indicates whether to use cache.
...@@ -34,6 +35,7 @@ class PaymentAppInstaller { ...@@ -34,6 +35,7 @@ class PaymentAppInstaller {
// |callback| to send back registeration result. // |callback| to send back registeration result.
static void Install(WebContents* web_contents, static void Install(WebContents* web_contents,
const std::string& app_name, const std::string& app_name,
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,
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/payments/payment_app_provider_impl.h" #include "content/browser/payments/payment_app_provider_impl.h"
#include "base/base64.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/browser/payments/payment_app_context_impl.h" #include "content/browser/payments/payment_app_context_impl.h"
#include "content/browser/payments/payment_app_installer.h" #include "content/browser/payments/payment_app_installer.h"
...@@ -17,6 +18,8 @@ ...@@ -17,6 +18,8 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/common/time.mojom.h" #include "mojo/common/time.mojom.h"
#include "third_party/WebKit/public/mojom/service_worker/service_worker_provider_type.mojom.h" #include "third_party/WebKit/public/mojom/service_worker/service_worker_provider_type.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
namespace content { namespace content {
namespace { namespace {
...@@ -401,6 +404,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp( ...@@ -401,6 +404,7 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp(
WebContents* web_contents, WebContents* web_contents,
payments::mojom::PaymentRequestEventDataPtr event_data, payments::mojom::PaymentRequestEventDataPtr event_data,
const std::string& app_name, const std::string& app_name,
const SkBitmap& app_icon,
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,
...@@ -420,8 +424,19 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp( ...@@ -420,8 +424,19 @@ void PaymentAppProviderImpl::InstallAndInvokePaymentApp(
return; return;
} }
std::string string_encoded_icon;
if (!app_icon.empty()) {
gfx::Image decoded_image = gfx::Image::CreateFrom1xBitmap(app_icon);
scoped_refptr<base::RefCountedMemory> raw_data =
decoded_image.As1xPNGBytes();
base::Base64Encode(
base::StringPiece(raw_data->front_as<char>(), raw_data->size()),
&string_encoded_icon);
}
PaymentAppInstaller::Install( PaymentAppInstaller::Install(
web_contents, app_name, url, scope, sw_use_cache, enabled_methods, web_contents, app_name, string_encoded_icon, url, scope, sw_use_cache,
enabled_methods,
base::BindOnce(&OnInstallPaymentApp, std::move(event_data), base::BindOnce(&OnInstallPaymentApp, std::move(event_data),
std::move(callback))); std::move(callback)));
} }
......
...@@ -28,6 +28,7 @@ class CONTENT_EXPORT PaymentAppProviderImpl : public PaymentAppProvider { ...@@ -28,6 +28,7 @@ class CONTENT_EXPORT PaymentAppProviderImpl : public PaymentAppProvider {
WebContents* web_contents, WebContents* web_contents,
payments::mojom::PaymentRequestEventDataPtr event_data, payments::mojom::PaymentRequestEventDataPtr event_data,
const std::string& app_name, const std::string& app_name,
const SkBitmap& app_icon,
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,
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "content/public/browser/stored_payment_app.h" #include "content/public/browser/stored_payment_app.h"
#include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.h" #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.h"
class SkBitmap;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
...@@ -51,6 +53,7 @@ class CONTENT_EXPORT PaymentAppProvider { ...@@ -51,6 +53,7 @@ class CONTENT_EXPORT PaymentAppProvider {
WebContents* web_contents, WebContents* web_contents,
payments::mojom::PaymentRequestEventDataPtr event_data, payments::mojom::PaymentRequestEventDataPtr event_data,
const std::string& app_name, const std::string& app_name,
const SkBitmap& app_icon,
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,
......
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