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

Unified Diff: chrome/browser/ui/gtk/website_settings_popup_gtk.cc

Issue 9732007: Add GTK Website Settings UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « chrome/browser/ui/gtk/website_settings_popup_gtk.h ('k') | chrome/browser/ui/website_settings_ui.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/gtk/website_settings_popup_gtk.cc
diff --git a/chrome/browser/ui/gtk/website_settings_popup_gtk.cc b/chrome/browser/ui/gtk/website_settings_popup_gtk.cc
new file mode 100644
index 0000000000000000000000000000000000000000..115c122e2544ef66c425014006420b15b811e0b3
--- /dev/null
+++ b/chrome/browser/ui/gtk/website_settings_popup_gtk.cc
@@ -0,0 +1,337 @@
+// 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_popup_gtk.h"
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/i18n/rtl.h"
+#include "base/string_number_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/certificate_viewer.h"
+#include "chrome/browser/page_info_model.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
+#include "chrome/browser/ui/gtk/browser_window_gtk.h"
+#include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
+#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
+#include "chrome/browser/ui/gtk/gtk_util.h"
+#include "chrome/browser/ui/gtk/theme_service_gtk.h"
+#include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/cert_store.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+#include "grit/theme_resources.h"
+#include "ui/base/gtk/gtk_hig_constants.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+using content::OpenURLParams;
+
+WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk(
+ gfx::NativeWindow parent,
+ Profile* profile,
+ TabContentsWrapper* tab_contents_wrapper,
+ const GURL& url,
+ const SSLStatus& ssl,
+ bool show_history)
+ : website_settings_(NULL),
+ parent_(parent),
+ contents_(NULL),
+ theme_service_(ThemeServiceGtk::GetFrom(profile)),
+ profile_(profile),
+ tab_contents_wrapper_(tab_contents_wrapper) {
+ BrowserWindowGtk* browser_window =
+ BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
+ anchor_ = browser_window->
+ GetToolbar()->GetLocationBarView()->location_icon_widget();
+
+ InitContents();
+
+ website_settings_.reset(
+ new WebsiteSettingsModel(this,
+ profile,
+ url,
+ ssl,
+ content::CertStore::GetInstance(),
+ tab_contents_wrapper->content_settings()));
+
+ BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
+ BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
+ BubbleGtk::ARROW_LOCATION_TOP_LEFT;
+ bubble_ = BubbleGtk::Show(anchor_,
+ NULL, // |rect|
+ contents_,
+ arrow_location,
+ true, // |match_system_theme|
+ true, // |grab_input|
+ theme_service_,
+ this); // |delegate|
+ if (!bubble_) {
+ NOTREACHED();
+ return;
+ }
+}
+
+WebsiteSettingsPopupGtk::~WebsiteSettingsPopupGtk() {
+}
+
+void WebsiteSettingsPopupGtk::BubbleClosing(BubbleGtk* bubble,
+ bool closed_by_escape) {
+ delete this;
+}
+
+void WebsiteSettingsPopupGtk::InitContents() {
+ if (!contents_) {
+ contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
+ gtk_container_set_border_width(GTK_CONTAINER(contents_),
+ ui::kContentAreaBorder);
+ } else {
+ gtk_util::RemoveAllChildren(contents_);
+ }
+
+ site_info_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
+ gtk_box_pack_start(GTK_BOX(contents_),
+ CreateSection("Site Information", site_info_contents_),
+ FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(contents_),
+ gtk_hseparator_new(),
+ FALSE, FALSE, 0);
+ cookies_section_content_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
+ gtk_box_pack_start(GTK_BOX(contents_),
+ CreateSection("Cookies and Site Data",
+ cookies_section_content_),
+ FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(contents_),
+ gtk_hseparator_new(),
+ FALSE, FALSE, 0);
+ permissions_section_content_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
+ gtk_box_pack_start(GTK_BOX(contents_),
+ CreateSection("Permissions", permissions_section_content_),
+ FALSE, FALSE, 0);
+
+ /*
+ GtkWidget* help_link = theme_service_->BuildChromeLinkButton(
+ l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK));
+ GtkWidget* help_link_hbox = gtk_hbox_new(FALSE, 0);
+ // Stick it in an hbox so it doesn't expand to the whole width.
+ gtk_box_pack_start(GTK_BOX(help_link_hbox), help_link, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(contents_), help_link_hbox, FALSE, FALSE, 0);
+ g_signal_connect(help_link, "clicked",
+ G_CALLBACK(OnHelpLinkClickedThunk), this);
+ */
Elliot Glaysher 2012/03/19 19:56:06 Commented out?
markusheintz_ 2012/03/20 20:44:12 removed
+
+ gtk_widget_show_all(contents_);
+}
+
+void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) {
+ GList* child = gtk_container_get_children(GTK_CONTAINER(container));
+ while (child) {
+ gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data));
+ child = child->next;
+ }
+}
+
+void WebsiteSettingsPopupGtk::SetSiteInfo(const std::string site_info) {
+ ClearContainer(site_info_contents_);
+ GtkWidget* label = theme_service_->BuildLabel(site_info,
+ ui::kGdkBlack);
+ GtkWidget* site_info_entry_box = gtk_hbox_new(FALSE, ui::kControlSpacing);
+ gtk_box_pack_start(GTK_BOX(site_info_entry_box), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(site_info_contents_), site_info_entry_box, FALSE, FALSE, 0);
Elliot Glaysher 2012/03/19 19:56:06 nit: lots of 80 col errors in this patch. won't po
markusheintz_ 2012/03/20 20:44:12 Done.
+ gtk_widget_show_all(site_info_contents_);
+}
+
+GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title,
+ GtkWidget* section_content) {
+ GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
+
+ // Add Section title
+ GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
+ gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0);
+
+ GtkWidget* label = theme_service_->BuildLabel(section_title,
+ ui::kGdkBlack);
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+ PangoAttrList* attributes = pango_attr_list_new();
+ pango_attr_list_insert(attributes,
+ pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+ gtk_label_set_attributes(GTK_LABEL(label), attributes);
+ pango_attr_list_unref(attributes);
+ gtk_util::SetLabelWidth(label, 400);
+ // Allow linebreaking in the middle of words if necessary, so that extremely
+ // long hostnames (longer than one line) will still be completely shown.
+ gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
+ gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0);
+
+ // Add section content
+ gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0);
+ return section_box;
+
+}
+
+void WebsiteSettingsPopupGtk::SetCookieInfo(const CookieInfoList& cookie_info_list) {
+ ClearContainer(cookies_section_content_);
+
+ // Create cookies info rows.
+ for (CookieInfoList::const_iterator it = cookie_info_list.begin();
+ it != cookie_info_list.end();
+ ++it) {
+ GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0);
+
+ GtkWidget* label = theme_service_->BuildLabel(it->text, ui::kGdkBlack);
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+ // PangoAttrList* attributes = pango_attr_list_new();
+ // pango_attr_list_insert(attributes,
+ // pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+ // gtk_label_set_attributes(GTK_LABEL(first_party_cookie_label), attributes);
+ // pango_attr_list_unref(attributes);
+ gtk_util::SetLabelWidth(label, 200);
+ // Allow linebreaking in the middle of words if necessary, so that extremely
+ // long hostnames (longer than one line) will still be completely shown.
+ gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
+ 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);
+ std::string info_str = " (" + allowed_count + " allowed / " + blocked_count + " blocked)";
+ GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
+ gtk_label_set_selectable(GTK_LABEL(info), TRUE);
+ gtk_util::SetLabelWidth(info, 200);
+ gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(cookies_section_content_),
+ cookies_info,
+ FALSE, FALSE, 0);
+ }
+
+ // Create links row.
+ GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
+
+ GtkWidget* show_cookie_settings_link = theme_service_->BuildChromeLinkButton(
+ "Manage cookie settings");
+ g_signal_connect(show_cookie_settings_link, "clicked",
+ G_CALLBACK(OnCookieSettingsLinkClickedThunk), this);
+ gtk_box_pack_start(GTK_BOX(link_hbox), show_cookie_settings_link,
+ FALSE, FALSE, 0);
+
+ GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton(
+ "Show cookies");
+ g_signal_connect(view_cookies_link, "clicked",
+ G_CALLBACK(OnCookiesLinkClickedThunk), this);
+ gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
+ FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(cookies_section_content_), link_hbox, FALSE, FALSE, 0);
+
+ gtk_widget_show_all(cookies_section_content_);
+}
+
+void WebsiteSettingsPopupGtk::SetPermissionInfo(
+ const PermissionInfoList& permission_info_list) {
+ ClearContainer(permissions_section_content_);
+
+ for (PermissionInfoList::const_iterator permission =
+ permission_info_list.begin();
+ permission != permission_info_list.end();
+ ++permission) {
+ std::string permission_text;
+ switch (permission->type) {
+ case CONTENT_SETTINGS_TYPE_POPUPS:
+ permission_text = "Popups";
Elliot Glaysher 2012/03/19 19:56:06 shouldn't this be localized?
markusheintz_ 2012/03/20 20:44:12 Done.
+ break;
+ case CONTENT_SETTINGS_TYPE_PLUGINS:
+ permission_text = "Plugins";
+ break;
+ case CONTENT_SETTINGS_TYPE_GEOLOCATION:
+ permission_text = "Location";
+ break;
+ case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
+ permission_text = "Notifications";
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ GtkWidget* label = theme_service_->BuildLabel(permission_text,
+ ui::kGdkBlack);
+ gtk_util::SetLabelWidth(label, 280);
+ GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+ GtkWidget* combo_box = gtk_combo_box_new_text();
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "ALLOW");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "BLOCK");
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box),
+ permission->setting == CONTENT_SETTING_ALLOW ? 0 : 1);
+ g_signal_connect(combo_box, "changed",
+ G_CALLBACK(OnPermissionChangedThunk), this);
+
+ gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(permissions_section_content_), hbox, FALSE,
+ FALSE, 0);
+ }
+
+ GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton(
+ "Manage permission settings");
+ g_signal_connect(show_content_settings_link, "clicked",
+ G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this);
+ GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link,
+ FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(permissions_section_content_), link_hbox,
+ FALSE, FALSE, 0);
+
+ gtk_widget_show_all(permissions_section_content_);
+}
+
+void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) {
+ new CollectedCookiesGtk(GTK_WINDOW(parent_),
+ tab_contents_wrapper_);
+ bubble_->Close();
+}
+
+void WebsiteSettingsPopupGtk::OnCookieSettingsLinkClicked(GtkWidget* widget) {
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
+ browser->OpenURL(OpenURLParams(
+ GURL(std::string(
+ chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
+ content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK,
+ false));
+ bubble_->Close();
+}
+
+void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(
+ GtkWidget* widget) {
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
+ browser->OpenURL(OpenURLParams(
+ GURL(std::string(
+ chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
+ content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK,
+ false));
+ bubble_->Close();
+}
+
+void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) {
+ LOG(ERROR) << " *** OnPermissionChanged";
+}
+
+// static
+void WebsiteSettingsUI::Show(gfx::NativeWindow parent,
+ Profile* profile,
+ TabContentsWrapper* tab_contents_wrapper,
+ const GURL& url,
+ const content::SSLStatus& ssl,
+ bool show_history) {
+ new WebsiteSettingsPopupGtk(parent, profile, tab_contents_wrapper, url, ssl,
+ show_history);
+}
« no previous file with comments | « chrome/browser/ui/gtk/website_settings_popup_gtk.h ('k') | chrome/browser/ui/website_settings_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698