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

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

Issue 2866623003: PaymentRequest.canMakePayment() query quota on desktop. (Closed)
Patch Set: frame 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 frame_origin_(GURL(render_frame_host->GetLastCommittedURL()).GetOrigin()),
29 observer_for_testing_(observer_for_testing), 34 observer_for_testing_(observer_for_testing),
30 journey_logger_(delegate_->IsIncognito(), 35 journey_logger_(delegate_->IsIncognito(),
31 web_contents_->GetLastCommittedURL(), 36 web_contents_->GetLastCommittedURL(),
32 delegate_->GetUkmService()) { 37 delegate_->GetUkmService()) {
33 // OnConnectionTerminated will be called when the Mojo pipe is closed. This 38 // 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 39 // will happen as a result of many renderer-side events (both successful and
35 // erroneous in nature). 40 // erroneous in nature).
36 // TODO(crbug.com/683636): Investigate using 41 // TODO(crbug.com/683636): Investigate using
37 // set_connection_error_with_reason_handler with Binding::CloseWithReason. 42 // set_connection_error_with_reason_handler with Binding::CloseWithReason.
38 binding_.set_connection_error_handler(base::Bind( 43 binding_.set_connection_error_handler(base::Bind(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } else { 165 } else {
161 journey_logger_.RecordJourneyStatsHistograms( 166 journey_logger_.RecordJourneyStatsHistograms(
162 JourneyLogger::COMPLETION_STATUS_COMPLETED); 167 JourneyLogger::COMPLETION_STATUS_COMPLETED);
163 // When the renderer closes the connection, 168 // When the renderer closes the connection,
164 // PaymentRequest::OnConnectionTerminated will be called. 169 // PaymentRequest::OnConnectionTerminated will be called.
165 client_->OnComplete(); 170 client_->OnComplete();
166 } 171 }
167 } 172 }
168 173
169 void PaymentRequest::CanMakePayment() { 174 void PaymentRequest::CanMakePayment() {
170 // TODO(crbug.com/704676): Implement a quota policy for this method. 175 bool can_make_payment = state()->CanMakePayment();
171 // PaymentRequest.canMakePayments() never returns false in incognito mode. 176 if (delegate_->IsIncognito()) {
172 client_->OnCanMakePayment( 177 client_->OnCanMakePayment(
173 delegate_->IsIncognito() || state()->CanMakePayment() 178 mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT);
174 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT 179 journey_logger_.SetCanMakePaymentValue(true);
175 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); 180 } else if (CanMakePaymentQueryFactory::GetInstance()
176 journey_logger_.SetCanMakePaymentValue(delegate_->IsIncognito() || 181 ->GetForContext(web_contents_->GetBrowserContext())
177 state()->CanMakePayment()); 182 ->CanQuery(frame_origin_, spec()->stringified_method_data())) {
183 client_->OnCanMakePayment(
184 can_make_payment
185 ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT
186 : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT);
187 journey_logger_.SetCanMakePaymentValue(can_make_payment);
188 } else if (OriginSecurityChecker::IsOriginLocalhostOrFile(frame_origin_)) {
189 client_->OnCanMakePayment(
190 can_make_payment
191 ? mojom::CanMakePaymentQueryResult::WARNING_CAN_MAKE_PAYMENT
192 : mojom::CanMakePaymentQueryResult::WARNING_CANNOT_MAKE_PAYMENT);
193 journey_logger_.SetCanMakePaymentValue(can_make_payment);
194 } else {
195 client_->OnCanMakePayment(
196 mojom::CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED);
197 }
198
178 if (observer_for_testing_) 199 if (observer_for_testing_)
179 observer_for_testing_->OnCanMakePaymentCalled(); 200 observer_for_testing_->OnCanMakePaymentCalled();
180 } 201 }
181 202
182 void PaymentRequest::OnPaymentResponseAvailable( 203 void PaymentRequest::OnPaymentResponseAvailable(
183 mojom::PaymentResponsePtr response) { 204 mojom::PaymentResponsePtr response) {
184 client_->OnPaymentResponse(std::move(response)); 205 client_->OnPaymentResponse(std::move(response));
185 } 206 }
186 207
187 void PaymentRequest::OnShippingOptionIdSelected( 208 void PaymentRequest::OnShippingOptionIdSelected(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (observer_for_testing_) 247 if (observer_for_testing_)
227 observer_for_testing_->OnConnectionTerminated(); 248 observer_for_testing_->OnConnectionTerminated();
228 manager_->DestroyRequest(this); 249 manager_->DestroyRequest(this);
229 } 250 }
230 251
231 void PaymentRequest::Pay() { 252 void PaymentRequest::Pay() {
232 state_->GeneratePaymentResponse(); 253 state_->GeneratePaymentResponse();
233 } 254 }
234 255
235 } // namespace payments 256 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request.h ('k') | components/payments/content/payment_request_spec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698