Chromium Code Reviews| 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/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 Loading... | |
| 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 Item { | |
|
meacer
2014/08/15 22:20:25
nit: This could use a better name, such as Geoloca
mhm
2014/08/15 23:18:57
Done.
| |
| 175 INDEX_EXACT = 0, | |
| 176 INDEX_CITY = 1, | |
| 177 INDEX_STATE = 2, | |
| 178 INDEX_COUNTRY = 3 | |
| 179 }; | |
| 180 | |
| 181 GeolocationAllowComboboxModel() {} | |
| 182 virtual ~GeolocationAllowComboboxModel() {} | |
| 183 | |
| 184 virtual int GetItemCount() const OVERRIDE; | |
| 185 virtual base::string16 GetItemAt(int index) OVERRIDE; | |
| 186 virtual int GetDefaultIndex() const OVERRIDE; | |
| 187 }; | |
| 188 | |
| 189 int GeolocationAllowComboboxModel::GetItemCount() const { | |
| 190 return 4; | |
|
meacer
2014/08/15 22:20:25
Add an INDEX_COUNT to the enum and return it from
mhm
2014/08/15 23:18:57
Done.
| |
| 191 } | |
| 192 | |
| 193 base::string16 GeolocationAllowComboboxModel::GetItemAt(int index) { | |
| 194 switch (index) { | |
| 195 case INDEX_EXACT: | |
| 196 return l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); | |
| 197 case INDEX_CITY: | |
| 198 return l10n_util::GetStringUTF16(IDS_PERMISSION_CITY); | |
| 199 case INDEX_STATE: | |
| 200 return l10n_util::GetStringUTF16(IDS_PERMISSION_STATE); | |
| 201 default: | |
| 202 return l10n_util::GetStringUTF16(IDS_PERMISSION_COUNTRY); | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 int GeolocationAllowComboboxModel::GetDefaultIndex() const { | |
| 207 return INDEX_EXACT; | |
| 208 } | |
| 209 | |
| 170 /////////////////////////////////////////////////////////////////////////////// | 210 /////////////////////////////////////////////////////////////////////////////// |
| 171 // View implementation for the permissions bubble. | 211 // View implementation for the permissions bubble. |
| 172 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, | 212 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
| 173 public views::ButtonListener, | 213 public views::ButtonListener, |
| 174 public views::ComboboxListener, | 214 public views::ComboboxListener, |
| 175 public PermissionCombobox::Listener { | 215 public PermissionCombobox::Listener { |
| 176 public: | 216 public: |
| 177 PermissionsBubbleDelegateView( | 217 PermissionsBubbleDelegateView( |
| 178 views::View* anchor, | 218 views::View* anchor, |
| 179 PermissionBubbleViewViews* owner, | 219 PermissionBubbleViewViews* owner, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 200 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; | 240 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; |
| 201 | 241 |
| 202 // PermissionCombobox::Listener: | 242 // PermissionCombobox::Listener: |
| 203 virtual void PermissionSelectionChanged(int index, bool allowed) OVERRIDE; | 243 virtual void PermissionSelectionChanged(int index, bool allowed) OVERRIDE; |
| 204 | 244 |
| 205 private: | 245 private: |
| 206 PermissionBubbleViewViews* owner_; | 246 PermissionBubbleViewViews* owner_; |
| 207 views::Button* allow_; | 247 views::Button* allow_; |
| 208 views::Button* deny_; | 248 views::Button* deny_; |
| 209 views::Combobox* allow_combobox_; | 249 views::Combobox* allow_combobox_; |
| 250 views::Combobox* geolocation_combobox_; | |
| 210 base::string16 hostname_; | 251 base::string16 hostname_; |
| 211 scoped_ptr<PermissionMenuModel> menu_button_model_; | 252 scoped_ptr<PermissionMenuModel> menu_button_model_; |
| 212 std::vector<PermissionCombobox*> customize_comboboxes_; | 253 std::vector<PermissionCombobox*> customize_comboboxes_; |
| 213 | 254 |
| 214 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); | 255 DISALLOW_COPY_AND_ASSIGN(PermissionsBubbleDelegateView); |
| 215 }; | 256 }; |
| 216 | 257 |
| 217 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( | 258 PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
| 218 views::View* anchor, | 259 views::View* anchor, |
| 219 PermissionBubbleViewViews* owner, | 260 PermissionBubbleViewViews* owner, |
| 220 const std::vector<PermissionBubbleRequest*>& requests, | 261 const std::vector<PermissionBubbleRequest*>& requests, |
| 221 const std::vector<bool>& accept_state, | 262 const std::vector<bool>& accept_state, |
| 222 bool customization_mode) | 263 bool customization_mode) |
| 223 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), | 264 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), |
| 224 owner_(owner), | 265 owner_(owner), |
| 225 allow_(NULL), | 266 allow_(NULL), |
| 226 deny_(NULL), | 267 deny_(NULL), |
| 227 allow_combobox_(NULL) { | 268 allow_combobox_(NULL), |
| 269 geolocation_combobox_(NULL) { | |
| 228 DCHECK(!requests.empty()); | 270 DCHECK(!requests.empty()); |
| 229 | 271 |
| 230 RemoveAllChildViews(true); | 272 RemoveAllChildViews(true); |
| 231 customize_comboboxes_.clear(); | 273 customize_comboboxes_.clear(); |
| 232 set_close_on_esc(false); | 274 set_close_on_esc(false); |
| 233 set_close_on_deactivate(false); | 275 set_close_on_deactivate(false); |
| 234 | 276 |
| 235 SetLayoutManager(new views::BoxLayout( | 277 SetLayoutManager(new views::BoxLayout( |
| 236 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); | 278 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); |
| 237 | 279 |
| 238 // TODO(gbillock): support other languages than English. | 280 // TODO(gbillock): support other languages than English. |
| 239 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(), | 281 hostname_ = net::FormatUrl(requests[0]->GetRequestingHostname(), |
| 240 "en", | 282 "en", |
| 241 net::kFormatUrlOmitUsernamePassword | | 283 net::kFormatUrlOmitUsernamePassword | |
| 242 net::kFormatUrlOmitTrailingSlashOnBareHostname, | 284 net::kFormatUrlOmitTrailingSlashOnBareHostname, |
| 243 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 285 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
| 244 | 286 |
| 245 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 287 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 288 | |
| 246 for (size_t index = 0; index < requests.size(); index++) { | 289 for (size_t index = 0; index < requests.size(); index++) { |
| 247 DCHECK(index < accept_state.size()); | 290 DCHECK(index < accept_state.size()); |
| 248 // The row is laid out containing a leading-aligned label area and a | 291 // The row is laid out containing a leading-aligned label area and a |
| 249 // trailing column which will be filled during customization with a | 292 // trailing column which will be filled during customization with a |
| 250 // combobox. | 293 // combobox. |
| 251 views::View* row = new views::View(); | 294 views::View* row = new views::View(); |
| 252 views::GridLayout* row_layout = new views::GridLayout(row); | 295 views::GridLayout* row_layout = new views::GridLayout(row); |
| 253 row->SetLayoutManager(row_layout); | 296 row->SetLayoutManager(row_layout); |
| 254 views::ColumnSet* columns = row_layout->AddColumnSet(0); | 297 views::ColumnSet* columns = row_layout->AddColumnSet(0); |
| 255 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 298 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 360 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, |
| 318 0, views::GridLayout::USE_PREF, 0, 0); | 361 0, views::GridLayout::USE_PREF, 0, 0); |
| 319 button_layout->StartRow(0, 0); | 362 button_layout->StartRow(0, 0); |
| 320 | 363 |
| 321 // Allow button is a regular button when there's only one option, and a | 364 // 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 | 365 // STYLE_ACTION Combobox when there are more than one option and |
| 323 // customization is an option. | 366 // customization is an option. |
| 324 | 367 |
| 325 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); | 368 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); |
| 326 if (requests.size() == 1) { | 369 if (requests.size() == 1) { |
| 327 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); | 370 if (requests[0]->GetType() == PermissionBubbleRequest::Type::kGeolocation) { |
|
meacer
2014/08/15 22:20:25
nit: You might want to add a comment as to why geo
mhm
2014/08/15 23:18:57
Done.
| |
| 328 allow_button->SetStyle(views::Button::STYLE_BUTTON); | 371 views::Combobox* geolocation_combobox = |
| 329 button_layout->AddView(allow_button); | 372 new views::Combobox(new GeolocationAllowComboboxModel()); |
| 330 allow_ = allow_button; | 373 geolocation_combobox->set_listener(this); |
| 374 geolocation_combobox->SetStyle(views::Combobox::STYLE_ACTION); | |
| 375 button_layout->AddView(geolocation_combobox); | |
| 376 geolocation_combobox_ = geolocation_combobox; | |
| 377 } else { | |
| 378 views::LabelButton* allow_button = | |
| 379 new views::LabelButton(this, allow_text); | |
| 380 allow_button->SetStyle(views::Button::STYLE_BUTTON); | |
| 381 button_layout->AddView(allow_button); | |
| 382 allow_ = allow_button; | |
| 383 } | |
| 331 } else { | 384 } else { |
| 332 views::Combobox* allow_combobox = new views::Combobox( | 385 views::Combobox* allow_combobox = new views::Combobox( |
| 333 new CustomizeAllowComboboxModel()); | 386 new CustomizeAllowComboboxModel()); |
| 334 allow_combobox->set_listener(this); | 387 allow_combobox->set_listener(this); |
| 335 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION); | 388 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION); |
| 336 button_layout->AddView(allow_combobox); | 389 button_layout->AddView(allow_combobox); |
| 337 allow_combobox_ = allow_combobox; | 390 allow_combobox_ = allow_combobox; |
| 338 } | 391 } |
| 339 | 392 |
| 340 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); | 393 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 | 457 |
| 405 void PermissionsBubbleDelegateView::OnPerformAction( | 458 void PermissionsBubbleDelegateView::OnPerformAction( |
| 406 views::Combobox* combobox) { | 459 views::Combobox* combobox) { |
| 407 if (combobox == allow_combobox_) { | 460 if (combobox == allow_combobox_) { |
| 408 if (combobox->selected_index() == | 461 if (combobox->selected_index() == |
| 409 CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) | 462 CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) |
| 410 owner_->SetCustomizationMode(); | 463 owner_->SetCustomizationMode(); |
| 411 else if (combobox->selected_index() == | 464 else if (combobox->selected_index() == |
| 412 CustomizeAllowComboboxModel::INDEX_ALLOW) | 465 CustomizeAllowComboboxModel::INDEX_ALLOW) |
| 413 owner_->Accept(); | 466 owner_->Accept(); |
| 414 } | 467 } else if (combobox == geolocation_combobox_) |
|
meacer
2014/08/15 22:20:25
Braces around if block since the previous block ha
mhm
2014/08/15 23:18:57
Done.
| |
| 468 owner_->Accept(combobox->selected_index()); | |
| 415 } | 469 } |
| 416 | 470 |
| 417 ////////////////////////////////////////////////////////////////////////////// | 471 ////////////////////////////////////////////////////////////////////////////// |
| 418 // PermissionBubbleViewViews | 472 // PermissionBubbleViewViews |
| 419 | 473 |
| 420 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) | 474 PermissionBubbleViewViews::PermissionBubbleViewViews(views::View* anchor_view) |
| 421 : anchor_view_(anchor_view), | 475 : anchor_view_(anchor_view), |
| 422 delegate_(NULL), | 476 delegate_(NULL), |
| 423 bubble_delegate_(NULL) {} | 477 bubble_delegate_(NULL) {} |
| 424 | 478 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 if (delegate_) | 520 if (delegate_) |
| 467 delegate_->Closing(); | 521 delegate_->Closing(); |
| 468 } | 522 } |
| 469 | 523 |
| 470 void PermissionBubbleViewViews::Toggle(int index, bool value) { | 524 void PermissionBubbleViewViews::Toggle(int index, bool value) { |
| 471 if (delegate_) | 525 if (delegate_) |
| 472 delegate_->ToggleAccept(index, value); | 526 delegate_->ToggleAccept(index, value); |
| 473 } | 527 } |
| 474 | 528 |
| 475 void PermissionBubbleViewViews::Accept() { | 529 void PermissionBubbleViewViews::Accept() { |
| 530 Accept(-1); | |
| 531 } | |
| 532 | |
| 533 void PermissionBubbleViewViews::Accept(int choice) { | |
| 476 if (delegate_) | 534 if (delegate_) |
| 477 delegate_->Accept(); | 535 delegate_->Accept(choice); |
| 478 } | 536 } |
| 479 | 537 |
| 480 void PermissionBubbleViewViews::Deny() { | 538 void PermissionBubbleViewViews::Deny() { |
| 481 if (delegate_) | 539 if (delegate_) |
| 482 delegate_->Deny(); | 540 delegate_->Deny(); |
| 483 } | 541 } |
| 484 | 542 |
| 485 void PermissionBubbleViewViews::SetCustomizationMode() { | 543 void PermissionBubbleViewViews::SetCustomizationMode() { |
| 486 if (delegate_) | 544 if (delegate_) |
| 487 delegate_->SetCustomizationMode(); | 545 delegate_->SetCustomizationMode(); |
| 488 } | 546 } |
| OLD | NEW |