Commit 1f162d50 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Single HTTP GET for colocated SW manifests.

Before this patch, if both payment method manifest and the web app
manifest of a payment app were located in the same file, then Chrome
would retrieve the same file twice with two separate HTTP GET requests,
when looking for installable service worker based payment handlers.

This patch compares the URL of the payment method manifest and the web
app manifest and, if the two are the same, uses the in-memory copy of
the payment method manifest content as the web app manifest content
instead of re-downloading it again.

After this patch, when Chrome is looking for installable service worker
based payment handlers, if the web app manifest and the payment method
manifest files are located in the same file, then Chrome performs only
one HTTP GET request to retrieve it.

This patch does not modify Android payment app signature verification,
which always makes two separate HTTP GET requests for the payment method
manifest and the web app manifest, without comparing the two URLs for
equivalence.

Bug: 1069954
Change-Id: I83f82058caf3153e8ab2807acea05d350abd9b32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148114Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759213}
parent 8846bc49
......@@ -6,6 +6,7 @@ source_set("browsertests") {
testonly = true
sources = [
"colocated_payment_manifests_browsertest.cc",
"empty_parameters_browsertest.cc",
"has_enrolled_instrument_browsertest.cc",
"has_enrolled_instrument_query_quota_browsertest.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "chrome/test/payments/payment_request_platform_browsertest_base.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
namespace {
class ColocatedPaymentManifestsTest
: public PaymentRequestPlatformBrowserTestBase {};
// When "/pay" contains both the payment method manifest and the web app
// manifest, then payment should still work.
IN_PROC_BROWSER_TEST_F(ColocatedPaymentManifestsTest, CanPay) {
std::string method_name =
https_server()->GetURL("a.com", "/orenpay.com/pay").spec();
ASSERT_NE('/', method_name[method_name.length() - 1]);
NavigateTo("b.com", "/can_make_payment_checker.html");
EXPECT_EQ("true", content::EvalJs(
GetActiveWebContents(),
content::JsReplace("canMakePayment($1)", method_name)));
NavigateTo("b.com", "/payment_handler_status.html");
EXPECT_EQ("success",
content::EvalJs(GetActiveWebContents(),
content::JsReplace("getStatus($1)", method_name)));
}
} // namespace
} // namespace payments
......@@ -131,15 +131,17 @@ void InstallablePaymentAppCrawler::OnPaymentMethodManifestDownloaded(
number_of_payment_method_manifest_to_parse_++;
parser_->ParsePaymentMethodManifest(
method_manifest_url, content, base::BindOnce(
&InstallablePaymentAppCrawler::OnPaymentMethodManifestParsed,
weak_ptr_factory_.GetWeakPtr(), method_manifest_url,
method_manifest_url_after_redirects));
method_manifest_url, content,
base::BindOnce(
&InstallablePaymentAppCrawler::OnPaymentMethodManifestParsed,
weak_ptr_factory_.GetWeakPtr(), method_manifest_url,
method_manifest_url_after_redirects, content));
}
void InstallablePaymentAppCrawler::OnPaymentMethodManifestParsed(
const GURL& method_manifest_url,
const GURL& method_manifest_url_after_redirects,
const std::string& content,
const std::vector<GURL>& default_applications,
const std::vector<url::Origin>& supported_origins,
bool all_origins_supported) {
......@@ -182,6 +184,14 @@ void InstallablePaymentAppCrawler::OnPaymentMethodManifestParsed(
number_of_web_app_manifest_to_download_++;
downloaded_web_app_manifests_.insert(web_app_manifest_url);
if (method_manifest_url_after_redirects == web_app_manifest_url) {
OnPaymentWebAppManifestDownloaded(
method_manifest_url, web_app_manifest_url, web_app_manifest_url,
content, /*error_message=*/"");
continue;
}
downloader_->DownloadWebAppManifest(
url::Origin::Create(method_manifest_url_after_redirects),
web_app_manifest_url,
......
......@@ -29,7 +29,7 @@ class GURL;
namespace content {
class RenderFrameHost;
class WebContents;
}
} // namespace content
namespace payments {
......@@ -82,6 +82,7 @@ class InstallablePaymentAppCrawler : public content::WebContentsObserver {
void OnPaymentMethodManifestParsed(
const GURL& method_manifest_url,
const GURL& method_manifest_url_after_redirects,
const std::string& content,
const std::vector<GURL>& default_applications,
const std::vector<url::Origin>& supported_origins,
bool all_origins_supported);
......
Just-in-time installable payment handler that serves both the payment method
manifest and the web app manifest directly at the payment method identifier URL
https://a.com:<port>/orenpay.com/pay. This payment handler always can make
payments and responds to a payment request with {"status": "success"}.
/*
* Copyright 2020 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
self.addEventListener('canmakepayment', (event) => {
event.respondWith(true);
});
self.addEventListener('paymentrequest', (event) => {
event.respondWith({
methodName: event.methodData[0].supportedMethods,
details: {status: 'success'},
});
});
{
"default_applications": ["pay"],
"name": "Nick Pay",
"icons": [{
"src": "icon.png",
"sizes": "40x40",
"type": "image/png"
}],
"serviceworker": {
"src": "app.js"
}
}
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