Chromium Code Reviews| Index: chrome/browser/ui/views/website_settings/permissions_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc b/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc |
| index fb6b22f822113694cd6c10cea3f0c0692f2aa216..f88e12cb70b4e17bbda4ceba02f3e4dc42f0a0f0 100644 |
| --- a/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc |
| +++ b/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc |
| @@ -167,6 +167,47 @@ int CustomizeAllowComboboxModel::GetDefaultIndex() const { |
| return INDEX_ALLOW; |
| } |
| +// A combobox originating on the Allow button allowing for granular geolocation |
| +// sharing. |
| +class GeolocationAllowComboboxModel : public ui::ComboboxModel { |
| + public: |
| + enum GeolocationPrecision { |
| + INDEX_EXACT = 0, |
| + INDEX_CITY = 1, |
| + INDEX_STATE = 2, |
| + INDEX_COUNTRY = 3, |
| + INDEX_COUNT = 4 |
| + }; |
| + |
| + GeolocationAllowComboboxModel() {} |
| + virtual ~GeolocationAllowComboboxModel() {} |
| + |
| + virtual int GetItemCount() const OVERRIDE; |
| + virtual base::string16 GetItemAt(int index) OVERRIDE; |
| + virtual int GetDefaultIndex() const OVERRIDE; |
| +}; |
| + |
| +int GeolocationAllowComboboxModel::GetItemCount() const { |
| + return INDEX_COUNT; |
| +} |
| + |
| +base::string16 GeolocationAllowComboboxModel::GetItemAt(int index) { |
| + switch (index) { |
| + case INDEX_EXACT: |
| + return l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); |
| + case INDEX_CITY: |
| + return l10n_util::GetStringUTF16(IDS_PERMISSION_CITY); |
| + case INDEX_STATE: |
| + return l10n_util::GetStringUTF16(IDS_PERMISSION_STATE); |
| + default: |
| + return l10n_util::GetStringUTF16(IDS_PERMISSION_COUNTRY); |
| + } |
| +} |
| + |
| +int GeolocationAllowComboboxModel::GetDefaultIndex() const { |
| + return INDEX_EXACT; |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| // View implementation for the permissions bubble. |
| class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
| @@ -207,6 +248,7 @@ class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
| views::Button* allow_; |
| views::Button* deny_; |
| views::Combobox* allow_combobox_; |
| + views::Combobox* geolocation_combobox_; |
| base::string16 hostname_; |
| scoped_ptr<PermissionMenuModel> menu_button_model_; |
| std::vector<PermissionCombobox*> customize_comboboxes_; |
| @@ -224,7 +266,8 @@ PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
| owner_(owner), |
| allow_(NULL), |
| deny_(NULL), |
| - allow_combobox_(NULL) { |
| + allow_combobox_(NULL), |
| + geolocation_combobox_(NULL) { |
| DCHECK(!requests.empty()); |
| RemoveAllChildViews(true); |
| @@ -243,6 +286,7 @@ PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
| net::UnescapeRule::SPACES, NULL, NULL, NULL); |
| ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + |
| for (size_t index = 0; index < requests.size(); index++) { |
| DCHECK(index < accept_state.size()); |
| // The row is laid out containing a leading-aligned label area and a |
| @@ -324,10 +368,22 @@ PermissionsBubbleDelegateView::PermissionsBubbleDelegateView( |
| base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); |
| if (requests.size() == 1) { |
| - views::LabelButton* allow_button = new views::LabelButton(this, allow_text); |
| - allow_button->SetStyle(views::Button::STYLE_BUTTON); |
| - button_layout->AddView(allow_button); |
| - allow_ = allow_button; |
| + if (requests[0]->GetType() == PermissionBubbleRequest::Type::kGeolocation) { |
| + // Geolocation shows a combobox instead of a simple button giving users |
| + // the ability to specifiy the precision of the shared location. |
|
meacer
2014/08/15 23:34:46
specifiy -> specify
|
| + views::Combobox* geolocation_combobox = |
| + new views::Combobox(new GeolocationAllowComboboxModel()); |
| + geolocation_combobox->set_listener(this); |
| + geolocation_combobox->SetStyle(views::Combobox::STYLE_ACTION); |
| + button_layout->AddView(geolocation_combobox); |
| + geolocation_combobox_ = geolocation_combobox; |
| + } else { |
| + views::LabelButton* allow_button = |
| + new views::LabelButton(this, allow_text); |
| + allow_button->SetStyle(views::Button::STYLE_BUTTON); |
| + button_layout->AddView(allow_button); |
| + allow_ = allow_button; |
| + } |
| } else { |
| views::Combobox* allow_combobox = new views::Combobox( |
| new CustomizeAllowComboboxModel()); |
| @@ -406,11 +462,14 @@ void PermissionsBubbleDelegateView::OnPerformAction( |
| views::Combobox* combobox) { |
| if (combobox == allow_combobox_) { |
| if (combobox->selected_index() == |
| - CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) |
| + CustomizeAllowComboboxModel::INDEX_CUSTOMIZE) { |
| owner_->SetCustomizationMode(); |
| - else if (combobox->selected_index() == |
| - CustomizeAllowComboboxModel::INDEX_ALLOW) |
| + } else if (combobox->selected_index() == |
| + CustomizeAllowComboboxModel::INDEX_ALLOW) { |
| owner_->Accept(); |
| + } |
| + } else if (combobox == geolocation_combobox_) { |
| + owner_->Accept(combobox->selected_index()); |
| } |
| } |
| @@ -473,8 +532,12 @@ void PermissionBubbleViewViews::Toggle(int index, bool value) { |
| } |
| void PermissionBubbleViewViews::Accept() { |
| + Accept(-1); |
| +} |
| + |
| +void PermissionBubbleViewViews::Accept(int choice) { |
| if (delegate_) |
| - delegate_->Accept(); |
| + delegate_->Accept(choice); |
| } |
| void PermissionBubbleViewViews::Deny() { |