OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/website_settings_popup.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include <gtk/gtk.h> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/i18n/rtl.h" |
| 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/certificate_viewer.h" |
| 17 #include "chrome/browser/page_info_model.h" |
| 18 #include "chrome/browser/website_settings_model.h" |
| 19 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 21 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 22 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
| 23 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h" |
| 24 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 25 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 26 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 27 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 29 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/cert_store.h" |
| 31 #include "content/public/common/ssl_status.h" |
| 32 #include "googleurl/src/gurl.h" |
| 33 #include "grit/generated_resources.h" |
| 34 #include "grit/locale_settings.h" |
| 35 #include "grit/theme_resources.h" |
| 36 #include "ui/base/gtk/gtk_hig_constants.h" |
| 37 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/image/image.h" |
| 40 |
| 41 using content::OpenURLParams; |
| 42 |
| 43 using content::SSLStatus; |
| 44 |
| 45 namespace { |
| 46 |
| 47 // NOTE: ICON_STATE_OK ... ICON_STATE_ERROR must be listed in increasing |
| 48 // order of severity. Code may depend on this order. |
| 49 enum SectionStateIcon { |
| 50 // No icon. |
| 51 ICON_NONE = -1, |
| 52 // State is OK. |
| 53 ICON_STATE_OK, |
| 54 // For example, if state is OK but contains mixed content. |
| 55 ICON_STATE_WARNING_MINOR, |
| 56 // For example, if content was served over HTTP. |
| 57 ICON_STATE_WARNING_MAJOR, |
| 58 // For example, unverified identity over HTTPS. |
| 59 ICON_STATE_ERROR, |
| 60 // An information icon. |
| 61 ICON_STATE_INFO, |
| 62 // Icon for internal pages. |
| 63 ICON_STATE_INTERNAL_PAGE, |
| 64 }; |
| 65 |
| 66 /* |
| 67 // Mapping for |WebsiteSettings::SiteIdentityStatus| to icon ids. |
| 68 SectionStateIcon kIdentityIconIds[] = { |
| 69 ICON_NONE, // SITE_IDENTITY_STATUS_UNKNOWN |
| 70 ICON_STATE_OK, // SITE_IDENTITY_STATUS_CERT |
| 71 ICON_STATE_OK, // SITE_IDENTITY_STATUS_EV_CERT |
| 72 ICON_STATE_OK, // SITE_IDENTITY_STATUS_DNSSEC_CERT |
| 73 ICON_STATE_WARNING_MINOR, // SITE_IDENTITY_STATUS_CERT_REVOKATION_UNKOWN |
| 74 ICON_STATE_WARNING_MAJOR, // SITE_IDENTITY_STATUS_NO_CERT |
| 75 ICON_STATE_ERROR, // SITE_IDENTITY_STATUS_ERROR |
| 76 ICON_STATE_INTERNAL_PAGE // SITE_IDENTITY_STATUS_INTERNAL_PAGE |
| 77 }; |
| 78 |
| 79 // Mapping for |WebsiteSettings::SiteConnectionStatus| to icon ids. |
| 80 SectionStateIcon kConnectionIconIds[] = { |
| 81 ICON_NONE, // SITE_CONNECTION_STATUS_UNKNOWN |
| 82 ICON_STATE_OK, // SITE_CONNECTION_STATUS_ENCRYPTED |
| 83 ICON_STATE_WARNING_MINOR, // SITE_CONNECTION_STATUS_MIXED_CONTENT |
| 84 ICON_STATE_WARNING_MAJOR, // SITE_CONNECTION_STATUS_UNENCRYPTED |
| 85 ICON_STATE_ERROR, // SITE_CONNECTION_STATUS_ENCRYPTED_ERROR |
| 86 ICON_STATE_INTERNAL_PAGE, // SITE_CONNECTION_STATUS_INTERNAL_PAGE |
| 87 }; |
| 88 */ |
| 89 |
| 90 class WebsiteSettingsPopupGtk : public WebsiteSettingsPopup, |
| 91 public WebsiteSettingsUI, |
| 92 public BubbleDelegateGtk { |
| 93 public: |
| 94 WebsiteSettingsPopupGtk(gfx::NativeWindow parent, |
| 95 Profile* profile, |
| 96 TabContentsWrapper* wrapper, |
| 97 const GURL& url, |
| 98 const SSLStatus& ssl, |
| 99 bool show_history); |
| 100 virtual ~WebsiteSettingsPopupGtk(); |
| 101 |
| 102 // WebsiteSettingsUI methods. |
| 103 virtual void Update() OVERRIDE; |
| 104 |
| 105 // BubbleDelegateGtk implementation. |
| 106 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; |
| 107 |
| 108 private: |
| 109 // Layouts the different sections retrieved from the model. |
| 110 void InitContents(); |
| 111 |
| 112 //void ShowConnectionDetails(bool show_details, GtkWidget* vbox); |
| 113 |
| 114 //void ShowIdentityDetails(bool show_details, GtkWidget* vbox); |
| 115 GtkWidget* CreateSection(std::string section_title, |
| 116 GtkWidget* section_content); |
| 117 GtkWidget* CreateCookiesDetails(); |
| 118 GtkWidget* CreateCookiesInfo(const std::string& text, |
| 119 int allowed, |
| 120 int bocked); |
| 121 |
| 122 void InitIcons(); |
| 123 |
| 124 gfx::Image* GetIconImage(SectionStateIcon icon_id); |
| 125 |
| 126 //GtkWidget* CreateIdentitySection(); |
| 127 //GtkWidget* CreateConnectionSection(); |
| 128 //GtkWidget* CreateHistorySection(); |
| 129 GtkWidget* CreateInfoSection(); |
| 130 GtkWidget* CreateCookiesSection(); |
| 131 GtkWidget* CreatePermissionSection(); |
| 132 |
| 133 // Link button callbacks. |
| 134 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnCookiesLinkClicked); |
| 135 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnHelpLinkClicked); |
| 136 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnPermissionChanged); |
| 137 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
| 138 OnPermissionsSettingsLinkClicked); |
| 139 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, OnViewCertLinkClicked); |
| 140 |
| 141 /* |
| 142 // TODO: one argument to open or close; |
| 143 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
| 144 OnShowConnectionDetailsLinkClicked); |
| 145 CHROMEGTK_CALLBACK_0(WebsiteSettingsPopupGtk, void, |
| 146 OnShowIdentityDetailsLinkClicked); |
| 147 */ |
| 148 |
| 149 WebsiteSettingsModel website_settings_; |
| 150 |
| 151 // The url for this dialog. Should be unique among active dialogs. |
| 152 GURL url_; |
| 153 |
| 154 // The id of the certificate for this page. |
| 155 int cert_id_; |
| 156 |
| 157 // Parent window. |
| 158 GtkWindow* parent_; |
| 159 |
| 160 // The virtual box containing the sections. |
| 161 GtkWidget* contents_; |
| 162 |
| 163 // The widget relative to which we are positioned. |
| 164 GtkWidget* anchor_; |
| 165 |
| 166 // Provides colors and stuff. |
| 167 ThemeServiceGtk* theme_service_; |
| 168 |
| 169 BubbleGtk* bubble_; |
| 170 |
| 171 Profile* profile_; |
| 172 |
| 173 TabContentsWrapper* tab_contents_wrapper_; |
| 174 |
| 175 // All possible icons that go next to the text descriptions to indicate state. |
| 176 std::vector<gfx::Image*> icons_; |
| 177 |
| 178 std::map<std::string, GtkWidget*> ui_elements_; |
| 179 |
| 180 GtkWidget* identity_details_; |
| 181 bool identity_details_displayed_; |
| 182 |
| 183 GtkWidget* connection_details_; |
| 184 bool connection_details_displayed_; |
| 185 |
| 186 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsPopupGtk); |
| 187 }; |
| 188 |
| 189 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk( |
| 190 gfx::NativeWindow parent, |
| 191 Profile* profile, |
| 192 TabContentsWrapper* tab_contents_wrapper, |
| 193 const GURL& url, |
| 194 const SSLStatus& ssl, |
| 195 bool show_history) |
| 196 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 197 website_settings_(this, |
| 198 profile, |
| 199 url, |
| 200 ssl, |
| 201 content::CertStore::GetInstance(), |
| 202 tab_contents_wrapper->content_settings())), |
| 203 url_(url), |
| 204 cert_id_(ssl.cert_id), |
| 205 parent_(parent), |
| 206 contents_(NULL), |
| 207 theme_service_(ThemeServiceGtk::GetFrom(profile)), |
| 208 profile_(profile), |
| 209 tab_contents_wrapper_(tab_contents_wrapper), |
| 210 identity_details_(NULL), |
| 211 identity_details_displayed_(false), |
| 212 connection_details_(NULL), |
| 213 connection_details_displayed_(false) { |
| 214 BrowserWindowGtk* browser_window = |
| 215 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); |
| 216 |
| 217 anchor_ = browser_window-> |
| 218 GetToolbar()->GetLocationBarView()->location_icon_widget(); |
| 219 |
| 220 InitIcons(); |
| 221 InitContents(); |
| 222 |
| 223 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? |
| 224 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : |
| 225 BubbleGtk::ARROW_LOCATION_TOP_LEFT; |
| 226 bubble_ = BubbleGtk::Show(anchor_, |
| 227 NULL, // |rect| |
| 228 contents_, |
| 229 arrow_location, |
| 230 true, // |match_system_theme| |
| 231 true, // |grab_input| |
| 232 theme_service_, |
| 233 this); // |delegate| |
| 234 if (!bubble_) { |
| 235 NOTREACHED(); |
| 236 return; |
| 237 } |
| 238 } |
| 239 |
| 240 WebsiteSettingsPopupGtk::~WebsiteSettingsPopupGtk() { |
| 241 } |
| 242 |
| 243 void WebsiteSettingsPopupGtk::Update() { |
| 244 InitContents(); |
| 245 } |
| 246 |
| 247 void WebsiteSettingsPopupGtk::BubbleClosing(BubbleGtk* bubble, |
| 248 bool closed_by_escape) { |
| 249 delete this; |
| 250 } |
| 251 |
| 252 void WebsiteSettingsPopupGtk::InitContents() { |
| 253 if (!contents_) { |
| 254 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); |
| 255 gtk_container_set_border_width(GTK_CONTAINER(contents_), |
| 256 ui::kContentAreaBorder); |
| 257 } else { |
| 258 gtk_util::RemoveAllChildren(contents_); |
| 259 } |
| 260 |
| 261 /* |
| 262 gtk_box_pack_start(GTK_BOX(contents_), |
| 263 CreateIdentitySection(), |
| 264 FALSE, FALSE, 0); |
| 265 gtk_box_pack_start(GTK_BOX(contents_), |
| 266 CreateConnectionSection(), |
| 267 FALSE, FALSE, 0); |
| 268 gtk_box_pack_start(GTK_BOX(contents_), |
| 269 gtk_hseparator_new(), |
| 270 FALSE, FALSE, 0); |
| 271 gtk_box_pack_start(GTK_BOX(contents_), |
| 272 CreateHistorySection(), |
| 273 FALSE, FALSE, 0); |
| 274 */ |
| 275 |
| 276 gtk_box_pack_start(GTK_BOX(contents_), |
| 277 CreateInfoSection(), |
| 278 FALSE, FALSE, 0); |
| 279 gtk_box_pack_start(GTK_BOX(contents_), |
| 280 gtk_hseparator_new(), |
| 281 FALSE, FALSE, 0); |
| 282 gtk_box_pack_start(GTK_BOX(contents_), |
| 283 CreateCookiesSection(), |
| 284 FALSE, FALSE, 0); |
| 285 gtk_box_pack_start(GTK_BOX(contents_), |
| 286 gtk_hseparator_new(), |
| 287 FALSE, FALSE, 0); |
| 288 gtk_box_pack_start(GTK_BOX(contents_), |
| 289 CreatePermissionSection(), |
| 290 FALSE, FALSE, 0); |
| 291 |
| 292 /* |
| 293 GtkWidget* help_link = theme_service_->BuildChromeLinkButton( |
| 294 l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)); |
| 295 GtkWidget* help_link_hbox = gtk_hbox_new(FALSE, 0); |
| 296 // Stick it in an hbox so it doesn't expand to the whole width. |
| 297 gtk_box_pack_start(GTK_BOX(help_link_hbox), help_link, FALSE, FALSE, 0); |
| 298 gtk_box_pack_start(GTK_BOX(contents_), help_link_hbox, FALSE, FALSE, 0); |
| 299 g_signal_connect(help_link, "clicked", |
| 300 G_CALLBACK(OnHelpLinkClickedThunk), this); |
| 301 */ |
| 302 |
| 303 gtk_widget_show_all(contents_); |
| 304 } |
| 305 |
| 306 void WebsiteSettingsPopupGtk::InitIcons() { |
| 307 // Loads the icons into the vector. The order must match the SectionStateIcon |
| 308 // enum. |
| 309 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 310 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_GOOD)); |
| 311 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MINOR)); |
| 312 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MAJOR)); |
| 313 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_BAD)); |
| 314 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_INFO)); |
| 315 icons_.push_back(&rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_26)); |
| 316 } |
| 317 |
| 318 gfx::Image* WebsiteSettingsPopupGtk::GetIconImage(SectionStateIcon icon_id) { |
| 319 if (icon_id == ICON_NONE) |
| 320 return NULL; |
| 321 // The bubble uses new, various icons. |
| 322 return icons_[icon_id]; |
| 323 } |
| 324 |
| 325 GtkWidget* WebsiteSettingsPopupGtk::CreateInfoSection() { |
| 326 std::string site_identity_text; |
| 327 |
| 328 WebsiteSettingsModel::SiteIdentityStatus status = |
| 329 website_settings_.site_identity_status(); |
| 330 switch (status) { |
| 331 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_CERT: |
| 332 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_DNSSEC_CERT: |
| 333 site_identity_text = "Identity verified"; |
| 334 break; |
| 335 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_EV_CERT: |
| 336 site_identity_text = UTF16ToUTF8(website_settings_.organization_name()); |
| 337 site_identity_text += " - Identity verified"; |
| 338 break; |
| 339 default: |
| 340 site_identity_text = "Identity not verified"; |
| 341 break; |
| 342 } |
| 343 |
| 344 GtkWidget* label = theme_service_->BuildLabel(site_identity_text, |
| 345 ui::kGdkBlack); |
| 346 GtkWidget* site_info_entry_box = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 347 gtk_box_pack_start(GTK_BOX(site_info_entry_box), label, FALSE, FALSE, 0); |
| 348 |
| 349 GtkWidget* section_content = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 350 gtk_box_pack_start(GTK_BOX(section_content), site_info_entry_box, FALSE, FALSE
, 0); |
| 351 |
| 352 std::string section_title = "Site Information"; |
| 353 |
| 354 return CreateSection(section_title, section_content); |
| 355 } |
| 356 |
| 357 /* |
| 358 GtkWidget* WebsiteSettingsPopupGtk::CreateIdentitySection() { |
| 359 WebsiteSettingsModel::SiteIdentityStatus status = |
| 360 website_settings_.site_identity_status(); |
| 361 |
| 362 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 363 |
| 364 GtkWidget* vbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 365 gtk_box_pack_start(GTK_BOX(section_box), vbox, FALSE, FALSE, 0); |
| 366 |
| 367 // Add icon. |
| 368 SectionStateIcon icon_id = kIdentityIconIds[status]; |
| 369 GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
| 370 if (pixbuf) { |
| 371 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 372 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); |
| 373 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
| 374 } |
| 375 |
| 376 // Add headline. |
| 377 std::string headline; |
| 378 switch (status) { |
| 379 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_CERT: |
| 380 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_DNSSEC_CERT: |
| 381 headline = "Identity verified"; |
| 382 break; |
| 383 case WebsiteSettingsModel::SITE_IDENTITY_STATUS_EV_CERT: |
| 384 headline = UTF16ToUTF8(website_settings_.organization_name()); |
| 385 headline += " - Identity verified"; |
| 386 break; |
| 387 default: |
| 388 headline = "Identity not verified"; |
| 389 break; |
| 390 } |
| 391 |
| 392 GtkWidget* label = theme_service_->BuildLabel(headline, |
| 393 ui::kGdkBlack); |
| 394 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 395 PangoAttrList* attributes = pango_attr_list_new(); |
| 396 pango_attr_list_insert(attributes, |
| 397 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 398 gtk_label_set_attributes(GTK_LABEL(label), attributes); |
| 399 pango_attr_list_unref(attributes); |
| 400 gtk_util::SetLabelWidth(label, 320); |
| 401 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 402 // long hostnames (longer than one line) will still be completely shown. |
| 403 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 404 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 405 |
| 406 // Add button |
| 407 GtkWidget* show_details_button = gtk_button_new_with_label("Show details"); |
| 408 GtkWidget* details_link_hbox = gtk_hbox_new(FALSE, 0); |
| 409 // Stick it in an hbox so it doesn't expand to the whole width. |
| 410 gtk_box_pack_start(GTK_BOX(details_link_hbox), show_details_button, |
| 411 FALSE, FALSE, 0); |
| 412 gtk_box_pack_start(GTK_BOX(vbox), details_link_hbox, FALSE, FALSE, 0); |
| 413 g_signal_connect(show_details_button, "clicked", |
| 414 G_CALLBACK(OnShowIdentityDetailsLinkClickedThunk), this); |
| 415 |
| 416 // |
| 417 identity_details_ = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 418 gtk_box_pack_start(GTK_BOX(section_box), identity_details_, TRUE, TRUE, 0); |
| 419 |
| 420 return section_box; |
| 421 } |
| 422 |
| 423 void WebsiteSettingsPopupGtk::ShowIdentityDetails(bool show_details, |
| 424 GtkWidget* vbox ) { |
| 425 // Remove all |
| 426 GList* child = gtk_container_get_children(GTK_CONTAINER(vbox)); |
| 427 while (child) { |
| 428 //Glist* next = child->next() ? child->next() : NULL; |
| 429 gtk_container_remove(GTK_CONTAINER(vbox), GTK_WIDGET(child->data)); |
| 430 child = child->next; |
| 431 } |
| 432 |
| 433 if (!show_details) return; |
| 434 // Add details |
| 435 GtkWidget* label = theme_service_->BuildLabel( |
| 436 UTF16ToUTF8(website_settings_.site_identity_details()), ui::kGdkBlack); |
| 437 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 438 gtk_util::SetLabelWidth(label, 400); |
| 439 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 440 // long hostnames (longer than one line) will still be completely shown. |
| 441 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 442 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 443 |
| 444 // Add certificat button |
| 445 if (website_settings_.site_connection_status() == |
| 446 WebsiteSettingsModel::SITE_CONNECTION_STATUS_ENCRYPTED) { |
| 447 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton( |
| 448 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON)); |
| 449 GtkWidget* cert_link_hbox = gtk_hbox_new(FALSE, 0); |
| 450 // Stick it in an hbox so it doesn't expand to the whole width. |
| 451 gtk_box_pack_start(GTK_BOX(cert_link_hbox), view_cert_link, |
| 452 FALSE, FALSE, 0); |
| 453 gtk_box_pack_start(GTK_BOX(vbox), cert_link_hbox, FALSE, FALSE, 0); |
| 454 g_signal_connect(view_cert_link, "clicked", |
| 455 G_CALLBACK(OnViewCertLinkClickedThunk), this); |
| 456 } |
| 457 } |
| 458 |
| 459 GtkWidget* WebsiteSettingsPopupGtk::CreateConnectionSection() { |
| 460 WebsiteSettingsModel::SiteConnectionStatus status = |
| 461 website_settings_.site_connection_status(); |
| 462 |
| 463 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 464 |
| 465 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 466 gtk_box_pack_start(GTK_BOX(section_box), hbox, FALSE, FALSE, 0); |
| 467 |
| 468 // Add icon |
| 469 SectionStateIcon icon_id = kConnectionIconIds[status]; |
| 470 GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
| 471 if (pixbuf) { |
| 472 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 473 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); |
| 474 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
| 475 } |
| 476 |
| 477 // Add text |
| 478 std::string headline; |
| 479 switch (status) { |
| 480 case WebsiteSettingsModel::SITE_CONNECTION_STATUS_ENCRYPTED: |
| 481 headline = "Encrypted Connection"; |
| 482 break; |
| 483 case WebsiteSettingsModel::SITE_CONNECTION_STATUS_UNENCRYPTED: |
| 484 headline = "Unencrypted Connection"; |
| 485 break; |
| 486 case WebsiteSettingsModel::SITE_CONNECTION_STATUS_MIXED_CONTENT: |
| 487 headline = "Website contains mixed content"; |
| 488 break; |
| 489 default: |
| 490 headline = "Error"; |
| 491 break; |
| 492 } |
| 493 GtkWidget* label = theme_service_->BuildLabel(headline, |
| 494 ui::kGdkBlack); |
| 495 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 496 PangoAttrList* attributes = pango_attr_list_new(); |
| 497 pango_attr_list_insert(attributes, |
| 498 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 499 gtk_label_set_attributes(GTK_LABEL(label), attributes); |
| 500 pango_attr_list_unref(attributes); |
| 501 gtk_util::SetLabelWidth(label, 320); |
| 502 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 503 // long hostnames (longer than one line) will still be completely shown. |
| 504 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 505 |
| 506 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| 507 |
| 508 // Add button |
| 509 GtkWidget* show_details_button = gtk_button_new_with_label("Show details"); |
| 510 |
| 511 GtkWidget* details_link_hbox = gtk_hbox_new(FALSE, 0); |
| 512 // Stick it in an hbox so it doesn't expand to the whole width. |
| 513 gtk_box_pack_start(GTK_BOX(details_link_hbox), show_details_button, |
| 514 FALSE, FALSE, 0); |
| 515 gtk_box_pack_start(GTK_BOX(hbox), details_link_hbox, FALSE, FALSE, 0); |
| 516 g_signal_connect(show_details_button, "clicked", |
| 517 G_CALLBACK(OnShowConnectionDetailsLinkClickedThunk), this); |
| 518 |
| 519 // Add details box |
| 520 connection_details_ = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 521 gtk_box_pack_start(GTK_BOX(section_box), connection_details_, TRUE, TRUE, 0); |
| 522 |
| 523 return section_box; |
| 524 } |
| 525 |
| 526 void WebsiteSettingsPopupGtk::ShowConnectionDetails(bool show, GtkWidget* vbox)
{ |
| 527 // Remove all |
| 528 GList* child = gtk_container_get_children(GTK_CONTAINER(vbox)); |
| 529 while (child) { |
| 530 //Glist* next = child->next() ? child->next() : NULL; |
| 531 gtk_container_remove(GTK_CONTAINER(vbox), GTK_WIDGET(child->data)); |
| 532 child = child->next; |
| 533 } |
| 534 |
| 535 if (!show) return; |
| 536 |
| 537 // Add details |
| 538 GtkWidget* label = theme_service_->BuildLabel( |
| 539 UTF16ToUTF8(website_settings_.site_connection_details()), ui::kGdkBlack); |
| 540 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 541 gtk_util::SetLabelWidth(label, 400); |
| 542 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 543 // long hostnames (longer than one line) will still be completely shown. |
| 544 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 545 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 546 } |
| 547 |
| 548 GtkWidget* WebsiteSettingsPopupGtk::CreateHistorySection() { |
| 549 GtkWidget* section_box = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 550 |
| 551 SectionStateIcon icon_id = ICON_STATE_INFO; |
| 552 GdkPixbuf* pixbuf = GetIconImage(icon_id)->ToGdkPixbuf(); |
| 553 if (pixbuf) { |
| 554 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 555 gtk_box_pack_start(GTK_BOX(section_box), image, FALSE, FALSE, 0); |
| 556 gtk_misc_set_alignment(GTK_MISC(image), 0, 0); |
| 557 } |
| 558 |
| 559 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 560 gtk_box_pack_start(GTK_BOX(section_box), vbox, TRUE, TRUE, 0); |
| 561 |
| 562 GtkWidget* label = theme_service_->BuildLabel("Last Visit", |
| 563 ui::kGdkBlack); |
| 564 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 565 PangoAttrList* attributes = pango_attr_list_new(); |
| 566 pango_attr_list_insert(attributes, |
| 567 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 568 gtk_label_set_attributes(GTK_LABEL(label), attributes); |
| 569 pango_attr_list_unref(attributes); |
| 570 gtk_util::SetLabelWidth(label, 400); |
| 571 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 572 // long hostnames (longer than one line) will still be completely shown. |
| 573 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 574 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 575 |
| 576 return section_box; |
| 577 } |
| 578 |
| 579 void WebsiteSettingsPopupGtk::OnShowConnectionDetailsLinkClicked(GtkWidget* widg
et) { |
| 580 connection_details_displayed_ = !connection_details_displayed_; |
| 581 ShowConnectionDetails(connection_details_displayed_, connection_details_); |
| 582 gtk_widget_show_all(contents_); |
| 583 } |
| 584 |
| 585 void WebsiteSettingsPopupGtk::OnShowIdentityDetailsLinkClicked(GtkWidget* widget
) { |
| 586 identity_details_displayed_ = !identity_details_displayed_; |
| 587 ShowIdentityDetails(identity_details_displayed_, identity_details_); |
| 588 gtk_widget_show_all(contents_); |
| 589 } |
| 590 */ |
| 591 |
| 592 |
| 593 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title, |
| 594 GtkWidget* section_content) { |
| 595 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 596 |
| 597 // Add Section title |
| 598 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 599 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0); |
| 600 |
| 601 GtkWidget* label = theme_service_->BuildLabel(section_title, |
| 602 ui::kGdkBlack); |
| 603 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 604 PangoAttrList* attributes = pango_attr_list_new(); |
| 605 pango_attr_list_insert(attributes, |
| 606 pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 607 gtk_label_set_attributes(GTK_LABEL(label), attributes); |
| 608 pango_attr_list_unref(attributes); |
| 609 gtk_util::SetLabelWidth(label, 400); |
| 610 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 611 // long hostnames (longer than one line) will still be completely shown. |
| 612 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 613 gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0); |
| 614 |
| 615 // Add section content |
| 616 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0); |
| 617 return section_box; |
| 618 |
| 619 } |
| 620 |
| 621 GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesSection() { |
| 622 return CreateSection("Cookies and Site Data", CreateCookiesDetails()); |
| 623 } |
| 624 |
| 625 GtkWidget* WebsiteSettingsPopupGtk::CreatePermissionSection() { |
| 626 GtkWidget* content_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 627 |
| 628 PermissionInfoList permission_info_list; |
| 629 website_settings_.GetPermissionInfos(&permission_info_list); |
| 630 for (PermissionInfoList::iterator permission = permission_info_list.begin(); |
| 631 permission != permission_info_list.end(); |
| 632 ++permission) { |
| 633 std::string permission_text; |
| 634 switch (permission->type) { |
| 635 case CONTENT_SETTINGS_TYPE_POPUPS: |
| 636 permission_text = "Popups"; |
| 637 break; |
| 638 case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 639 permission_text = "Plugins"; |
| 640 break; |
| 641 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 642 permission_text = "Location"; |
| 643 break; |
| 644 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 645 permission_text = "Notifications"; |
| 646 break; |
| 647 default: |
| 648 NOTREACHED(); |
| 649 break; |
| 650 } |
| 651 GtkWidget* label = theme_service_->BuildLabel(permission_text, |
| 652 ui::kGdkBlack); |
| 653 gtk_util::SetLabelWidth(label, 280); |
| 654 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| 655 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| 656 |
| 657 GtkWidget* combo_box = gtk_combo_box_new_text(); |
| 658 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "ALLOW"); |
| 659 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "BLOCK"); |
| 660 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), |
| 661 permission->setting == CONTENT_SETTING_ALLOW ? 0 :
1); |
| 662 g_signal_connect(combo_box, "changed", |
| 663 G_CALLBACK(OnPermissionChangedThunk), this); |
| 664 |
| 665 gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0); |
| 666 |
| 667 gtk_box_pack_start(GTK_BOX(content_vbox), hbox, FALSE, FALSE, 0); |
| 668 } |
| 669 |
| 670 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton( |
| 671 "Manage permission settings"); |
| 672 g_signal_connect(show_content_settings_link, "clicked", |
| 673 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this); |
| 674 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); |
| 675 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link, |
| 676 FALSE, FALSE, 0); |
| 677 |
| 678 gtk_box_pack_start(GTK_BOX(content_vbox), link_hbox, |
| 679 FALSE, FALSE, 0); |
| 680 |
| 681 return CreateSection("Permissions", content_vbox); |
| 682 } |
| 683 |
| 684 GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesInfo( |
| 685 const std::string& text, int allowed, int blocked) { // TODO add icon id |
| 686 // Create first party cookies line |
| 687 // TODO |
| 688 GtkWidget* label = theme_service_->BuildLabel(text, ui::kGdkBlack); |
| 689 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 690 // PangoAttrList* attributes = pango_attr_list_new(); |
| 691 // pango_attr_list_insert(attributes, |
| 692 // pango_attr_weight_new(PANGO_WEIGHT_BOLD)); |
| 693 // gtk_label_set_attributes(GTK_LABEL(first_party_cookie_label), attributes); |
| 694 // pango_attr_list_unref(attributes); |
| 695 gtk_util::SetLabelWidth(label, 200); |
| 696 // Allow linebreaking in the middle of words if necessary, so that extremely |
| 697 // long hostnames (longer than one line) will still be completely shown. |
| 698 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); |
| 699 |
| 700 std::string allowed_count = base::IntToString(allowed); |
| 701 std::string blocked_count = base::IntToString(blocked); |
| 702 std::string info_str = " (" + allowed_count + " allowed / " + blocked_count +
" blocked)"; |
| 703 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack); |
| 704 gtk_label_set_selectable(GTK_LABEL(info), TRUE); |
| 705 gtk_util::SetLabelWidth(info, 200); |
| 706 |
| 707 |
| 708 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| 709 // TODO add icon |
| 710 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
| 711 gtk_box_pack_start(GTK_BOX(hbox), info, FALSE, FALSE, 0); |
| 712 |
| 713 return hbox; |
| 714 } |
| 715 |
| 716 GtkWidget* WebsiteSettingsPopupGtk::CreateCookiesDetails() { |
| 717 GtkWidget* content_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); |
| 718 |
| 719 CookieInfoList cookie_info_list; |
| 720 website_settings_.GetCookieInfos(&cookie_info_list); |
| 721 for (CookieInfoList::const_iterator it = cookie_info_list.begin(); |
| 722 it != cookie_info_list.end(); |
| 723 ++it) { |
| 724 gtk_box_pack_start(GTK_BOX(content_vbox), |
| 725 CreateCookiesInfo(it->text, it->allowed, it->blocked), |
| 726 FALSE, FALSE, 0); |
| 727 } |
| 728 |
| 729 // Create Link line |
| 730 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton( |
| 731 "Show cookies"); |
| 732 g_signal_connect(view_cookies_link, "clicked", |
| 733 G_CALLBACK(OnCookiesLinkClickedThunk), this); |
| 734 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); |
| 735 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link, |
| 736 FALSE, FALSE, 0); |
| 737 //GtkWidget* show_cookie_settings_link = theme_service_->BuildChromeLinkButton
( |
| 738 // "Manage cookie settings"); |
| 739 //g_signal_connect(show_cookie_settings_link, "clicked", |
| 740 // G_CALLBACK(OnCookieSettingsLinkClickedThunk), this); |
| 741 |
| 742 //gtk_box_pack_start(GTK_BOX(hbox), show_cookie_settings_link, |
| 743 // FALSE, FALSE, 0); |
| 744 |
| 745 gtk_box_pack_start(GTK_BOX(content_vbox), link_hbox, FALSE, FALSE, 0); |
| 746 |
| 747 return content_vbox; |
| 748 } |
| 749 |
| 750 void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) { |
| 751 ShowCertificateViewerByID(GTK_WINDOW(parent_), cert_id_); |
| 752 bubble_->Close(); |
| 753 } |
| 754 |
| 755 void WebsiteSettingsPopupGtk::OnHelpLinkClicked(GtkWidget* widget) { |
| 756 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 757 browser->OpenURL(OpenURLParams( |
| 758 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
| 759 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
| 760 bubble_->Close(); |
| 761 } |
| 762 |
| 763 |
| 764 void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) { |
| 765 new CollectedCookiesGtk(GTK_WINDOW(parent_), |
| 766 tab_contents_wrapper_); |
| 767 bubble_->Close(); |
| 768 } |
| 769 |
| 770 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(GtkWidget* widget
) { |
| 771 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 772 browser->OpenURL(OpenURLParams( |
| 773 GURL(std::string( |
| 774 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage), |
| 775 content::Referrer(), |
| 776 NEW_FOREGROUND_TAB, |
| 777 content::PAGE_TRANSITION_LINK, |
| 778 false)); |
| 779 bubble_->Close(); |
| 780 } |
| 781 |
| 782 void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) { |
| 783 LOG(ERROR) << " *** OnPermissionChanged"; |
| 784 } |
| 785 |
| 786 } // namespace |
| 787 |
| 788 // static |
| 789 void WebsiteSettingsPopup::Show(gfx::NativeWindow parent, |
| 790 Profile* profile, |
| 791 TabContentsWrapper* tab_contents_wrapper, |
| 792 const GURL& url, |
| 793 const content::SSLStatus& ssl, |
| 794 bool show_history) { |
| 795 new WebsiteSettingsPopupGtk(parent, profile, tab_contents_wrapper, url, ssl, |
| 796 show_history); |
| 797 } |
| 798 |
| 799 WebsiteSettingsPopup::WebsiteSettingsPopup() {} |
| 800 WebsiteSettingsPopup::~WebsiteSettingsPopup() {} |
OLD | NEW |