Commit 1b8e49eb authored by gogerald's avatar gogerald Committed by Commit Bot

[Payments] Use url.mojom.Url for stricter type check

Bug: 812297
Change-Id: Ifb855b4e52ed3fde171569a017fa856cad5cc2dd
Reviewed-on: https://chromium-review.googlesource.com/940324
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539979}
parent 58df1a56
......@@ -189,7 +189,7 @@ PaymentManager* PaymentAppContentUnitTestBase::CreatePaymentManager(
for (const auto& candidate_manager :
payment_app_context()->payment_managers_) {
if (!base::ContainsKey(existing_managers, candidate_manager.first)) {
candidate_manager.first->Init(sw_script_url.spec(), scope_url.spec());
candidate_manager.first->Init(sw_script_url, scope_url.spec());
base::RunLoop().RunUntilIdle();
return candidate_manager.first;
}
......
......@@ -14,6 +14,7 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/browser_thread.h"
#include "url/origin.h"
namespace content {
......@@ -34,12 +35,26 @@ PaymentManager::PaymentManager(
&PaymentManager::OnConnectionError, base::Unretained(this)));
}
void PaymentManager::Init(const std::string& context,
const std::string& scope) {
void PaymentManager::Init(const GURL& context_url, const std::string& scope) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
should_set_payment_app_info_ = true;
context_ = GURL(context);
context_url_ = context_url;
scope_ = GURL(scope);
if (!context_url_.is_valid()) {
binding_.CloseWithReason(0U, "Invalid context URL.");
return;
}
if (!scope_.is_valid()) {
binding_.CloseWithReason(1U, "Invalid scope URL.");
return;
}
if (!url::IsSameOriginWith(context_url_, scope_)) {
binding_.CloseWithReason(
2U, "Scope URL is not from the same origin of the context URL.");
return;
}
}
void PaymentManager::DeletePaymentInstrument(
......@@ -107,7 +122,7 @@ void PaymentManager::SetPaymentInstrumentIntermediateCallback(
}
payment_app_context_->payment_app_database()->FetchAndWritePaymentAppInfo(
context_, scope_, user_hint_, std::move(callback));
context_url_, scope_, user_hint_, std::move(callback));
should_set_payment_app_info_ = false;
}
......
......@@ -32,7 +32,7 @@ class CONTENT_EXPORT PaymentManager : public payments::mojom::PaymentManager {
friend class PaymentManagerTest;
// payments::mojom::PaymentManager methods:
void Init(const std::string& context, const std::string& scope) override;
void Init(const GURL& context_url, const std::string& scope) override;
void DeletePaymentInstrument(
const std::string& instrument_key,
DeletePaymentInstrumentCallback callback) override;
......@@ -60,7 +60,7 @@ class CONTENT_EXPORT PaymentManager : public payments::mojom::PaymentManager {
PaymentAppContextImpl* payment_app_context_;
bool should_set_payment_app_info_;
GURL context_;
GURL context_url_;
GURL scope_;
std::string user_hint_;
mojo::Binding<payments::mojom::PaymentManager> binding_;
......
......@@ -52,7 +52,7 @@ PaymentManager::PaymentManager(ServiceWorkerRegistration* registration)
manager_.set_connection_error_handler(WTF::Bind(
&PaymentManager::OnServiceConnectionError, WrapWeakPersistent(this)));
manager_->Init(registration_->GetExecutionContext()->Url().GetString(),
manager_->Init(registration_->GetExecutionContext()->Url(),
registration_->scope());
}
......
......@@ -39,7 +39,10 @@ struct PaymentInstrument {
// by payment_manager.cc and runs in browser side.
interface PaymentManager {
// |context_url| is the url of the web page creating this interface.
Init(string context_url, string service_worker_scope);
// |service_worker_scope| is passed as string since it is from
// ServiceWorkerRegistration and the interface is used for
// ServiceWorkerRegistration.idl
Init(url.mojom.Url context_url, string service_worker_scope);
DeletePaymentInstrument(string instrument_key)
=> (PaymentHandlerStatus status);
GetPaymentInstrument(string instrument_key)
......
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