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

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

Issue 2611253004: [Payment Request] Change the lifetime management of PaymentRequestImpl (Closed)
Patch Set: PaymentRequestImpl -> PaymentRequest Created 3 years, 11 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.h" 5 #include "chrome/browser/ui/views/payments/payment_request_dialog.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/payments/payment_request_impl.h"
12 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" 11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
14 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h" 14 #include "components/constrained_window/constrained_window_views.h"
15 #include "components/payments/payment_request.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/views/layout/fill_layout.h" 18 #include "ui/views/layout/fill_layout.h"
19 19
20 namespace chrome { 20 namespace chrome {
21 21
22 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { 22 void ShowPaymentRequestDialog(payments::PaymentRequest* request) {
23 constrained_window::ShowWebModalDialogViews( 23 constrained_window::ShowWebModalDialogViews(
24 new payments::PaymentRequestDialog(impl), impl->web_contents()); 24 new payments::PaymentRequestDialog(request), request->web_contents());
25 } 25 }
26 26
27 } // namespace chrome 27 } // namespace chrome
28 28
29 namespace payments { 29 namespace payments {
30 namespace { 30 namespace {
31 31
32 // This function creates an instance of a PaymentRequestSheetController 32 // This function creates an instance of a PaymentRequestSheetController
33 // subclass of concrete type |Controller|, passing it non-owned pointers to 33 // subclass of concrete type |Controller|, passing it non-owned pointers to
34 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by 34 // |dialog| and the |request| that initiated that dialog. |map| should be owned
35 // |dialog|. 35 // by |dialog|.
36 template<typename Controller> 36 template <typename Controller>
37 std::unique_ptr<views::View> CreateViewAndInstallController( 37 std::unique_ptr<views::View> CreateViewAndInstallController(
38 payments::ControllerMap* map, 38 payments::ControllerMap* map,
39 payments::PaymentRequestImpl* impl, 39 payments::PaymentRequest* request,
40 payments::PaymentRequestDialog* dialog) { 40 payments::PaymentRequestDialog* dialog) {
41 std::unique_ptr<Controller> controller = 41 std::unique_ptr<Controller> controller =
42 base::MakeUnique<Controller>(impl, dialog); 42 base::MakeUnique<Controller>(request, dialog);
43 std::unique_ptr<views::View> view = controller->CreateView(); 43 std::unique_ptr<views::View> view = controller->CreateView();
44 (*map)[view.get()] = std::move(controller); 44 (*map)[view.get()] = std::move(controller);
45 return view; 45 return view;
46 } 46 }
47 47
48 } // namespace 48 } // namespace
49 49
50 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 50 PaymentRequestDialog::PaymentRequestDialog(PaymentRequest* request)
51 : impl_(impl) { 51 : request_(request) {
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 PaymentRequestDialog::~PaymentRequestDialog() {} 61 PaymentRequestDialog::~PaymentRequestDialog() {}
62 62
63 ui::ModalType PaymentRequestDialog::GetModalType() const { 63 ui::ModalType PaymentRequestDialog::GetModalType() const {
64 return ui::MODAL_TYPE_CHILD; 64 return ui::MODAL_TYPE_CHILD;
65 } 65 }
66 66
67 bool PaymentRequestDialog::Cancel() { 67 bool PaymentRequestDialog::Cancel() {
68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
69 impl_->Cancel(); 69 request_->Cancel();
70 return true; 70 return true;
71 } 71 }
72 72
73 bool PaymentRequestDialog::ShouldShowCloseButton() const { 73 bool PaymentRequestDialog::ShouldShowCloseButton() const {
74 // Don't show the normal close button on the dialog. This is because the 74 // Don't show the normal close button on the dialog. This is because the
75 // typical dialog header doesn't allow displaying anything other that the 75 // typical dialog header doesn't allow displaying anything other that the
76 // title and the close button. This is insufficient for the PaymentRequest 76 // title and the close button. This is insufficient for the PaymentRequest
77 // dialog, which must sometimes show the back arrow next to the title. 77 // dialog, which must sometimes show the back arrow next to the title.
78 // Moreover, the title (and back arrow) should animate with the view they're 78 // Moreover, the title (and back arrow) should animate with the view they're
79 // attached to. 79 // attached to.
80 return false; 80 return false;
81 } 81 }
82 82
83 int PaymentRequestDialog::GetDialogButtons() const { 83 int PaymentRequestDialog::GetDialogButtons() const {
84 // The buttons should animate along with the different dialog sheets since 84 // The buttons should animate along with the different dialog sheets since
85 // each sheet presents a different set of buttons. Because of this, hide the 85 // each sheet presents a different set of buttons. Because of this, hide the
86 // usual dialog buttons. 86 // usual dialog buttons.
87 return ui::DIALOG_BUTTON_NONE; 87 return ui::DIALOG_BUTTON_NONE;
88 } 88 }
89 89
90 void PaymentRequestDialog::GoBack() { 90 void PaymentRequestDialog::GoBack() {
91 view_stack_.Pop(); 91 view_stack_.Pop();
92 } 92 }
93 93
94 void PaymentRequestDialog::ShowOrderSummary() { 94 void PaymentRequestDialog::ShowOrderSummary() {
95 view_stack_.Push( 95 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>(
96 CreateViewAndInstallController<OrderSummaryViewController>( 96 &controller_map_, request_, this),
97 &controller_map_, impl_, this), 97 true);
98 true);
99 } 98 }
100 99
101 void PaymentRequestDialog::CloseDialog() { 100 void PaymentRequestDialog::CloseDialog() {
102 GetWidget()->Close(); 101 GetWidget()->Close();
103 } 102 }
104 103
105 void PaymentRequestDialog::ShowInitialPaymentSheet() { 104 void PaymentRequestDialog::ShowInitialPaymentSheet() {
106 view_stack_.Push( 105 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>(
107 CreateViewAndInstallController<PaymentSheetViewController>( 106 &controller_map_, request_, this),
108 &controller_map_, impl_, this), 107 false);
109 false);
110 } 108 }
111 109
112 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 110 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
113 return gfx::Size(450, 450); 111 return gfx::Size(450, 450);
114 } 112 }
115 113
116 void PaymentRequestDialog::ViewHierarchyChanged( 114 void PaymentRequestDialog::ViewHierarchyChanged(
117 const ViewHierarchyChangedDetails& details) { 115 const ViewHierarchyChangedDetails& details) {
118 // When a view that is associated with a controller is removed from this 116 // When a view that is associated with a controller is removed from this
119 // view's descendants, dispose of the controller. 117 // view's descendants, dispose of the controller.
120 if (!details.is_add && 118 if (!details.is_add &&
121 controller_map_.find(details.child) != controller_map_.end()) { 119 controller_map_.find(details.child) != controller_map_.end()) {
122 DCHECK(!details.move_view); 120 DCHECK(!details.move_view);
123 controller_map_.erase(details.child); 121 controller_map_.erase(details.child);
124 } 122 }
125 } 123 }
126 124
127 } // namespace payments 125 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698