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

Side by Side Diff: chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.cc

Issue 10827374: (GTK only) Add icons to the "Permissions" tab of the Website Settings UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add explicit PermissionSelector dtor. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" 5 #include "chrome/browser/ui/gtk/website_settings/website_settings_popup_gtk.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/certificate_viewer.h" 10 #include "chrome/browser/certificate_viewer.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" 13 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
14 #include "chrome/browser/ui/gtk/browser_window_gtk.h" 14 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
15 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h" 15 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" 16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
17 #include "chrome/browser/ui/gtk/gtk_util.h" 17 #include "chrome/browser/ui/gtk/gtk_util.h"
18 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 18 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
19 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" 19 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
20 #include "chrome/browser/ui/gtk/website_settings/permission_selector.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents.h"
21 #include "chrome/browser/ui/website_settings/website_settings.h" 22 #include "chrome/browser/ui/website_settings/website_settings.h"
22 #include "chrome/browser/ui/website_settings/website_settings_utils.h" 23 #include "chrome/browser/ui/website_settings/website_settings_utils.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "content/public/browser/cert_store.h" 25 #include "content/public/browser/cert_store.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 #include "grit/locale_settings.h" 29 #include "grit/locale_settings.h"
29 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
30 #include "ui/base/gtk/gtk_hig_constants.h" 31 #include "ui/base/gtk/gtk_hig_constants.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
33 34
34 using content::OpenURLParams; 35 using content::OpenURLParams;
35 36
36 namespace { 37 namespace {
37 38
38 // The background color of the tabs if a theme other than the native GTK theme 39 // The background color of the tabs if a theme other than the native GTK theme
39 // is selected. 40 // is selected.
40 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); 41 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff);
41 42
43 GtkWidget* CreateTextLabel(const std::string& text,
44 int width,
45 GtkThemeService* theme_service) {
46 GtkWidget* label = theme_service->BuildLabel(text, ui::kGdkBlack);
47 if (width > 0)
48 gtk_util::SetLabelWidth(label, width);
49 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
50 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
51 return label;
52 }
53
42 class InternalPageInfoPopupGtk : public BubbleDelegateGtk { 54 class InternalPageInfoPopupGtk : public BubbleDelegateGtk {
43 public: 55 public:
44 explicit InternalPageInfoPopupGtk(gfx::NativeWindow parent, 56 explicit InternalPageInfoPopupGtk(gfx::NativeWindow parent,
45 Profile* profile); 57 Profile* profile);
46 virtual ~InternalPageInfoPopupGtk(); 58 virtual ~InternalPageInfoPopupGtk();
47 59
48 private: 60 private:
49 // BubbleDelegateGtk implementation. 61 // BubbleDelegateGtk implementation.
50 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; 62 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE;
51 63
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0); 295 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0);
284 296
285 gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0); 297 gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0);
286 298
287 // Add section content 299 // Add section content
288 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0); 300 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0);
289 return section_box; 301 return section_box;
290 302
291 } 303 }
292 304
305 void WebsiteSettingsPopupGtk::OnPermissionChanged(
306 PermissionSelector* selector) {
307 presenter_->OnSitePermissionChanged(selector->type(),
308 selector->setting());
309 }
310
311 void WebsiteSettingsPopupGtk::OnComboboxShown() {
312 bubble_->HandlePointerAndKeyboardUngrabbedByContent();
313 }
314
293 void WebsiteSettingsPopupGtk::SetCookieInfo( 315 void WebsiteSettingsPopupGtk::SetCookieInfo(
294 const CookieInfoList& cookie_info_list) { 316 const CookieInfoList& cookie_info_list) {
295 DCHECK(cookies_section_contents_); 317 DCHECK(cookies_section_contents_);
296 ClearContainer(cookies_section_contents_); 318 ClearContainer(cookies_section_contents_);
297 319
298 // Create cookies info rows. 320 // Create cookies info rows.
299 for (CookieInfoList::const_iterator it = cookie_info_list.begin(); 321 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
300 it != cookie_info_list.end(); 322 it != cookie_info_list.end();
301 ++it) { 323 ++it) {
324 // Create the cookies info box.
302 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0); 325 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0);
303 GtkWidget* label = CreateTextLabel(it->cookie_source, 200);
304 gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0);
305 326
306 std::string allowed_count = base::IntToString(it->allowed); 327 // Add the icon to the cookies info box
307 std::string blocked_count = base::IntToString(it->blocked); 328 GdkPixbuf* pixbuf = WebsiteSettingsUI::GetPermissionIcon(
308 // TODO(markusheintz): Add a localized label here once we decided how this 329 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW).ToGdkPixbuf();
309 // information should be displayed. 330 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
310 std::string info_str = " (" + allowed_count + " allowed / " 331 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
311 + blocked_count + " blocked)"; 332 gtk_box_pack_start(GTK_BOX(cookies_info), image, FALSE, FALSE, 0);
333
334 // Add the allowed and blocked cookies counts to the cookies info box.
335 std::string info_str = l10n_util::GetStringFUTF8(
336 IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE,
337 UTF8ToUTF16(it->cookie_source),
338 base::IntToString16(it->allowed),
339 base::IntToString16(it->blocked));
312 340
313 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack); 341 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
314 gtk_label_set_selectable(GTK_LABEL(info), TRUE); 342 gtk_label_set_selectable(GTK_LABEL(info), TRUE);
315 gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0); 343 const int kPadding = 4;
344 gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, kPadding);
316 345
346 // Add the cookies info box to the section box.
317 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), 347 gtk_box_pack_start(GTK_BOX(cookies_section_contents_),
318 cookies_info, 348 cookies_info,
319 FALSE, FALSE, 0); 349 FALSE, FALSE, 0);
320 } 350 }
321 351
322 // Create row with links for cookie settings and for the cookies dialog. 352 // Create row with links for cookie settings and for the cookies dialog.
323 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); 353 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
324 354
325 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton( 355 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton(
326 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA)); 356 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA));
327 g_signal_connect(view_cookies_link, "clicked", 357 g_signal_connect(view_cookies_link, "clicked",
328 G_CALLBACK(OnCookiesLinkClickedThunk), this); 358 G_CALLBACK(OnCookiesLinkClickedThunk), this);
329 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link, 359 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
330 FALSE, FALSE, 0); 360 FALSE, FALSE, 0);
331 361
332 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox, 362 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox,
333 TRUE, FALSE, 0); 363 TRUE, FALSE, 0);
334 364
335 gtk_widget_show_all(cookies_section_contents_); 365 gtk_widget_show_all(cookies_section_contents_);
336 } 366 }
337 367
338 GtkWidget* WebsiteSettingsPopupGtk::CreateTextLabel(const std::string& text,
339 int width) {
340 GtkWidget* label = theme_service_->BuildLabel(text, ui::kGdkBlack);
341 gtk_util::SetLabelWidth(label, width);
342 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
343 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
344 return label;
345 }
346
347 void WebsiteSettingsPopupGtk::SetIdentityInfo( 368 void WebsiteSettingsPopupGtk::SetIdentityInfo(
348 const IdentityInfo& identity_info) { 369 const IdentityInfo& identity_info) {
349 // Create popup header. 370 // Create popup header.
350 DCHECK(header_box_); 371 DCHECK(header_box_);
351 ClearContainer(header_box_); 372 ClearContainer(header_box_);
352 373
353 GtkWidget* identity_label = theme_service_->BuildLabel( 374 GtkWidget* identity_label = theme_service_->BuildLabel(
354 identity_info.site_identity, ui::kGdkBlack); 375 identity_info.site_identity, ui::kGdkBlack);
355 gtk_label_set_selectable(GTK_LABEL(identity_label), TRUE); 376 gtk_label_set_selectable(GTK_LABEL(identity_label), TRUE);
356 PangoAttrList* attributes = pango_attr_list_new(); 377 PangoAttrList* attributes = pango_attr_list_new();
(...skipping 10 matching lines...) Expand all
367 case WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT: 388 case WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT:
368 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT: 389 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
369 identity_status_text = 390 identity_status_text =
370 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED); 391 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED);
371 break; 392 break;
372 default: 393 default:
373 identity_status_text = 394 identity_status_text =
374 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED); 395 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED);
375 break; 396 break;
376 } 397 }
377 GtkWidget* status_label = CreateTextLabel(identity_status_text, 400); 398 GtkWidget* status_label =
399 CreateTextLabel(identity_status_text, 400, theme_service_);
378 gtk_box_pack_start( 400 gtk_box_pack_start(
379 GTK_BOX(header_box_), status_label, FALSE, FALSE, 0); 401 GTK_BOX(header_box_), status_label, FALSE, FALSE, 0);
380 gtk_widget_show_all(header_box_); 402 gtk_widget_show_all(header_box_);
381 403
382 // Create identity tab contents. 404 // Create identity tab contents.
383 DCHECK(identity_tab_contents_); 405 DCHECK(identity_tab_contents_);
384 ClearContainer(identity_tab_contents_); 406 ClearContainer(identity_tab_contents_);
385 407
386 // Create identity section. 408 // Create identity section.
387 GtkWidget* identity_description = 409 GtkWidget* identity_description =
388 CreateTextLabel(identity_info.identity_status_description, 300); 410 CreateTextLabel(identity_info.identity_status_description, 300,
411 theme_service_);
389 GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing); 412 GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
390 gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE, 413 gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE,
391 0); 414 0);
392 if (identity_info.cert_id) { 415 if (identity_info.cert_id) {
393 cert_id_ = identity_info.cert_id; 416 cert_id_ = identity_info.cert_id;
394 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton( 417 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton(
395 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON)); 418 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON));
396 g_signal_connect(view_cert_link, "clicked", 419 g_signal_connect(view_cert_link, "clicked",
397 G_CALLBACK(OnViewCertLinkClickedThunk), this); 420 G_CALLBACK(OnViewCertLinkClickedThunk), this);
398 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); 421 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
399 gtk_box_pack_start(GTK_BOX(link_hbox), view_cert_link, 422 gtk_box_pack_start(GTK_BOX(link_hbox), view_cert_link,
400 FALSE, FALSE, 0); 423 FALSE, FALSE, 0);
401 gtk_box_pack_start(GTK_BOX(identity_box), link_hbox, FALSE, FALSE, 0); 424 gtk_box_pack_start(GTK_BOX(identity_box), link_hbox, FALSE, FALSE, 0);
402 } 425 }
403 426
427
404 // Create connection section. 428 // Create connection section.
405 GtkWidget* connection_description = 429 GtkWidget* connection_description =
406 CreateTextLabel(identity_info.connection_status_description, 300); 430 CreateTextLabel(identity_info.connection_status_description, 300,
431 theme_service_);
407 GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing); 432 GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
408 gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE, 433 gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE,
409 FALSE, 0); 434 FALSE, 0);
410 435
411 // Add to contents. 436 // Add to contents.
412 gtk_box_pack_start( 437 gtk_box_pack_start(
413 GTK_BOX(identity_tab_contents_), CreateSection( 438 GTK_BOX(identity_tab_contents_), CreateSection(
414 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_IDENTITY), 439 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_IDENTITY),
415 identity_box), 440 identity_box),
416 TRUE, 441 TRUE,
(...skipping 12 matching lines...) Expand all
429 FALSE, 454 FALSE,
430 0); 455 0);
431 456
432 gtk_widget_show_all(identity_tab_contents_); 457 gtk_widget_show_all(identity_tab_contents_);
433 } 458 }
434 459
435 void WebsiteSettingsPopupGtk::SetFirstVisit(const string16& first_visit) { 460 void WebsiteSettingsPopupGtk::SetFirstVisit(const string16& first_visit) {
436 DCHECK(first_visit_contents_); 461 DCHECK(first_visit_contents_);
437 ClearContainer(first_visit_contents_); 462 ClearContainer(first_visit_contents_);
438 463
439 GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400); 464 GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400,
465 theme_service_);
440 gtk_box_pack_start( 466 gtk_box_pack_start(
441 GTK_BOX(first_visit_contents_), first_visit_label, FALSE, FALSE, 0); 467 GTK_BOX(first_visit_contents_), first_visit_label, FALSE, FALSE, 0);
442 gtk_widget_show_all(first_visit_contents_); 468 gtk_widget_show_all(first_visit_contents_);
443 } 469 }
444 470
445 void WebsiteSettingsPopupGtk::SetPermissionInfo( 471 void WebsiteSettingsPopupGtk::SetPermissionInfo(
446 const PermissionInfoList& permission_info_list) { 472 const PermissionInfoList& permission_info_list) {
447 DCHECK(permissions_section_contents_); 473 DCHECK(permissions_section_contents_);
448 ClearContainer(permissions_section_contents_); 474 ClearContainer(permissions_section_contents_);
475 // Clear the map since the UI is reconstructed.
476 selectors_.clear();
449 477
450 for (PermissionInfoList::const_iterator permission = 478 for (PermissionInfoList::const_iterator permission =
451 permission_info_list.begin(); 479 permission_info_list.begin();
452 permission != permission_info_list.end(); 480 permission != permission_info_list.end();
453 ++permission) { 481 ++permission) {
454 // Add a label for the permission type. 482 PermissionSelector* selector =
455 GtkWidget* label = CreateTextLabel(UTF16ToUTF8( 483 new PermissionSelector(
456 WebsiteSettingsUI::PermissionTypeToUIString(permission->type)), 250); 484 theme_service_,
457 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); 485 permission->type,
458 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 486 permission->setting,
459 487 permission->default_setting);
460 GtkListStore* store = 488 selector->AddObserver(this);
461 gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); 489 GtkWidget* hbox = selector->CreateUI();
462 GtkTreeIter iter; 490 selectors_.push_back(selector);
463 // Add option for permission "Global Default" to the combobox model.
464 std::string setting_str;
465 switch (permission->default_setting) {
466 case CONTENT_SETTING_ALLOW:
467 setting_str = l10n_util::GetStringUTF8(
468 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW);
469 break;
470 case CONTENT_SETTING_BLOCK:
471 setting_str = l10n_util::GetStringUTF8(
472 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK);
473 break;
474 case CONTENT_SETTING_ASK:
475 setting_str = l10n_util::GetStringUTF8(
476 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK);
477 break;
478 default:
479 break;
480 }
481 gtk_list_store_append(store, &iter);
482 gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
483 CONTENT_SETTING_DEFAULT, 2, permission->type, -1);
484 GtkWidget* combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
485 // Add option for permission "Allow" to the combobox model.
486 setting_str = l10n_util::GetStringUTF8(
487 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW);
488 gtk_list_store_append(store, &iter);
489 gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
490 CONTENT_SETTING_ALLOW, 2, permission->type, -1);
491 // The content settings type fullscreen does not support the concept of
492 // blocking.
493 if (permission->type != CONTENT_SETTINGS_TYPE_FULLSCREEN) {
494 // Add option for permission "BLOCK" to the combobox model.
495 setting_str = l10n_util::GetStringUTF8(
496 IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK);
497 gtk_list_store_append(store, &iter);
498 gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
499 CONTENT_SETTING_BLOCK, 2, permission->type, -1);
500 }
501 // Remove reference to the store to prevent leaking.
502 g_object_unref(G_OBJECT(store));
503
504 GtkCellRenderer* cell = gtk_cell_renderer_text_new();
505 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), cell, TRUE );
506 gtk_cell_layout_set_attributes(
507 GTK_CELL_LAYOUT(combo_box), cell, "text", 0, NULL);
508
509 // Select the combobox entry for the currently configured permission value.
510 int active = -1;
511 switch (permission->setting) {
512 case CONTENT_SETTING_DEFAULT: active = 0;
513 break;
514 case CONTENT_SETTING_ALLOW: active = 1;
515 break;
516 case CONTENT_SETTING_BLOCK: active = 2;
517 break;
518 default:
519 NOTREACHED() << "Bad content setting:" << permission->setting;
520 break;
521 }
522 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), active);
523
524 // Add change listener to the combobox.
525 g_signal_connect(combo_box, "changed",
526 G_CALLBACK(OnPermissionChangedThunk), this);
527 // Once the popup (window) for a combobox is shown, the bubble container
528 // (window) loses it's focus. Therefore it necessary to reset the focus to
529 // the bubble container after the combobox popup is closed.
530 g_signal_connect(combo_box, "notify::popup-shown",
531 G_CALLBACK(OnComboBoxShownThunk), this);
532 gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0);
533
534 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), hbox, FALSE, 491 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), hbox, FALSE,
535 FALSE, 0); 492 FALSE, 0);
536 } 493 }
537 494
538 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton( 495 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton(
539 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_PERMISSION_SETTINGS)); 496 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_PERMISSION_SETTINGS));
540 g_signal_connect(show_content_settings_link, "clicked", 497 g_signal_connect(show_content_settings_link, "clicked",
541 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this); 498 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this);
542 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0); 499 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
543 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link, 500 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link,
544 FALSE, FALSE, 0); 501 FALSE, FALSE, 0);
545 502
546 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), link_hbox, 503 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), link_hbox,
547 FALSE, FALSE, 0); 504 FALSE, FALSE, 0);
548 505
549 gtk_widget_show_all(permissions_section_contents_); 506 gtk_widget_show_all(permissions_section_contents_);
550 } 507 }
551 508
552 void WebsiteSettingsPopupGtk::OnComboBoxShown(GtkWidget* widget,
553 GParamSpec* property) {
554 // GtkComboBox grabs the keyboard and pointer when it displays its popup,
555 // which steals the grabs that BubbleGtk had installed. When the popup is
556 // hidden, we notify BubbleGtk so it can try to reacquire the grabs
557 // (otherwise, GTK won't activate our widgets when the user clicks in them).
558 gboolean popup_shown = FALSE;
559 g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown,
560 NULL);
561 if (!popup_shown)
562 bubble_->HandlePointerAndKeyboardUngrabbedByContent();
563 }
564
565 void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) { 509 void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) {
566 new CollectedCookiesGtk(GTK_WINDOW(parent_), 510 new CollectedCookiesGtk(GTK_WINDOW(parent_),
567 tab_contents_); 511 tab_contents_);
568 bubble_->Close(); 512 bubble_->Close();
569 } 513 }
570 514
571 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked( 515 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(
572 GtkWidget* widget) { 516 GtkWidget* widget) {
573 browser_->OpenURL(OpenURLParams( 517 browser_->OpenURL(OpenURLParams(
574 GURL(std::string( 518 GURL(std::string(
575 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage), 519 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
576 content::Referrer(), 520 content::Referrer(),
577 NEW_FOREGROUND_TAB, 521 NEW_FOREGROUND_TAB,
578 content::PAGE_TRANSITION_LINK, 522 content::PAGE_TRANSITION_LINK,
579 false)); 523 false));
580 bubble_->Close(); 524 bubble_->Close();
581 } 525 }
582 526
583 void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) {
584 GtkTreeIter it;
585 bool has_active = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &it);
586 DCHECK(has_active);
587 GtkTreeModel* store =
588 GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)));
589
590 int value = -1;
591 int type = -1;
592 gtk_tree_model_get(store, &it, 1, &value, 2, &type, -1);
593
594 if (presenter_.get())
595 presenter_->OnSitePermissionChanged(ContentSettingsType(type),
596 ContentSetting(value));
597 }
598
599 void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) { 527 void WebsiteSettingsPopupGtk::OnViewCertLinkClicked(GtkWidget* widget) {
600 DCHECK_NE(cert_id_, 0); 528 DCHECK_NE(cert_id_, 0);
601 ShowCertificateViewerByID( 529 ShowCertificateViewerByID(
602 tab_contents_->web_contents(), GTK_WINDOW(parent_), cert_id_); 530 tab_contents_->web_contents(), GTK_WINDOW(parent_), cert_id_);
603 bubble_->Close(); 531 bubble_->Close();
604 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698