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

Side by Side Diff: chrome/browser/ui/gtk/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
(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/gtk/website_settings_popup_gtk.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/certificate_viewer.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
14 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
15 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
17 #include "chrome/browser/ui/gtk/gtk_util.h"
18 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
19 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
20 #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_utils.h"
23 #include "chrome/common/url_constants.h"
24 #include "content/public/browser/cert_store.h"
25 #include "googleurl/src/gurl.h"
26 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h"
28 #include "grit/locale_settings.h"
29 #include "grit/theme_resources.h"
30 #include "ui/base/gtk/gtk_hig_constants.h"
31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h"
33
34 using content::OpenURLParams;
35
36 namespace {
37
38 // The background color of the tabs if a theme other than the native GTK theme
39 // is selected.
40 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff);
41
42 class InternalPageInfoPopupGtk : public BubbleDelegateGtk {
43 public:
44 explicit InternalPageInfoPopupGtk(gfx::NativeWindow parent,
45 Profile* profile);
46 virtual ~InternalPageInfoPopupGtk();
47
48 private:
49 // BubbleDelegateGtk implementation.
50 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE;
51
52 // The popup bubble container.
53 BubbleGtk* bubble_;
54
55 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupGtk);
56 };
57
58 InternalPageInfoPopupGtk::InternalPageInfoPopupGtk(
59 gfx::NativeWindow parent, Profile* profile) {
60 GtkWidget* contents = gtk_hbox_new(FALSE, ui::kContentAreaSpacing);
61 gtk_container_set_border_width(GTK_CONTAINER(contents),
62 ui::kContentAreaBorder);
63 // Add the popup icon.
64 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
65 GdkPixbuf* pixbuf = rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_26).ToGdkPixbuf();
66 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
67 gtk_box_pack_start(GTK_BOX(contents), image, FALSE, FALSE, 0);
68 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
69
70 // Add the popup text.
71 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile);
72 GtkWidget* label = theme_service->BuildLabel(
73 l10n_util::GetStringUTF8(IDS_PAGE_INFO_INTERNAL_PAGE), ui::kGdkBlack);
74 gtk_label_set_selectable(GTK_LABEL(label), FALSE);
75 PangoAttrList* attributes = pango_attr_list_new();
76 pango_attr_list_insert(attributes,
77 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
78 gtk_box_pack_start(GTK_BOX(contents), label, FALSE, FALSE, 0);
79
80 gtk_widget_show_all(contents);
81
82 // Create the bubble.
83 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
84 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
85 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
86 BrowserWindowGtk* browser_window =
87 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
88 GtkWidget* anchor = browser_window->
89 GetToolbar()->GetLocationBarView()->location_icon_widget();
90 bubble_ = BubbleGtk::Show(anchor,
91 NULL, // |rect|
92 contents,
93 arrow_location,
94 BubbleGtk::MATCH_SYSTEM_THEME |
95 BubbleGtk::POPUP_WINDOW |
96 BubbleGtk::GRAB_INPUT,
97 theme_service,
98 this); // |delegate|
99 DCHECK(bubble_);
100 }
101
102 InternalPageInfoPopupGtk::~InternalPageInfoPopupGtk() {
103 }
104
105 void InternalPageInfoPopupGtk::BubbleClosing(BubbleGtk* bubble,
106 bool closed_by_escape) {
107 delete this;
108 }
109
110 } // namespace
111
112 // static
113 void WebsiteSettingsPopupGtk::Show(gfx::NativeWindow parent,
114 Profile* profile,
115 TabContents* tab_contents,
116 const GURL& url,
117 const content::SSLStatus& ssl) {
118 if (InternalChromePage(url))
119 new InternalPageInfoPopupGtk(parent, profile);
120 else
121 new WebsiteSettingsPopupGtk(parent, profile, tab_contents, url, ssl);
122 }
123
124 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk(
125 gfx::NativeWindow parent,
126 Profile* profile,
127 TabContents* tab_contents,
128 const GURL& url,
129 const content::SSLStatus& ssl)
130 : parent_(parent),
131 contents_(NULL),
132 theme_service_(GtkThemeService::GetFrom(profile)),
133 profile_(profile),
134 tab_contents_(tab_contents),
135 browser_(NULL),
136 cert_id_(0),
137 header_box_(NULL),
138 cookies_section_contents_(NULL),
139 permissions_section_contents_(NULL),
140 identity_tab_contents_(NULL),
141 first_visit_contents_(NULL),
142 presenter_(NULL) {
143 BrowserWindowGtk* browser_window =
144 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
145 browser_ = browser_window->browser();
146 anchor_ = browser_window->
147 GetToolbar()->GetLocationBarView()->location_icon_widget();
148
149 InitContents();
150
151 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
152 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
153 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
154 bubble_ = BubbleGtk::Show(anchor_,
155 NULL, // |rect|
156 contents_,
157 arrow_location,
158 BubbleGtk::MATCH_SYSTEM_THEME |
159 BubbleGtk::POPUP_WINDOW |
160 BubbleGtk::GRAB_INPUT,
161 theme_service_,
162 this); // |delegate|
163 if (!bubble_) {
164 NOTREACHED();
165 return;
166 }
167
168 presenter_.reset(new WebsiteSettings(this, profile,
169 tab_contents->content_settings(),
170 tab_contents->infobar_tab_helper(),
171 url, ssl,
172 content::CertStore::GetInstance()));
173 }
174
175 WebsiteSettingsPopupGtk::~WebsiteSettingsPopupGtk() {
176 }
177
178 void WebsiteSettingsPopupGtk::BubbleClosing(BubbleGtk* bubble,
179 bool closed_by_escape) {
180 if (presenter_.get()) {
181 presenter_->OnUIClosing();
182 presenter_.reset();
183 }
184 delete this;
185 }
186
187 void WebsiteSettingsPopupGtk::InitContents() {
188 if (!contents_) {
189 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
190 gtk_container_set_border_width(GTK_CONTAINER(contents_),
191 ui::kContentAreaBorder);
192 } else {
193 gtk_util::RemoveAllChildren(contents_);
194 }
195
196 // Create popup header.
197 header_box_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
198 gtk_box_pack_start(GTK_BOX(contents_), header_box_, FALSE, FALSE, 0);
199
200 // Create the container for the contents of the permissions tab.
201 GtkWidget* permission_tab_contents = gtk_vbox_new(FALSE, ui::kControlSpacing);
202 gtk_container_set_border_width(GTK_CONTAINER(permission_tab_contents), 10);
203 cookies_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
204 std::string title = l10n_util::GetStringUTF8(
205 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA);
206 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
207 CreateSection(title,
208 cookies_section_contents_),
209 FALSE, FALSE, 0);
210 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
211 gtk_hseparator_new(),
212 FALSE, FALSE, 0);
213 permissions_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
214 title = l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
215 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
216 CreateSection(title,
217 permissions_section_contents_),
218 FALSE, FALSE, 0);
219
220 // Create the container for the contents of the identity tab.
221 GtkWidget* info_tab = gtk_vbox_new(FALSE, ui::kControlSpacing);
222 identity_tab_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
223 gtk_container_set_border_width(GTK_CONTAINER(identity_tab_contents_), 10);
224 gtk_box_pack_start(GTK_BOX(info_tab),
225 identity_tab_contents_,
226 FALSE, FALSE, 0);
227 first_visit_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
228 GtkWidget* history_contents = CreateSection(
229 l10n_util::GetStringUTF8(IDS_PAGE_INFO_SITE_INFO_TITLE),
230 first_visit_contents_);
231 gtk_container_set_border_width(GTK_CONTAINER(history_contents), 10);
232 gtk_box_pack_start(GTK_BOX(info_tab), gtk_hseparator_new(), FALSE, FALSE, 0);
233 gtk_box_pack_start(GTK_BOX(info_tab), history_contents, FALSE, FALSE, 0);
234
235 // Create tab container and add all tabs.
236 GtkWidget* notebook = gtk_notebook_new();
237 if (theme_service_->UsingNativeTheme())
238 gtk_widget_modify_bg(notebook, GTK_STATE_NORMAL, NULL);
239 else
240 gtk_widget_modify_bg(notebook, GTK_STATE_NORMAL, &kBackgroundColor);
241
242 GtkWidget* label = theme_service_->BuildLabel(
243 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
244 ui::kGdkBlack);
245 gtk_widget_show(label);
246 gtk_notebook_append_page(
247 GTK_NOTEBOOK(notebook), permission_tab_contents, label);
248
249 label = theme_service_->BuildLabel(
250 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION),
251 ui::kGdkBlack);
252 gtk_widget_show(label);
253 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), info_tab, label);
254
255 gtk_box_pack_start(GTK_BOX(contents_), notebook, FALSE, FALSE, 0);
256 gtk_widget_show_all(contents_);
257 }
258
259 void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) {
260 GList* child = gtk_container_get_children(GTK_CONTAINER(container));
261 while (child) {
262 gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data));
263 child = child->next;
264 }
265 }
266
267 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title,
268 GtkWidget* section_content) {
269 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
270
271 // Add Section title
272 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
273
274 GtkWidget* label = theme_service_->BuildLabel(section_title,
275 ui::kGdkBlack);
276 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
277 PangoAttrList* attributes = pango_attr_list_new();
278 pango_attr_list_insert(attributes,
279 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
280 gtk_label_set_attributes(GTK_LABEL(label), attributes);
281 pango_attr_list_unref(attributes);
282 gtk_util::SetLabelWidth(label, 400);
283 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0);
284
285 gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0);
286
287 // Add section content
288 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0);
289 return section_box;
290
291 }
292
293 void WebsiteSettingsPopupGtk::SetCookieInfo(
294 const CookieInfoList& cookie_info_list) {
295 DCHECK(cookies_section_contents_);
296 ClearContainer(cookies_section_contents_);
297
298 // Create cookies info rows.
299 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
300 it != cookie_info_list.end();
301 ++it) {
302 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
306 std::string allowed_count = base::IntToString(it->allowed);
307 std::string blocked_count = base::IntToString(it->blocked);
308 // TODO(markusheintz): Add a localized label here once we decided how this
309 // information should be displayed.
310 std::string info_str = " (" + allowed_count + " allowed / "
311 + blocked_count + " blocked)";
312
313 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
314 gtk_label_set_selectable(GTK_LABEL(info), TRUE);
315 gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0);
316
317 gtk_box_pack_start(GTK_BOX(cookies_section_contents_),
318 cookies_info,
319 FALSE, FALSE, 0);
320 }
321
322 // Create row with links for cookie settings and for the cookies dialog.
323 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
324
325 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton(
326 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA));
327 g_signal_connect(view_cookies_link, "clicked",
328 G_CALLBACK(OnCookiesLinkClickedThunk), this);
329 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
330 FALSE, FALSE, 0);
331
332 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox,
333 TRUE, FALSE, 0);
334
335 gtk_widget_show_all(cookies_section_contents_);
336 }
337
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(
348 const IdentityInfo& identity_info) {
349 // Create popup header.
350 DCHECK(header_box_);
351 ClearContainer(header_box_);
352
353 GtkWidget* identity_label = theme_service_->BuildLabel(
354 identity_info.site_identity, ui::kGdkBlack);
355 gtk_label_set_selectable(GTK_LABEL(identity_label), TRUE);
356 PangoAttrList* attributes = pango_attr_list_new();
357 pango_attr_list_insert(attributes,
358 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
359 gtk_label_set_attributes(GTK_LABEL(identity_label), attributes);
360 pango_attr_list_unref(attributes);
361 gtk_util::SetLabelWidth(identity_label, 400);
362 gtk_box_pack_start(GTK_BOX(header_box_), identity_label, FALSE, FALSE, 0);
363
364 std::string identity_status_text;
365 switch (identity_info.identity_status) {
366 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
367 case WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT:
368 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
369 identity_status_text =
370 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED);
371 break;
372 default:
373 identity_status_text =
374 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED);
375 break;
376 }
377 GtkWidget* status_label = CreateTextLabel(identity_status_text, 400);
378 gtk_box_pack_start(
379 GTK_BOX(header_box_), status_label, FALSE, FALSE, 0);
380 gtk_widget_show_all(header_box_);
381
382 // Create identity tab contents.
383 DCHECK(identity_tab_contents_);
384 ClearContainer(identity_tab_contents_);
385
386 // Create identity section.
387 GtkWidget* identity_description =
388 CreateTextLabel(identity_info.identity_status_description, 300);
389 GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
390 gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE,
391 0);
392 if (identity_info.cert_id) {
393 cert_id_ = identity_info.cert_id;
394 GtkWidget* view_cert_link = theme_service_->BuildChromeLinkButton(
395 l10n_util::GetStringUTF8(IDS_PAGEINFO_CERT_INFO_BUTTON));
396 g_signal_connect(view_cert_link, "clicked",
397 G_CALLBACK(OnViewCertLinkClickedThunk), this);
398 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
399 gtk_box_pack_start(GTK_BOX(link_hbox), view_cert_link,
400 FALSE, FALSE, 0);
401 gtk_box_pack_start(GTK_BOX(identity_box), link_hbox, FALSE, FALSE, 0);
402 }
403
404 // Create connection section.
405 GtkWidget* connection_description =
406 CreateTextLabel(identity_info.connection_status_description, 300);
407 GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
408 gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE,
409 FALSE, 0);
410
411 // Add to contents.
412 gtk_box_pack_start(
413 GTK_BOX(identity_tab_contents_), CreateSection(
414 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_IDENTITY),
415 identity_box),
416 TRUE,
417 FALSE,
418 0);
419 gtk_box_pack_start(GTK_BOX(identity_tab_contents_),
420 gtk_hseparator_new(),
421 FALSE, FALSE, 0);
422 gtk_box_pack_start(
423 GTK_BOX(identity_tab_contents_),
424 CreateSection(
425 l10n_util::GetStringUTF8(
426 IDS_WEBSITE_SETTINGS_TITLE_CONNECTION),
427 connection_box),
428 TRUE,
429 FALSE,
430 0);
431
432 gtk_widget_show_all(identity_tab_contents_);
433 }
434
435 void WebsiteSettingsPopupGtk::SetFirstVisit(const string16& first_visit) {
436 DCHECK(first_visit_contents_);
437 ClearContainer(first_visit_contents_);
438
439 GtkWidget* first_visit_label = CreateTextLabel(UTF16ToUTF8(first_visit), 400);
440 gtk_box_pack_start(
441 GTK_BOX(first_visit_contents_), first_visit_label, FALSE, FALSE, 0);
442 gtk_widget_show_all(first_visit_contents_);
443 }
444
445 void WebsiteSettingsPopupGtk::SetPermissionInfo(
446 const PermissionInfoList& permission_info_list) {
447 DCHECK(permissions_section_contents_);
448 ClearContainer(permissions_section_contents_);
449
450 for (PermissionInfoList::const_iterator permission =
451 permission_info_list.begin();
452 permission != permission_info_list.end();
453 ++permission) {
454 // Add a label for the permission type.
455 GtkWidget* label = CreateTextLabel(UTF16ToUTF8(
456 WebsiteSettingsUI::PermissionTypeToUIString(permission->type)), 250);
457 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
458 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
459
460 GtkListStore* store =
461 gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
462 GtkTreeIter iter;
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,
535 FALSE, 0);
536 }
537
538 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton(
539 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_SHOW_PERMISSION_SETTINGS));
540 g_signal_connect(show_content_settings_link, "clicked",
541 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this);
542 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
543 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link,
544 FALSE, FALSE, 0);
545
546 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), link_hbox,
547 FALSE, FALSE, 0);
548
549 gtk_widget_show_all(permissions_section_contents_);
550 }
551
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) {
566 new CollectedCookiesGtk(GTK_WINDOW(parent_),
567 tab_contents_);
568 bubble_->Close();
569 }
570
571 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(
572 GtkWidget* widget) {
573 browser_->OpenURL(OpenURLParams(
574 GURL(std::string(
575 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
576 content::Referrer(),
577 NEW_FOREGROUND_TAB,
578 content::PAGE_TRANSITION_LINK,
579 false));
580 bubble_->Close();
581 }
582
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) {
600 DCHECK_NE(cert_id_, 0);
601 ShowCertificateViewerByID(
602 tab_contents_->web_contents(), GTK_WINDOW(parent_), cert_id_);
603 bubble_->Close();
604 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698