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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_dialog_view.cc

Issue 2724063002: [Payments] Add a Pay button in the Order summary screen (Closed)
Patch Set: addressed comments 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 "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 30 matching lines...) Expand all
41 std::unique_ptr<views::View> view = controller->CreateView(); 41 std::unique_ptr<views::View> view = controller->CreateView();
42 (*map)[view.get()] = std::move(controller); 42 (*map)[view.get()] = std::move(controller);
43 return view; 43 return view;
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 PaymentRequestDialogView::PaymentRequestDialogView( 48 PaymentRequestDialogView::PaymentRequestDialogView(
49 PaymentRequest* request, 49 PaymentRequest* request,
50 PaymentRequestDialogView::ObserverForTest* observer) 50 PaymentRequestDialogView::ObserverForTest* observer)
51 : request_(request), observer_for_testing_(observer) { 51 : request_(request), observer_for_testing_(observer), being_closed_(false) {
52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
53 SetLayoutManager(new views::FillLayout()); 53 SetLayoutManager(new views::FillLayout());
54 54
55 view_stack_.set_owned_by_client(); 55 view_stack_.set_owned_by_client();
56 AddChildView(&view_stack_); 56 AddChildView(&view_stack_);
57 57
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 being_closed_ = true;
74 controller_map_.clear();
71 request_->UserCancelled(); 75 request_->UserCancelled();
72 return true; 76 return true;
73 } 77 }
74 78
75 bool PaymentRequestDialogView::ShouldShowCloseButton() const { 79 bool PaymentRequestDialogView::ShouldShowCloseButton() const {
76 // Don't show the normal close button on the dialog. This is because the 80 // 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 81 // typical dialog header doesn't allow displaying anything other that the
78 // title and the close button. This is insufficient for the PaymentRequest 82 // title and the close button. This is insufficient for the PaymentRequest
79 // dialog, which must sometimes show the back arrow next to the title. 83 // 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 84 // 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
133 if (observer_for_testing_) 137 if (observer_for_testing_)
134 observer_for_testing_->OnCreditCardEditorOpened(); 138 observer_for_testing_->OnCreditCardEditorOpened();
135 } 139 }
136 140
137 void PaymentRequestDialogView::ShowDialog() { 141 void PaymentRequestDialogView::ShowDialog() {
138 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); 142 constrained_window::ShowWebModalDialogViews(this, request_->web_contents());
139 } 143 }
140 144
141 void PaymentRequestDialogView::CloseDialog() { 145 void PaymentRequestDialogView::CloseDialog() {
142 // This calls PaymentRequestDialogView::Cancel() before closing. 146 // This calls PaymentRequestDialogView::Cancel() before closing.
147 // ViewHierarchyChanged() also gets called after Cancel().
143 GetWidget()->Close(); 148 GetWidget()->Close();
144 } 149 }
145 150
146 void PaymentRequestDialogView::ShowInitialPaymentSheet() { 151 void PaymentRequestDialogView::ShowInitialPaymentSheet() {
147 view_stack_.Push( 152 view_stack_.Push(
148 CreateViewAndInstallController( 153 CreateViewAndInstallController(
149 base::MakeUnique<PaymentSheetViewController>(request_, this), 154 base::MakeUnique<PaymentSheetViewController>(request_, this),
150 &controller_map_), 155 &controller_map_),
151 /* animate = */ false); 156 /* animate = */ false);
152 if (observer_for_testing_) 157 if (observer_for_testing_)
153 observer_for_testing_->OnDialogOpened(); 158 observer_for_testing_->OnDialogOpened();
154 } 159 }
155 160
156 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { 161 gfx::Size PaymentRequestDialogView::GetPreferredSize() const {
157 return gfx::Size(450, 450); 162 return gfx::Size(450, 450);
158 } 163 }
159 164
160 void PaymentRequestDialogView::ViewHierarchyChanged( 165 void PaymentRequestDialogView::ViewHierarchyChanged(
161 const ViewHierarchyChangedDetails& details) { 166 const ViewHierarchyChangedDetails& details) {
167 if (being_closed_)
168 return;
169
162 // When a view that is associated with a controller is removed from this 170 // When a view that is associated with a controller is removed from this
163 // view's descendants, dispose of the controller. 171 // view's descendants, dispose of the controller.
164 if (!details.is_add && 172 if (!details.is_add &&
165 controller_map_.find(details.child) != controller_map_.end()) { 173 controller_map_.find(details.child) != controller_map_.end()) {
166 DCHECK(!details.move_view); 174 DCHECK(!details.move_view);
167 controller_map_.erase(details.child); 175 controller_map_.erase(details.child);
168 } 176 }
169 } 177 }
170 178
171 } // namespace payments 179 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698