mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 5 | #include "components/payments/content/payment_request.h" |
| 6 | |
anthonyvd | d23ed70 | 2017-04-05 15:29:00 | [diff] [blame] | 7 | #include <string> |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 8 | #include <utility> |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 9 | |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame] | 10 | #include "base/memory/ptr_util.h" |
Mathieu Perreault | 627b97c | 2017-08-12 00:44:22 | [diff] [blame] | 11 | #include "base/stl_util.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 12 | #include "components/payments/content/can_make_payment_query_factory.h" |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 13 | #include "components/payments/content/origin_security_checker.h" |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 14 | #include "components/payments/content/payment_details_validation.h" |
| 15 | #include "components/payments/content/payment_request_web_contents_manager.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 16 | #include "components/payments/core/can_make_payment_query.h" |
anthonyvd | 6a43b93 | 2017-05-11 18:39:27 | [diff] [blame] | 17 | #include "components/payments/core/payment_prefs.h" |
| 18 | #include "components/prefs/pref_service.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 19 | #include "content/public/browser/browser_thread.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 20 | #include "content/public/browser/render_frame_host.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 21 | #include "content/public/browser/web_contents.h" |
| 22 | |
| 23 | namespace payments { |
| 24 | |
| 25 | PaymentRequest::PaymentRequest( |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 26 | content::RenderFrameHost* render_frame_host, |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 27 | content::WebContents* web_contents, |
| 28 | std::unique_ptr<PaymentRequestDelegate> delegate, |
| 29 | PaymentRequestWebContentsManager* manager, |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 30 | mojo::InterfaceRequest<mojom::PaymentRequest> request, |
mathp | 300fa54 | 2017-03-27 19:29:37 | [diff] [blame] | 31 | ObserverForTest* observer_for_testing) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 32 | : web_contents_(web_contents), |
| 33 | delegate_(std::move(delegate)), |
| 34 | manager_(manager), |
mathp | 300fa54 | 2017-03-27 19:29:37 | [diff] [blame] | 35 | binding_(this, std::move(request)), |
Rouslan Solomakhin | 115f723 | 2017-08-01 15:24:38 | [diff] [blame] | 36 | top_level_origin_(web_contents_->GetLastCommittedURL().GetOrigin()), |
| 37 | frame_origin_(render_frame_host->GetLastCommittedURL().GetOrigin()), |
sebsg | 20b49d7b | 2017-05-04 20:23:17 | [diff] [blame] | 38 | observer_for_testing_(observer_for_testing), |
| 39 | journey_logger_(delegate_->IsIncognito(), |
| 40 | web_contents_->GetLastCommittedURL(), |
Anthony Vallee-Dubois | dc1dbf1a | 2017-07-17 15:01:13 | [diff] [blame] | 41 | delegate_->GetUkmRecorder()), |
| 42 | weak_ptr_factory_(this) { |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 43 | // OnConnectionTerminated will be called when the Mojo pipe is closed. This |
| 44 | // will happen as a result of many renderer-side events (both successful and |
| 45 | // erroneous in nature). |
| 46 | // TODO(crbug.com/683636): Investigate using |
| 47 | // set_connection_error_with_reason_handler with Binding::CloseWithReason. |
| 48 | binding_.set_connection_error_handler(base::Bind( |
Anthony Vallee-Dubois | dc1dbf1a | 2017-07-17 15:01:13 | [diff] [blame] | 49 | &PaymentRequest::OnConnectionTerminated, weak_ptr_factory_.GetWeakPtr())); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | PaymentRequest::~PaymentRequest() {} |
| 53 | |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 54 | void PaymentRequest::Init(mojom::PaymentRequestClientPtr client, |
| 55 | std::vector<mojom::PaymentMethodDataPtr> method_data, |
| 56 | mojom::PaymentDetailsPtr details, |
| 57 | mojom::PaymentOptionsPtr options) { |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 58 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 59 | client_ = std::move(client); |
| 60 | |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 61 | const GURL last_committed_url = delegate_->GetLastCommittedURL(); |
| 62 | if (!OriginSecurityChecker::IsOriginSecure(last_committed_url)) { |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 63 | LOG(ERROR) << "Not in a secure origin"; |
| 64 | OnConnectionTerminated(); |
| 65 | return; |
| 66 | } |
| 67 | |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 68 | bool allowed_origin = |
| 69 | OriginSecurityChecker::IsSchemeCryptographic(last_committed_url) || |
| 70 | OriginSecurityChecker::IsOriginLocalhostOrFile(last_committed_url); |
| 71 | if (!allowed_origin) { |
| 72 | LOG(ERROR) << "Only localhost, file://, and cryptographic scheme origins " |
| 73 | "allowed"; |
| 74 | } |
| 75 | |
| 76 | bool invalid_ssl = |
| 77 | OriginSecurityChecker::IsSchemeCryptographic(last_committed_url) && |
| 78 | !delegate_->IsSslCertificateValid(); |
| 79 | if (invalid_ssl) |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 80 | LOG(ERROR) << "SSL certificate is not valid"; |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 81 | |
| 82 | if (!allowed_origin || invalid_ssl) { |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 83 | // Don't show UI. Resolve .canMakepayment() with "false". Reject .show() |
| 84 | // with "NotSupportedError". |
| 85 | spec_ = base::MakeUnique<PaymentRequestSpec>( |
| 86 | mojom::PaymentOptions::New(), mojom::PaymentDetails::New(), |
| 87 | std::vector<mojom::PaymentMethodDataPtr>(), this, |
| 88 | delegate_->GetApplicationLocale()); |
| 89 | state_ = base::MakeUnique<PaymentRequestState>( |
| 90 | spec_.get(), this, delegate_->GetApplicationLocale(), |
sebsg | c6719b3 | 2017-07-05 19:54:47 | [diff] [blame] | 91 | delegate_->GetPersonalDataManager(), delegate_.get(), &journey_logger_); |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 95 | std::string error; |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 96 | if (!validatePaymentDetails(details, &error)) { |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 97 | LOG(ERROR) << error; |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 98 | OnConnectionTerminated(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 99 | return; |
| 100 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 101 | |
jinho.bang | fcb5ec9 | 2017-03-29 08:08:02 | [diff] [blame] | 102 | if (!details->total) { |
| 103 | LOG(ERROR) << "Missing total"; |
| 104 | OnConnectionTerminated(); |
| 105 | return; |
| 106 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 107 | |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 108 | spec_ = base::MakeUnique<PaymentRequestSpec>( |
mathp | c0d616a | 2017-03-15 14:09:33 | [diff] [blame] | 109 | std::move(options), std::move(details), std::move(method_data), this, |
| 110 | delegate_->GetApplicationLocale()); |
| 111 | state_ = base::MakeUnique<PaymentRequestState>( |
| 112 | spec_.get(), this, delegate_->GetApplicationLocale(), |
sebsg | c6719b3 | 2017-07-05 19:54:47 | [diff] [blame] | 113 | delegate_->GetPersonalDataManager(), delegate_.get(), &journey_logger_); |
Mathieu Perreault | 627b97c | 2017-08-12 00:44:22 | [diff] [blame] | 114 | |
| 115 | journey_logger_.SetRequestedInformation( |
| 116 | spec_->request_shipping(), spec_->request_payer_email(), |
| 117 | spec_->request_payer_phone(), spec_->request_payer_name()); |
| 118 | |
| 119 | // Log metrics around which payment methods are requested by the merchant. |
| 120 | GURL google_pay_url(kGooglePayMethodName); |
| 121 | GURL android_pay_url(kAndroidPayMethodName); |
| 122 | // Looking for payment methods that are NOT google-related payment methods. |
| 123 | auto non_google_it = |
| 124 | std::find_if(spec_->url_payment_method_identifiers().begin(), |
| 125 | spec_->url_payment_method_identifiers().end(), |
| 126 | [google_pay_url, android_pay_url](const GURL& url) { |
| 127 | return url != google_pay_url && url != android_pay_url; |
| 128 | }); |
| 129 | journey_logger_.SetRequestedPaymentMethodTypes( |
| 130 | /*requested_basic_card=*/!spec_->supported_card_networks().empty(), |
| 131 | /*requested_method_google=*/ |
| 132 | base::ContainsValue(spec_->url_payment_method_identifiers(), |
| 133 | google_pay_url) || |
| 134 | base::ContainsValue(spec_->url_payment_method_identifiers(), |
| 135 | android_pay_url), |
| 136 | /*requested_method_other=*/non_google_it != |
| 137 | spec_->url_payment_method_identifiers().end()); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void PaymentRequest::Show() { |
tmartino | 8ce92285 | 2017-01-09 22:23:10 | [diff] [blame] | 141 | if (!client_.is_bound() || !binding_.is_bound()) { |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 142 | LOG(ERROR) << "Attempted Show(), but binding(s) missing."; |
| 143 | OnConnectionTerminated(); |
tmartino | 8ce92285 | 2017-01-09 22:23:10 | [diff] [blame] | 144 | return; |
| 145 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 146 | |
rouslan | 7d433cc2 | 2017-05-08 15:18:07 | [diff] [blame] | 147 | // A tab can display only one PaymentRequest UI at a time. |
| 148 | if (!manager_->CanShow(this)) { |
| 149 | LOG(ERROR) << "A PaymentRequest UI is already showing"; |
sebsg | 828269bc | 2017-06-09 19:11:12 | [diff] [blame] | 150 | journey_logger_.SetNotShown( |
| 151 | JourneyLogger::NOT_SHOWN_REASON_CONCURRENT_REQUESTS); |
rouslan | 7d433cc2 | 2017-05-08 15:18:07 | [diff] [blame] | 152 | client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
| 153 | OnConnectionTerminated(); |
| 154 | return; |
| 155 | } |
| 156 | |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 157 | if (!state_->AreRequestedMethodsSupported()) { |
sebsg | 828269bc | 2017-06-09 19:11:12 | [diff] [blame] | 158 | journey_logger_.SetNotShown( |
| 159 | JourneyLogger::NOT_SHOWN_REASON_NO_SUPPORTED_PAYMENT_METHOD); |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 160 | client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED); |
| 161 | if (observer_for_testing_) |
| 162 | observer_for_testing_->OnNotSupportedError(); |
| 163 | OnConnectionTerminated(); |
| 164 | return; |
| 165 | } |
| 166 | |
mathp | 57c8c86 | 2017-06-16 20:15:45 | [diff] [blame] | 167 | journey_logger_.SetEventOccurred(JourneyLogger::EVENT_SHOWN); |
sebsg | 8f4fa4d | 2017-06-13 15:25:45 | [diff] [blame] | 168 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 169 | delegate_->ShowDialog(this); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 170 | } |
| 171 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 172 | void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) { |
| 173 | std::string error; |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 174 | if (!validatePaymentDetails(details, &error)) { |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 175 | LOG(ERROR) << error; |
| 176 | OnConnectionTerminated(); |
| 177 | return; |
| 178 | } |
Rouslan Solomakhin | 4cbda82 | 2017-08-23 18:50:39 | [diff] [blame^] | 179 | |
| 180 | if (!details->total) { |
| 181 | LOG(ERROR) << "Missing total"; |
| 182 | OnConnectionTerminated(); |
| 183 | return; |
| 184 | } |
| 185 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 186 | spec_->UpdateWith(std::move(details)); |
| 187 | } |
| 188 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 189 | void PaymentRequest::Abort() { |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 190 | // The API user has decided to abort. If a successful abort message is |
| 191 | // returned to the renderer, the Mojo message pipe is closed, which triggers |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 192 | // PaymentRequest::OnConnectionTerminated, which destroys this object. |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 193 | // Otherwise, the abort promise is rejected and the pipe is not closed. |
| 194 | // The abort is only successful if the payment app wasn't yet invoked. |
| 195 | // TODO(crbug.com/716546): Add a merchant abort metric |
| 196 | |
| 197 | bool accepting_abort = !state_->IsPaymentAppInvoked(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 198 | if (accepting_abort) |
| 199 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT); |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 200 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 201 | if (client_.is_bound()) |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 202 | client_->OnAbort(accepting_abort); |
| 203 | |
| 204 | if (observer_for_testing_) |
| 205 | observer_for_testing_->OnAbortCalled(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 206 | } |
| 207 | |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 208 | void PaymentRequest::Complete(mojom::PaymentComplete result) { |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 209 | if (!client_.is_bound()) |
| 210 | return; |
| 211 | |
Rouslan Solomakhin | e347319 | 2017-06-16 14:54:57 | [diff] [blame] | 212 | // Failed transactions show an error. Successful and unknown-state |
| 213 | // transactions don't show an error. |
| 214 | if (result == mojom::PaymentComplete::FAIL) { |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 215 | delegate_->ShowErrorMessage(); |
| 216 | } else { |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 217 | DCHECK(!has_recorded_completion_); |
sebsg | f8272a2 | 2017-05-26 14:32:58 | [diff] [blame] | 218 | journey_logger_.SetCompleted(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 219 | has_recorded_completion_ = true; |
| 220 | |
anthonyvd | 6a43b93 | 2017-05-11 18:39:27 | [diff] [blame] | 221 | delegate_->GetPrefService()->SetBoolean(kPaymentsFirstTransactionCompleted, |
| 222 | true); |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 223 | // When the renderer closes the connection, |
| 224 | // PaymentRequest::OnConnectionTerminated will be called. |
| 225 | client_->OnComplete(); |
sebsg | 8a93b27 | 2017-05-11 19:30:22 | [diff] [blame] | 226 | state_->RecordUseStats(); |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 227 | } |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void PaymentRequest::CanMakePayment() { |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 231 | bool can_make_payment = state()->CanMakePayment(); |
| 232 | if (delegate_->IsIncognito()) { |
| 233 | client_->OnCanMakePayment( |
| 234 | mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT); |
| 235 | journey_logger_.SetCanMakePaymentValue(true); |
| 236 | } else if (CanMakePaymentQueryFactory::GetInstance() |
| 237 | ->GetForContext(web_contents_->GetBrowserContext()) |
Rouslan Solomakhin | 115f723 | 2017-08-01 15:24:38 | [diff] [blame] | 238 | ->CanQuery(top_level_origin_, frame_origin_, |
| 239 | spec()->stringified_method_data())) { |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 240 | client_->OnCanMakePayment( |
| 241 | can_make_payment |
| 242 | ? mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT |
| 243 | : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT); |
| 244 | journey_logger_.SetCanMakePaymentValue(can_make_payment); |
Rouslan Solomakhin | 115f723 | 2017-08-01 15:24:38 | [diff] [blame] | 245 | } else if (OriginSecurityChecker::IsOriginLocalhostOrFile( |
| 246 | frame_origin_.GetURL())) { |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 247 | client_->OnCanMakePayment( |
| 248 | can_make_payment |
| 249 | ? mojom::CanMakePaymentQueryResult::WARNING_CAN_MAKE_PAYMENT |
| 250 | : mojom::CanMakePaymentQueryResult::WARNING_CANNOT_MAKE_PAYMENT); |
| 251 | journey_logger_.SetCanMakePaymentValue(can_make_payment); |
| 252 | } else { |
| 253 | client_->OnCanMakePayment( |
| 254 | mojom::CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED); |
| 255 | } |
| 256 | |
mathp | 300fa54 | 2017-03-27 19:29:37 | [diff] [blame] | 257 | if (observer_for_testing_) |
| 258 | observer_for_testing_->OnCanMakePaymentCalled(); |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 259 | } |
| 260 | |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 261 | void PaymentRequest::OnPaymentResponseAvailable( |
| 262 | mojom::PaymentResponsePtr response) { |
mathp | 57c8c86 | 2017-06-16 20:15:45 | [diff] [blame] | 263 | journey_logger_.SetEventOccurred( |
| 264 | JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS); |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 265 | client_->OnPaymentResponse(std::move(response)); |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 266 | } |
| 267 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 268 | void PaymentRequest::OnShippingOptionIdSelected( |
| 269 | std::string shipping_option_id) { |
| 270 | client_->OnShippingOptionChange(shipping_option_id); |
| 271 | } |
| 272 | |
| 273 | void PaymentRequest::OnShippingAddressSelected( |
| 274 | mojom::PaymentAddressPtr address) { |
| 275 | client_->OnShippingAddressChange(std::move(address)); |
| 276 | } |
| 277 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 278 | void PaymentRequest::UserCancelled() { |
| 279 | // If |client_| is not bound, then the object is already being destroyed as |
| 280 | // a result of a renderer event. |
| 281 | if (!client_.is_bound()) |
| 282 | return; |
| 283 | |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 284 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); |
sebsg | 20b49d7b | 2017-05-04 20:23:17 | [diff] [blame] | 285 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 286 | // This sends an error to the renderer, which informs the API user. |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 287 | client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 288 | |
| 289 | // We close all bindings and ask to be destroyed. |
| 290 | client_.reset(); |
| 291 | binding_.Close(); |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 292 | if (observer_for_testing_) |
| 293 | observer_for_testing_->OnConnectionTerminated(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 294 | manager_->DestroyRequest(this); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 295 | } |
| 296 | |
sebsg | 2c8558a | 2017-05-17 18:54:10 | [diff] [blame] | 297 | void PaymentRequest::DidStartNavigation(bool is_user_initiated) { |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 298 | RecordFirstAbortReason(is_user_initiated |
| 299 | ? JourneyLogger::ABORT_REASON_USER_NAVIGATION |
| 300 | : JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION); |
sebsg | 2c8558a | 2017-05-17 18:54:10 | [diff] [blame] | 301 | } |
| 302 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 303 | void PaymentRequest::OnConnectionTerminated() { |
| 304 | // We are here because of a browser-side error, or likely as a result of the |
| 305 | // connection_error_handler on |binding_|, which can mean that the renderer |
| 306 | // has decided to close the pipe for various reasons (see all uses of |
| 307 | // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close |
| 308 | // the binding and the dialog, and ask to be deleted. |
| 309 | client_.reset(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 310 | binding_.Close(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 311 | delegate_->CloseDialog(); |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 312 | if (observer_for_testing_) |
| 313 | observer_for_testing_->OnConnectionTerminated(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 314 | |
| 315 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_MOJO_CONNECTION_ERROR); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 316 | manager_->DestroyRequest(this); |
| 317 | } |
| 318 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 319 | void PaymentRequest::Pay() { |
mathp | 57c8c86 | 2017-06-16 20:15:45 | [diff] [blame] | 320 | journey_logger_.SetEventOccurred(JourneyLogger::EVENT_PAY_CLICKED); |
Mathieu Perreault | 49a97e5 | 2017-08-15 01:51:36 | [diff] [blame] | 321 | journey_logger_.SetEventOccurred(JourneyLogger::EVENT_SELECTED_CREDIT_CARD); |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 322 | state_->GeneratePaymentResponse(); |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 323 | } |
| 324 | |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 325 | void PaymentRequest::RecordFirstAbortReason( |
| 326 | JourneyLogger::AbortReason abort_reason) { |
| 327 | if (!has_recorded_completion_) { |
| 328 | has_recorded_completion_ = true; |
| 329 | journey_logger_.SetAborted(abort_reason); |
sebsg | 2c8558a | 2017-05-17 18:54:10 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 333 | } // namespace payments |