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

Side by Side Diff: chrome/browser/ui/views/extensions/device_permissions_dialog_view.cc

Issue 2045093002: In DevicePermissionsDialogView disable Connect button if no device selected (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: in DevicePermissionsDialogView disable Connect button if no device selected Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/extensions/device_permissions_dialog_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h" 12 #include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
13 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
14 #include "components/constrained_window/constrained_window_views.h" 14 #include "components/constrained_window/constrained_window_views.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager.h" 15 #include "components/web_modal/web_contents_modal_dialog_manager.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "device/usb/usb_device.h" 17 #include "device/usb/usb_device.h"
18 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/models/table_model.h" 20 #include "ui/base/models/table_model.h"
21 #include "ui/base/models/table_model_observer.h" 21 #include "ui/base/models/table_model_observer.h"
22 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/table/table_view.h" 23 #include "ui/views/controls/table/table_view.h"
24 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/layout_constants.h" 25 #include "ui/views/layout/layout_constants.h"
26 #include "ui/views/window/dialog_client_view.h"
26 27
27 using device::UsbDevice; 28 using device::UsbDevice;
28 using extensions::DevicePermissionsPrompt; 29 using extensions::DevicePermissionsPrompt;
29 30
30 class DevicePermissionsTableModel 31 class DevicePermissionsTableModel
31 : public ui::TableModel, 32 : public ui::TableModel,
32 public DevicePermissionsPrompt::Prompt::Observer { 33 public DevicePermissionsPrompt::Prompt::Observer {
33 public: 34 public:
34 explicit DevicePermissionsTableModel( 35 explicit DevicePermissionsTableModel(
35 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt) 36 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 -1, 109 -1,
109 0.2f)); 110 0.2f));
110 table_columns.back().title = l10n_util::GetStringUTF16( 111 table_columns.back().title = l10n_util::GetStringUTF16(
111 IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN); 112 IDS_DEVICE_PERMISSIONS_DIALOG_SERIAL_NUMBER_COLUMN);
112 113
113 table_model_.reset(new DevicePermissionsTableModel(prompt_)); 114 table_model_.reset(new DevicePermissionsTableModel(prompt_));
114 table_view_ = new views::TableView(table_model_.get(), 115 table_view_ = new views::TableView(table_model_.get(),
115 table_columns, 116 table_columns,
116 views::TEXT_ONLY, 117 views::TEXT_ONLY,
117 !prompt_->multiple()); 118 !prompt_->multiple());
119 table_view_->SetObserver(this);
118 120
119 views::View* table_parent = table_view_->CreateParentIfNecessary(); 121 views::View* table_parent = table_view_->CreateParentIfNecessary();
120 AddChildView(table_parent); 122 AddChildView(table_parent);
121 layout->SetFlexForView(table_parent, 1); 123 layout->SetFlexForView(table_parent, 1);
122 } 124 }
123 125
124 DevicePermissionsDialogView::~DevicePermissionsDialogView() { 126 DevicePermissionsDialogView::~DevicePermissionsDialogView() {
125 RemoveAllChildViews(true); 127 RemoveAllChildViews(true);
126 } 128 }
127 129
(...skipping 12 matching lines...) Expand all
140 } 142 }
141 143
142 base::string16 DevicePermissionsDialogView::GetDialogButtonLabel( 144 base::string16 DevicePermissionsDialogView::GetDialogButtonLabel(
143 ui::DialogButton button) const { 145 ui::DialogButton button) const {
144 if (button == ui::DIALOG_BUTTON_OK) { 146 if (button == ui::DIALOG_BUTTON_OK) {
145 return l10n_util::GetStringUTF16(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT); 147 return l10n_util::GetStringUTF16(IDS_DEVICE_PERMISSIONS_DIALOG_SELECT);
146 } 148 }
147 return views::DialogDelegateView::GetDialogButtonLabel(button); 149 return views::DialogDelegateView::GetDialogButtonLabel(button);
148 } 150 }
149 151
152 bool DevicePermissionsDialogView::IsDialogButtonEnabled(
153 ui::DialogButton button) const {
154 return button != ui::DIALOG_BUTTON_OK ||
155 !table_view_->selection_model().empty();
156 }
157
150 ui::ModalType DevicePermissionsDialogView::GetModalType() const { 158 ui::ModalType DevicePermissionsDialogView::GetModalType() const {
151 return ui::MODAL_TYPE_CHILD; 159 return ui::MODAL_TYPE_CHILD;
152 } 160 }
153 161
154 base::string16 DevicePermissionsDialogView::GetWindowTitle() const { 162 base::string16 DevicePermissionsDialogView::GetWindowTitle() const {
155 return prompt_->GetHeading(); 163 return prompt_->GetHeading();
156 } 164 }
157 165
158 gfx::Size DevicePermissionsDialogView::GetPreferredSize() const { 166 gfx::Size DevicePermissionsDialogView::GetPreferredSize() const {
159 return gfx::Size(500, 250); 167 return gfx::Size(500, 250);
160 } 168 }
161 169
170 void DevicePermissionsDialogView::OnSelectionChanged() {
171 GetDialogClientView()->UpdateDialogButtons();
172 }
173
162 void ChromeDevicePermissionsPrompt::ShowDialogViews() { 174 void ChromeDevicePermissionsPrompt::ShowDialogViews() {
163 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
164 176
165 web_modal::WebContentsModalDialogManager* manager = 177 web_modal::WebContentsModalDialogManager* manager =
166 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents()); 178 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents());
167 if (manager) { 179 if (manager) {
168 constrained_window::ShowWebModalDialogViews( 180 constrained_window::ShowWebModalDialogViews(
169 new DevicePermissionsDialogView(prompt()), web_contents()); 181 new DevicePermissionsDialogView(prompt()), web_contents());
170 } else { 182 } else {
171 base::ThreadTaskRunnerHandle::Get()->PostTask( 183 base::ThreadTaskRunnerHandle::Get()->PostTask(
172 FROM_HERE, 184 FROM_HERE,
173 base::Bind(&DevicePermissionsPrompt::Prompt::Dismissed, prompt())); 185 base::Bind(&DevicePermissionsPrompt::Prompt::Dismissed, prompt()));
174 } 186 }
175 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/device_permissions_dialog_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698