blob: ee12e5867b59b9d26ca1b41cbc072e8308ba4410 [file] [log] [blame]
[email protected]67e79992012-02-13 20:47:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a503c97c2010-07-16 13:05:482// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0d8b9aa2011-01-19 18:35:505#include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
[email protected]a503c97c2010-07-16 13:05:486
[email protected]ccea03c2010-12-17 03:31:507#include <string>
[email protected]3853a4c2013-02-11 17:15:578#include "base/prefs/pref_service.h"
[email protected]b0cb5e82012-07-19 19:22:479#include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
10#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
11#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
12#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
13#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
14#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
15#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
[email protected]faa022d2012-11-07 21:52:1216#include "chrome/browser/browsing_data/cookies_tree_model.h"
[email protected]b0cb5e82012-07-19 19:22:4717#include "chrome/browser/browsing_data/local_data_container.h"
[email protected]30fde822011-10-28 09:49:0518#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]b6ef09a2012-03-08 21:53:2519#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]9a611a92011-05-07 17:06:1820#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]4a8adfa02013-03-19 22:37:4621#include "chrome/browser/infobars/infobar_service.h"
[email protected]8ecad5e2010-12-02 21:18:3322#include "chrome/browser/profiles/profile.h"
[email protected]48a5cd62012-02-29 20:24:2023#include "chrome/browser/ui/browser_dialogs.h"
[email protected]87586fb72012-07-02 13:15:0224#include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
[email protected]9d4984e2011-08-24 19:16:0225#include "chrome/browser/ui/gtk/constrained_window_gtk.h"
[email protected]425328c3e2011-03-16 15:36:0026#include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h"
[email protected]0d8b9aa2011-01-19 18:35:5027#include "chrome/browser/ui/gtk/gtk_util.h"
[email protected]432115822011-07-10 15:52:2728#include "chrome/common/chrome_notification_types.h"
[email protected]30fde822011-10-28 09:49:0529#include "chrome/common/pref_names.h"
[email protected]e41d0082013-05-16 04:37:5430#include "components/web_modal/web_contents_modal_dialog_manager.h"
[email protected]6c2381d2011-10-19 02:52:5331#include "content/public/browser/notification_source.h"
[email protected]1f0b50b2012-06-22 20:37:1632#include "content/public/browser/web_contents.h"
33#include "content/public/browser/web_contents_view.h"
[email protected]a503c97c2010-07-16 13:05:4834#include "grit/generated_resources.h"
[email protected]5b9bc352012-07-18 13:13:3435#include "net/cookies/canonical_cookie.h"
[email protected]82c7bfb2011-08-29 22:08:5836#include "ui/base/gtk/gtk_hig_constants.h"
[email protected]c051a1b2011-01-21 23:30:1737#include "ui/base/l10n/l10n_util.h"
[email protected]a503c97c2010-07-16 13:05:4838
[email protected]e41d0082013-05-16 04:37:5439using web_modal::WebContentsModalDialogManager;
40
[email protected]a503c97c2010-07-16 13:05:4841namespace {
[email protected]df0f6e82010-08-20 21:35:3242// Width and height of the cookie tree view.
43const int kTreeViewWidth = 450;
[email protected]a503c97c2010-07-16 13:05:4844const int kTreeViewHeight = 150;
[email protected]df0f6e82010-08-20 21:35:3245
[email protected]425328c3e2011-03-16 15:36:0046// The page numbers of the pages in the notebook.
47const gint kAllowedPageNumber = 0;
48const gint kBlockedPageNumber = 1;
49
[email protected]df0f6e82010-08-20 21:35:3250// Padding within the banner box.
51const int kBannerPadding = 3;
52
53// Returns the text to display in the info bar when content settings were
54// created.
55const std::string GetInfobarLabel(ContentSetting setting,
56 bool multiple_domains_added,
57 const string16& domain_name) {
58 if (multiple_domains_added) {
59 switch (setting) {
60 case CONTENT_SETTING_BLOCK:
61 return l10n_util::GetStringUTF8(
62 IDS_COLLECTED_COOKIES_MULTIPLE_BLOCK_RULES_CREATED);
63
64 case CONTENT_SETTING_ALLOW:
65 return l10n_util::GetStringUTF8(
66 IDS_COLLECTED_COOKIES_MULTIPLE_ALLOW_RULES_CREATED);
67
68 case CONTENT_SETTING_SESSION_ONLY:
69 return l10n_util::GetStringUTF8(
70 IDS_COLLECTED_COOKIES_MULTIPLE_SESSION_RULES_CREATED);
71
72 default:
73 NOTREACHED();
74 return std::string();
75 }
76 }
77
78 switch (setting) {
79 case CONTENT_SETTING_BLOCK:
80 return l10n_util::GetStringFUTF8(
81 IDS_COLLECTED_COOKIES_BLOCK_RULE_CREATED, domain_name);
82
83 case CONTENT_SETTING_ALLOW:
84 return l10n_util::GetStringFUTF8(
85 IDS_COLLECTED_COOKIES_ALLOW_RULE_CREATED, domain_name);
86
87 case CONTENT_SETTING_SESSION_ONLY:
88 return l10n_util::GetStringFUTF8(
89 IDS_COLLECTED_COOKIES_SESSION_RULE_CREATED, domain_name);
90
91 default:
92 NOTREACHED();
93 return std::string();
94 }
95}
[email protected]a3627e62011-09-07 00:04:5796
[email protected]a503c97c2010-07-16 13:05:4897} // namespace
98
[email protected]87586fb72012-07-02 13:15:0299namespace chrome {
[email protected]48a5cd62012-02-29 20:24:20100
101// Declared in browser_dialogs.h so others don't have to depend on our header.
[email protected]b95f1842012-10-19 22:34:15102void ShowCollectedCookiesDialog(content::WebContents* web_contents) {
[email protected]48a5cd62012-02-29 20:24:20103 // Deletes itself on close.
[email protected]1f0b50b2012-06-22 20:37:16104 new CollectedCookiesGtk(
[email protected]b95f1842012-10-19 22:34:15105 web_contents->GetView()->GetTopLevelNativeWindow(),
106 web_contents);
[email protected]48a5cd62012-02-29 20:24:20107}
108
[email protected]87586fb72012-07-02 13:15:02109} // namespace chrome
[email protected]48a5cd62012-02-29 20:24:20110
[email protected]a503c97c2010-07-16 13:05:48111CollectedCookiesGtk::CollectedCookiesGtk(GtkWindow* parent,
[email protected]b95f1842012-10-19 22:34:15112 content::WebContents* web_contents)
113 : web_contents_(web_contents),
[email protected]78e049b2011-03-19 20:45:26114 status_changed_(false) {
[email protected]c5f51192012-09-28 04:09:50115 TabSpecificContentSettings* content_settings =
[email protected]b95f1842012-10-19 22:34:15116 TabSpecificContentSettings::FromWebContents(web_contents);
[email protected]432115822011-07-10 15:52:27117 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
[email protected]c5f51192012-09-28 04:09:50118 content::Source<TabSpecificContentSettings>(content_settings));
[email protected]a503c97c2010-07-16 13:05:48119
120 Init();
121}
122
123void CollectedCookiesGtk::Init() {
[email protected]82c7bfb2011-08-29 22:08:58124 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
125 gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing);
[email protected]723d52122013-03-15 10:45:34126 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this);
[email protected]a503c97c2010-07-16 13:05:48127
128 GtkWidget* label = gtk_label_new(
129 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_DIALOG_TITLE).c_str());
130 gtk_box_pack_start(GTK_BOX(dialog_), label, TRUE, TRUE, 0);
131
[email protected]425328c3e2011-03-16 15:36:00132 notebook_ = gtk_notebook_new();
133 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook_), GTK_POS_TOP);
134 gtk_box_pack_start(GTK_BOX(dialog_), notebook_, TRUE, TRUE, 0);
[email protected]a503c97c2010-07-16 13:05:48135
[email protected]425328c3e2011-03-16 15:36:00136 GtkWidget* allowed_pane = CreateAllowedPane();
[email protected]a503c97c2010-07-16 13:05:48137 label = gtk_label_new(
[email protected]425328c3e2011-03-16 15:36:00138 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_TAB_LABEL)
139 .c_str());
140 gtk_widget_show(label);
141 gtk_notebook_insert_page(GTK_NOTEBOOK(notebook_), allowed_pane, label,
142 kAllowedPageNumber);
143
144 GtkWidget* blocked_pane = CreateBlockedPane();
145 label = gtk_label_new(
146 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_TAB_LABEL)
147 .c_str());
148 gtk_widget_show(label);
149 gtk_notebook_insert_page(GTK_NOTEBOOK(notebook_), blocked_pane, label,
150 kBlockedPageNumber);
151 // Hook up the signal only after all pages are inserted, otherwise not
152 // all member variables used in OnSwitchPage() will be properly initialized.
153 g_signal_connect(notebook_, "switch-page", G_CALLBACK(OnSwitchPageThunk),
154 this);
155
156 // Cookie info view.
157 cookie_info_view_ = gtk_chrome_cookie_view_new(false);
158 gtk_box_pack_start(GTK_BOX(dialog_), cookie_info_view_, TRUE, TRUE, 0);
159 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_info_view_));
160 gtk_widget_show_all(cookie_info_view_);
161
162 // Infobar.
163 infobar_ = gtk_frame_new(NULL);
164 GtkWidget* infobar_contents = gtk_hbox_new(FALSE, kBannerPadding);
165 gtk_container_set_border_width(GTK_CONTAINER(infobar_contents),
166 kBannerPadding);
167 gtk_container_add(GTK_CONTAINER(infobar_), infobar_contents);
168 GtkWidget* info_image =
169 gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO,
170 GTK_ICON_SIZE_SMALL_TOOLBAR);
171 gtk_box_pack_start(GTK_BOX(infobar_contents), info_image, FALSE, FALSE, 0);
172 infobar_label_ = gtk_label_new(NULL);
173 gtk_box_pack_start(
174 GTK_BOX(infobar_contents), infobar_label_, FALSE, FALSE, 0);
175 gtk_widget_show_all(infobar_);
176 gtk_widget_set_no_show_all(infobar_, TRUE);
177 gtk_widget_hide(infobar_);
178 gtk_box_pack_start(GTK_BOX(dialog_), infobar_, TRUE, TRUE, 0);
179
180 // Close button.
181 GtkWidget* button_box = gtk_hbutton_box_new();
182 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_END);
[email protected]82c7bfb2011-08-29 22:08:58183 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00184 gtk_box_pack_end(GTK_BOX(dialog_), button_box, FALSE, TRUE, 0);
185 close_button_ = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
186 gtk_button_set_label(GTK_BUTTON(close_button_),
187 l10n_util::GetStringUTF8(IDS_CLOSE).c_str());
188 g_signal_connect(close_button_, "clicked", G_CALLBACK(OnCloseThunk), this);
189 gtk_box_pack_end(GTK_BOX(button_box), close_button_, FALSE, TRUE, 0);
190
191 // Show the dialog.
192 allowed_cookies_tree_adapter_->Init();
193 blocked_cookies_tree_adapter_->Init();
194 EnableControls();
195 ShowCookieInfo(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_)));
[email protected]85e69fa2013-03-15 21:54:49196 window_ = CreateWebContentsModalDialogGtk(dialog_, close_button_);
[email protected]37d6cba2013-03-14 23:53:22197
198 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
199 WebContentsModalDialogManager::FromWebContents(web_contents_);
200 web_contents_modal_dialog_manager->ShowDialog(window_);
[email protected]425328c3e2011-03-16 15:36:00201}
202
203GtkWidget* CollectedCookiesGtk::CreateAllowedPane() {
[email protected]82c7bfb2011-08-29 22:08:58204 GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00205
206 GtkWidget* label = gtk_label_new(
[email protected]a503c97c2010-07-16 13:05:48207 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL).
208 c_str());
209 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
[email protected]425328c3e2011-03-16 15:36:00210 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, FALSE, FALSE,
[email protected]82c7bfb2011-08-29 22:08:58211 ui::kControlSpacing);
[email protected]a503c97c2010-07-16 13:05:48212
213 GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL);
214 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window),
215 GTK_POLICY_AUTOMATIC,
216 GTK_POLICY_AUTOMATIC);
217 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window),
218 GTK_SHADOW_ETCHED_IN);
219 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0);
220
[email protected]58d30652012-06-11 19:56:34221 TabSpecificContentSettings* content_settings =
[email protected]b95f1842012-10-19 22:34:15222 TabSpecificContentSettings::FromWebContents(web_contents_);
[email protected]a503c97c2010-07-16 13:05:48223
[email protected]3ff0ff72012-08-01 17:33:51224 const LocalSharedObjectsContainer& allowed_data =
[email protected]af878c1e2012-03-06 11:23:54225 content_settings->allowed_local_shared_objects();
[email protected]3ff0ff72012-08-01 17:33:51226 allowed_cookies_tree_model_ = allowed_data.CreateCookiesTreeModel();
227
[email protected]a503c97c2010-07-16 13:05:48228 allowed_cookies_tree_adapter_.reset(
[email protected]6d90ee622010-08-18 07:42:27229 new gtk_tree::TreeAdapter(this, allowed_cookies_tree_model_.get()));
[email protected]a503c97c2010-07-16 13:05:48230 allowed_tree_ = gtk_tree_view_new_with_model(
231 GTK_TREE_MODEL(allowed_cookies_tree_adapter_->tree_store()));
[email protected]df0f6e82010-08-20 21:35:32232 gtk_widget_set_size_request(allowed_tree_, kTreeViewWidth, kTreeViewHeight);
[email protected]a503c97c2010-07-16 13:05:48233 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(allowed_tree_), FALSE);
234 gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(allowed_tree_), TRUE);
235 gtk_container_add(GTK_CONTAINER(scroll_window), allowed_tree_);
236
237 GtkTreeViewColumn* title_column = gtk_tree_view_column_new();
238 GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new();
239 gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE);
240 gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf",
[email protected]6d90ee622010-08-18 07:42:27241 gtk_tree::TreeAdapter::COL_ICON);
[email protected]a503c97c2010-07-16 13:05:48242 GtkCellRenderer* title_renderer = gtk_cell_renderer_text_new();
243 gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE);
244 gtk_tree_view_column_add_attribute(title_column, title_renderer, "text",
[email protected]6d90ee622010-08-18 07:42:27245 gtk_tree::TreeAdapter::COL_TITLE);
[email protected]a503c97c2010-07-16 13:05:48246 gtk_tree_view_column_set_title(
247 title_column, l10n_util::GetStringUTF8(
248 IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str());
249 gtk_tree_view_append_column(GTK_TREE_VIEW(allowed_tree_), title_column);
250 g_signal_connect(allowed_tree_, "row-expanded",
251 G_CALLBACK(OnTreeViewRowExpandedThunk), this);
[email protected]cf9e0782010-07-19 20:49:30252 allowed_selection_ =
253 gtk_tree_view_get_selection(GTK_TREE_VIEW(allowed_tree_));
254 gtk_tree_selection_set_mode(allowed_selection_, GTK_SELECTION_MULTIPLE);
255 g_signal_connect(allowed_selection_, "changed",
256 G_CALLBACK(OnTreeViewSelectionChangeThunk), this);
257
258 GtkWidget* button_box = gtk_hbutton_box_new();
259 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
[email protected]82c7bfb2011-08-29 22:08:58260 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00261 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), button_box, FALSE, FALSE,
[email protected]82c7bfb2011-08-29 22:08:58262 ui::kControlSpacing);
[email protected]cf9e0782010-07-19 20:49:30263 block_allowed_cookie_button_ = gtk_button_new_with_label(
264 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_BLOCK_BUTTON).c_str());
265 g_signal_connect(block_allowed_cookie_button_, "clicked",
266 G_CALLBACK(OnBlockAllowedButtonClickedThunk), this);
267 gtk_container_add(GTK_CONTAINER(button_box), block_allowed_cookie_button_);
[email protected]a503c97c2010-07-16 13:05:48268
[email protected]425328c3e2011-03-16 15:36:00269 // Wrap the vbox inside an hbox so that we can specify padding along the
270 // horizontal axis.
271 GtkWidget* box = gtk_hbox_new(FALSE, 0);
272 gtk_box_pack_start(GTK_BOX(box), cookie_list_vbox, TRUE, TRUE,
[email protected]82c7bfb2011-08-29 22:08:58273 ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00274 return box;
275}
[email protected]df0f6e82010-08-20 21:35:32276
[email protected]425328c3e2011-03-16 15:36:00277GtkWidget* CollectedCookiesGtk::CreateBlockedPane() {
[email protected]b95f1842012-10-19 22:34:15278 PrefService* prefs = Profile::FromBrowserContext(
279 web_contents_->GetBrowserContext())->GetPrefs();
[email protected]a503c97c2010-07-16 13:05:48280
[email protected]82c7bfb2011-08-29 22:08:58281 GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00282
283 GtkWidget* label = gtk_label_new(
[email protected]df0f6e82010-08-20 21:35:32284 l10n_util::GetStringUTF8(
[email protected]30fde822011-10-28 09:49:05285 prefs->GetBoolean(prefs::kBlockThirdPartyCookies) ?
[email protected]df0f6e82010-08-20 21:35:32286 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED :
287 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL).c_str());
288 gtk_widget_set_size_request(label, kTreeViewWidth, -1);
289 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
[email protected]a503c97c2010-07-16 13:05:48290 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
[email protected]425328c3e2011-03-16 15:36:00291 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, TRUE, TRUE,
[email protected]82c7bfb2011-08-29 22:08:58292 ui::kControlSpacing);
[email protected]a503c97c2010-07-16 13:05:48293
[email protected]425328c3e2011-03-16 15:36:00294 GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL);
[email protected]a503c97c2010-07-16 13:05:48295 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window),
296 GTK_POLICY_AUTOMATIC,
297 GTK_POLICY_AUTOMATIC);
298 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window),
299 GTK_SHADOW_ETCHED_IN);
300 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0);
301
[email protected]58d30652012-06-11 19:56:34302 TabSpecificContentSettings* content_settings =
[email protected]b95f1842012-10-19 22:34:15303 TabSpecificContentSettings::FromWebContents(web_contents_);
[email protected]425328c3e2011-03-16 15:36:00304
[email protected]3ff0ff72012-08-01 17:33:51305 const LocalSharedObjectsContainer& blocked_data =
[email protected]af878c1e2012-03-06 11:23:54306 content_settings->blocked_local_shared_objects();
[email protected]3ff0ff72012-08-01 17:33:51307 blocked_cookies_tree_model_ = blocked_data.CreateCookiesTreeModel();
308
[email protected]a503c97c2010-07-16 13:05:48309 blocked_cookies_tree_adapter_.reset(
[email protected]6d90ee622010-08-18 07:42:27310 new gtk_tree::TreeAdapter(this, blocked_cookies_tree_model_.get()));
[email protected]a503c97c2010-07-16 13:05:48311 blocked_tree_ = gtk_tree_view_new_with_model(
312 GTK_TREE_MODEL(blocked_cookies_tree_adapter_->tree_store()));
[email protected]df0f6e82010-08-20 21:35:32313 gtk_widget_set_size_request(blocked_tree_, kTreeViewWidth, kTreeViewHeight);
[email protected]a503c97c2010-07-16 13:05:48314 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(blocked_tree_), FALSE);
315 gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(blocked_tree_), TRUE);
316 gtk_container_add(GTK_CONTAINER(scroll_window), blocked_tree_);
317
[email protected]425328c3e2011-03-16 15:36:00318 GtkTreeViewColumn* title_column = gtk_tree_view_column_new();
319 GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new();
[email protected]a503c97c2010-07-16 13:05:48320 gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE);
321 gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf",
[email protected]6d90ee622010-08-18 07:42:27322 gtk_tree::TreeAdapter::COL_ICON);
[email protected]425328c3e2011-03-16 15:36:00323 GtkCellRenderer* title_renderer = gtk_cell_renderer_text_new();
[email protected]a503c97c2010-07-16 13:05:48324 gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE);
325 gtk_tree_view_column_add_attribute(title_column, title_renderer, "text",
[email protected]6d90ee622010-08-18 07:42:27326 gtk_tree::TreeAdapter::COL_TITLE);
[email protected]a503c97c2010-07-16 13:05:48327 gtk_tree_view_column_set_title(
328 title_column, l10n_util::GetStringUTF8(
329 IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str());
330 gtk_tree_view_append_column(GTK_TREE_VIEW(blocked_tree_), title_column);
331 g_signal_connect(blocked_tree_, "row-expanded",
332 G_CALLBACK(OnTreeViewRowExpandedThunk), this);
[email protected]cf9e0782010-07-19 20:49:30333 blocked_selection_ =
334 gtk_tree_view_get_selection(GTK_TREE_VIEW(blocked_tree_));
335 gtk_tree_selection_set_mode(blocked_selection_, GTK_SELECTION_MULTIPLE);
336 g_signal_connect(blocked_selection_, "changed",
337 G_CALLBACK(OnTreeViewSelectionChangeThunk), this);
338
[email protected]425328c3e2011-03-16 15:36:00339 GtkWidget* button_box = gtk_hbutton_box_new();
[email protected]cf9e0782010-07-19 20:49:30340 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START);
[email protected]82c7bfb2011-08-29 22:08:58341 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00342 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), button_box, FALSE, FALSE,
[email protected]82c7bfb2011-08-29 22:08:58343 ui::kControlSpacing);
[email protected]cf9e0782010-07-19 20:49:30344 allow_blocked_cookie_button_ = gtk_button_new_with_label(
345 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOW_BUTTON).c_str());
346 g_signal_connect(allow_blocked_cookie_button_, "clicked",
347 G_CALLBACK(OnAllowBlockedButtonClickedThunk), this);
348 gtk_container_add(GTK_CONTAINER(button_box), allow_blocked_cookie_button_);
349 for_session_blocked_cookie_button_ = gtk_button_new_with_label(
350 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON).
351 c_str());
352 g_signal_connect(for_session_blocked_cookie_button_, "clicked",
353 G_CALLBACK(OnForSessionBlockedButtonClickedThunk), this);
354 gtk_container_add(GTK_CONTAINER(button_box),
355 for_session_blocked_cookie_button_);
[email protected]a503c97c2010-07-16 13:05:48356
[email protected]425328c3e2011-03-16 15:36:00357 // Wrap the vbox inside an hbox so that we can specify padding along the
358 // horizontal axis.
359 GtkWidget* box = gtk_hbox_new(FALSE, 0);
360 gtk_box_pack_start(GTK_BOX(box), cookie_list_vbox, TRUE, TRUE,
[email protected]82c7bfb2011-08-29 22:08:58361 ui::kControlSpacing);
[email protected]425328c3e2011-03-16 15:36:00362 return box;
363}
[email protected]df0f6e82010-08-20 21:35:32364
[email protected]425328c3e2011-03-16 15:36:00365void CollectedCookiesGtk::ShowCookieInfo(gint current_page) {
366 if (current_page == kAllowedPageNumber) {
367 ShowSelectionInfo(allowed_selection_, allowed_cookies_tree_adapter_.get());
368 } else if (current_page == kBlockedPageNumber) {
369 ShowSelectionInfo(blocked_selection_, blocked_cookies_tree_adapter_.get());
370 }
371}
[email protected]a503c97c2010-07-16 13:05:48372
[email protected]425328c3e2011-03-16 15:36:00373void CollectedCookiesGtk::ShowSelectionInfo(GtkTreeSelection* selection,
374 gtk_tree::TreeAdapter* adapter) {
375 // Check if one "cookie" node is selected. Don't allow more than one.
376 GtkTreeModel* model;
377 GList* paths = gtk_tree_selection_get_selected_rows(selection, &model);
378 if (g_list_length(paths) == 1) {
379 GList* item = g_list_first(paths);
380 GtkTreeIter iter;
381 gtk_tree_model_get_iter(model, &iter,
382 reinterpret_cast<GtkTreePath*>(item->data));
383 CookieTreeNode* node =
384 static_cast<CookieTreeNode*>(adapter->GetNode(&iter));
385 const CookieTreeNode::DetailedInfo detailed_info = node->GetDetailedInfo();
386 if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) {
387 gtk_chrome_cookie_view_display_cookie(
388 GTK_CHROME_COOKIE_VIEW(cookie_info_view_),
389 detailed_info.cookie->Domain(),
390 *detailed_info.cookie);
391 } else {
392 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_info_view_));
393 }
394 } else {
395 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_info_view_));
396 }
397
[email protected]6391e4a2011-03-21 19:46:38398 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL);
[email protected]425328c3e2011-03-16 15:36:00399 g_list_free(paths);
[email protected]a503c97c2010-07-16 13:05:48400}
401
402CollectedCookiesGtk::~CollectedCookiesGtk() {
403 gtk_widget_destroy(dialog_);
404}
405
[email protected]8d9842a2012-07-13 10:39:04406bool CollectedCookiesGtk::SelectionContainsHostNode(
[email protected]cf9e0782010-07-19 20:49:30407 GtkTreeSelection* selection, gtk_tree::TreeAdapter* adapter) {
408 // Check whether at least one "origin" node is selected.
409 GtkTreeModel* model;
410 GList* paths =
411 gtk_tree_selection_get_selected_rows(selection, &model);
[email protected]8d9842a2012-07-13 10:39:04412 bool contains_host_node = false;
[email protected]cf9e0782010-07-19 20:49:30413 for (GList* item = paths; item; item = item->next) {
414 GtkTreeIter iter;
415 gtk_tree_model_get_iter(
416 model, &iter, reinterpret_cast<GtkTreePath*>(item->data));
417 CookieTreeNode* node =
418 static_cast<CookieTreeNode*>(adapter->GetNode(&iter));
419 if (node->GetDetailedInfo().node_type !=
[email protected]8d9842a2012-07-13 10:39:04420 CookieTreeNode::DetailedInfo::TYPE_HOST)
[email protected]cf9e0782010-07-19 20:49:30421 continue;
[email protected]8d9842a2012-07-13 10:39:04422 CookieTreeHostNode* host_node = static_cast<CookieTreeHostNode*>(
[email protected]cf9e0782010-07-19 20:49:30423 node);
[email protected]8d9842a2012-07-13 10:39:04424 if (!host_node->CanCreateContentException())
[email protected]cf9e0782010-07-19 20:49:30425 continue;
[email protected]8d9842a2012-07-13 10:39:04426 contains_host_node = true;
[email protected]cf9e0782010-07-19 20:49:30427 }
428 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL);
429 g_list_free(paths);
[email protected]8d9842a2012-07-13 10:39:04430 return contains_host_node;
[email protected]cf9e0782010-07-19 20:49:30431}
432
433void CollectedCookiesGtk::EnableControls() {
434 // Update button states.
435 bool enable_for_allowed_cookies =
[email protected]8d9842a2012-07-13 10:39:04436 SelectionContainsHostNode(allowed_selection_,
[email protected]cf9e0782010-07-19 20:49:30437 allowed_cookies_tree_adapter_.get());
438 gtk_widget_set_sensitive(block_allowed_cookie_button_,
439 enable_for_allowed_cookies);
440
441 bool enable_for_blocked_cookies =
[email protected]8d9842a2012-07-13 10:39:04442 SelectionContainsHostNode(blocked_selection_,
[email protected]cf9e0782010-07-19 20:49:30443 blocked_cookies_tree_adapter_.get());
444 gtk_widget_set_sensitive(allow_blocked_cookie_button_,
445 enable_for_blocked_cookies);
446 gtk_widget_set_sensitive(for_session_blocked_cookie_button_,
447 enable_for_blocked_cookies);
448}
449
[email protected]432115822011-07-10 15:52:27450void CollectedCookiesGtk::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53451 const content::NotificationSource& source,
452 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27453 DCHECK(type == chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN);
[email protected]37d6cba2013-03-14 23:53:22454 gtk_widget_destroy(window_);
[email protected]a503c97c2010-07-16 13:05:48455}
456
457void CollectedCookiesGtk::OnClose(GtkWidget* close_button) {
[email protected]78e049b2011-03-19 20:45:26458 if (status_changed_) {
[email protected]0be09932013-01-08 02:03:50459 CollectedCookiesInfoBarDelegate::Create(
460 InfoBarService::FromWebContents(web_contents_));
[email protected]78e049b2011-03-19 20:45:26461 }
[email protected]37d6cba2013-03-14 23:53:22462 gtk_widget_destroy(window_);
[email protected]a503c97c2010-07-16 13:05:48463}
464
[email protected]cf9e0782010-07-19 20:49:30465void CollectedCookiesGtk::AddExceptions(GtkTreeSelection* selection,
466 gtk_tree::TreeAdapter* adapter,
467 ContentSetting setting) {
468 GtkTreeModel* model;
469 GList* paths =
470 gtk_tree_selection_get_selected_rows(selection, &model);
[email protected]df0f6e82010-08-20 21:35:32471 string16 last_domain_name;
472 bool multiple_domains_added = false;
[email protected]cf9e0782010-07-19 20:49:30473 for (GList* item = paths; item; item = item->next) {
474 GtkTreeIter iter;
475 gtk_tree_model_get_iter(
476 model, &iter, reinterpret_cast<GtkTreePath*>(item->data));
[email protected]bcb02132010-11-23 14:38:49477 CookieTreeNode* node =
478 static_cast<CookieTreeNode*>(adapter->GetNode(&iter));
479 if (node->GetDetailedInfo().node_type !=
[email protected]8d9842a2012-07-13 10:39:04480 CookieTreeNode::DetailedInfo::TYPE_HOST)
[email protected]bcb02132010-11-23 14:38:49481 continue;
[email protected]8d9842a2012-07-13 10:39:04482 CookieTreeHostNode* host_node = static_cast<CookieTreeHostNode*>(
[email protected]bcb02132010-11-23 14:38:49483 node);
[email protected]8d9842a2012-07-13 10:39:04484 if (host_node->CanCreateContentException()) {
[email protected]df0f6e82010-08-20 21:35:32485 if (!last_domain_name.empty())
486 multiple_domains_added = true;
[email protected]8d9842a2012-07-13 10:39:04487 last_domain_name = host_node->GetTitle();
[email protected]b95f1842012-10-19 22:34:15488 Profile* profile =
489 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
[email protected]8d9842a2012-07-13 10:39:04490 host_node->CreateContentException(
[email protected]cadac622013-06-11 16:46:36491 CookieSettings::Factory::GetForProfile(profile).get(), setting);
[email protected]cf9e0782010-07-19 20:49:30492 }
493 }
494 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL);
495 g_list_free(paths);
[email protected]df0f6e82010-08-20 21:35:32496 if (last_domain_name.empty()) {
497 gtk_widget_hide(infobar_);
498 } else {
499 gtk_label_set_text(
500 GTK_LABEL(infobar_label_), GetInfobarLabel(
501 setting, multiple_domains_added, last_domain_name).c_str());
502 gtk_widget_show(infobar_);
503 }
[email protected]78e049b2011-03-19 20:45:26504 status_changed_ = true;
[email protected]cf9e0782010-07-19 20:49:30505}
506
507void CollectedCookiesGtk::OnBlockAllowedButtonClicked(GtkWidget* button) {
508 AddExceptions(allowed_selection_, allowed_cookies_tree_adapter_.get(),
509 CONTENT_SETTING_BLOCK);
510}
511
512void CollectedCookiesGtk::OnAllowBlockedButtonClicked(GtkWidget* button) {
513 AddExceptions(blocked_selection_, blocked_cookies_tree_adapter_.get(),
514 CONTENT_SETTING_ALLOW);
515}
516
517void CollectedCookiesGtk::OnForSessionBlockedButtonClicked(GtkWidget* button) {
518 AddExceptions(blocked_selection_, blocked_cookies_tree_adapter_.get(),
519 CONTENT_SETTING_SESSION_ONLY);
520}
521
[email protected]425328c3e2011-03-16 15:36:00522void CollectedCookiesGtk::OnSwitchPage(GtkWidget* notebook,
523 gpointer page,
524 guint page_num) {
525 EnableControls();
526 ShowCookieInfo(page_num);
527}
528
[email protected]a503c97c2010-07-16 13:05:48529void CollectedCookiesGtk::OnTreeViewRowExpanded(GtkWidget* tree_view,
[email protected]425328c3e2011-03-16 15:36:00530 GtkTreeIter* iter,
531 GtkTreePath* path) {
[email protected]a503c97c2010-07-16 13:05:48532 // When a row in the tree is expanded, expand all the children too.
533 g_signal_handlers_block_by_func(
534 tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this);
535 gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE);
536 g_signal_handlers_unblock_by_func(
537 tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this);
538}
[email protected]cf9e0782010-07-19 20:49:30539
540void CollectedCookiesGtk::OnTreeViewSelectionChange(GtkWidget* selection) {
541 EnableControls();
[email protected]425328c3e2011-03-16 15:36:00542 ShowCookieInfo(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_)));
[email protected]cf9e0782010-07-19 20:49:30543}
[email protected]723d52122013-03-15 10:45:34544
545void CollectedCookiesGtk::OnDestroy(GtkWidget* widget) {
546 delete this;
547}