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..b359c77974e48b32846157c66cc187b717445c1b |
--- /dev/null |
+++ b/chrome/browser/ui/gtk/website_settings_popup_gtk.cc |
@@ -0,0 +1,800 @@ |
+// 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/website_settings_popup.h" |
+ |
+#include <vector> |
+ |
+#include <gtk/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/website_settings_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/bubble/bubble_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 "content/public/common/ssl_status.h" |
+#include "googleurl/src/gurl.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" |
+#include "ui/gfx/image/image.h" |
+ |
+using content::OpenURLParams; |
+ |
+using content::SSLStatus; |
+ |
+namespace { |
+ |
+// NOTE: ICON_STATE_OK ... ICON_STATE_ERROR must be listed in increasing |
+// order of severity. Code may depend on this order. |
+enum SectionStateIcon { |
+ // No icon. |
+ ICON_NONE = -1, |
+ // State is OK. |
+ ICON_STATE_OK, |
+ // For example, if state is OK but contains mixed content. |
+ ICON_STATE_WARNING_MINOR, |
+ // For example, if content was served over HTTP. |
+ ICON_STATE_WARNING_MAJOR, |
+ // For example, unverified identity over HTTPS. |
+ ICON_STATE_ERROR, |
+ // An information icon. |
+ ICON_STATE_INFO, |
+ // Icon for internal pages. |
+ ICON_STATE_INTERNAL_PAGE, |
+}; |
+ |
+/* |
+// Mapping for |WebsiteSettings::SiteIdentityStatus| to icon ids. |
+SectionStateIcon kIdentityIconIds[] = { |
+ ICON_NONE, // SITE_IDENTITY_STATUS_UNKNOWN |
+ ICON_STATE_OK, // SITE_IDENTITY_STATUS_CERT |
+ ICON_STATE_OK, // SITE_IDENTITY_STATUS_EV_CERT |
+ ICON_STATE_OK, // SITE_IDENTITY_STATUS_DNSSEC_CERT |
+ ICON_STATE_WARNING_MINOR, // SITE_IDENTITY_STATUS_CERT_REVOKATION_UNKOWN |
+ ICON_STATE_WARNING_MAJOR, // SITE_IDENTITY_STATUS_NO_CERT |
+ ICON_STATE_ERROR, // SITE_IDENTITY_STATUS_ERROR |
+ ICON_STATE_INTERNAL_PAGE // SITE_IDENTITY_STATUS_INTERNAL_PAGE |
+}; |
+ |
+// Mapping for |WebsiteSettings::SiteConnectionStatus| to icon ids. |
+SectionStateIcon kConnectionIconIds[] = { |
+ ICON_NONE, // SITE_CONNECTION_STATUS_UNKNOWN |
+ ICON_STATE_OK, // SITE_CONNECTION_STATUS_ENCRYPTED |
+ ICON_STATE_WARNING_MINOR, // SITE_CONNECTION_STATUS_MIXED_CONTENT |
+ ICON_STATE_WARNING_MAJOR, // SITE_CONNECTION_STATUS_UNENCRYPTED |
+ ICON_STATE_ERROR, // SITE_CONNECTION_STATUS_ENCRYPTED_ERROR |
+ ICON_STATE_INTERNAL_PAGE, // SITE_CONNECTION_STATUS_INTERNAL_PAGE |
+}; |
+*/ |
+ |
+class WebsiteSettingsPopupGtk : public WebsiteSettingsPopup, |
+ public WebsiteSettingsUI, |
+ public BubbleDelegateGtk { |
+ public: |
+ WebsiteSettingsPopupGtk(gfx::NativeWindow parent, |
+ Profile* profile, |
+ TabContentsWrapper* wrapper, |
+ const GURL& url, |
+ const SSLStatus& ssl, |
+ bool show_history); |
+ virtual ~WebsiteSettingsPopupGtk(); |
+ |
+ // WebsiteSettingsUI methods. |
+ virtual void Update() OVERRIDE; |
+ |
+ // BubbleDelegateGtk implementation. |
+ virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; |
+ |
+ private: |
+ // Layouts the different sections retrieved from the model. |
+ void InitContents(); |
+ |
+ //void ShowConnectionDetails(bool show_details, GtkWidget* vbox); |
+ |
+ //void ShowIdentityDetails(bool show_details, GtkWidget* vbox); |
+ GtkWidget* CreateSection(std::string section_title, |
+ GtkWidget* section_content); |
+ GtkWidget* CreateCookiesDetails(); |
+ GtkWidget* CreateCookiesInfo(const std::string& text, |
+ int allowed, |
+ int bocked); |
+ |
+ void InitIcons(); |
+ |
+ gfx::Image* GetIconImage(SectionStateIcon icon_id); |
+ |
+ //GtkWidget* CreateIdentitySection(); |
+ //GtkWidget* CreateConnectionSection(); |
+ //GtkWidget* CreateHistorySection(); |
+ GtkWidget* CreateInfoSection(); |
+ GtkWidget* CreateCookiesSection(); |
+ GtkWidget* CreatePermissionSection(); |
+ |
+ // Link button callbacks. |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnCookiesLinkClicked); |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnHelpLinkClicked); |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnPermissionChanged); |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
+ OnPermissionsSettingsLinkClicked); |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnViewCertLinkClicked); |
+ |
+ /* |
+ // TODO: one argument to open or close; |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
+ OnShowConnectionDetailsLinkClicked); |
+ CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
+ OnShowIdentityDetailsLinkClicked); |
+ */ |
+ |
+ WebsiteSettingsModel website_settings_; |
+ |
+ // The url for this dialog. Should be unique among active dialogs. |
+ GURL url_; |
+ |
+ // The id of the certificate for this page. |
+ int cert_id_; |
+ |
+ // Parent window. |
+ GtkWindow* parent_; |
+ |
+ // The virtual box containing the sections. |
+ GtkWidget* contents_; |
+ |
+ // The widget relative to which we are positioned. |
+ GtkWidget* anchor_; |
+ |
+ // Provides colors and stuff. |
+ ThemeServiceGtk* theme_service_; |
+ |
+ BubbleGtk* bubble_; |
+ |
+ Profile* profile_; |
+ |
+ TabContentsWrapper* tab_contents_wrapper_; |
+ |
+ // All possible icons that go next to the text descriptions to indicate state. |
+ std::vector<gfx::Image*> icons_; |
+ |
+ std::map<std::string, GtkWidget*> ui_elements_; |
+ |
+ GtkWidget* identity_details_; |
+ bool identity_details_displayed_; |
+ |
+ GtkWidget* connection_details_; |
+ bool connection_details_displayed_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupGtk); |
+}; |
+ |
+WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk( |
+ gfx::NativeWindow parent, |
+ Profile* profile, |
+ TabContentsWrapper* tab_contents_wrapper, |
+ const GURL& url, |
+ const SSLStatus& ssl, |
+ bool show_history) |
+ : ALLOW_THIS_IN_INITIALIZER_LIST( |
+ website_settings_(this, |
+ profile, |
+ url, |
+ ssl, |
+ content::CertStore::GetInstance(), |
+ tab_contents_wrapper->content_settings())), |
+ url_(url), |
+ cert_id_(ssl.cert_id), |
+ parent_(parent), |
+ contents_(NULL), |
+ theme_service_(ThemeServiceGtk::GetFrom(profile)), |
+ profile_(profile), |
+ tab_contents_wrapper_(tab_contents_wrapper), |
+ identity_details_(NULL), |
+ identity_details_displayed_(false), |
+ connection_details_(NULL), |
+ connection_details_displayed_(false) { |
+ BrowserWindowGtk* browser_window = |
+ BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); |
+ |
+ anchor_ = browser_window-> |
+ GetToolbar()->GetLocationBarView()->location_icon_widget(); |
+ |
+ InitIcons(); |
+ InitContents(); |
+ |
+ 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::Update() { |
+ InitContents(); |
+} |
+ |
+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_); |
+ } |
+ |
+ /* |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreateIdentitySection(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreateConnectionSection(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ gtk_hseparator_new(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreateHistorySection(), |
+ FALSE, FALSE, 0); |
+ */ |
+ |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreateInfoSection(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ gtk_hseparator_new(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreateCookiesSection(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ gtk_hseparator_new(), |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(contents_), |
+ CreatePermissionSection(), |
+ 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); |
+ */ |
+ |
+ gtk_widget_show_all(contents_); |
+} |
+ |
+void WebsiteSettingsPopupGtk::InitIcons() { |
+ // Loads the icons into the vector. The order must match the SectionStateIcon |
+ // enum. |
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_GOOD)); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MINOR)); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MAJOR)); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_BAD)); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_INFO)); |
+ icons_.push_back(&rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_26)); |
+} |
+ |
+gfx::Image* WebsiteSettingsPopupGtk::GetIconImage(SectionStateIcon icon_id) { |
+ if (icon_id == ICON_NONE) |
+ return NULL; |
+ // The bubble uses new, various icons. |
+ return icons_[icon_id]; |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateInfoSection() { |
+ std::string site_identity_text; |
+ |
+ WebsiteSettingsModel::SiteIdentityStatus status = |
+ website_settings_.site_identity_status(); |
+ switch (status) { |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_CERT: |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_DNSSEC_CERT: |
+ site_identity_text = "Identity verified"; |
+ break; |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_EV_CERT: |
+ site_identity_text = UTF16ToUTF8(website_settings_.organization_name()); |
+ site_identity_text += " - Identity verified"; |
+ break; |
+ default: |
+ site_identity_text = "Identity not verified"; |
+ break; |
+ } |
+ |
+ GtkWidget* label = theme_service_->BuildLabel(site_identity_text, |
+ 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); |
+ |
+ GtkWidget* section_content = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_content), site_info_entry_box, FALSE, FALSE, 0); |
+ |
+ std::string section_title = "Site Information"; |
+ |
+ return CreateSection(section_title, section_content); |
+} |
+ |
+/* |
+GtkWidget* WebsiteSettingsPopupGtk::CreateIdentitySection() { |
+ WebsiteSettingsModel::SiteIdentityStatus status = |
+ website_settings_.site_identity_status(); |
+ |
+ GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ |
+ GtkWidget* vbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_box), vbox, FALSE, FALSE, 0); |
+ |
+ // Add icon. |
+ SectionStateIcon icon_id = kIdentityIconIds[status]; |
+ GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
+ if (pixbuf) { |
+ GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
+ gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); |
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
+ } |
+ |
+ // Add headline. |
+ std::string headline; |
+ switch (status) { |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_CERT: |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_DNSSEC_CERT: |
+ headline = "Identity verified"; |
+ break; |
+ case WebsiteSettingsModel::SITE_IDENTITY_STATUS_EV_CERT: |
+ headline = UTF16ToUTF8(website_settings_.organization_name()); |
+ headline += " - Identity verified"; |
+ break; |
+ default: |
+ headline = "Identity not verified"; |
+ break; |
+ } |
+ |
+ GtkWidget* label = theme_service_->BuildLabel(headline, |
+ 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, 320); |
+ // 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(vbox), label, FALSE, FALSE, 0); |
+ |
+ // Add button |
+ GtkWidget* show_details_button = gtk_button_new_with_label("Show details"); |
+ GtkWidget* details_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(details_link_hbox), show_details_button, |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(vbox), details_link_hbox, FALSE, FALSE, 0); |
+ g_signal_connect(show_details_button, "clicked", |
+ G_CALLBACK(OnShowIdentityDetailsLinkClickedThunk), this); |
+ |
+ // |
+ identity_details_ = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_box), identity_details_, TRUE, TRUE, 0); |
+ |
+ return section_box; |
+} |
+ |
+void WebsiteSettingsPopupGtk::ShowIdentityDetails(bool show_details, |
+ GtkWidget* vbox ) { |
+ // Remove all |
+ GList* child = gtk_container_get_children(GTK_CONTAINER(vbox)); |
+ while (child) { |
+ //Glist* next = child->next() ? child->next() : NULL; |
+ gtk_container_remove(GTK_CONTAINER(vbox), GTK_WIDGET(child->data)); |
+ child = child->next; |
+ } |
+ |
+ if (!show_details) return; |
+ // Add details |
+ GtkWidget* label = theme_service_->BuildLabel( |
+ UTF16ToUTF8(website_settings_.site_identity_details()), ui::kGdkBlack); |
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
+ 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(vbox), label, FALSE, FALSE, 0); |
+ |
+ // Add certificat button |
+ if (website_settings_.site_connection_status() == |
+ WebsiteSettingsModel::SITE_CONNECTION_STATUS_ENCRYPTED) { |
+ GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton( |
+ l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
+ GtkWidget* cert_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(cert_link_hbox), view_cert_link, |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(vbox), cert_link_hbox, FALSE, FALSE, 0); |
+ g_signal_connect(view_cert_link, "clicked", |
+ G_CALLBACK(OnViewCertLinkClickedThunk), this); |
+ } |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateConnectionSection() { |
+ WebsiteSettingsModel::SiteConnectionStatus status = |
+ website_settings_.site_connection_status(); |
+ |
+ GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ |
+ GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_box), hbox, FALSE, FALSE, 0); |
+ |
+ // Add icon |
+ SectionStateIcon icon_id = kConnectionIconIds[status]; |
+ GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
+ if (pixbuf) { |
+ GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
+ gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); |
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
+ } |
+ |
+ // Add text |
+ std::string headline; |
+ switch (status) { |
+ case WebsiteSettingsModel::SITE_CONNECTION_STATUS_ENCRYPTED: |
+ headline = "Encrypted Connection"; |
+ break; |
+ case WebsiteSettingsModel::SITE_CONNECTION_STATUS_UNENCRYPTED: |
+ headline = "Unencrypted Connection"; |
+ break; |
+ case WebsiteSettingsModel::SITE_CONNECTION_STATUS_MIXED_CONTENT: |
+ headline = "Website contains mixed content"; |
+ break; |
+ default: |
+ headline = "Error"; |
+ break; |
+ } |
+ GtkWidget* label = theme_service_->BuildLabel(headline, |
+ 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, 320); |
+ // 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(hbox), label, FALSE, FALSE, 0); |
+ |
+ // Add button |
+ GtkWidget* show_details_button = gtk_button_new_with_label("Show details"); |
+ |
+ GtkWidget* details_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(details_link_hbox), show_details_button, |
+ FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(hbox), details_link_hbox, FALSE, FALSE, 0); |
+ g_signal_connect(show_details_button, "clicked", |
+ G_CALLBACK(OnShowConnectionDetailsLinkClickedThunk), this); |
+ |
+ // Add details box |
+ connection_details_ = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_box), connection_details_, TRUE, TRUE, 0); |
+ |
+ return section_box; |
+} |
+ |
+void WebsiteSettingsPopupGtk::ShowConnectionDetails(bool show, GtkWidget* vbox) { |
+ // Remove all |
+ GList* child = gtk_container_get_children(GTK_CONTAINER(vbox)); |
+ while (child) { |
+ //Glist* next = child->next() ? child->next() : NULL; |
+ gtk_container_remove(GTK_CONTAINER(vbox), GTK_WIDGET(child->data)); |
+ child = child->next; |
+ } |
+ |
+ if (!show) return; |
+ |
+ // Add details |
+ GtkWidget* label = theme_service_->BuildLabel( |
+ UTF16ToUTF8(website_settings_.site_connection_details()), ui::kGdkBlack); |
+ gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
+ 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(vbox), label, FALSE, FALSE, 0); |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateHistorySection() { |
+ GtkWidget* section_box = gtk_hbox_new(FALSE, ui::kControlSpacing); |
+ |
+ SectionStateIcon icon_id = ICON_STATE_INFO; |
+ GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
+ if (pixbuf) { |
+ GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
+ gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, 0); |
+ gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
+ } |
+ |
+ GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0); |
+ |
+ GtkWidget* label = theme_service_->BuildLabel("Last Visit", |
+ 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(vbox), label, FALSE, FALSE, 0); |
+ |
+ return section_box; |
+} |
+ |
+void WebsiteSettingsPopupGtk::OnShowConnectionDetailsLinkClicked(GtkWidget* widget) { |
+ connection_details_displayed_ = !connection_details_displayed_; |
+ ShowConnectionDetails(connection_details_displayed_, connection_details_); |
+ gtk_widget_show_all(contents_); |
+} |
+ |
+void WebsiteSettingsPopupGtk::OnShowIdentityDetailsLinkClicked(GtkWidget* widget) { |
+ identity_details_displayed_ = !identity_details_displayed_; |
+ ShowIdentityDetails(identity_details_displayed_, identity_details_); |
+ gtk_widget_show_all(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; |
+ |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesSection() { |
+ return CreateSection("Cookies and Site Data", CreateCookiesDetails()); |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreatePermissionSection() { |
+ GtkWidget* content_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ |
+ PermissionInfoList permission_info_list; |
+ website_settings_.GetPermissionInfos(&permission_info_list); |
+ for (PermissionInfoList::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"; |
+ 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(content_vbox), 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(content_vbox), link_hbox, |
+ FALSE, FALSE, 0); |
+ |
+ return CreateSection("Permissions", content_vbox); |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesInfo( |
+ const std::string& text, int allowed, int blocked) { // TODO add icon id |
+ // Create first party cookies line |
+ // TODO |
+ GtkWidget* label = theme_service_->BuildLabel(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); |
+ |
+ std::string allowed_count = base::IntToString(allowed); |
+ std::string blocked_count = base::IntToString(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); |
+ |
+ |
+ GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
+ // TODO add icon |
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(hbox), info, FALSE, FALSE, 0); |
+ |
+ return hbox; |
+} |
+ |
+GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesDetails() { |
+ GtkWidget* content_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
+ |
+ CookieInfoList cookie_info_list; |
+ website_settings_.GetCookieInfos(&cookie_info_list); |
+ for (CookieInfoList::const_iterator it = cookie_info_list.begin(); |
+ it != cookie_info_list.end(); |
+ ++it) { |
+ gtk_box_pack_start(GTK_BOX(content_vbox), |
+ CreateCookiesInfo(it->text, it->allowed, it->blocked), |
+ FALSE, FALSE, 0); |
+ } |
+ |
+ // Create Link line |
+ GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton( |
+ "Show cookies"); |
+ g_signal_connect(view_cookies_link, "clicked", |
+ G_CALLBACK(OnCookiesLinkClickedThunk), this); |
+ GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); |
+ gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link, |
+ FALSE, 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(hbox), show_cookie_settings_link, |
+ // FALSE, FALSE, 0); |
+ |
+ gtk_box_pack_start(GTK_BOX(content_vbox), link_hbox, FALSE, FALSE, 0); |
+ |
+ return content_vbox; |
+} |
+ |
+void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) { |
+ ShowCertificateViewerByID(GTK_WINDOW(parent_), cert_id_); |
+ bubble_->Close(); |
+} |
+ |
+void WebsiteSettingsPopupGtk::OnHelpLinkClicked(GtkWidget* widget) { |
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
+ browser->OpenURL(OpenURLParams( |
+ GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
+ NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
+ bubble_->Close(); |
+} |
+ |
+ |
+void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) { |
+ new CollectedCookiesGtk(GTK_WINDOW(parent_), |
+ tab_contents_wrapper_); |
+ 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"; |
+} |
+ |
+} // namespace |
+ |
+// static |
+void WebsiteSettingsPopup::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); |
+} |
+ |
+WebsiteSettingsPopup::WebsiteSettingsPopup() {} |
+WebsiteSettingsPopup::~WebsiteSettingsPopup() {} |