Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: components/payments/content/payment_request.cc

Issue 2866623003: PaymentRequest.canMakePayment() query quota on desktop. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/content/payment_request.h" 5 #include "components/payments/content/payment_request.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "components/payments/content/can_make_payment_query_factory.h"
11 #include "components/payments/content/origin_security_checker.h" 12 #include "components/payments/content/origin_security_checker.h"
12 #include "components/payments/content/payment_details_validation.h" 13 #include "components/payments/content/payment_details_validation.h"
13 #include "components/payments/content/payment_request_web_contents_manager.h" 14 #include "components/payments/content/payment_request_web_contents_manager.h"
15 #include "components/payments/core/can_make_payment_query.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
16 19
17 namespace payments { 20 namespace payments {
18 21
19 PaymentRequest::PaymentRequest( 22 PaymentRequest::PaymentRequest(
23 content::RenderFrameHost* render_frame_host,
20 content::WebContents* web_contents, 24 content::WebContents* web_contents,
21 std::unique_ptr<PaymentRequestDelegate> delegate, 25 std::unique_ptr<PaymentRequestDelegate> delegate,
22 PaymentRequestWebContentsManager* manager, 26 PaymentRequestWebContentsManager* manager,
23 mojo::InterfaceRequest<mojom::PaymentRequest> request, 27 mojo::InterfaceRequest<mojom::PaymentRequest> request,
24 ObserverForTest* observer_for_testing) 28 ObserverForTest* observer_for_testing)
25 : web_contents_(web_contents), 29 : web_contents_(web_contents),
26 delegate_(std::move(delegate)), 30 delegate_(std::move(delegate)),
27 manager_(manager), 31 manager_(manager),
28 binding_(this, std::move(request)), 32 binding_(this, std::move(request)),
33 iframe_origin_(
34 GURL(render_frame_host->GetLastCommittedURL()).GetOrigin()),
29 observer_for_testing_(observer_for_testing), 35 observer_for_testing_(observer_for_testing),
30 journey_logger_(delegate_->IsIncognito(), 36 journey_logger_(delegate_->IsIncognito(),
31 web_contents_->GetLastCommittedURL(), 37 web_contents_->GetLastCommittedURL(),
32 delegate_->GetUkmService()) { 38 delegate_->GetUkmService()) {
33 // OnConnectionTerminated will be called when the Mojo pipe is closed. This 39 // OnConnectionTerminated will be called when the Mojo pipe is closed. This
34 // will happen as a result of many renderer-side events (both successful and 40 // will happen as a result of many renderer-side events (both successful and
35 // erroneous in nature). 41 // erroneous in nature).
36 // TODO(crbug.com/683636): Investigate using 42 // TODO(crbug.com/683636): Investigate using
37 // set_connection_error_with_reason_handler with Binding::CloseWithReason. 43 // set_connection_error_with_reason_handler with Binding::CloseWithReason.
38 binding_.set_connection_error_handler(base::Bind( 44 binding_.set_connection_error_handler(base::Bind(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } else { 147 } else {
142 journey_logger_.RecordJourneyStatsHistograms( 148 journey_logger_.RecordJourneyStatsHistograms(
143 JourneyLogger::COMPLETION_STATUS_COMPLETED); 149 JourneyLogger::COMPLETION_STATUS_COMPLETED);
144 // When the renderer closes the connection, 150 // When the renderer closes the connection,
145 // PaymentRequest::OnConnectionTerminated will be called. 151 // PaymentRequest::OnConnectionTerminated will be called.
146 client_->OnComplete(); 152 client_->OnComplete();
147 } 153 }
148 } 154 }
149 155
150 void PaymentRequest::CanMakePayment() { 156 void PaymentRequest::CanMakePayment() {
151 // TODO(crbug.com/704676): Implement a quota policy for this method. 157 bool can_make_payment = state()->CanMakePayment();
152 // PaymentRequest.canMakePayments() never returns false in incognito mode. 158 if (delegate_->IsIncognito()) {
153 client_->OnCanMakePayment( 159 client_->OnCanMakePayment(
154 delegate_->IsIncognito() || state()->CanMakePayment() 160 mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT);
155 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT 161 journey_logger_.SetCanMakePaymentValue(true);
156 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); 162 } else if (CanMakePaymentQueryFactory::GetInstance()
157 journey_logger_.SetCanMakePaymentValue(delegate_->IsIncognito() || 163 ->GetForContext(web_contents_->GetBrowserContext())
158 state()->CanMakePayment()); 164 ->CanQuery(iframe_origin_,
165 spec()->stringified_method_data())) {
166 client_->OnCanMakePayment(
167 can_make_payment
168 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT
169 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT);
170 journey_logger_.SetCanMakePaymentValue(can_make_payment);
171 } else if (OriginSecurityChecker::IsOriginLocalhostOrFile(iframe_origin_)) {
172 client_->OnCanMakePayment(
173 can_make_payment
174 ? mojom::CanMakePaymentQueryResult::WARNING_CAN_MAKE_PAYMENT
175 : mojom::CanMakePaymentQueryResult::WARNING_CANNOT_MAKE_PAYMENT);
176 journey_logger_.SetCanMakePaymentValue(can_make_payment);
177 } else {
178 client_->OnCanMakePayment(
179 mojom::CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED);
180 }
181
159 if (observer_for_testing_) 182 if (observer_for_testing_)
160 observer_for_testing_->OnCanMakePaymentCalled(); 183 observer_for_testing_->OnCanMakePaymentCalled();
161 } 184 }
162 185
163 void PaymentRequest::OnPaymentResponseAvailable( 186 void PaymentRequest::OnPaymentResponseAvailable(
164 mojom::PaymentResponsePtr response) { 187 mojom::PaymentResponsePtr response) {
165 client_->OnPaymentResponse(std::move(response)); 188 client_->OnPaymentResponse(std::move(response));
166 } 189 }
167 190
168 void PaymentRequest::OnShippingOptionIdSelected( 191 void PaymentRequest::OnShippingOptionIdSelected(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 binding_.Close(); 226 binding_.Close();
204 delegate_->CloseDialog(); 227 delegate_->CloseDialog();
205 manager_->DestroyRequest(this); 228 manager_->DestroyRequest(this);
206 } 229 }
207 230
208 void PaymentRequest::Pay() { 231 void PaymentRequest::Pay() {
209 state_->GeneratePaymentResponse(); 232 state_->GeneratePaymentResponse();
210 } 233 }
211 234
212 } // namespace payments 235 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698