OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/device_permissions_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/device_permissions_dialog_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" | 8 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" |
9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
10 #include "components/constrained_window/constrained_window_views.h" | 10 #include "components/constrained_window/constrained_window_views.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 observer_ = observer; | 68 observer_ = observer; |
69 } | 69 } |
70 | 70 |
71 void DevicePermissionsTableModel::OnDevicesChanged() { | 71 void DevicePermissionsTableModel::OnDevicesChanged() { |
72 if (observer_) { | 72 if (observer_) { |
73 observer_->OnModelChanged(); | 73 observer_->OnModelChanged(); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 DevicePermissionsDialogView::DevicePermissionsDialogView( | 77 DevicePermissionsDialogView::DevicePermissionsDialogView( |
78 DevicePermissionsPrompt::Delegate* delegate, | |
79 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) | 78 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) |
80 : delegate_(delegate), prompt_(prompt) { | 79 : prompt_(prompt) { |
81 views::BoxLayout* layout = | 80 views::BoxLayout* layout = |
82 new views::BoxLayout(views::BoxLayout::kVertical, | 81 new views::BoxLayout(views::BoxLayout::kVertical, |
83 views::kButtonHEdgeMarginNew, | 82 views::kButtonHEdgeMarginNew, |
84 0, | 83 0, |
85 views::kRelatedControlVerticalSpacing); | 84 views::kRelatedControlVerticalSpacing); |
86 SetLayoutManager(layout); | 85 SetLayoutManager(layout); |
87 | 86 |
88 views::Label* label = new views::Label(prompt_->GetPromptMessage()); | 87 views::Label* label = new views::Label(prompt_->GetPromptMessage()); |
89 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 88 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
90 label->SetMultiLine(true); | 89 label->SetMultiLine(true); |
(...skipping 24 matching lines...) Expand all Loading... |
115 views::View* table_parent = table_view_->CreateParentIfNecessary(); | 114 views::View* table_parent = table_view_->CreateParentIfNecessary(); |
116 AddChildView(table_parent); | 115 AddChildView(table_parent); |
117 layout->SetFlexForView(table_parent, 1); | 116 layout->SetFlexForView(table_parent, 1); |
118 } | 117 } |
119 | 118 |
120 DevicePermissionsDialogView::~DevicePermissionsDialogView() { | 119 DevicePermissionsDialogView::~DevicePermissionsDialogView() { |
121 RemoveAllChildViews(true); | 120 RemoveAllChildViews(true); |
122 } | 121 } |
123 | 122 |
124 bool DevicePermissionsDialogView::Cancel() { | 123 bool DevicePermissionsDialogView::Cancel() { |
125 std::vector<scoped_refptr<UsbDevice>> empty; | 124 prompt_->Dismissed(); |
126 delegate_->OnUsbDevicesChosen(empty); | |
127 return true; | 125 return true; |
128 } | 126 } |
129 | 127 |
130 bool DevicePermissionsDialogView::Accept() { | 128 bool DevicePermissionsDialogView::Accept() { |
131 std::vector<scoped_refptr<UsbDevice>> devices; | |
132 for (int index : table_view_->selection_model().selected_indices()) { | 129 for (int index : table_view_->selection_model().selected_indices()) { |
133 prompt_->GrantDevicePermission(index); | 130 prompt_->GrantDevicePermission(index); |
134 devices.push_back(prompt_->GetDevice(index)); | |
135 } | 131 } |
136 delegate_->OnUsbDevicesChosen(devices); | 132 prompt_->Dismissed(); |
137 return true; | 133 return true; |
138 } | 134 } |
139 | 135 |
140 base::string16 DevicePermissionsDialogView::GetDialogButtonLabel( | 136 base::string16 DevicePermissionsDialogView::GetDialogButtonLabel( |
141 ui::DialogButton button) const { | 137 ui::DialogButton button) const { |
142 if (button == ui::DIALOG_BUTTON_OK) { | 138 if (button == ui::DIALOG_BUTTON_OK) { |
143 return l10n_util::GetStringUTF16(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT); | 139 return l10n_util::GetStringUTF16(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT); |
144 } | 140 } |
145 return views::DialogDelegateView::GetDialogButtonLabel(button); | 141 return views::DialogDelegateView::GetDialogButtonLabel(button); |
146 } | 142 } |
147 | 143 |
148 ui::ModalType DevicePermissionsDialogView::GetModalType() const { | 144 ui::ModalType DevicePermissionsDialogView::GetModalType() const { |
149 return ui::MODAL_TYPE_CHILD; | 145 return ui::MODAL_TYPE_CHILD; |
150 } | 146 } |
151 | 147 |
152 base::string16 DevicePermissionsDialogView::GetWindowTitle() const { | 148 base::string16 DevicePermissionsDialogView::GetWindowTitle() const { |
153 return prompt_->GetHeading(); | 149 return prompt_->GetHeading(); |
154 } | 150 } |
155 | 151 |
156 gfx::Size DevicePermissionsDialogView::GetPreferredSize() const { | 152 gfx::Size DevicePermissionsDialogView::GetPreferredSize() const { |
157 return gfx::Size(500, 250); | 153 return gfx::Size(500, 250); |
158 } | 154 } |
159 | 155 |
160 void ChromeDevicePermissionsPrompt::ShowDialog() { | 156 void ChromeDevicePermissionsPrompt::ShowDialog() { |
161 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
162 constrained_window::ShowWebModalDialogViews( | 158 constrained_window::ShowWebModalDialogViews( |
163 new DevicePermissionsDialogView(delegate(), prompt()), web_contents()); | 159 new DevicePermissionsDialogView(prompt()), web_contents()); |
164 } | 160 } |
OLD | NEW |