Commit 3f4e1b8a authored by Nick Burris's avatar Nick Burris Committed by Chromium LUCI CQ

Ensure SecurePaymentConfirmationAppFactory owns InternalAuthenticator

This patch ensures that the InternalAuthenticator created by
SecurePaymentConfirmationAppFactory is always owned by a
WebContentsObserver, to ensure that the authenticator is outlived by
its RenderFrameHost.

Bug: 1169317
Change-Id: Ie22c3796d642589f912b880bcdadeb3badde8180
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644743
Commit-Queue: Nick Burris <nburris@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Auto-Submit: Nick Burris <nburris@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846426}
parent 0b4f7fef
...@@ -72,13 +72,13 @@ void SecurePaymentConfirmationAppFactory:: ...@@ -72,13 +72,13 @@ void SecurePaymentConfirmationAppFactory::
OnIsUserVerifyingPlatformAuthenticatorAvailable( OnIsUserVerifyingPlatformAuthenticatorAvailable(
base::WeakPtr<PaymentAppFactory::Delegate> delegate, base::WeakPtr<PaymentAppFactory::Delegate> delegate,
mojom::SecurePaymentConfirmationRequestPtr request, mojom::SecurePaymentConfirmationRequestPtr request,
std::unique_ptr<autofill::InternalAuthenticator> authenticator,
bool is_available) { bool is_available) {
if (!delegate || !delegate->GetWebContents()) if (!delegate || !delegate->GetWebContents())
return; return;
if (!is_available && !base::FeatureList::IsEnabled( if (!authenticator_ ||
features::kSecurePaymentConfirmationDebug)) { (!is_available && !base::FeatureList::IsEnabled(
features::kSecurePaymentConfirmationDebug))) {
delegate->OnDoneCreatingPaymentApps(); delegate->OnDoneCreatingPaymentApps();
return; return;
} }
...@@ -98,8 +98,9 @@ void SecurePaymentConfirmationAppFactory:: ...@@ -98,8 +98,9 @@ void SecurePaymentConfirmationAppFactory::
WebDataServiceBase::Handle handle = WebDataServiceBase::Handle handle =
web_data_service->GetSecurePaymentConfirmationInstruments( web_data_service->GetSecurePaymentConfirmationInstruments(
std::move(request->credential_ids), this); std::move(request->credential_ids), this);
requests_[handle] = std::make_unique<Request>( requests_[handle] =
delegate, web_data_service, std::move(request), std::move(authenticator)); std::make_unique<Request>(delegate, web_data_service, std::move(request),
std::move(authenticator_));
} }
SecurePaymentConfirmationAppFactory::SecurePaymentConfirmationAppFactory() SecurePaymentConfirmationAppFactory::SecurePaymentConfirmationAppFactory()
...@@ -133,16 +134,16 @@ void SecurePaymentConfirmationAppFactory::Create( ...@@ -133,16 +134,16 @@ void SecurePaymentConfirmationAppFactory::Create(
return; return;
} }
std::unique_ptr<autofill::InternalAuthenticator> authenticator = // Observe the web contents to ensure the authenticator outlives it.
delegate->CreateInternalAuthenticator(); Observe(delegate->GetWebContents());
auto* authenticator_ptr = authenticator.get();
authenticator_ptr->IsUserVerifyingPlatformAuthenticatorAvailable( authenticator_ = delegate->CreateInternalAuthenticator();
authenticator_->IsUserVerifyingPlatformAuthenticatorAvailable(
base::BindOnce(&SecurePaymentConfirmationAppFactory:: base::BindOnce(&SecurePaymentConfirmationAppFactory::
OnIsUserVerifyingPlatformAuthenticatorAvailable, OnIsUserVerifyingPlatformAuthenticatorAvailable,
weak_ptr_factory_.GetWeakPtr(), delegate, weak_ptr_factory_.GetWeakPtr(), delegate,
method_data->secure_payment_confirmation.Clone(), method_data->secure_payment_confirmation.Clone()));
std::move(authenticator)));
return; return;
} }
} }
...@@ -150,6 +151,14 @@ void SecurePaymentConfirmationAppFactory::Create( ...@@ -150,6 +151,14 @@ void SecurePaymentConfirmationAppFactory::Create(
delegate->OnDoneCreatingPaymentApps(); delegate->OnDoneCreatingPaymentApps();
} }
void SecurePaymentConfirmationAppFactory::RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) {
if (authenticator_ &&
authenticator_->GetRenderFrameHost() == render_frame_host) {
authenticator_.reset();
}
}
struct SecurePaymentConfirmationAppFactory::Request struct SecurePaymentConfirmationAppFactory::Request
: public content::WebContentsObserver { : public content::WebContentsObserver {
Request( Request(
...@@ -168,6 +177,15 @@ struct SecurePaymentConfirmationAppFactory::Request ...@@ -168,6 +177,15 @@ struct SecurePaymentConfirmationAppFactory::Request
Request(const Request& other) = delete; Request(const Request& other) = delete;
Request& operator=(const Request& other) = delete; Request& operator=(const Request& other) = delete;
// WebContentsObserver:
void RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) override {
if (authenticator &&
authenticator->GetRenderFrameHost() == render_frame_host) {
authenticator.reset();
}
}
base::WeakPtr<PaymentAppFactory::Delegate> delegate; base::WeakPtr<PaymentAppFactory::Delegate> delegate;
scoped_refptr<payments::PaymentManifestWebDataService> web_data_service; scoped_refptr<payments::PaymentManifestWebDataService> web_data_service;
mojom::SecurePaymentConfirmationRequestPtr mojo_request; mojom::SecurePaymentConfirmationRequestPtr mojo_request;
...@@ -224,7 +242,7 @@ void SecurePaymentConfirmationAppFactory::OnAppIconDecoded( ...@@ -224,7 +242,7 @@ void SecurePaymentConfirmationAppFactory::OnAppIconDecoded(
const SkBitmap& decoded_icon) { const SkBitmap& decoded_icon) {
DCHECK(request); DCHECK(request);
if (!request->delegate || !request->web_contents() || if (!request->delegate || !request->web_contents() ||
!request->delegate->GetSpec() || !request->delegate->GetSpec() || !request->authenticator ||
request->authenticator->GetRenderFrameHost() != request->authenticator->GetRenderFrameHost() !=
request->web_contents()->GetMainFrame()) { request->web_contents()->GetMainFrame()) {
request->delegate->OnDoneCreatingPaymentApps(); request->delegate->OnDoneCreatingPaymentApps();
......
...@@ -11,13 +11,16 @@ ...@@ -11,13 +11,16 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/payments/content/payment_app_factory.h" #include "components/payments/content/payment_app_factory.h"
#include "components/webdata/common/web_data_service_consumer.h" #include "components/webdata/common/web_data_service_consumer.h"
#include "content/public/browser/web_contents_observer.h"
namespace payments { namespace payments {
struct SecurePaymentConfirmationInstrument; struct SecurePaymentConfirmationInstrument;
class SecurePaymentConfirmationAppFactory : public PaymentAppFactory, class SecurePaymentConfirmationAppFactory
public WebDataServiceConsumer { : public PaymentAppFactory,
public WebDataServiceConsumer,
public content::WebContentsObserver {
public: public:
SecurePaymentConfirmationAppFactory(); SecurePaymentConfirmationAppFactory();
~SecurePaymentConfirmationAppFactory() override; ~SecurePaymentConfirmationAppFactory() override;
...@@ -38,10 +41,12 @@ class SecurePaymentConfirmationAppFactory : public PaymentAppFactory, ...@@ -38,10 +41,12 @@ class SecurePaymentConfirmationAppFactory : public PaymentAppFactory,
WebDataServiceBase::Handle handle, WebDataServiceBase::Handle handle,
std::unique_ptr<WDTypedResult> result) override; std::unique_ptr<WDTypedResult> result) override;
// WebContentsObserver:
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void OnIsUserVerifyingPlatformAuthenticatorAvailable( void OnIsUserVerifyingPlatformAuthenticatorAvailable(
base::WeakPtr<PaymentAppFactory::Delegate> delegate, base::WeakPtr<PaymentAppFactory::Delegate> delegate,
mojom::SecurePaymentConfirmationRequestPtr request, mojom::SecurePaymentConfirmationRequestPtr request,
std::unique_ptr<autofill::InternalAuthenticator> authenticator,
bool is_available); bool is_available);
void OnAppIconDecoded( void OnAppIconDecoded(
...@@ -49,6 +54,8 @@ class SecurePaymentConfirmationAppFactory : public PaymentAppFactory, ...@@ -49,6 +54,8 @@ class SecurePaymentConfirmationAppFactory : public PaymentAppFactory,
std::unique_ptr<Request> request, std::unique_ptr<Request> request,
const SkBitmap& decoded_image); const SkBitmap& decoded_image);
std::unique_ptr<autofill::InternalAuthenticator> authenticator_;
std::map<WebDataServiceBase::Handle, std::unique_ptr<Request>> requests_; std::map<WebDataServiceBase::Handle, std::unique_ptr<Request>> requests_;
base::WeakPtrFactory<SecurePaymentConfirmationAppFactory> weak_ptr_factory_{ base::WeakPtrFactory<SecurePaymentConfirmationAppFactory> weak_ptr_factory_{
this}; this};
......
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