Commit 535fe30b authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment][Desktop] Reduce dependency on Views.

Before this patch, the service worker payment app factory in C++
depended on the payment request delegate interface, whose concrete
implementation depended on the desktop Views framework, which should not
be used on Android.

This patch moves the references to the delegate from the service worker
payment app factory into the payment request state object, which is not
used on Android at this time.

After this patch, it's possible to use the service worker payment app
factory on Android.

Design: https://bit.ly/cross-platform-pay-app-factory

Bug: 1022512
Change-Id: I649673ffdfe419708d796249c68998080efaa00f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217849
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774300}
parent 00b64553
...@@ -310,6 +310,12 @@ bool PaymentAppServiceBridge::MayCrawlForInstallablePaymentApps() { ...@@ -310,6 +310,12 @@ bool PaymentAppServiceBridge::MayCrawlForInstallablePaymentApps() {
return may_crawl_for_installable_payment_apps_; return may_crawl_for_installable_payment_apps_;
} }
bool PaymentAppServiceBridge::IsOffTheRecord() const {
Profile* profile =
Profile::FromBrowserContext(web_contents_->GetBrowserContext());
return profile && profile->IsOffTheRecord();
}
const std::vector<autofill::AutofillProfile*>& const std::vector<autofill::AutofillProfile*>&
PaymentAppServiceBridge::GetBillingProfiles() { PaymentAppServiceBridge::GetBillingProfiles() {
NOTREACHED(); NOTREACHED();
...@@ -328,6 +334,10 @@ PaymentAppServiceBridge::GetPaymentRequestDelegate() const { ...@@ -328,6 +334,10 @@ PaymentAppServiceBridge::GetPaymentRequestDelegate() const {
return nullptr; return nullptr;
} }
void PaymentAppServiceBridge::ShowProcessingSpinner() {
// Java UI determines when the show a spinner itself.
}
PaymentRequestSpec* PaymentAppServiceBridge::GetSpec() const { PaymentRequestSpec* PaymentAppServiceBridge::GetSpec() const {
return spec_; return spec_;
} }
......
...@@ -71,9 +71,11 @@ class PaymentAppServiceBridge : public PaymentAppFactory::Delegate { ...@@ -71,9 +71,11 @@ class PaymentAppServiceBridge : public PaymentAppFactory::Delegate {
scoped_refptr<PaymentManifestWebDataService> scoped_refptr<PaymentManifestWebDataService>
GetPaymentManifestWebDataService() const override; GetPaymentManifestWebDataService() const override;
bool MayCrawlForInstallablePaymentApps() override; bool MayCrawlForInstallablePaymentApps() override;
bool IsOffTheRecord() const override;
const std::vector<autofill::AutofillProfile*>& GetBillingProfiles() override; const std::vector<autofill::AutofillProfile*>& GetBillingProfiles() override;
bool IsRequestedAutofillDataAvailable() override; bool IsRequestedAutofillDataAvailable() override;
ContentPaymentRequestDelegate* GetPaymentRequestDelegate() const override; ContentPaymentRequestDelegate* GetPaymentRequestDelegate() const override;
void ShowProcessingSpinner() override;
PaymentRequestSpec* GetSpec() const override; PaymentRequestSpec* GetSpec() const override;
void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) override; void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) override;
void OnPaymentAppCreationError(const std::string& error_message) override; void OnPaymentAppCreationError(const std::string& error_message) override;
......
...@@ -54,14 +54,19 @@ class PaymentAppFactory { ...@@ -54,14 +54,19 @@ class PaymentAppFactory {
virtual scoped_refptr<PaymentManifestWebDataService> virtual scoped_refptr<PaymentManifestWebDataService>
GetPaymentManifestWebDataService() const = 0; GetPaymentManifestWebDataService() const = 0;
virtual bool MayCrawlForInstallablePaymentApps() = 0; virtual bool MayCrawlForInstallablePaymentApps() = 0;
virtual bool IsOffTheRecord() const = 0;
virtual PaymentRequestSpec* GetSpec() const = 0;
// Tells the UI to show the processing spinner. Only desktop UI needs this
// notification.
virtual void ShowProcessingSpinner() = 0;
// These parameters are only used to create native payment apps. // These parameters are only used to create the autofill payment app.
virtual const std::vector<autofill::AutofillProfile*>& virtual const std::vector<autofill::AutofillProfile*>&
GetBillingProfiles() = 0; GetBillingProfiles() = 0;
virtual bool IsRequestedAutofillDataAvailable() = 0; virtual bool IsRequestedAutofillDataAvailable() = 0;
virtual ContentPaymentRequestDelegate* GetPaymentRequestDelegate() virtual ContentPaymentRequestDelegate* GetPaymentRequestDelegate()
const = 0; const = 0;
virtual PaymentRequestSpec* GetSpec() const = 0;
// Called when an app is created. // Called when an app is created.
virtual void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) = 0; virtual void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) = 0;
......
...@@ -103,6 +103,10 @@ ContentPaymentRequestDelegate* PaymentRequestState::GetPaymentRequestDelegate() ...@@ -103,6 +103,10 @@ ContentPaymentRequestDelegate* PaymentRequestState::GetPaymentRequestDelegate()
return payment_request_delegate_; return payment_request_delegate_;
} }
void PaymentRequestState::ShowProcessingSpinner() {
GetPaymentRequestDelegate()->ShowProcessingSpinner();
}
PaymentRequestSpec* PaymentRequestState::GetSpec() const { PaymentRequestSpec* PaymentRequestState::GetSpec() const {
return spec_; return spec_;
} }
...@@ -149,6 +153,10 @@ bool PaymentRequestState::MayCrawlForInstallablePaymentApps() { ...@@ -149,6 +153,10 @@ bool PaymentRequestState::MayCrawlForInstallablePaymentApps() {
!spec_->supports_basic_card(); !spec_->supports_basic_card();
} }
bool PaymentRequestState::IsOffTheRecord() const {
return GetPaymentRequestDelegate()->IsOffTheRecord();
}
void PaymentRequestState::OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) { void PaymentRequestState::OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) {
if (app->type() == PaymentApp::Type::AUTOFILL) { if (app->type() == PaymentApp::Type::AUTOFILL) {
journey_logger_->SetEventOccurred( journey_logger_->SetEventOccurred(
......
...@@ -130,6 +130,7 @@ class PaymentRequestState : public PaymentAppFactory::Delegate, ...@@ -130,6 +130,7 @@ class PaymentRequestState : public PaymentAppFactory::Delegate,
// PaymentAppFactory::Delegate // PaymentAppFactory::Delegate
content::WebContents* GetWebContents() override; content::WebContents* GetWebContents() override;
ContentPaymentRequestDelegate* GetPaymentRequestDelegate() const override; ContentPaymentRequestDelegate* GetPaymentRequestDelegate() const override;
void ShowProcessingSpinner() override;
PaymentRequestSpec* GetSpec() const override; PaymentRequestSpec* GetSpec() const override;
const GURL& GetTopOrigin() override; const GURL& GetTopOrigin() override;
const GURL& GetFrameOrigin() override; const GURL& GetFrameOrigin() override;
...@@ -142,6 +143,7 @@ class PaymentRequestState : public PaymentAppFactory::Delegate, ...@@ -142,6 +143,7 @@ class PaymentRequestState : public PaymentAppFactory::Delegate,
const std::vector<autofill::AutofillProfile*>& GetBillingProfiles() override; const std::vector<autofill::AutofillProfile*>& GetBillingProfiles() override;
bool IsRequestedAutofillDataAvailable() override; bool IsRequestedAutofillDataAvailable() override;
bool MayCrawlForInstallablePaymentApps() override; bool MayCrawlForInstallablePaymentApps() override;
bool IsOffTheRecord() const override;
void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) override; void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) override;
void OnPaymentAppCreationError(const std::string& error_message) override; void OnPaymentAppCreationError(const std::string& error_message) override;
bool SkipCreatingNativePaymentApps() const override; bool SkipCreatingNativePaymentApps() const override;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/payments/content/content_payment_request_delegate.h"
#include "components/payments/content/payment_manifest_web_data_service.h" #include "components/payments/content/payment_manifest_web_data_service.h"
#include "components/payments/content/service_worker_payment_app.h" #include "components/payments/content/service_worker_payment_app.h"
#include "components/payments/content/service_worker_payment_app_finder.h" #include "components/payments/content/service_worker_payment_app_finder.h"
...@@ -65,16 +64,14 @@ class ServiceWorkerPaymentAppCreator { ...@@ -65,16 +64,14 @@ class ServiceWorkerPaymentAppCreator {
} }
base::RepeatingClosure show_processing_spinner = base::BindRepeating( base::RepeatingClosure show_processing_spinner = base::BindRepeating(
&PaymentRequestDelegate::ShowProcessingSpinner, &PaymentAppFactory::Delegate::ShowProcessingSpinner, delegate_);
delegate_->GetPaymentRequestDelegate()->GetWeakPtr());
for (auto& installed_app : apps) { for (auto& installed_app : apps) {
auto app = std::make_unique<ServiceWorkerPaymentApp>( auto app = std::make_unique<ServiceWorkerPaymentApp>(
delegate_->GetWebContents()->GetBrowserContext(), delegate_->GetWebContents()->GetBrowserContext(),
delegate_->GetTopOrigin(), delegate_->GetFrameOrigin(), delegate_->GetTopOrigin(), delegate_->GetFrameOrigin(),
delegate_->GetSpec(), std::move(installed_app.second), delegate_->GetSpec(), std::move(installed_app.second),
delegate_->GetPaymentRequestDelegate()->IsOffTheRecord(), delegate_->IsOffTheRecord(), show_processing_spinner);
show_processing_spinner);
app->ValidateCanMakePayment(base::BindOnce( app->ValidateCanMakePayment(base::BindOnce(
&ServiceWorkerPaymentAppCreator::OnSWPaymentAppValidated, &ServiceWorkerPaymentAppCreator::OnSWPaymentAppValidated,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
...@@ -87,8 +84,7 @@ class ServiceWorkerPaymentAppCreator { ...@@ -87,8 +84,7 @@ class ServiceWorkerPaymentAppCreator {
delegate_->GetWebContents(), delegate_->GetTopOrigin(), delegate_->GetWebContents(), delegate_->GetTopOrigin(),
delegate_->GetFrameOrigin(), delegate_->GetSpec(), delegate_->GetFrameOrigin(), delegate_->GetSpec(),
std::move(installable_app.second), installable_app.first.spec(), std::move(installable_app.second), installable_app.first.spec(),
delegate_->GetPaymentRequestDelegate()->IsOffTheRecord(), delegate_->IsOffTheRecord(), show_processing_spinner);
show_processing_spinner);
app->ValidateCanMakePayment(base::BindOnce( app->ValidateCanMakePayment(base::BindOnce(
&ServiceWorkerPaymentAppCreator::OnSWPaymentAppValidated, &ServiceWorkerPaymentAppCreator::OnSWPaymentAppValidated,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
......
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