| 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/gtk/collected_cookies_gtk.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include "base/prefs/pref_service.h" | |
| 9 #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" | |
| 16 #include "chrome/browser/browsing_data/cookies_tree_model.h" | |
| 17 #include "chrome/browser/browsing_data/local_data_container.h" | |
| 18 #include "chrome/browser/chrome_notification_types.h" | |
| 19 #include "chrome/browser/content_settings/cookie_settings.h" | |
| 20 #include "chrome/browser/content_settings/local_shared_objects_container.h" | |
| 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 22 #include "chrome/browser/infobars/infobar_service.h" | |
| 23 #include "chrome/browser/profiles/profile.h" | |
| 24 #include "chrome/browser/ui/browser_dialogs.h" | |
| 25 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" | |
| 26 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | |
| 27 #include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h" | |
| 28 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 29 #include "chrome/common/pref_names.h" | |
| 30 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 31 #include "content/public/browser/notification_source.h" | |
| 32 #include "content/public/browser/web_contents.h" | |
| 33 #include "content/public/browser/web_contents_view.h" | |
| 34 #include "grit/generated_resources.h" | |
| 35 #include "net/cookies/canonical_cookie.h" | |
| 36 #include "ui/base/gtk/gtk_hig_constants.h" | |
| 37 #include "ui/base/l10n/l10n_util.h" | |
| 38 | |
| 39 using web_modal::WebContentsModalDialogManager; | |
| 40 | |
| 41 namespace { | |
| 42 // Width and height of the cookie tree view. | |
| 43 const int kTreeViewWidth = 450; | |
| 44 const int kTreeViewHeight = 150; | |
| 45 | |
| 46 // The page numbers of the pages in the notebook. | |
| 47 const gint kAllowedPageNumber = 0; | |
| 48 const gint kBlockedPageNumber = 1; | |
| 49 | |
| 50 // Padding within the banner box. | |
| 51 const int kBannerPadding = 3; | |
| 52 | |
| 53 // Returns the text to display in the info bar when content settings were | |
| 54 // created. | |
| 55 const std::string GetInfobarLabel(ContentSetting setting, | |
| 56 bool multiple_domains_added, | |
| 57 const base::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 } | |
| 96 | |
| 97 } // namespace | |
| 98 | |
| 99 namespace chrome { | |
| 100 | |
| 101 // Declared in browser_dialogs.h so others don't have to depend on our header. | |
| 102 void ShowCollectedCookiesDialog(content::WebContents* web_contents) { | |
| 103 // Deletes itself on close. | |
| 104 new CollectedCookiesGtk( | |
| 105 web_contents->GetView()->GetTopLevelNativeWindow(), | |
| 106 web_contents); | |
| 107 } | |
| 108 | |
| 109 } // namespace chrome | |
| 110 | |
| 111 CollectedCookiesGtk::CollectedCookiesGtk(GtkWindow* parent, | |
| 112 content::WebContents* web_contents) | |
| 113 : web_contents_(web_contents), | |
| 114 status_changed_(false) { | |
| 115 TabSpecificContentSettings* content_settings = | |
| 116 TabSpecificContentSettings::FromWebContents(web_contents); | |
| 117 registrar_.Add(this, chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | |
| 118 content::Source<TabSpecificContentSettings>(content_settings)); | |
| 119 | |
| 120 Init(); | |
| 121 } | |
| 122 | |
| 123 void CollectedCookiesGtk::Init() { | |
| 124 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); | |
| 125 gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing); | |
| 126 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this); | |
| 127 | |
| 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 | |
| 132 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); | |
| 135 | |
| 136 GtkWidget* allowed_pane = CreateAllowedPane(); | |
| 137 label = gtk_label_new( | |
| 138 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); | |
| 183 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing); | |
| 184 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_))); | |
| 196 window_ = CreateWebContentsModalDialogGtk(dialog_, close_button_); | |
| 197 | |
| 198 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
| 199 WebContentsModalDialogManager::FromWebContents(web_contents_); | |
| 200 web_contents_modal_dialog_manager->ShowDialog(window_); | |
| 201 } | |
| 202 | |
| 203 GtkWidget* CollectedCookiesGtk::CreateAllowedPane() { | |
| 204 GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); | |
| 205 | |
| 206 GtkWidget* label = gtk_label_new( | |
| 207 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL). | |
| 208 c_str()); | |
| 209 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 210 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, FALSE, FALSE, | |
| 211 ui::kControlSpacing); | |
| 212 | |
| 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 | |
| 221 TabSpecificContentSettings* content_settings = | |
| 222 TabSpecificContentSettings::FromWebContents(web_contents_); | |
| 223 | |
| 224 const LocalSharedObjectsContainer& allowed_data = | |
| 225 content_settings->allowed_local_shared_objects(); | |
| 226 allowed_cookies_tree_model_ = allowed_data.CreateCookiesTreeModel(); | |
| 227 | |
| 228 allowed_cookies_tree_adapter_.reset( | |
| 229 new gtk_tree::TreeAdapter(this, allowed_cookies_tree_model_.get())); | |
| 230 allowed_tree_ = gtk_tree_view_new_with_model( | |
| 231 GTK_TREE_MODEL(allowed_cookies_tree_adapter_->tree_store())); | |
| 232 gtk_widget_set_size_request(allowed_tree_, kTreeViewWidth, kTreeViewHeight); | |
| 233 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", | |
| 241 gtk_tree::TreeAdapter::COL_ICON); | |
| 242 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", | |
| 245 gtk_tree::TreeAdapter::COL_TITLE); | |
| 246 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); | |
| 252 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); | |
| 260 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing); | |
| 261 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), button_box, FALSE, FALSE, | |
| 262 ui::kControlSpacing); | |
| 263 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_); | |
| 268 | |
| 269 delete_allowed_cookie_button_ = gtk_button_new_with_label( | |
| 270 l10n_util::GetStringUTF8(IDS_COOKIES_REMOVE_LABEL).c_str()); | |
| 271 g_signal_connect(delete_allowed_cookie_button_, "clicked", | |
| 272 G_CALLBACK(OnDeleteAllowedButtonClickedThunk), this); | |
| 273 gtk_container_add(GTK_CONTAINER(button_box), delete_allowed_cookie_button_); | |
| 274 | |
| 275 // Wrap the vbox inside an hbox so that we can specify padding along the | |
| 276 // horizontal axis. | |
| 277 GtkWidget* box = gtk_hbox_new(FALSE, 0); | |
| 278 gtk_box_pack_start(GTK_BOX(box), cookie_list_vbox, TRUE, TRUE, | |
| 279 ui::kControlSpacing); | |
| 280 return box; | |
| 281 } | |
| 282 | |
| 283 GtkWidget* CollectedCookiesGtk::CreateBlockedPane() { | |
| 284 PrefService* prefs = Profile::FromBrowserContext( | |
| 285 web_contents_->GetBrowserContext())->GetPrefs(); | |
| 286 | |
| 287 GtkWidget* cookie_list_vbox = gtk_vbox_new(FALSE, ui::kControlSpacing); | |
| 288 | |
| 289 GtkWidget* label = gtk_label_new( | |
| 290 l10n_util::GetStringUTF8( | |
| 291 prefs->GetBoolean(prefs::kBlockThirdPartyCookies) ? | |
| 292 IDS_COLLECTED_COOKIES_BLOCKED_THIRD_PARTY_BLOCKING_ENABLED : | |
| 293 IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL).c_str()); | |
| 294 gtk_widget_set_size_request(label, kTreeViewWidth, -1); | |
| 295 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 296 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 297 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), label, TRUE, TRUE, | |
| 298 ui::kControlSpacing); | |
| 299 | |
| 300 GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); | |
| 301 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), | |
| 302 GTK_POLICY_AUTOMATIC, | |
| 303 GTK_POLICY_AUTOMATIC); | |
| 304 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), | |
| 305 GTK_SHADOW_ETCHED_IN); | |
| 306 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); | |
| 307 | |
| 308 TabSpecificContentSettings* content_settings = | |
| 309 TabSpecificContentSettings::FromWebContents(web_contents_); | |
| 310 | |
| 311 const LocalSharedObjectsContainer& blocked_data = | |
| 312 content_settings->blocked_local_shared_objects(); | |
| 313 blocked_cookies_tree_model_ = blocked_data.CreateCookiesTreeModel(); | |
| 314 | |
| 315 blocked_cookies_tree_adapter_.reset( | |
| 316 new gtk_tree::TreeAdapter(this, blocked_cookies_tree_model_.get())); | |
| 317 blocked_tree_ = gtk_tree_view_new_with_model( | |
| 318 GTK_TREE_MODEL(blocked_cookies_tree_adapter_->tree_store())); | |
| 319 gtk_widget_set_size_request(blocked_tree_, kTreeViewWidth, kTreeViewHeight); | |
| 320 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(blocked_tree_), FALSE); | |
| 321 gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW(blocked_tree_), TRUE); | |
| 322 gtk_container_add(GTK_CONTAINER(scroll_window), blocked_tree_); | |
| 323 | |
| 324 GtkTreeViewColumn* title_column = gtk_tree_view_column_new(); | |
| 325 GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); | |
| 326 gtk_tree_view_column_pack_start(title_column, pixbuf_renderer, FALSE); | |
| 327 gtk_tree_view_column_add_attribute(title_column, pixbuf_renderer, "pixbuf", | |
| 328 gtk_tree::TreeAdapter::COL_ICON); | |
| 329 GtkCellRenderer* title_renderer = gtk_cell_renderer_text_new(); | |
| 330 gtk_tree_view_column_pack_start(title_column, title_renderer, TRUE); | |
| 331 gtk_tree_view_column_add_attribute(title_column, title_renderer, "text", | |
| 332 gtk_tree::TreeAdapter::COL_TITLE); | |
| 333 gtk_tree_view_column_set_title( | |
| 334 title_column, l10n_util::GetStringUTF8( | |
| 335 IDS_COOKIES_DOMAIN_COLUMN_HEADER).c_str()); | |
| 336 gtk_tree_view_append_column(GTK_TREE_VIEW(blocked_tree_), title_column); | |
| 337 g_signal_connect(blocked_tree_, "row-expanded", | |
| 338 G_CALLBACK(OnTreeViewRowExpandedThunk), this); | |
| 339 blocked_selection_ = | |
| 340 gtk_tree_view_get_selection(GTK_TREE_VIEW(blocked_tree_)); | |
| 341 gtk_tree_selection_set_mode(blocked_selection_, GTK_SELECTION_MULTIPLE); | |
| 342 g_signal_connect(blocked_selection_, "changed", | |
| 343 G_CALLBACK(OnTreeViewSelectionChangeThunk), this); | |
| 344 | |
| 345 GtkWidget* button_box = gtk_hbutton_box_new(); | |
| 346 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_START); | |
| 347 gtk_box_set_spacing(GTK_BOX(button_box), ui::kControlSpacing); | |
| 348 gtk_box_pack_start(GTK_BOX(cookie_list_vbox), button_box, FALSE, FALSE, | |
| 349 ui::kControlSpacing); | |
| 350 allow_blocked_cookie_button_ = gtk_button_new_with_label( | |
| 351 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_ALLOW_BUTTON).c_str()); | |
| 352 g_signal_connect(allow_blocked_cookie_button_, "clicked", | |
| 353 G_CALLBACK(OnAllowBlockedButtonClickedThunk), this); | |
| 354 gtk_container_add(GTK_CONTAINER(button_box), allow_blocked_cookie_button_); | |
| 355 for_session_blocked_cookie_button_ = gtk_button_new_with_label( | |
| 356 l10n_util::GetStringUTF8(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON). | |
| 357 c_str()); | |
| 358 g_signal_connect(for_session_blocked_cookie_button_, "clicked", | |
| 359 G_CALLBACK(OnForSessionBlockedButtonClickedThunk), this); | |
| 360 gtk_container_add(GTK_CONTAINER(button_box), | |
| 361 for_session_blocked_cookie_button_); | |
| 362 | |
| 363 // Wrap the vbox inside an hbox so that we can specify padding along the | |
| 364 // horizontal axis. | |
| 365 GtkWidget* box = gtk_hbox_new(FALSE, 0); | |
| 366 gtk_box_pack_start(GTK_BOX(box), cookie_list_vbox, TRUE, TRUE, | |
| 367 ui::kControlSpacing); | |
| 368 return box; | |
| 369 } | |
| 370 | |
| 371 void CollectedCookiesGtk::ShowCookieInfo(gint current_page) { | |
| 372 if (current_page == kAllowedPageNumber) { | |
| 373 ShowSelectionInfo(allowed_selection_, allowed_cookies_tree_adapter_.get()); | |
| 374 } else if (current_page == kBlockedPageNumber) { | |
| 375 ShowSelectionInfo(blocked_selection_, blocked_cookies_tree_adapter_.get()); | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 void CollectedCookiesGtk::ShowSelectionInfo(GtkTreeSelection* selection, | |
| 380 gtk_tree::TreeAdapter* adapter) { | |
| 381 // Check if one "cookie" node is selected. Don't allow more than one. | |
| 382 GtkTreeModel* model; | |
| 383 GList* paths = gtk_tree_selection_get_selected_rows(selection, &model); | |
| 384 if (g_list_length(paths) == 1) { | |
| 385 GList* item = g_list_first(paths); | |
| 386 GtkTreeIter iter; | |
| 387 gtk_tree_model_get_iter(model, &iter, | |
| 388 reinterpret_cast<GtkTreePath*>(item->data)); | |
| 389 CookieTreeNode* node = | |
| 390 static_cast<CookieTreeNode*>(adapter->GetNode(&iter)); | |
| 391 const CookieTreeNode::DetailedInfo detailed_info = node->GetDetailedInfo(); | |
| 392 if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { | |
| 393 gtk_chrome_cookie_view_display_cookie( | |
| 394 GTK_CHROME_COOKIE_VIEW(cookie_info_view_), | |
| 395 detailed_info.cookie->Domain(), | |
| 396 *detailed_info.cookie); | |
| 397 } else { | |
| 398 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_info_view_)); | |
| 399 } | |
| 400 } else { | |
| 401 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_info_view_)); | |
| 402 } | |
| 403 | |
| 404 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL); | |
| 405 g_list_free(paths); | |
| 406 } | |
| 407 | |
| 408 CollectedCookiesGtk::~CollectedCookiesGtk() { | |
| 409 gtk_widget_destroy(dialog_); | |
| 410 } | |
| 411 | |
| 412 bool CollectedCookiesGtk::SelectionContainsHostNode( | |
| 413 GtkTreeSelection* selection, gtk_tree::TreeAdapter* adapter) { | |
| 414 // Check whether at least one "origin" node is selected. | |
| 415 GtkTreeModel* model; | |
| 416 GList* paths = | |
| 417 gtk_tree_selection_get_selected_rows(selection, &model); | |
| 418 bool contains_host_node = false; | |
| 419 for (GList* item = paths; item; item = item->next) { | |
| 420 GtkTreeIter iter; | |
| 421 gtk_tree_model_get_iter( | |
| 422 model, &iter, reinterpret_cast<GtkTreePath*>(item->data)); | |
| 423 CookieTreeNode* node = | |
| 424 static_cast<CookieTreeNode*>(adapter->GetNode(&iter)); | |
| 425 if (node->GetDetailedInfo().node_type != | |
| 426 CookieTreeNode::DetailedInfo::TYPE_HOST) | |
| 427 continue; | |
| 428 CookieTreeHostNode* host_node = static_cast<CookieTreeHostNode*>( | |
| 429 node); | |
| 430 if (!host_node->CanCreateContentException()) | |
| 431 continue; | |
| 432 contains_host_node = true; | |
| 433 } | |
| 434 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL); | |
| 435 g_list_free(paths); | |
| 436 return contains_host_node; | |
| 437 } | |
| 438 | |
| 439 void CollectedCookiesGtk::EnableControls() { | |
| 440 // Update button states. | |
| 441 bool enable_for_allowed_cookies = | |
| 442 SelectionContainsHostNode(allowed_selection_, | |
| 443 allowed_cookies_tree_adapter_.get()); | |
| 444 gtk_widget_set_sensitive(block_allowed_cookie_button_, | |
| 445 enable_for_allowed_cookies); | |
| 446 gtk_widget_set_sensitive( | |
| 447 delete_allowed_cookie_button_, | |
| 448 gtk_tree_selection_count_selected_rows(allowed_selection_) > 0); | |
| 449 | |
| 450 bool enable_for_blocked_cookies = | |
| 451 SelectionContainsHostNode(blocked_selection_, | |
| 452 blocked_cookies_tree_adapter_.get()); | |
| 453 gtk_widget_set_sensitive(allow_blocked_cookie_button_, | |
| 454 enable_for_blocked_cookies); | |
| 455 gtk_widget_set_sensitive(for_session_blocked_cookie_button_, | |
| 456 enable_for_blocked_cookies); | |
| 457 } | |
| 458 | |
| 459 void CollectedCookiesGtk::Observe(int type, | |
| 460 const content::NotificationSource& source, | |
| 461 const content::NotificationDetails& details) { | |
| 462 DCHECK(type == chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN); | |
| 463 gtk_widget_destroy(window_); | |
| 464 } | |
| 465 | |
| 466 void CollectedCookiesGtk::OnClose(GtkWidget* close_button) { | |
| 467 if (status_changed_) { | |
| 468 CollectedCookiesInfoBarDelegate::Create( | |
| 469 InfoBarService::FromWebContents(web_contents_)); | |
| 470 } | |
| 471 gtk_widget_destroy(window_); | |
| 472 } | |
| 473 | |
| 474 void CollectedCookiesGtk::AddExceptions(GtkTreeSelection* selection, | |
| 475 gtk_tree::TreeAdapter* adapter, | |
| 476 ContentSetting setting) { | |
| 477 GtkTreeModel* model; | |
| 478 GList* paths = | |
| 479 gtk_tree_selection_get_selected_rows(selection, &model); | |
| 480 base::string16 last_domain_name; | |
| 481 bool multiple_domains_added = false; | |
| 482 for (GList* item = paths; item; item = item->next) { | |
| 483 GtkTreeIter iter; | |
| 484 gtk_tree_model_get_iter( | |
| 485 model, &iter, reinterpret_cast<GtkTreePath*>(item->data)); | |
| 486 CookieTreeNode* node = | |
| 487 static_cast<CookieTreeNode*>(adapter->GetNode(&iter)); | |
| 488 if (node->GetDetailedInfo().node_type != | |
| 489 CookieTreeNode::DetailedInfo::TYPE_HOST) | |
| 490 continue; | |
| 491 CookieTreeHostNode* host_node = static_cast<CookieTreeHostNode*>( | |
| 492 node); | |
| 493 if (host_node->CanCreateContentException()) { | |
| 494 if (!last_domain_name.empty()) | |
| 495 multiple_domains_added = true; | |
| 496 last_domain_name = host_node->GetTitle(); | |
| 497 Profile* profile = | |
| 498 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
| 499 host_node->CreateContentException( | |
| 500 CookieSettings::Factory::GetForProfile(profile).get(), setting); | |
| 501 } | |
| 502 } | |
| 503 g_list_foreach(paths, reinterpret_cast<GFunc>(gtk_tree_path_free), NULL); | |
| 504 g_list_free(paths); | |
| 505 if (last_domain_name.empty()) { | |
| 506 gtk_widget_hide(infobar_); | |
| 507 } else { | |
| 508 gtk_label_set_text( | |
| 509 GTK_LABEL(infobar_label_), GetInfobarLabel( | |
| 510 setting, multiple_domains_added, last_domain_name).c_str()); | |
| 511 gtk_widget_show(infobar_); | |
| 512 } | |
| 513 status_changed_ = true; | |
| 514 } | |
| 515 | |
| 516 void CollectedCookiesGtk::OnBlockAllowedButtonClicked(GtkWidget* button) { | |
| 517 AddExceptions(allowed_selection_, allowed_cookies_tree_adapter_.get(), | |
| 518 CONTENT_SETTING_BLOCK); | |
| 519 } | |
| 520 | |
| 521 void CollectedCookiesGtk::OnDeleteAllowedButtonClicked(GtkWidget* button) { | |
| 522 GtkTreeModel* model; | |
| 523 GList* paths = gtk_tree_selection_get_selected_rows( | |
| 524 allowed_selection_, &model); | |
| 525 for (GList* item = paths; item; item = item->next) { | |
| 526 GtkTreeIter iter; | |
| 527 gtk_tree_model_get_iter( | |
| 528 model, &iter, reinterpret_cast<GtkTreePath*>(item->data)); | |
| 529 CookieTreeNode* node = static_cast<CookieTreeNode*>( | |
| 530 allowed_cookies_tree_adapter_->GetNode(&iter)); | |
| 531 allowed_cookies_tree_model_->DeleteCookieNode(node); | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 void CollectedCookiesGtk::OnAllowBlockedButtonClicked(GtkWidget* button) { | |
| 536 AddExceptions(blocked_selection_, blocked_cookies_tree_adapter_.get(), | |
| 537 CONTENT_SETTING_ALLOW); | |
| 538 } | |
| 539 | |
| 540 void CollectedCookiesGtk::OnForSessionBlockedButtonClicked(GtkWidget* button) { | |
| 541 AddExceptions(blocked_selection_, blocked_cookies_tree_adapter_.get(), | |
| 542 CONTENT_SETTING_SESSION_ONLY); | |
| 543 } | |
| 544 | |
| 545 void CollectedCookiesGtk::OnSwitchPage(GtkWidget* notebook, | |
| 546 gpointer page, | |
| 547 guint page_num) { | |
| 548 EnableControls(); | |
| 549 ShowCookieInfo(page_num); | |
| 550 } | |
| 551 | |
| 552 void CollectedCookiesGtk::OnTreeViewRowExpanded(GtkWidget* tree_view, | |
| 553 GtkTreeIter* iter, | |
| 554 GtkTreePath* path) { | |
| 555 // When a row in the tree is expanded, expand all the children too. | |
| 556 g_signal_handlers_block_by_func( | |
| 557 tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); | |
| 558 gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE); | |
| 559 g_signal_handlers_unblock_by_func( | |
| 560 tree_view, reinterpret_cast<gpointer>(OnTreeViewRowExpandedThunk), this); | |
| 561 } | |
| 562 | |
| 563 void CollectedCookiesGtk::OnTreeViewSelectionChange(GtkWidget* selection) { | |
| 564 EnableControls(); | |
| 565 ShowCookieInfo(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_))); | |
| 566 } | |
| 567 | |
| 568 void CollectedCookiesGtk::OnDestroy(GtkWidget* widget) { | |
| 569 delete this; | |
| 570 } | |
| OLD | NEW |