Commit 8272b59d authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Chromium LUCI CQ

[Web Payment] Check if in TWA.

Before this patch, Web Payment would enable app store integration on
Chrome OS when invoked from an origin that has a TWA, even if not
currently running in a TWA. This allowed tabs to invoke the app store
billing flow.

This patch returns an empty TWA package name to Web Payment when
Browser::app_controller() is null.

After this patch, Web Payment enables the app the store billing flow
only when running inside of a TWA.

Bug: 1156537
Change-Id: Ie0ba5b0980be193dfcab36177d652e4ed2635407
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580011Reviewed-by: default avatarJeevan Shikaram <jshikaram@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834984}
parent e6f37df5
......@@ -267,6 +267,14 @@ std::string ChromePaymentRequestDelegate::GetTwaPackageName() const {
if (!rfh || !rfh->IsCurrent())
return "";
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
if (!web_contents)
return "";
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser || !browser->app_controller())
return "";
auto* apk_web_app_service = chromeos::ApkWebAppService::Get(
Profile::FromBrowserContext(rfh->GetBrowserContext()));
if (!apk_web_app_service)
......@@ -274,8 +282,7 @@ std::string ChromePaymentRequestDelegate::GetTwaPackageName() const {
base::Optional<std::string> twa_package_name =
apk_web_app_service->GetPackageNameForWebApp(
content::WebContents::FromRenderFrameHost(rfh)
->GetLastCommittedURL());
web_contents->GetLastCommittedURL());
return twa_package_name.has_value() ? twa_package_name.value() : "";
#else
......
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