diff options
author | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-18 02:21:57 +0000 |
---|---|---|
committer | markusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-18 02:21:57 +0000 |
commit | c8d6b485995362620025e3b7ad74772beac803d7 (patch) | |
tree | f3cd858c4dbcba9f6e4eed3c85d66baeac34d7dc | |
parent | d031a26f379cce8fb07348055db7f24f8db2678d (diff) | |
download | chromium_src-c8d6b485995362620025e3b7ad74772beac803d7.zip chromium_src-c8d6b485995362620025e3b7ad74772beac803d7.tar.gz chromium_src-c8d6b485995362620025e3b7ad74772beac803d7.tar.bz2 |
(GTK only) Add icons to the "Permissions" tab of the Website Settings UI.
BUG=140450
TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10827374
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152220 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/gtk/browser_window_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/OWNERS | 1 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/permission_selector.cc | 175 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/permission_selector.h | 73 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/permission_selector_observer.h | 27 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc (renamed from chrome/browser/ui/gtk/website_settings_popup_gtk.cc) | 192 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h (renamed from chrome/browser/ui/gtk/website_settings_popup_gtk.h) | 24 | ||||
-rw-r--r-- | chrome/browser/ui/views/website_settings/permission_selector_view.cc | 7 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 7 |
9 files changed, 360 insertions, 148 deletions
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 8f10673..8b207cb 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -73,7 +73,7 @@ #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/ui/gtk/task_manager_gtk.h" #include "chrome/browser/ui/gtk/update_recommended_dialog.h" -#include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" +#include "chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/page_info_bubble.h" diff --git a/chrome/browser/ui/gtk/website_settings/OWNERS b/chrome/browser/ui/gtk/website_settings/OWNERS new file mode 100644 index 0000000..60e0f3b --- /dev/null +++ b/chrome/browser/ui/gtk/website_settings/OWNERS @@ -0,0 +1 @@ +markusheintz@chromium.org diff --git a/chrome/browser/ui/gtk/website_settings/permission_selector.cc b/chrome/browser/ui/gtk/website_settings/permission_selector.cc new file mode 100644 index 0000000..6118840 --- /dev/null +++ b/chrome/browser/ui/gtk/website_settings/permission_selector.cc @@ -0,0 +1,175 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/gtk/website_settings/permission_selector.h" + +#include <gtk/gtk.h> + +#include "base/compiler_specific.h" +#include "chrome/browser/ui/gtk/gtk_theme_service.h" +#include "chrome/browser/ui/gtk/gtk_util.h" +#include "chrome/browser/ui/website_settings/website_settings_ui.h" +#include "grit/generated_resources.h" +#include "ui/base/gtk/gtk_hig_constants.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/image/image.h" + +namespace { + +GtkWidget* CreateTextLabel(const std::string& text, + int width, + GtkThemeService* theme_service) { + GtkWidget* label = theme_service->BuildLabel(text, ui::kGdkBlack); + if (width > 0) + gtk_util::SetLabelWidth(label, width); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); + return label; +} + +} // namespace + +PermissionSelector::PermissionSelector(GtkThemeService* theme_service, + ContentSettingsType type, + ContentSetting setting, + ContentSetting default_setting) + : theme_service_(theme_service), + type_(type), + setting_(setting), + default_setting_(default_setting), + icon_(NULL) { + DCHECK_NE(default_setting, CONTENT_SETTING_DEFAULT); +} + +PermissionSelector::~PermissionSelector() { +} + +GtkWidget* PermissionSelector::CreateUI() { + // Create permission info box. + const int kChildSpacing = 4; + GtkWidget* hbox = gtk_hbox_new(FALSE, kChildSpacing); + + // Add permission type icon. + GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon( + type_, setting_).ToGdkPixbuf(); + icon_ = gtk_image_new_from_pixbuf(pixbuf); + gtk_box_pack_start(GTK_BOX(hbox), icon_, FALSE, FALSE, 0); + + // Add a label for the permission type. + GtkWidget* label = CreateTextLabel( + l10n_util::GetStringFUTF8( + IDS_WEBSITE_SETTINGS_PERMISSION_TYPE, + WebsiteSettingsUI::PermissionTypeToUIString(type_)), + 0, + theme_service_); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + GtkListStore* store = + gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); + GtkTreeIter iter; + // Add option for permission "Global Default" to the combobox model. + std::string setting_str = l10n_util::GetStringFUTF8( + IDS_WEBSITE_SETTINGS_DEFAULT_PERMISSION_LABEL, + WebsiteSettingsUI::PermissionValueToUIString(default_setting_)); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, + CONTENT_SETTING_DEFAULT, -1); + GtkWidget* combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); + // Add option for permission "Allow" to the combobox model. + setting_str = l10n_util::GetStringFUTF8( + IDS_WEBSITE_SETTINGS_PERMISSION_LABEL, + WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_ALLOW)); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, + CONTENT_SETTING_ALLOW, -1); + // The content settings type fullscreen does not support the concept of + // blocking. + if (type_ != CONTENT_SETTINGS_TYPE_FULLSCREEN) { + // Add option for permission "BLOCK" to the combobox model. + setting_str = l10n_util::GetStringFUTF8( + IDS_WEBSITE_SETTINGS_PERMISSION_LABEL, + WebsiteSettingsUI::PermissionValueToUIString(CONTENT_SETTING_BLOCK)); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, + CONTENT_SETTING_BLOCK, -1); + } + // Remove reference to the store to prevent leaking. + g_object_unref(G_OBJECT(store)); + + GtkCellRenderer* cell = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, TRUE ); + gtk_cell_layout_set_attributes( + GTK_CELL_LAYOUT(combo_box), cell, "text", 0, NULL); + + // Select the combobox entry for the currently configured permission value. + int active = -1; + switch (setting_) { + case CONTENT_SETTING_DEFAULT: active = 0; + break; + case CONTENT_SETTING_ALLOW: active = 1; + break; + case CONTENT_SETTING_BLOCK: active = 2; + break; + default: + NOTREACHED() << "Bad content setting:" << setting_; + break; + } + gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), active); + + // Add change listener to the combobox. + g_signal_connect(combo_box, "changed", + G_CALLBACK(OnPermissionChangedThunk), this); + // Once the popup (window) for a combobox is shown, the bubble container + // (window) loses it's focus. Therefore it necessary to reset the focus to + // the bubble container after the combobox popup is closed. + g_signal_connect(combo_box, "notify::popup-shown", + G_CALLBACK(OnComboBoxShownThunk), this); + gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0); + + return hbox; +} + +void PermissionSelector::AddObserver(PermissionSelectorObserver* observer) { + observer_list_.AddObserver(observer); +} + +void PermissionSelector::OnPermissionChanged(GtkWidget* widget) { + // Get the selected setting. + GtkTreeIter it; + bool has_active = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &it); + DCHECK(has_active); + GtkTreeModel* store = + GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget))); + int value = -1; + gtk_tree_model_get(store, &it, 1, &value, -1); + setting_ = ContentSetting(value); + + // Change the permission icon according the the selected setting. + GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon( + type_, setting_).ToGdkPixbuf(); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); + + FOR_EACH_OBSERVER(PermissionSelectorObserver, + observer_list_, + OnPermissionChanged(this)); +} + +void PermissionSelector::OnComboBoxShown(GtkWidget* widget, + GParamSpec* property) { + // GtkComboBox grabs the keyboard and pointer when it displays its popup, + // which steals the grabs that BubbleGtk had installed. When the popup is + // hidden, we notify BubbleGtk so it can try to reacquire the grabs + // (otherwise, GTK won't activate our widgets when the user clicks in them). + // When then combobox popup is closed we notify the + // |PermissionSelectorObserver|s so that BubbleGtk can grab the keyboard and + // pointer. + gboolean popup_shown = FALSE; + g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown, + NULL); + if (!popup_shown) { + FOR_EACH_OBSERVER(PermissionSelectorObserver, + observer_list_, + OnComboboxShown()); + } +} diff --git a/chrome/browser/ui/gtk/website_settings/permission_selector.h b/chrome/browser/ui/gtk/website_settings/permission_selector.h new file mode 100644 index 0000000..629fea9 --- /dev/null +++ b/chrome/browser/ui/gtk/website_settings/permission_selector.h @@ -0,0 +1,73 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ +#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/observer_list.h" +#include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h" +#include "chrome/common/content_settings.h" +#include "chrome/common/content_settings_types.h" +#include "ui/base/gtk/gtk_signal.h" + +class GtkThemeService; +typedef struct _GParamSpec GParamSpec; +typedef struct _GtkWidget GtkWidget; + +// The class |PermissionSelector| allows to change the permission |setting| of a +// given permission |type|. +class PermissionSelector { + public: + // Creates a |PermissionSelector| for the given permission |type|. |setting| + // is the current permissions setting. It is possible to pass + // |CONTENT_SETTING_DEFAULT| as value for |setting|. |default_setting| is the + // effective default setting for the given permission |type|. It is not + // allowed to pass |CONTENT_SETTING_DEFAULT| as value for |default_setting|. + PermissionSelector(GtkThemeService* theme_service_, + ContentSettingsType type, + ContentSetting setting, + ContentSetting default_setting); + ~PermissionSelector(); + + // Creates the UI for the |PermissionSelector| and returns the widget that + // contains the UI elements. The ownership of the widget is transfered to the + // caller. + GtkWidget* CreateUI(); + + // Adds an |observer|. + void AddObserver(PermissionSelectorObserver* observer); + + // Returns the current permission setting. + ContentSetting setting() const { return setting_; } + + // Returns the permissions type. + ContentSettingsType type() const { return type_; } + + private: + CHROMEGTK_CALLBACK_0(PermissionSelector, void, OnPermissionChanged); + CHROMEGTK_CALLBACK_1(PermissionSelector, void, OnComboBoxShown, GParamSpec*); + + GtkThemeService* theme_service_; + + // The permission type. + ContentSettingsType type_; + // The current permission setting. + ContentSetting setting_; + // The effective default setting. This is required to create the proper UI + // string for the default setting. + ContentSetting default_setting_; + + // The permission type icon. The icon is changed depending on the selected + // setting. + // Owned by the widget hierarchy created by the CreateUI method. + GtkWidget* icon_; + + ObserverList<PermissionSelectorObserver, false> observer_list_; + + DISALLOW_COPY_AND_ASSIGN(PermissionSelector); +}; + +#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ diff --git a/chrome/browser/ui/gtk/website_settings/permission_selector_observer.h b/chrome/browser/ui/gtk/website_settings/permission_selector_observer.h new file mode 100644 index 0000000..224aee0 --- /dev/null +++ b/chrome/browser/ui/gtk/website_settings/permission_selector_observer.h @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_ +#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_ + +class PermissionSelector; + +class PermissionSelectorObserver { + public: + // This method is called when a permission setting is changed by a + // |selector|. + virtual void OnPermissionChanged(PermissionSelector* selector) = 0; + + // GtkComboBox grabs the keyboard and pointer when it displays its popup, + // which steals the grabs that BubbleGtk had installed. When the combobox + // popup is hidden, we notify BubbleGtk so it can try to reacquire the grabs + // (otherwise, GTK won't activate our widgets when the user clicks in them). + // OnComboboxShown is called when a combobox popup is closed. + virtual void OnComboboxShown() = 0; + + protected: + virtual ~PermissionSelectorObserver() {} +}; + +#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_OBSERVER_H_ diff --git a/chrome/browser/ui/gtk/website_settings_popup_gtk.cc b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc index ab63632..be7529c 100644 --- a/chrome/browser/ui/gtk/website_settings_popup_gtk.cc +++ b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" +#include "chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h" #include "base/i18n/rtl.h" #include "base/string_number_conversions.h" @@ -17,6 +17,7 @@ #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/gtk/gtk_theme_service.h" #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" +#include "chrome/browser/ui/gtk/website_settings/permission_selector.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/ui/website_settings/website_settings.h" #include "chrome/browser/ui/website_settings/website_settings_utils.h" @@ -39,6 +40,17 @@ namespace { // is selected. const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); +GtkWidget* CreateTextLabel(const std::string& text, + int width, + GtkThemeService* theme_service) { + GtkWidget* label = theme_service->BuildLabel(text, ui::kGdkBlack); + if (width > 0) + gtk_util::SetLabelWidth(label, width); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); + return label; +} + class InternalPageInfoPopupGtk : public BubbleDelegateGtk { public: explicit InternalPageInfoPopupGtk(gfx::NativeWindow parent, @@ -290,6 +302,16 @@ GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title, } +void WebsiteSettingsPopupGtk::OnPermissionChanged( + PermissionSelector* selector) { + presenter_->OnSitePermissionChanged(selector->type(), + selector->setting()); +} + +void WebsiteSettingsPopupGtk::OnComboboxShown() { + bubble_->HandlePointerAndKeyboardUngrabbedByContent(); +} + void WebsiteSettingsPopupGtk::SetCookieInfo( const CookieInfoList& cookie_info_list) { DCHECK(cookies_section_contents_); @@ -299,21 +321,29 @@ void WebsiteSettingsPopupGtk::SetCookieInfo( for (CookieInfoList::const_iterator it = cookie_info_list.begin(); it != cookie_info_list.end(); ++it) { + // Create the cookies info box. GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0); - GtkWidget* label = CreateTextLabel(it->cookie_source, 200); - gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0); - std::string allowed_count = base::IntToString(it->allowed); - std::string blocked_count = base::IntToString(it->blocked); - // TODO(markusheintz): Add a localized label here once we decided how this - // information should be displayed. - std::string info_str = " (" + allowed_count + " allowed / " - + blocked_count + " blocked)"; + // Add the icon to the cookies info box + GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon( + CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW).ToGdkPixbuf(); + GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); + gtk_misc_set_alignment(GTK_MISC(image), 0, 0); + gtk_box_pack_start(GTK_BOX(cookies_info), image, FALSE, FALSE, 0); + + // Add the allowed and blocked cookies counts to the cookies info box. + std::string info_str = l10n_util::GetStringFUTF8( + IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE, + UTF8ToUTF16(it->cookie_source), + base::IntToString16(it->allowed), + base::IntToString16(it->blocked)); GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack); gtk_label_set_selectable(GTK_LABEL(info), TRUE); - gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0); + const int kPadding = 4; + gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, kPadding); + // Add the cookies info box to the section box. gtk_box_pack_start(GTK_BOX(cookies_section_contents_), cookies_info, FALSE, FALSE, 0); @@ -335,15 +365,6 @@ void WebsiteSettingsPopupGtk::SetCookieInfo( gtk_widget_show_all(cookies_section_contents_); } -GtkWidget* WebsiteSettingsPopupGtk::CreateTextLabel(const std::string& text, - int width) { - GtkWidget* label = theme_service_->BuildLabel(text, ui::kGdkBlack); - gtk_util::SetLabelWidth(label, width); - gtk_label_set_selectable(GTK_LABEL(label), TRUE); - gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); - return label; -} - void WebsiteSettingsPopupGtk::SetIdentityInfo( const IdentityInfo& identity_info) { // Create popup header. @@ -374,7 +395,8 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED); break; } - GtkWidget* status_label = CreateTextLabel(identity_status_text, 400); + GtkWidget* status_label = + CreateTextLabel(identity_status_text, 400, theme_service_); gtk_box_pack_start( GTK_BOX(header_box_), status_label, FALSE, FALSE, 0); gtk_widget_show_all(header_box_); @@ -385,7 +407,8 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( // Create identity section. GtkWidget* identity_description = - CreateTextLabel(identity_info.identity_status_description, 300); + CreateTextLabel(identity_info.identity_status_description, 300, + theme_service_); GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing); gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE, 0); @@ -401,9 +424,11 @@ void WebsiteSettingsPopupGtk::SetIdentityInfo( gtk_box_pack_start(GTK_BOX(identity_box), link_hbox, FALSE, FALSE, 0); } + // Create connection section. GtkWidget* connection_description = - CreateTextLabel(identity_info.connection_status_description, 300); + CreateTextLabel(identity_info.connection_status_description, 300, + theme_service_); GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing); gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE, FALSE, 0); @@ -436,7 +461,8 @@ void WebsiteSettingsPopupGtk::SetFirstVisit(const string16& first_visit) { DCHECK(first_visit_contents_); ClearContainer(first_visit_contents_); - GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400); + GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400, + theme_service_); gtk_box_pack_start( GTK_BOX(first_visit_contents_), first_visit_label, FALSE, FALSE, 0); gtk_widget_show_all(first_visit_contents_); @@ -446,91 +472,22 @@ void WebsiteSettingsPopupGtk::SetPermissionInfo( const PermissionInfoList& permission_info_list) { DCHECK(permissions_section_contents_); ClearContainer(permissions_section_contents_); + // Clear the map since the UI is reconstructed. + selectors_.clear(); for (PermissionInfoList::const_iterator permission = permission_info_list.begin(); permission != permission_info_list.end(); ++permission) { - // Add a label for the permission type. - GtkWidget* label = CreateTextLabel(UTF16ToUTF8( - WebsiteSettingsUI::PermissionTypeToUIString(permission->type)), 250); - GtkWidget* hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - - GtkListStore* store = - gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); - GtkTreeIter iter; - // Add option for permission "Global Default" to the combobox model. - std::string setting_str; - switch (permission->default_setting) { - case CONTENT_SETTING_ALLOW: - setting_str = l10n_util::GetStringUTF8( - IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); - break; - case CONTENT_SETTING_BLOCK: - setting_str = l10n_util::GetStringUTF8( - IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); - break; - case CONTENT_SETTING_ASK: - setting_str = l10n_util::GetStringUTF8( - IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK); - break; - default: - break; - } - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, - CONTENT_SETTING_DEFAULT, 2, permission->type, -1); - GtkWidget* combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); - // Add option for permission "Allow" to the combobox model. - setting_str = l10n_util::GetStringUTF8( - IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, - CONTENT_SETTING_ALLOW, 2, permission->type, -1); - // The content settings type fullscreen does not support the concept of - // blocking. - if (permission->type != CONTENT_SETTINGS_TYPE_FULLSCREEN) { - // Add option for permission "BLOCK" to the combobox model. - setting_str = l10n_util::GetStringUTF8( - IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, - CONTENT_SETTING_BLOCK, 2, permission->type, -1); - } - // Remove reference to the store to prevent leaking. - g_object_unref(G_OBJECT(store)); - - GtkCellRenderer* cell = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, TRUE ); - gtk_cell_layout_set_attributes( - GTK_CELL_LAYOUT(combo_box), cell, "text", 0, NULL); - - // Select the combobox entry for the currently configured permission value. - int active = -1; - switch (permission->setting) { - case CONTENT_SETTING_DEFAULT: active = 0; - break; - case CONTENT_SETTING_ALLOW: active = 1; - break; - case CONTENT_SETTING_BLOCK: active = 2; - break; - default: - NOTREACHED() << "Bad content setting:" << permission->setting; - break; - } - gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), active); - - // Add change listener to the combobox. - g_signal_connect(combo_box, "changed", - G_CALLBACK(OnPermissionChangedThunk), this); - // Once the popup (window) for a combobox is shown, the bubble container - // (window) loses it's focus. Therefore it necessary to reset the focus to - // the bubble container after the combobox popup is closed. - g_signal_connect(combo_box, "notify::popup-shown", - G_CALLBACK(OnComboBoxShownThunk), this); - gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0); - + PermissionSelector* selector = + new PermissionSelector( + theme_service_, + permission->type, + permission->setting, + permission->default_setting); + selector->AddObserver(this); + GtkWidget* hbox = selector->CreateUI(); + selectors_.push_back(selector); gtk_box_pack_start(GTK_BOX(permissions_section_contents_), hbox, FALSE, FALSE, 0); } @@ -549,19 +506,6 @@ void WebsiteSettingsPopupGtk::SetPermissionInfo( gtk_widget_show_all(permissions_section_contents_); } -void WebsiteSettingsPopupGtk::OnComboBoxShown(GtkWidget* widget, - GParamSpec* property) { - // GtkComboBox grabs the keyboard and pointer when it displays its popup, - // which steals the grabs that BubbleGtk had installed. When the popup is - // hidden, we notify BubbleGtk so it can try to reacquire the grabs - // (otherwise, GTK won't activate our widgets when the user clicks in them). - gboolean popup_shown = FALSE; - g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown, - NULL); - if (!popup_shown) - bubble_->HandlePointerAndKeyboardUngrabbedByContent(); -} - void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) { new CollectedCookiesGtk(GTK_WINDOW(parent_), tab_contents_); @@ -580,22 +524,6 @@ void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked( bubble_->Close(); } -void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) { - GtkTreeIter it; - bool has_active = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &it); - DCHECK(has_active); - GtkTreeModel* store = - GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget))); - - int value = -1; - int type = -1; - gtk_tree_model_get(store, &it, 1, &value, 2, &type, -1); - - if (presenter_.get()) - presenter_->OnSitePermissionChanged(ContentSettingsType(type), - ContentSetting(value)); -} - void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) { DCHECK_NE(cert_id_, 0); ShowCertificateViewerByID( diff --git a/chrome/browser/ui/gtk/website_settings_popup_gtk.h b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h index a96014f1..986add7 100644 --- a/chrome/browser/ui/gtk/website_settings_popup_gtk.h +++ b/chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h @@ -2,20 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_ -#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_ +#ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_ +#define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_ #include <gtk/gtk.h> #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" +#include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h" #include "chrome/browser/ui/website_settings/website_settings_ui.h" class Browser; class GtkThemeService; class GURL; +class PermissionSelector; class Profile; class TabContents; class WebsiteSettings; @@ -26,6 +29,7 @@ struct SSLStatus; // GTK implementation of the website settings UI. class WebsiteSettingsPopupGtk : public WebsiteSettingsUI, + public PermissionSelectorObserver, public BubbleDelegateGtk { public: // Creates a |WebsiteSettingsPopupGtk| and displays the UI. The |url| @@ -54,6 +58,10 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI, virtual void SetIdentityInfo(const IdentityInfo& identity_info) OVERRIDE; virtual void SetFirstVisit(const string16& first_visit) OVERRIDE; + // PermissionSelectorObserver implementations. + virtual void OnPermissionChanged(PermissionSelector* selector) OVERRIDE; + virtual void OnComboboxShown() OVERRIDE; + // BubbleDelegateGtk implementation. virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; @@ -66,9 +74,6 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI, // Removes all children of |container|. void ClearContainer(GtkWidget* container); - // Creates a label that contains the given |text| and has the given |width|. - GtkWidget* CreateTextLabel(const std::string& text, int width); - // Creates a popup section and returns a virtual box that contains the // section content. GtkWidget* CreateSection(std::string section_title, @@ -76,11 +81,8 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI, // Callbacks for the link buttons. CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnCookiesLinkClicked); - CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnPermissionChanged); CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnPermissionsSettingsLinkClicked); - CHROMEGTK_CALLBACK_1(WebsiteSettingsPopupGtk, void, OnComboBoxShown, - GParamSpec*); CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnViewCertLinkClicked); // Parent window. @@ -129,7 +131,11 @@ class WebsiteSettingsPopupGtk : public WebsiteSettingsUI, // |presenter_|. The |presenter_| handles these events and updates the UI. scoped_ptr<WebsiteSettings> presenter_; + // The permission selectors that allow the user to change individual + // permissions. + ScopedVector<PermissionSelector> selectors_; + DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupGtk); }; -#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_POPUP_GTK_H_ +#endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_WEBSITE_SETTINGS_POPUP_GTK_H_ diff --git a/chrome/browser/ui/views/website_settings/permission_selector_view.cc b/chrome/browser/ui/views/website_settings/permission_selector_view.cc index 85dc1f3..874878f 100644 --- a/chrome/browser/ui/views/website_settings/permission_selector_view.cc +++ b/chrome/browser/ui/views/website_settings/permission_selector_view.cc @@ -320,10 +320,9 @@ void PermissionSelectorView::SelectionChanged() { // Update the menu button text to reflect the new setting. menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( - menu_button_model_->current_setting(), - menu_button_model_->default_setting(), - content_settings::SETTING_SOURCE_USER)); - + menu_button_model_->current_setting(), + menu_button_model_->default_setting(), + content_settings::SETTING_SOURCE_USER)); FOR_EACH_OBSERVER(PermissionSelectorViewObserver, observer_list_, diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1e7ee7a..2552d02 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3334,8 +3334,11 @@ 'browser/ui/gtk/web_dialog_gtk.h', 'browser/ui/gtk/web_intent_picker_gtk.cc', 'browser/ui/gtk/web_intent_picker_gtk.h', - 'browser/ui/gtk/website_settings_popup_gtk.cc', - 'browser/ui/gtk/website_settings_popup_gtk.h', + 'browser/ui/gtk/website_settings/permission_selector.cc', + 'browser/ui/gtk/website_settings/permission_selector.h', + 'browser/ui/gtk/website_settings/permission_selector_observer.h', + 'browser/ui/gtk/website_settings/website_settings_popup_gtk.cc', + 'browser/ui/gtk/website_settings/website_settings_popup_gtk.h', 'browser/ui/gtk/zoom_bubble_gtk.cc', 'browser/ui/gtk/zoom_bubble_gtk.h', 'browser/ui/hung_plugin_tab_helper.cc', |