Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" | 11 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 12 #include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h" | |
| 12 #include "chrome/browser/ui/views/payments/error_message_view_controller.h" | 13 #include "chrome/browser/ui/views/payments/error_message_view_controller.h" |
| 13 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" | 14 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
| 14 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" | 15 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" |
| 15 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | 16 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
| 16 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" | 17 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
| 17 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h" | 18 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h" |
| 18 #include "chrome/browser/ui/views/payments/shipping_option_view_controller.h" | 19 #include "chrome/browser/ui/views/payments/shipping_option_view_controller.h" |
| 19 #include "components/constrained_window/constrained_window_views.h" | 20 #include "components/constrained_window/constrained_window_views.h" |
| 20 #include "components/payments/content/payment_request.h" | 21 #include "components/payments/content/payment_request.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
| 23 | 24 |
| 24 namespace chrome { | 25 namespace chrome { |
| 25 | 26 |
| 26 payments::PaymentRequestDialog* CreatePaymentRequestDialog( | 27 payments::PaymentRequestDialog* CreatePaymentRequestDialog( |
| 27 payments::PaymentRequest* request) { | 28 payments::PaymentRequest* request) { |
| 28 return new payments::PaymentRequestDialogView(request, | 29 return new payments::PaymentRequestDialogView(request, |
| 29 /* no observer */ nullptr); | 30 /* no observer */ nullptr); |
| 30 } | 31 } |
| 31 | 32 |
| 32 } // namespace chrome | 33 } // namespace chrome |
| 33 | 34 |
| 34 namespace payments { | 35 namespace payments { |
| 36 | |
| 37 class CvcUnmaskUIDelegate | |
|
Mathieu
2017/03/30 14:37:32
Can CvcUnmaskViewController be the autofill::payme
anthonyvd
2017/04/04 13:25:22
The UIDelegate is now the CvcUnmaskViewController.
| |
| 38 : public autofill::payments::FullCardRequest::UIDelegate, | |
| 39 public CvcUnmaskViewController::Observer { | |
| 40 public: | |
| 41 explicit CvcUnmaskUIDelegate(PaymentRequestDialogView* dialog, | |
|
please use gerrit instead
2017/03/30 13:14:09
Explicit keyword is used only for constructors wit
anthonyvd
2017/03/30 15:43:41
Ah, there was a time when this only took one param
| |
| 42 PaymentRequestSpec* spec, | |
| 43 PaymentRequestState* state) | |
| 44 : dialog_(dialog), spec_(spec), state_(state), weak_ptr_factory_(this) {} | |
| 45 | |
| 46 ~CvcUnmaskUIDelegate() override { OnClosed(); } | |
| 47 | |
| 48 // autofill::payments::FullCardRequest::UIDelegate: | |
| 49 void ShowUnmaskPrompt( | |
| 50 const autofill::CreditCard& card, | |
| 51 autofill::AutofillClient::UnmaskCardReason reason, | |
| 52 base::WeakPtr<autofill::CardUnmaskDelegate> delegate) override { | |
| 53 unmask_delegate_ = delegate; | |
| 54 std::unique_ptr<CvcUnmaskViewController> view_controller = | |
| 55 base::MakeUnique<CvcUnmaskViewController>( | |
| 56 spec_, state_, dialog_, card.TypeAndLastFourDigits(), card.type()); | |
| 57 | |
| 58 view_controller->AddObserver(this); | |
| 59 dialog_->ShowCvcUnmaskSheet(std::move(view_controller)); | |
| 60 } | |
| 61 | |
| 62 void OnUnmaskVerificationResult( | |
| 63 autofill::AutofillClient::PaymentsRpcResult result) override { | |
| 64 // TODO(anthonyvd): Check result and display UI. | |
| 65 } | |
| 66 | |
| 67 // CvcUnmaskViewController::Observer | |
| 68 void OnCvcConfirmed(const base::string16& cvc) override { | |
| 69 if (unmask_delegate_) { | |
| 70 autofill::CardUnmaskDelegate::UnmaskResponse response; | |
| 71 response.cvc = cvc; | |
| 72 unmask_delegate_->OnUnmaskResponse(response); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void OnClosed() override { | |
| 77 // TODO(anthonyvd): The dialog was closed, notify the full card request. | |
| 78 } | |
| 79 | |
| 80 base::WeakPtr<CvcUnmaskUIDelegate> AsWeakPtr() { | |
| 81 return weak_ptr_factory_.GetWeakPtr(); | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 PaymentRequestDialogView* dialog_; | |
| 86 PaymentRequestSpec* spec_; | |
| 87 PaymentRequestState* state_; | |
| 88 | |
| 89 base::WeakPtr<autofill::CardUnmaskDelegate> unmask_delegate_; | |
| 90 | |
| 91 base::WeakPtrFactory<CvcUnmaskUIDelegate> weak_ptr_factory_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(CvcUnmaskUIDelegate); | |
| 94 }; | |
| 95 | |
| 35 namespace { | 96 namespace { |
| 36 | 97 |
| 37 // This function creates an instance of a PaymentRequestSheetController | 98 // This function creates an instance of a PaymentRequestSheetController |
| 38 // subclass of concrete type |Controller|, passing it non-owned pointers to | 99 // subclass of concrete type |Controller|, passing it non-owned pointers to |
| 39 // |dialog| and the |request| that initiated that dialog. |map| should be owned | 100 // |dialog| and the |request| that initiated that dialog. |map| should be owned |
| 40 // by |dialog|. | 101 // by |dialog|. |
| 41 std::unique_ptr<views::View> CreateViewAndInstallController( | 102 std::unique_ptr<views::View> CreateViewAndInstallController( |
| 42 std::unique_ptr<PaymentRequestSheetController> controller, | 103 std::unique_ptr<PaymentRequestSheetController> controller, |
| 43 payments::ControllerMap* map) { | 104 payments::ControllerMap* map) { |
| 44 std::unique_ptr<views::View> view = controller->CreateView(); | 105 std::unique_ptr<views::View> view = controller->CreateView(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } | 231 } |
| 171 | 232 |
| 172 void PaymentRequestDialogView::ShowShippingOptionSheet() { | 233 void PaymentRequestDialogView::ShowShippingOptionSheet() { |
| 173 view_stack_.Push(CreateViewAndInstallController( | 234 view_stack_.Push(CreateViewAndInstallController( |
| 174 base::MakeUnique<ShippingOptionViewController>( | 235 base::MakeUnique<ShippingOptionViewController>( |
| 175 request_->spec(), request_->state(), this), | 236 request_->spec(), request_->state(), this), |
| 176 &controller_map_), | 237 &controller_map_), |
| 177 /* animate = */ true); | 238 /* animate = */ true); |
| 178 } | 239 } |
| 179 | 240 |
| 241 void PaymentRequestDialogView::ShowCvcUnmaskSheet( | |
| 242 std::unique_ptr<CvcUnmaskViewController> view_controller) { | |
| 243 view_stack_.Push(CreateViewAndInstallController(std::move(view_controller), | |
| 244 &controller_map_), | |
| 245 /* animate = */ true); | |
| 246 } | |
| 247 | |
| 180 void PaymentRequestDialogView::ShowCreditCardEditor() { | 248 void PaymentRequestDialogView::ShowCreditCardEditor() { |
| 181 view_stack_.Push(CreateViewAndInstallController( | 249 view_stack_.Push(CreateViewAndInstallController( |
| 182 base::MakeUnique<CreditCardEditorViewController>( | 250 base::MakeUnique<CreditCardEditorViewController>( |
| 183 request_->spec(), request_->state(), this), | 251 request_->spec(), request_->state(), this), |
| 184 &controller_map_), | 252 &controller_map_), |
| 185 /* animate = */ true); | 253 /* animate = */ true); |
| 186 if (observer_for_testing_) | 254 if (observer_for_testing_) |
| 187 observer_for_testing_->OnCreditCardEditorOpened(); | 255 observer_for_testing_->OnCreditCardEditorOpened(); |
| 188 } | 256 } |
| 189 | 257 |
| 190 void PaymentRequestDialogView::ShowShippingAddressEditor() { | 258 void PaymentRequestDialogView::ShowShippingAddressEditor() { |
| 191 view_stack_.Push(CreateViewAndInstallController( | 259 view_stack_.Push(CreateViewAndInstallController( |
| 192 base::MakeUnique<ShippingAddressEditorViewController>( | 260 base::MakeUnique<ShippingAddressEditorViewController>( |
| 193 request_->spec(), request_->state(), this), | 261 request_->spec(), request_->state(), this), |
| 194 &controller_map_), | 262 &controller_map_), |
| 195 /* animate = */ true); | 263 /* animate = */ true); |
| 196 if (observer_for_testing_) | 264 if (observer_for_testing_) |
| 197 observer_for_testing_->OnShippingAddressEditorOpened(); | 265 observer_for_testing_->OnShippingAddressEditorOpened(); |
| 198 } | 266 } |
| 199 | 267 |
| 200 void PaymentRequestDialogView::EditorViewUpdated() { | 268 void PaymentRequestDialogView::EditorViewUpdated() { |
| 201 if (observer_for_testing_) | 269 if (observer_for_testing_) |
| 202 observer_for_testing_->OnEditorViewUpdated(); | 270 observer_for_testing_->OnEditorViewUpdated(); |
| 203 } | 271 } |
| 204 | 272 |
| 273 base::WeakPtr<autofill::payments::FullCardRequest::UIDelegate> | |
| 274 PaymentRequestDialogView::GetFullCardRequestUIDelegate() { | |
| 275 cvc_unmask_ui_delegate_ = base::MakeUnique<CvcUnmaskUIDelegate>( | |
| 276 this, request_->spec(), request_->state()); | |
| 277 return cvc_unmask_ui_delegate_->AsWeakPtr(); | |
| 278 } | |
| 279 | |
| 205 void PaymentRequestDialogView::ShowInitialPaymentSheet() { | 280 void PaymentRequestDialogView::ShowInitialPaymentSheet() { |
| 206 view_stack_.Push(CreateViewAndInstallController( | 281 view_stack_.Push(CreateViewAndInstallController( |
| 207 base::MakeUnique<PaymentSheetViewController>( | 282 base::MakeUnique<PaymentSheetViewController>( |
| 208 request_->spec(), request_->state(), this), | 283 request_->spec(), request_->state(), this), |
| 209 &controller_map_), | 284 &controller_map_), |
| 210 /* animate = */ false); | 285 /* animate = */ false); |
| 211 if (observer_for_testing_) | 286 if (observer_for_testing_) |
| 212 observer_for_testing_->OnDialogOpened(); | 287 observer_for_testing_->OnDialogOpened(); |
| 213 } | 288 } |
| 214 | 289 |
| 215 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { | 290 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { |
| 216 return gfx::Size(450, 450); | 291 return gfx::Size(450, 450); |
| 217 } | 292 } |
| 218 | 293 |
| 219 void PaymentRequestDialogView::ViewHierarchyChanged( | 294 void PaymentRequestDialogView::ViewHierarchyChanged( |
| 220 const ViewHierarchyChangedDetails& details) { | 295 const ViewHierarchyChangedDetails& details) { |
| 221 if (being_closed_) | 296 if (being_closed_) |
| 222 return; | 297 return; |
| 223 | 298 |
| 224 // When a view that is associated with a controller is removed from this | 299 // When a view that is associated with a controller is removed from this |
| 225 // view's descendants, dispose of the controller. | 300 // view's descendants, dispose of the controller. |
| 226 if (!details.is_add && | 301 if (!details.is_add && |
| 227 controller_map_.find(details.child) != controller_map_.end()) { | 302 controller_map_.find(details.child) != controller_map_.end()) { |
| 228 DCHECK(!details.move_view); | 303 DCHECK(!details.move_view); |
| 229 controller_map_.erase(details.child); | 304 controller_map_.erase(details.child); |
| 230 } | 305 } |
| 231 } | 306 } |
| 232 | 307 |
| 233 } // namespace payments | 308 } // namespace payments |
| OLD | NEW |