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

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

Issue 2744633002: [Web Payments] Add the shipping method section to the payment sheet (Closed)
Patch Set: Created 3 years, 9 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 <algorithm> 7 #include <algorithm>
8 #include <set>
8 #include <unordered_map> 9 #include <unordered_map>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "components/autofill/core/browser/autofill_data_util.h" 13 #include "components/autofill/core/browser/autofill_data_util.h"
13 #include "components/autofill/core/browser/field_types.h" 14 #include "components/autofill/core/browser/field_types.h"
14 #include "components/autofill/core/browser/personal_data_manager.h" 15 #include "components/autofill/core/browser/personal_data_manager.h"
15 #include "components/payments/content/payment_details_validation.h" 16 #include "components/payments/content/payment_details_validation.h"
16 #include "components/payments/content/payment_request_web_contents_manager.h" 17 #include "components/payments/content/payment_request_web_contents_manager.h"
17 #include "components/payments/core/autofill_payment_instrument.h" 18 #include "components/payments/core/autofill_payment_instrument.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 LOG(ERROR) << error; 62 LOG(ERROR) << error;
62 OnConnectionTerminated(); 63 OnConnectionTerminated();
63 return; 64 return;
64 } 65 }
65 client_ = std::move(client); 66 client_ = std::move(client);
66 details_ = std::move(details); 67 details_ = std::move(details);
67 options_ = std::move(options); 68 options_ = std::move(options);
68 PopulateValidatedMethodData(method_data); 69 PopulateValidatedMethodData(method_data);
69 PopulateProfileCache(); 70 PopulateProfileCache();
70 SetDefaultProfileSelections(); 71 SetDefaultProfileSelections();
72 UpdateSelectedShippingOptionFromDetails();
71 } 73 }
72 74
73 void PaymentRequest::Show() { 75 void PaymentRequest::Show() {
74 if (!client_.is_bound() || !binding_.is_bound()) { 76 if (!client_.is_bound() || !binding_.is_bound()) {
75 LOG(ERROR) << "Attempted Show(), but binding(s) missing."; 77 LOG(ERROR) << "Attempted Show(), but binding(s) missing.";
76 OnConnectionTerminated(); 78 OnConnectionTerminated();
77 return; 79 return;
78 } 80 }
79 delegate_->ShowDialog(this); 81 delegate_->ShowDialog(this);
80 } 82 }
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 selected_contact_profile_ 382 selected_contact_profile_
381 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 383 ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
382 app_locale) 384 app_locale)
383 .empty())) { 385 .empty())) {
384 return false; 386 return false;
385 } 387 }
386 388
387 return true; 389 return true;
388 } 390 }
389 391
392 void PaymentRequest::UpdateSelectedShippingOptionFromDetails() {
393 selected_shipping_option_ = nullptr;
394
395 // As per the spec, the selected shipping option should initially be the last
396 // one in the array that has its selected field set to true.
397 auto selected_shipping_option_it = std::find_if(
398 details()->shipping_options.rbegin(), details()->shipping_options.rend(),
399 [](const payments::mojom::PaymentShippingOptionPtr& element) {
400 return element->selected;
401 });
402 if (selected_shipping_option_it != details()->shipping_options.rend()) {
403 selected_shipping_option_ = selected_shipping_option_it->get();
Mathieu 2017/03/09 19:07:03 I think it's fine to keep the pointer because |det
anthonyvd 2017/03/09 19:43:55 Done.
404 }
405 }
406
390 } // namespace payments 407 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698