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

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

Issue 2810193003: [Payments] Change how the dialog gets destroyed. (Closed)
Patch Set: added comment Created 3 years, 8 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 PaymentRequestDialogView::PaymentRequestDialogView( 61 PaymentRequestDialogView::PaymentRequestDialogView(
62 PaymentRequest* request, 62 PaymentRequest* request,
63 PaymentRequestDialogView::ObserverForTest* observer) 63 PaymentRequestDialogView::ObserverForTest* observer)
64 : request_(request), observer_for_testing_(observer), being_closed_(false) { 64 : request_(request), observer_for_testing_(observer), being_closed_(false) {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66 if (observer_for_testing_) 66 if (observer_for_testing_)
67 request->spec()->add_observer_for_testing(this); 67 request->spec()->add_observer_for_testing(this);
68 SetLayoutManager(new views::FillLayout()); 68 SetLayoutManager(new views::FillLayout());
69 69
70 view_stack_.set_owned_by_client(); 70 view_stack_ = base::MakeUnique<ViewStack>();
71 AddChildView(&view_stack_); 71 view_stack_->set_owned_by_client();
72 AddChildView(view_stack_.get());
72 73
73 SetupSpinnerOverlay(); 74 SetupSpinnerOverlay();
74 75
75 ShowInitialPaymentSheet(); 76 ShowInitialPaymentSheet();
76 } 77 }
77 78
78 PaymentRequestDialogView::~PaymentRequestDialogView() {} 79 PaymentRequestDialogView::~PaymentRequestDialogView() {}
79 80
80 ui::ModalType PaymentRequestDialogView::GetModalType() const { 81 ui::ModalType PaymentRequestDialogView::GetModalType() const {
81 return ui::MODAL_TYPE_CHILD; 82 return ui::MODAL_TYPE_CHILD;
82 } 83 }
83 84
84 bool PaymentRequestDialogView::Cancel() { 85 bool PaymentRequestDialogView::Cancel() {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
86 // Called when the widget is about to close. We send a message to the 87 // Called when the widget is about to close. We send a message to the
87 // PaymentRequest object to signal user cancellation. Before destroying the 88 // PaymentRequest object to signal user cancellation.
88 // PaymentRequest object, we destroy all controllers so that they are not left 89 //
89 // alive with an invalid PaymentRequest pointer. 90 // The order of destruction is important here. First destroy all the views
91 // because they may have pointers/delegates to their controllers. Then destroy
92 // all the controllers, because they may have pointers to PaymentRequestSpec/
93 // PaymentRequestState. Then send the signal to PaymentRequest to destroy.
90 being_closed_ = true; 94 being_closed_ = true;
95 view_stack_.reset();
91 controller_map_.clear(); 96 controller_map_.clear();
92 request_->UserCancelled(); 97 request_->UserCancelled();
93 return true; 98 return true;
94 } 99 }
95 100
96 bool PaymentRequestDialogView::ShouldShowCloseButton() const { 101 bool PaymentRequestDialogView::ShouldShowCloseButton() const {
97 // Don't show the normal close button on the dialog. This is because the 102 // Don't show the normal close button on the dialog. This is because the
98 // typical dialog header doesn't allow displaying anything other that the 103 // typical dialog header doesn't allow displaying anything other that the
99 // title and the close button. This is insufficient for the PaymentRequest 104 // title and the close button. This is insufficient for the PaymentRequest
100 // dialog, which must sometimes show the back arrow next to the title. 105 // dialog, which must sometimes show the back arrow next to the title.
(...skipping 13 matching lines...) Expand all
114 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); 119 constrained_window::ShowWebModalDialogViews(this, request_->web_contents());
115 } 120 }
116 121
117 void PaymentRequestDialogView::CloseDialog() { 122 void PaymentRequestDialogView::CloseDialog() {
118 // This calls PaymentRequestDialogView::Cancel() before closing. 123 // This calls PaymentRequestDialogView::Cancel() before closing.
119 // ViewHierarchyChanged() also gets called after Cancel(). 124 // ViewHierarchyChanged() also gets called after Cancel().
120 GetWidget()->Close(); 125 GetWidget()->Close();
121 } 126 }
122 127
123 void PaymentRequestDialogView::ShowErrorMessage() { 128 void PaymentRequestDialogView::ShowErrorMessage() {
124 view_stack_.Push(CreateViewAndInstallController( 129 view_stack_->Push(CreateViewAndInstallController(
125 base::MakeUnique<ErrorMessageViewController>( 130 base::MakeUnique<ErrorMessageViewController>(
126 request_->spec(), request_->state(), this), 131 request_->spec(), request_->state(), this),
127 &controller_map_), 132 &controller_map_),
128 /* animate = */ false); 133 /* animate = */ false);
129 if (observer_for_testing_) 134 if (observer_for_testing_)
130 observer_for_testing_->OnErrorMessageShown(); 135 observer_for_testing_->OnErrorMessageShown();
131 } 136 }
132 137
133 void PaymentRequestDialogView::OnSpecUpdated() { 138 void PaymentRequestDialogView::OnSpecUpdated() {
134 // Since this is called in tests only, |observer_for_testing_| is defined. 139 // Since this is called in tests only, |observer_for_testing_| is defined.
135 DCHECK(observer_for_testing_); 140 DCHECK(observer_for_testing_);
136 observer_for_testing_->OnSpecDoneUpdating(); 141 observer_for_testing_->OnSpecDoneUpdating();
137 } 142 }
138 143
139 void PaymentRequestDialogView::Pay() { 144 void PaymentRequestDialogView::Pay() {
140 request_->Pay(); 145 request_->Pay();
141 } 146 }
142 147
143 void PaymentRequestDialogView::GoBack() { 148 void PaymentRequestDialogView::GoBack() {
144 view_stack_.Pop(); 149 view_stack_->Pop();
145 150
146 if (observer_for_testing_) 151 if (observer_for_testing_)
147 observer_for_testing_->OnBackNavigation(); 152 observer_for_testing_->OnBackNavigation();
148 } 153 }
149 154
150 void PaymentRequestDialogView::ShowContactProfileSheet() { 155 void PaymentRequestDialogView::ShowContactProfileSheet() {
151 view_stack_.Push( 156 view_stack_->Push(
152 CreateViewAndInstallController( 157 CreateViewAndInstallController(
153 ProfileListViewController::GetContactProfileViewController( 158 ProfileListViewController::GetContactProfileViewController(
154 request_->spec(), request_->state(), this), 159 request_->spec(), request_->state(), this),
155 &controller_map_), 160 &controller_map_),
156 /* animate */ true); 161 /* animate */ true);
157 if (observer_for_testing_) 162 if (observer_for_testing_)
158 observer_for_testing_->OnContactInfoOpened(); 163 observer_for_testing_->OnContactInfoOpened();
159 } 164 }
160 165
161 void PaymentRequestDialogView::ShowOrderSummary() { 166 void PaymentRequestDialogView::ShowOrderSummary() {
162 view_stack_.Push(CreateViewAndInstallController( 167 view_stack_->Push(CreateViewAndInstallController(
163 base::MakeUnique<OrderSummaryViewController>( 168 base::MakeUnique<OrderSummaryViewController>(
164 request_->spec(), request_->state(), this), 169 request_->spec(), request_->state(), this),
165 &controller_map_), 170 &controller_map_),
166 /* animate = */ true); 171 /* animate = */ true);
167 if (observer_for_testing_) 172 if (observer_for_testing_)
168 observer_for_testing_->OnOrderSummaryOpened(); 173 observer_for_testing_->OnOrderSummaryOpened();
169 } 174 }
170 175
171 void PaymentRequestDialogView::ShowPaymentMethodSheet() { 176 void PaymentRequestDialogView::ShowPaymentMethodSheet() {
172 view_stack_.Push(CreateViewAndInstallController( 177 view_stack_->Push(CreateViewAndInstallController(
173 base::MakeUnique<PaymentMethodViewController>( 178 base::MakeUnique<PaymentMethodViewController>(
174 request_->spec(), request_->state(), this), 179 request_->spec(), request_->state(), this),
175 &controller_map_), 180 &controller_map_),
176 /* animate = */ true); 181 /* animate = */ true);
177 if (observer_for_testing_) 182 if (observer_for_testing_)
178 observer_for_testing_->OnPaymentMethodOpened(); 183 observer_for_testing_->OnPaymentMethodOpened();
179 } 184 }
180 185
181 void PaymentRequestDialogView::ShowShippingProfileSheet() { 186 void PaymentRequestDialogView::ShowShippingProfileSheet() {
182 view_stack_.Push( 187 view_stack_->Push(
183 CreateViewAndInstallController( 188 CreateViewAndInstallController(
184 ProfileListViewController::GetShippingProfileViewController( 189 ProfileListViewController::GetShippingProfileViewController(
185 request_->spec(), request_->state(), this), 190 request_->spec(), request_->state(), this),
186 &controller_map_), 191 &controller_map_),
187 /* animate = */ true); 192 /* animate = */ true);
188 if (observer_for_testing_) 193 if (observer_for_testing_)
189 observer_for_testing_->OnShippingAddressSectionOpened(); 194 observer_for_testing_->OnShippingAddressSectionOpened();
190 } 195 }
191 196
192 void PaymentRequestDialogView::ShowShippingOptionSheet() { 197 void PaymentRequestDialogView::ShowShippingOptionSheet() {
193 view_stack_.Push(CreateViewAndInstallController( 198 view_stack_->Push(CreateViewAndInstallController(
194 base::MakeUnique<ShippingOptionViewController>( 199 base::MakeUnique<ShippingOptionViewController>(
195 request_->spec(), request_->state(), this), 200 request_->spec(), request_->state(), this),
196 &controller_map_), 201 &controller_map_),
197 /* animate = */ true); 202 /* animate = */ true);
198 if (observer_for_testing_) 203 if (observer_for_testing_)
199 observer_for_testing_->OnShippingOptionSectionOpened(); 204 observer_for_testing_->OnShippingOptionSectionOpened();
200 } 205 }
201 206
202 void PaymentRequestDialogView::ShowCvcUnmaskPrompt( 207 void PaymentRequestDialogView::ShowCvcUnmaskPrompt(
203 const autofill::CreditCard& credit_card, 208 const autofill::CreditCard& credit_card,
204 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> 209 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>
205 result_delegate, 210 result_delegate,
206 content::WebContents* web_contents) { 211 content::WebContents* web_contents) {
207 view_stack_.Push(CreateViewAndInstallController( 212 view_stack_->Push(CreateViewAndInstallController(
208 base::MakeUnique<CvcUnmaskViewController>( 213 base::MakeUnique<CvcUnmaskViewController>(
209 request_->spec(), request_->state(), this, 214 request_->spec(), request_->state(), this,
210 credit_card, result_delegate, web_contents), 215 credit_card, result_delegate, web_contents),
211 &controller_map_), 216 &controller_map_),
212 /* animate = */ true); 217 /* animate = */ true);
213 if (observer_for_testing_) 218 if (observer_for_testing_)
214 observer_for_testing_->OnCvcPromptShown(); 219 observer_for_testing_->OnCvcPromptShown();
215 } 220 }
216 221
217 void PaymentRequestDialogView::ShowCreditCardEditor( 222 void PaymentRequestDialogView::ShowCreditCardEditor(
218 autofill::CreditCard* credit_card) { 223 autofill::CreditCard* credit_card) {
219 view_stack_.Push( 224 view_stack_->Push(
220 CreateViewAndInstallController( 225 CreateViewAndInstallController(
221 base::MakeUnique<CreditCardEditorViewController>( 226 base::MakeUnique<CreditCardEditorViewController>(
222 request_->spec(), request_->state(), this, credit_card), 227 request_->spec(), request_->state(), this, credit_card),
223 &controller_map_), 228 &controller_map_),
224 /* animate = */ true); 229 /* animate = */ true);
225 if (observer_for_testing_) 230 if (observer_for_testing_)
226 observer_for_testing_->OnCreditCardEditorOpened(); 231 observer_for_testing_->OnCreditCardEditorOpened();
227 } 232 }
228 233
229 void PaymentRequestDialogView::ShowShippingAddressEditor( 234 void PaymentRequestDialogView::ShowShippingAddressEditor(
230 autofill::AutofillProfile* profile) { 235 autofill::AutofillProfile* profile) {
231 view_stack_.Push(CreateViewAndInstallController( 236 view_stack_->Push(CreateViewAndInstallController(
232 base::MakeUnique<ShippingAddressEditorViewController>( 237 base::MakeUnique<ShippingAddressEditorViewController>(
233 request_->spec(), request_->state(), this, profile), 238 request_->spec(), request_->state(), this, profile),
234 &controller_map_), 239 &controller_map_),
235 /* animate = */ true); 240 /* animate = */ true);
236 if (observer_for_testing_) 241 if (observer_for_testing_)
237 observer_for_testing_->OnShippingAddressEditorOpened(); 242 observer_for_testing_->OnShippingAddressEditorOpened();
238 } 243 }
239 244
240 void PaymentRequestDialogView::EditorViewUpdated() { 245 void PaymentRequestDialogView::EditorViewUpdated() {
241 if (observer_for_testing_) 246 if (observer_for_testing_)
242 observer_for_testing_->OnEditorViewUpdated(); 247 observer_for_testing_->OnEditorViewUpdated();
243 } 248 }
244 249
245 void PaymentRequestDialogView::ShowProcessingSpinner() { 250 void PaymentRequestDialogView::ShowProcessingSpinner() {
246 throbber_.Start(); 251 throbber_.Start();
247 throbber_overlay_.SetVisible(true); 252 throbber_overlay_.SetVisible(true);
248 } 253 }
249 254
250 void PaymentRequestDialogView::ShowInitialPaymentSheet() { 255 void PaymentRequestDialogView::ShowInitialPaymentSheet() {
251 view_stack_.Push(CreateViewAndInstallController( 256 view_stack_->Push(CreateViewAndInstallController(
252 base::MakeUnique<PaymentSheetViewController>( 257 base::MakeUnique<PaymentSheetViewController>(
253 request_->spec(), request_->state(), this), 258 request_->spec(), request_->state(), this),
254 &controller_map_), 259 &controller_map_),
255 /* animate = */ false); 260 /* animate = */ false);
256 if (observer_for_testing_) 261 if (observer_for_testing_)
257 observer_for_testing_->OnDialogOpened(); 262 observer_for_testing_->OnDialogOpened();
258 } 263 }
259 264
260 void PaymentRequestDialogView::SetupSpinnerOverlay() { 265 void PaymentRequestDialogView::SetupSpinnerOverlay() {
261 throbber_.set_owned_by_client(); 266 throbber_.set_owned_by_client();
262 267
263 throbber_overlay_.set_owned_by_client(); 268 throbber_overlay_.set_owned_by_client();
264 throbber_overlay_.SetPaintToLayer(); 269 throbber_overlay_.SetPaintToLayer();
265 throbber_overlay_.SetVisible(false); 270 throbber_overlay_.SetVisible(false);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // When a view that is associated with a controller is removed from this 312 // When a view that is associated with a controller is removed from this
308 // view's descendants, dispose of the controller. 313 // view's descendants, dispose of the controller.
309 if (!details.is_add && 314 if (!details.is_add &&
310 controller_map_.find(details.child) != controller_map_.end()) { 315 controller_map_.find(details.child) != controller_map_.end()) {
311 DCHECK(!details.move_view); 316 DCHECK(!details.move_view);
312 controller_map_.erase(details.child); 317 controller_map_.erase(details.child);
313 } 318 }
314 } 319 }
315 320
316 } // namespace payments 321 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_request_dialog_view.h ('k') | chrome/browser/ui/views/payments/view_stack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698