diff options
Diffstat (limited to 'chrome/browser/gtk/options/cookies_view.cc')
-rw-r--r-- | chrome/browser/gtk/options/cookies_view.cc | 152 |
1 files changed, 117 insertions, 35 deletions
diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc index fb9c8c6..896e3b1 100644 --- a/chrome/browser/gtk/options/cookies_view.cc +++ b/chrome/browser/gtk/options/cookies_view.cc @@ -35,8 +35,8 @@ enum { // The currently open cookie manager, if any. CookiesView* instance_ = NULL; -void InitCookieDetailStyle(GtkWidget* entry, GtkStyle* label_style, - GtkStyle* dialog_style) { +void InitBrowserDetailStyle(GtkWidget* entry, GtkStyle* label_style, + GtkStyle* dialog_style) { gtk_widget_modify_fg(entry, GTK_STATE_NORMAL, &label_style->fg[GTK_STATE_NORMAL]); gtk_widget_modify_fg(entry, GTK_STATE_INSENSITIVE, @@ -57,20 +57,26 @@ CookiesView::~CookiesView() { } // static -void CookiesView::Show(Profile* profile) { +void CookiesView::Show( + Profile* profile, + BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper) { DCHECK(profile); + DCHECK(browsing_data_local_storage_helper); // If there's already an existing editor window, activate it. if (instance_) { gtk_window_present(GTK_WINDOW(instance_->dialog_)); } else { - instance_ = new CookiesView(profile); + instance_ = new CookiesView(profile, browsing_data_local_storage_helper); instance_->InitStylesAndShow(); } } -CookiesView::CookiesView(Profile* profile) +CookiesView::CookiesView( + Profile* profile, + BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper) : profile_(profile), + browsing_data_local_storage_helper_(browsing_data_local_storage_helper), filter_update_factory_(this) { Init(); } @@ -160,7 +166,8 @@ void CookiesView::Init() { GTK_SHADOW_ETCHED_IN); gtk_box_pack_start(GTK_BOX(cookie_list_vbox), scroll_window, TRUE, TRUE, 0); - cookies_tree_model_.reset(new CookiesTreeModel(profile_)); + cookies_tree_model_.reset(new CookiesTreeModel( + profile_, browsing_data_local_storage_helper_)); cookies_tree_adapter_.reset( new gtk_tree::TreeAdapter(this, cookies_tree_model_.get())); tree_ = gtk_tree_view_new_with_model( @@ -193,31 +200,54 @@ void CookiesView::Init() { G_CALLBACK(OnSelectionChanged), this); // Cookie details. - GtkWidget* details_frame = gtk_frame_new(NULL); - gtk_frame_set_shadow_type(GTK_FRAME(details_frame), GTK_SHADOW_ETCHED_IN); - gtk_box_pack_start(GTK_BOX(cookie_list_vbox), details_frame, + GtkWidget* cookie_details_frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(cookie_details_frame), + GTK_SHADOW_ETCHED_IN); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), cookie_details_frame, FALSE, FALSE, 0); cookie_details_table_ = gtk_table_new(7, 2, FALSE); - gtk_container_add(GTK_CONTAINER(details_frame), cookie_details_table_); + gtk_container_add(GTK_CONTAINER(cookie_details_frame), cookie_details_table_); gtk_table_set_col_spacing(GTK_TABLE(cookie_details_table_), 0, gtk_util::kLabelSpacing); int row = 0; - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL, - &cookie_name_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_CONTENT_LABEL, - &cookie_content_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL, - &cookie_domain_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_PATH_LABEL, - &cookie_path_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_SENDFOR_LABEL, - &cookie_send_for_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL, - &cookie_created_entry_); - InitCookieDetailRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL, - &cookie_expires_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL, + cookie_details_table_, &cookie_name_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_CONTENT_LABEL, + cookie_details_table_, &cookie_content_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL, + cookie_details_table_, &cookie_domain_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_PATH_LABEL, + cookie_details_table_, &cookie_path_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_SENDFOR_LABEL, + cookie_details_table_, &cookie_send_for_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL, + cookie_details_table_, &cookie_created_entry_); + InitDetailRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL, + cookie_details_table_, &cookie_expires_entry_); + + // Local storage details. + GtkWidget* local_storage_details_frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(local_storage_details_frame), + GTK_SHADOW_ETCHED_IN); + gtk_box_pack_start(GTK_BOX(cookie_list_vbox), local_storage_details_frame, + FALSE, FALSE, 0); + local_storage_details_table_ = gtk_table_new(3, 2, FALSE); + gtk_container_add(GTK_CONTAINER(local_storage_details_frame), + local_storage_details_table_); + gtk_table_set_col_spacing(GTK_TABLE(local_storage_details_table_), 0, + gtk_util::kLabelSpacing); + + row = 0; + InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL, + local_storage_details_table_, &local_storage_origin_entry_); + InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL, + local_storage_details_table_, &local_storage_size_entry_); + InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL, + local_storage_details_table_, + &local_storage_last_modified_entry_); + UpdateVisibleDetailedInfo(cookie_details_table_); // Populate the view. cookies_tree_adapter_->Init(); SetInitialTreeState(); @@ -231,30 +261,38 @@ void CookiesView::InitStylesAndShow() { GtkStyle* label_style = gtk_widget_get_style(description_label_); GtkStyle* dialog_style = gtk_widget_get_style(dialog_); - InitCookieDetailStyle(cookie_name_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_content_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_domain_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_path_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_send_for_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_created_entry_, label_style, dialog_style); - InitCookieDetailStyle(cookie_expires_entry_, label_style, dialog_style); + // Cookie details. + InitBrowserDetailStyle(cookie_name_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_content_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_domain_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_path_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_send_for_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_created_entry_, label_style, dialog_style); + InitBrowserDetailStyle(cookie_expires_entry_, label_style, dialog_style); + + // Local storage details. + InitBrowserDetailStyle(local_storage_origin_entry_, label_style, + dialog_style); + InitBrowserDetailStyle(local_storage_size_entry_, label_style, dialog_style); + InitBrowserDetailStyle(local_storage_last_modified_entry_, label_style, + dialog_style); gtk_widget_show_all(dialog_); } -void CookiesView::InitCookieDetailRow(int row, int label_id, - GtkWidget** entry) { +void CookiesView::InitDetailRow(int row, int label_id, + GtkWidget* details_table, GtkWidget** entry) { GtkWidget* name_label = gtk_label_new( l10n_util::GetStringUTF8(label_id).c_str()); gtk_misc_set_alignment(GTK_MISC(name_label), 1, 0.5); - gtk_table_attach(GTK_TABLE(cookie_details_table_), name_label, + gtk_table_attach(GTK_TABLE(details_table), name_label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); *entry = gtk_entry_new(); gtk_entry_set_editable(GTK_ENTRY(*entry), FALSE); gtk_entry_set_has_frame(GTK_ENTRY(*entry), FALSE); - gtk_table_attach_defaults(GTK_TABLE(cookie_details_table_), *entry, + gtk_table_attach_defaults(GTK_TABLE(details_table), *entry, 1, 2, row, row + 1); } @@ -279,9 +317,15 @@ void CookiesView::EnableControls() { static_cast<CookieTreeNode*>( cookies_tree_adapter_->GetNode(&iter))->GetDetailedInfo(); if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { + UpdateVisibleDetailedInfo(cookie_details_table_); PopulateCookieDetails(detailed_info.cookie->first, detailed_info.cookie->second); + } else if (detailed_info.node_type == + CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) { + UpdateVisibleDetailedInfo(local_storage_details_table_); + PopulateLocalStorageDetails(*detailed_info.local_storage_info); } else { + UpdateVisibleDetailedInfo(cookie_details_table_); ClearCookieDetails(); } } else { @@ -299,6 +343,12 @@ void CookiesView::SetCookieDetailsSensitivity(gboolean enabled) { gtk_widget_set_sensitive(cookie_expires_entry_, enabled); } +void CookiesView::SetLocalStorageDetailsSensitivity(gboolean enabled) { + gtk_widget_set_sensitive(local_storage_origin_entry_, enabled); + gtk_widget_set_sensitive(local_storage_size_entry_, enabled); + gtk_widget_set_sensitive(local_storage_last_modified_entry_, enabled); +} + void CookiesView::PopulateCookieDetails( const std::string& domain, const net::CookieMonster::CanonicalCookie& cookie) { @@ -326,6 +376,22 @@ void CookiesView::PopulateCookieDetails( SetCookieDetailsSensitivity(TRUE); } +void CookiesView::PopulateLocalStorageDetails( + const BrowsingDataLocalStorageHelper::LocalStorageInfo& + local_storage_info) { + gtk_entry_set_text(GTK_ENTRY(local_storage_origin_entry_), + local_storage_info.origin.c_str()); + gtk_entry_set_text(GTK_ENTRY(local_storage_size_entry_), + WideToUTF8(FormatBytes( + local_storage_info.size, + GetByteDisplayUnits(local_storage_info.size), + true)).c_str()); + gtk_entry_set_text(GTK_ENTRY(local_storage_last_modified_entry_), + WideToUTF8(base::TimeFormatFriendlyDateAndTime( + local_storage_info.last_modified)).c_str()); + SetLocalStorageDetailsSensitivity(TRUE); +} + void CookiesView::ClearCookieDetails() { std::string no_cookie = l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_NONESELECTED); @@ -387,6 +453,7 @@ void CookiesView::OnResponse(GtkDialog* dialog, int response_id, window->RemoveSelectedItems(); } else if (response_id == RESPONSE_REMOVE_ALL) { window->cookies_tree_model_->DeleteAllCookies(); + window->browsing_data_local_storage_helper_->DeleteAllLocalStorageFiles(); } else { gtk_widget_destroy(window->dialog_); } @@ -437,6 +504,21 @@ void CookiesView::UpdateFilterResults() { } } +void CookiesView::UpdateVisibleDetailedInfo(GtkWidget* table) { + // Toggle the parent (the table frame) visibility and sensitivity. + gtk_widget_show(gtk_widget_get_parent(table)); + // Toggle the other tables. + if (table == cookie_details_table_) { + SetCookieDetailsSensitivity(true); + SetLocalStorageDetailsSensitivity(false); + gtk_widget_hide(gtk_widget_get_parent(local_storage_details_table_)); + } else if (table == local_storage_details_table_) { + SetCookieDetailsSensitivity(false); + SetLocalStorageDetailsSensitivity(true); + gtk_widget_hide(gtk_widget_get_parent(cookie_details_table_)); + } +} + // static void CookiesView::OnFilterEntryActivated(GtkEntry* entry, CookiesView* window) { window->filter_update_factory_.RevokeAll(); |