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