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

Unified 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: Swapping to address InfoBar currying callback case 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 side-by-side diff with in-line comments
Download patch
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..2f9f1ef620dc17ca71fe681f4e7ecd0cf6a62bd3 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,46 @@ 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 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.
+ INDEX_EXACT = 0,
+ INDEX_CITY = 1,
+ INDEX_STATE = 2,
+ INDEX_COUNTRY = 3
+ };
+
+ 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 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.
+}
+
+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 +247,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 +265,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 +285,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 +367,20 @@ 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) {
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.
+ 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());
@@ -411,7 +464,8 @@ void PermissionsBubbleDelegateView::OnPerformAction(
else if (combobox->selected_index() ==
CustomizeAllowComboboxModel::INDEX_ALLOW)
owner_->Accept();
- }
+ } 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.
+ owner_->Accept(combobox->selected_index());
}
//////////////////////////////////////////////////////////////////////////////
@@ -473,8 +527,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() {

Powered by Google App Engine
This is Rietveld 408576698