| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ShowInitialPaymentSheet(); | 58 ShowInitialPaymentSheet(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 PaymentRequestDialogView::~PaymentRequestDialogView() {} | 61 PaymentRequestDialogView::~PaymentRequestDialogView() {} |
| 62 | 62 |
| 63 ui::ModalType PaymentRequestDialogView::GetModalType() const { | 63 ui::ModalType PaymentRequestDialogView::GetModalType() const { |
| 64 return ui::MODAL_TYPE_CHILD; | 64 return ui::MODAL_TYPE_CHILD; |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool PaymentRequestDialogView::Cancel() { | 67 bool PaymentRequestDialogView::Cancel() { |
| 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 68 // Called when the widget is about to close. We send a message to the | 69 // Called when the widget is about to close. We send a message to the |
| 69 // PaymentRequest object to signal user cancellation. | 70 // PaymentRequest object to signal user cancellation. Before destroying the |
| 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 // PaymentRequest object, we destroy all controllers so that they are not left |
| 72 // alive with an invalid PaymentRequest pointer. |
| 73 controller_map_.clear(); |
| 71 request_->UserCancelled(); | 74 request_->UserCancelled(); |
| 72 return true; | 75 return true; |
| 73 } | 76 } |
| 74 | 77 |
| 75 bool PaymentRequestDialogView::ShouldShowCloseButton() const { | 78 bool PaymentRequestDialogView::ShouldShowCloseButton() const { |
| 76 // Don't show the normal close button on the dialog. This is because the | 79 // Don't show the normal close button on the dialog. This is because the |
| 77 // typical dialog header doesn't allow displaying anything other that the | 80 // typical dialog header doesn't allow displaying anything other that the |
| 78 // title and the close button. This is insufficient for the PaymentRequest | 81 // title and the close button. This is insufficient for the PaymentRequest |
| 79 // dialog, which must sometimes show the back arrow next to the title. | 82 // dialog, which must sometimes show the back arrow next to the title. |
| 80 // Moreover, the title (and back arrow) should animate with the view they're | 83 // Moreover, the title (and back arrow) should animate with the view they're |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (observer_for_testing_) | 136 if (observer_for_testing_) |
| 134 observer_for_testing_->OnCreditCardEditorOpened(); | 137 observer_for_testing_->OnCreditCardEditorOpened(); |
| 135 } | 138 } |
| 136 | 139 |
| 137 void PaymentRequestDialogView::ShowDialog() { | 140 void PaymentRequestDialogView::ShowDialog() { |
| 138 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); | 141 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void PaymentRequestDialogView::CloseDialog() { | 144 void PaymentRequestDialogView::CloseDialog() { |
| 142 // This calls PaymentRequestDialogView::Cancel() before closing. | 145 // This calls PaymentRequestDialogView::Cancel() before closing. |
| 146 // ViewHierarchyChanged() also gets called after Cancel(). |
| 143 GetWidget()->Close(); | 147 GetWidget()->Close(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void PaymentRequestDialogView::ShowInitialPaymentSheet() { | 150 void PaymentRequestDialogView::ShowInitialPaymentSheet() { |
| 147 view_stack_.Push( | 151 view_stack_.Push( |
| 148 CreateViewAndInstallController( | 152 CreateViewAndInstallController( |
| 149 base::MakeUnique<PaymentSheetViewController>(request_, this), | 153 base::MakeUnique<PaymentSheetViewController>(request_, this), |
| 150 &controller_map_), | 154 &controller_map_), |
| 151 /* animate = */ false); | 155 /* animate = */ false); |
| 152 if (observer_for_testing_) | 156 if (observer_for_testing_) |
| 153 observer_for_testing_->OnDialogOpened(); | 157 observer_for_testing_->OnDialogOpened(); |
| 154 } | 158 } |
| 155 | 159 |
| 156 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { | 160 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { |
| 157 return gfx::Size(450, 450); | 161 return gfx::Size(450, 450); |
| 158 } | 162 } |
| 159 | 163 |
| 160 void PaymentRequestDialogView::ViewHierarchyChanged( | 164 void PaymentRequestDialogView::ViewHierarchyChanged( |
| 161 const ViewHierarchyChangedDetails& details) { | 165 const ViewHierarchyChangedDetails& details) { |
| 162 // When a view that is associated with a controller is removed from this | 166 // When a view that is associated with a controller is removed from this |
| 163 // view's descendants, dispose of the controller. | 167 // view's descendants, dispose of the controller. |
| 164 if (!details.is_add && | 168 if (!details.is_add && |
| 165 controller_map_.find(details.child) != controller_map_.end()) { | 169 controller_map_.find(details.child) != controller_map_.end()) { |
| 166 DCHECK(!details.move_view); | 170 DCHECK(!details.move_view); |
| 167 controller_map_.erase(details.child); | 171 controller_map_.erase(details.child); |
| 168 } | 172 } |
| 169 } | 173 } |
| 170 | 174 |
| 171 } // namespace payments | 175 } // namespace payments |
| OLD | NEW |