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

Side by Side Diff: chrome/browser/ui/views/website_settings/permissions_bubble_view.cc

Issue 454253002: Location chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing meacer@ comments Created 6 years, 4 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 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/website_settings/permissions_bubble_view.h" 5 #include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" 8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h"
9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse rver.h" 9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse rver.h"
10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (index == INDEX_ALLOW) 160 if (index == INDEX_ALLOW)
161 return l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); 161 return l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW);
162 else 162 else
163 return l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE); 163 return l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE);
164 } 164 }
165 165
166 int CustomizeAllowComboboxModel::GetDefaultIndex() const { 166 int CustomizeAllowComboboxModel::GetDefaultIndex() const {
167 return INDEX_ALLOW; 167 return INDEX_ALLOW;
168 } 168 }
169 169
170 // A combobox originating on the Allow button allowing for granular geolocation
171 // sharing.
172 class GeolocationAllowComboboxModel : public ui::ComboboxModel {
173 public:
174 enum GeolocationPrecision {
175 INDEX_EXACT = 0,
176 INDEX_CITY = 1,
177 INDEX_STATE = 2,
178 INDEX_COUNTRY = 3,
179 INDEX_COUNT = 4
180 };
181
182 GeolocationAllowComboboxModel() {}
183 virtual ~GeolocationAllowComboboxModel() {}
184
185 virtual int GetItemCount() const OVERRIDE;
186 virtual base::string16 GetItemAt(int index) OVERRIDE;
187 virtual int GetDefaultIndex() const OVERRIDE;
188 };
189
190 int GeolocationAllowComboboxModel::GetItemCount() const {
191 return INDEX_COUNT;
192 }
193
194 base::string16 GeolocationAllowComboboxModel::GetItemAt(int index) {
195 switch (index) {
196 case INDEX_EXACT:
197 return l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW);
198 case INDEX_CITY:
199 return l10n_util::GetStringUTF16(IDS_PERMISSION_CITY);
200 case INDEX_STATE:
201 return l10n_util::GetStringUTF16(IDS_PERMISSION_STATE);
202 default:
203 return l10n_util::GetStringUTF16(IDS_PERMISSION_COUNTRY);
204 }
205 }
206
207 int GeolocationAllowComboboxModel::GetDefaultIndex() const {
208 return INDEX_EXACT;
209 }
210
170 /////////////////////////////////////////////////////////////////////////////// 211 ///////////////////////////////////////////////////////////////////////////////
171 // View implementation for the permissions bubble. 212 // View implementation for the permissions bubble.
172 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, 213 class PermissionsBubbleDelegateView : public views::BubbleDelegateView,
173 public views::ButtonListener, 214 public views::ButtonListener,
174 public views::ComboboxListener, 215 public views::ComboboxListener,
175 public PermissionCombobox::Listener { 216 public PermissionCombobox::Listener {
176 public: 217 public:
177 PermissionsBubbleDelegateView( 218 PermissionsBubbleDelegateView(
178 views::View* anchor, 219 views::View* anchor,
179 PermissionBubbleViewViews* owner, 220 PermissionBubbleViewViews* owner,
(...skipping 20 matching lines...) Expand all
200 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; 241 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE;
201 242
202 // PermissionCombobox::Listener: 243 // PermissionCombobox::Listener:
203 virtual void PermissionSelectionChanged(int index, bool allowed) OVERRIDE; 244 virtual void PermissionSelectionChanged(int index, bool allowed) OVERRIDE;
204 245
205 private: 246 private:
206 PermissionBubbleViewViews* owner_; 247 PermissionBubbleViewViews* owner_;
207 views::Button* allow_; 248 views::Button* allow_;
208 views::Button* deny_; 249 views::Button* deny_;
209 views::Combobox* allow_combobox_; 250 views::Combobox* allow_combobox_;
251 views::Combobox* geolocation_combobox_;
210 base::string16 hostname_; 252 base::string16 hostname_;
211 scoped_ptr<PermissionMenuModel> menu_button_model_; 253 scoped_ptr<PermissionMenuModel> menu_button_model_;
212 std::vector<PermissionCombobox*> customize_comboboxes_; 254 std::vector<PermissionCombobox*> customize_comboboxes_;
213 255
214 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); 256 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView);
215 }; 257 };
216 258
217 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( 259 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView(
218 views::View* anchor, 260 views::View* anchor,
219 PermissionBubbleViewViews* owner, 261 PermissionBubbleViewViews* owner,
220 const std::vector<PermissionBubbleRequest*>& requests, 262 const std::vector<PermissionBubbleRequest*>& requests,
221 const std::vector<bool>& accept_state, 263 const std::vector<bool>& accept_state,
222 bool customization_mode) 264 bool customization_mode)
223 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), 265 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT),
224 owner_(owner), 266 owner_(owner),
225 allow_(NULL), 267 allow_(NULL),
226 deny_(NULL), 268 deny_(NULL),
227 allow_combobox_(NULL) { 269 allow_combobox_(NULL),
270 geolocation_combobox_(NULL) {
228 DCHECK(!requests.empty()); 271 DCHECK(!requests.empty());
229 272
230 RemoveAllChildViews(true); 273 RemoveAllChildViews(true);
231 customize_comboboxes_.clear(); 274 customize_comboboxes_.clear();
232 set_close_on_esc(false); 275 set_close_on_esc(false);
233 set_close_on_deactivate(false); 276 set_close_on_deactivate(false);
234 277
235 SetLayoutManager(new views::BoxLayout( 278 SetLayoutManager(new views::BoxLayout(
236 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); 279 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing));
237 280
238 // TODO(gbillock): support other languages than English. 281 // TODO(gbillock): support other languages than English.
239 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(), 282 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(),
240 "en", 283 "en",
241 net::kFormatUrlOmitUsernamePassword | 284 net::kFormatUrlOmitUsernamePassword |
242 net::kFormatUrlOmitTrailingSlashOnBareHostname, 285 net::kFormatUrlOmitTrailingSlashOnBareHostname,
243 net::UnescapeRule::SPACES, NULL, NULL, NULL); 286 net::UnescapeRule::SPACES, NULL, NULL, NULL);
244 287
245 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 288 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
289
246 for (size_t index = 0; index < requests.size(); index++) { 290 for (size_t index = 0; index < requests.size(); index++) {
247 DCHECK(index < accept_state.size()); 291 DCHECK(index < accept_state.size());
248 // The row is laid out containing a leading-aligned label area and a 292 // The row is laid out containing a leading-aligned label area and a
249 // trailing column which will be filled during customization with a 293 // trailing column which will be filled during customization with a
250 // combobox. 294 // combobox.
251 views::View* row = new views::View(); 295 views::View* row = new views::View();
252 views::GridLayout* row_layout = new views::GridLayout(row); 296 views::GridLayout* row_layout = new views::GridLayout(row);
253 row->SetLayoutManager(row_layout); 297 row->SetLayoutManager(row_layout);
254 views::ColumnSet* columns = row_layout->AddColumnSet(0); 298 views::ColumnSet* columns = row_layout->AddColumnSet(0);
255 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 299 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 361 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL,
318 0, views::GridLayout::USE_PREF, 0, 0); 362 0, views::GridLayout::USE_PREF, 0, 0);
319 button_layout->StartRow(0, 0); 363 button_layout->StartRow(0, 0);
320 364
321 // Allow button is a regular button when there's only one option, and a 365 // Allow button is a regular button when there's only one option, and a
322 // STYLE_ACTION Combobox when there are more than one option and 366 // STYLE_ACTION Combobox when there are more than one option and
323 // customization is an option. 367 // customization is an option.
324 368
325 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); 369 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW);
326 if (requests.size() == 1) { 370 if (requests.size() == 1) {
327 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); 371 if (requests[0]->GetType() == PermissionBubbleRequest::Type::kGeolocation) {
328 allow_button->SetStyle(views::Button::STYLE_BUTTON); 372 // Geolocation shows a combobox instead of a simple button giving users
329 button_layout->AddView(allow_button); 373 // the ability to specifiy the precision of the shared location.
meacer 2014/08/15 23:34:46 specifiy -> specify
330 allow_ = allow_button; 374 views::Combobox* geolocation_combobox =
375 new views::Combobox(new GeolocationAllowComboboxModel());
376 geolocation_combobox->set_listener(this);
377 geolocation_combobox->SetStyle(views::Combobox::STYLE_ACTION);
378 button_layout->AddView(geolocation_combobox);
379 geolocation_combobox_ = geolocation_combobox;
380 } else {
381 views::LabelButton* allow_button =
382 new views::LabelButton(this, allow_text);
383 allow_button->SetStyle(views::Button::STYLE_BUTTON);
384 button_layout->AddView(allow_button);
385 allow_ = allow_button;
386 }
331 } else { 387 } else {
332 views::Combobox* allow_combobox = new views::Combobox( 388 views::Combobox* allow_combobox = new views::Combobox(
333 new CustomizeAllowComboboxModel()); 389 new CustomizeAllowComboboxModel());
334 allow_combobox->set_listener(this); 390 allow_combobox->set_listener(this);
335 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION); 391 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION);
336 button_layout->AddView(allow_combobox); 392 button_layout->AddView(allow_combobox);
337 allow_combobox_ = allow_combobox; 393 allow_combobox_ = allow_combobox;
338 } 394 }
339 395
340 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); 396 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 455
400 void PermissionsBubbleDelegateView::PermissionSelectionChanged( 456 void PermissionsBubbleDelegateView::PermissionSelectionChanged(
401 int index, bool allowed) { 457 int index, bool allowed) {
402 owner_->Toggle(index, allowed); 458 owner_->Toggle(index, allowed);
403 } 459 }
404 460
405 void PermissionsBubbleDelegateView::OnPerformAction( 461 void PermissionsBubbleDelegateView::OnPerformAction(
406 views::Combobox* combobox) { 462 views::Combobox* combobox) {
407 if (combobox == allow_combobox_) { 463 if (combobox == allow_combobox_) {
408 if (combobox->selected_index() == 464 if (combobox->selected_index() ==
409 CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) 465 CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) {
410 owner_->SetCustomizationMode(); 466 owner_->SetCustomizationMode();
411 else if (combobox->selected_index() == 467 } else if (combobox->selected_index() ==
412 CustomizeAllowComboboxModel::INDEX_ALLOW) 468 CustomizeAllowComboboxModel::INDEX_ALLOW) {
413 owner_->Accept(); 469 owner_->Accept();
470 }
471 } else if (combobox == geolocation_combobox_) {
472 owner_->Accept(combobox->selected_index());
414 } 473 }
415 } 474 }
416 475
417 ////////////////////////////////////////////////////////////////////////////// 476 //////////////////////////////////////////////////////////////////////////////
418 // PermissionBubbleViewViews 477 // PermissionBubbleViewViews
419 478
420 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) 479 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view)
421 : anchor_view_(anchor_view), 480 : anchor_view_(anchor_view),
422 delegate_(NULL), 481 delegate_(NULL),
423 bubble_delegate_(NULL) {} 482 bubble_delegate_(NULL) {}
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (delegate_) 525 if (delegate_)
467 delegate_->Closing(); 526 delegate_->Closing();
468 } 527 }
469 528
470 void PermissionBubbleViewViews::Toggle(int index, bool value) { 529 void PermissionBubbleViewViews::Toggle(int index, bool value) {
471 if (delegate_) 530 if (delegate_)
472 delegate_->ToggleAccept(index, value); 531 delegate_->ToggleAccept(index, value);
473 } 532 }
474 533
475 void PermissionBubbleViewViews::Accept() { 534 void PermissionBubbleViewViews::Accept() {
535 Accept(-1);
536 }
537
538 void PermissionBubbleViewViews::Accept(int choice) {
476 if (delegate_) 539 if (delegate_)
477 delegate_->Accept(); 540 delegate_->Accept(choice);
478 } 541 }
479 542
480 void PermissionBubbleViewViews::Deny() { 543 void PermissionBubbleViewViews::Deny() {
481 if (delegate_) 544 if (delegate_)
482 delegate_->Deny(); 545 delegate_->Deny();
483 } 546 }
484 547
485 void PermissionBubbleViewViews::SetCustomizationMode() { 548 void PermissionBubbleViewViews::SetCustomizationMode() {
486 if (delegate_) 549 if (delegate_)
487 delegate_->SetCustomizationMode(); 550 delegate_->SetCustomizationMode();
488 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698