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.
5 #include "chrome/browser/ui/gtk/gtk_chrome_cookie_view.h"
7 #include "base/i18n/time_formatting.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/public/browser/indexed_db_context.h"
10 #include "grit/generated_resources.h"
11 #include "net/cookies/canonical_cookie.h"
12 #include "net/cookies/parsed_cookie.h"
13 #include "ui/base/gtk/gtk_hig_constants.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/text/bytes_formatting.h"
19 void InitBrowserDetailStyle(GtkWidget* entry, GtkStyle* label_style,
20 GtkStyle* dialog_style) {
21 gtk_widget_modify_fg(entry, GTK_STATE_NORMAL,
22 &label_style->fg[GTK_STATE_NORMAL]);
23 gtk_widget_modify_fg(entry, GTK_STATE_INSENSITIVE,
24 &label_style->fg[GTK_STATE_INSENSITIVE]);
25 // GTK_NO_WINDOW widgets like GtkLabel don't draw their own background, so we
26 // combine the normal or insensitive foreground of the label style with the
27 // normal background of the window style to achieve the "normal label" and
28 // "insensitive label" colors.
29 gtk_widget_modify_base(entry, GTK_STATE_NORMAL,
30 &dialog_style->bg[GTK_STATE_NORMAL]);
31 gtk_widget_modify_base(entry, GTK_STATE_INSENSITIVE,
32 &dialog_style->bg[GTK_STATE_NORMAL]);
35 GtkWidget* InitRowLabel(int row, int label_id, GtkWidget* details_table) {
36 GtkWidget* name_label = gtk_label_new(
37 l10n_util::GetStringUTF8(label_id).c_str());
38 gtk_misc_set_alignment(GTK_MISC(name_label), 1, 0.5);
39 gtk_table_attach(GTK_TABLE(details_table), name_label,
40 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
45 GtkWidget* InitDetailRow(int row, int label_id,
46 GtkWidget* details_table, GtkWidget** entry) {
47 GtkWidget* name_label = InitRowLabel(row, label_id, details_table);
49 *entry = gtk_entry_new();
50 gtk_editable_set_editable(GTK_EDITABLE(*entry), FALSE);
51 gtk_entry_set_has_frame(GTK_ENTRY(*entry), FALSE);
52 gtk_table_attach_defaults(GTK_TABLE(details_table), *entry,
58 GtkWidget* InitComboboxRow(int row, int label_id,
59 GtkWidget* details_table,
61 GtkListStore** store) {
62 GtkWidget* name_label = InitRowLabel(row, label_id, details_table);
64 *store = gtk_list_store_new(1, G_TYPE_STRING);
65 *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(*store));
66 g_object_unref(*store);
68 GtkCellRenderer* cell = gtk_cell_renderer_text_new();
69 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(*combobox), cell, TRUE);
70 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(*combobox), cell,
73 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
74 gtk_box_pack_start(GTK_BOX(hbox), *combobox, FALSE, FALSE, 0);
76 gtk_table_attach_defaults(GTK_TABLE(details_table), hbox,
82 void InitStyles(GtkChromeCookieView *self) {
83 GtkStyle* label_style = gtk_widget_get_style(self->first_label_);
84 GtkStyle* dialog_style = gtk_widget_get_style(GTK_WIDGET(self));
87 InitBrowserDetailStyle(self->cookie_name_entry_, label_style, dialog_style);
88 InitBrowserDetailStyle(self->cookie_content_entry_, label_style,
90 InitBrowserDetailStyle(self->cookie_domain_entry_, label_style, dialog_style);
91 InitBrowserDetailStyle(self->cookie_path_entry_, label_style, dialog_style);
92 InitBrowserDetailStyle(self->cookie_send_for_entry_, label_style,
94 InitBrowserDetailStyle(self->cookie_created_entry_, label_style,
96 if (self->cookie_expires_entry_) {
97 InitBrowserDetailStyle(self->cookie_expires_entry_, label_style,
102 InitBrowserDetailStyle(self->database_name_entry_, label_style, dialog_style);
103 InitBrowserDetailStyle(self->database_description_entry_, label_style,
105 InitBrowserDetailStyle(self->database_size_entry_, label_style, dialog_style);
106 InitBrowserDetailStyle(self->database_last_modified_entry_, label_style,
109 // Local storage details.
110 InitBrowserDetailStyle(self->local_storage_origin_entry_, label_style,
112 InitBrowserDetailStyle(self->local_storage_size_entry_, label_style,
114 InitBrowserDetailStyle(self->local_storage_last_modified_entry_, label_style,
118 InitBrowserDetailStyle(self->appcache_manifest_entry_, label_style,
120 InitBrowserDetailStyle(self->appcache_size_entry_, label_style, dialog_style);
121 InitBrowserDetailStyle(self->appcache_created_entry_, label_style,
123 InitBrowserDetailStyle(self->appcache_last_accessed_entry_, label_style,
126 // Local storage item.
127 InitBrowserDetailStyle(self->local_storage_item_origin_entry_, label_style,
129 InitBrowserDetailStyle(self->local_storage_item_key_entry_, label_style,
131 InitBrowserDetailStyle(self->local_storage_item_value_entry_, label_style,
134 // Database accessed item.
135 InitBrowserDetailStyle(self->database_accessed_origin_entry_, label_style,
137 InitBrowserDetailStyle(self->database_accessed_name_entry_, label_style,
139 InitBrowserDetailStyle(self->database_accessed_description_entry_,
140 label_style, dialog_style);
141 InitBrowserDetailStyle(self->database_accessed_size_entry_, label_style,
144 // AppCache created item.
145 InitBrowserDetailStyle(self->appcache_created_manifest_entry_, label_style,
149 void SetCookieDetailsSensitivity(GtkChromeCookieView *self,
151 gtk_widget_set_sensitive(self->cookie_name_entry_, enabled);
152 gtk_widget_set_sensitive(self->cookie_content_entry_, enabled);
153 gtk_widget_set_sensitive(self->cookie_domain_entry_, enabled);
154 gtk_widget_set_sensitive(self->cookie_path_entry_, enabled);
155 gtk_widget_set_sensitive(self->cookie_send_for_entry_, enabled);
156 gtk_widget_set_sensitive(self->cookie_created_entry_, enabled);
157 if (self->cookie_expires_entry_)
158 gtk_widget_set_sensitive(self->cookie_expires_entry_, enabled);
160 gtk_widget_set_sensitive(self->cookie_expires_combobox_, enabled);
163 void SetDatabaseDetailsSensitivity(GtkChromeCookieView *self,
165 gtk_widget_set_sensitive(self->database_name_entry_, enabled);
166 gtk_widget_set_sensitive(self->database_description_entry_, enabled);
167 gtk_widget_set_sensitive(self->database_size_entry_, enabled);
168 gtk_widget_set_sensitive(self->database_last_modified_entry_, enabled);
171 void SetLocalStorageDetailsSensitivity(GtkChromeCookieView *self,
173 gtk_widget_set_sensitive(self->local_storage_origin_entry_, enabled);
174 gtk_widget_set_sensitive(self->local_storage_size_entry_, enabled);
175 gtk_widget_set_sensitive(self->local_storage_last_modified_entry_, enabled);
178 void SetAppCacheDetailsSensitivity(GtkChromeCookieView *self,
180 gtk_widget_set_sensitive(self->appcache_manifest_entry_, enabled);
181 gtk_widget_set_sensitive(self->appcache_size_entry_, enabled);
182 gtk_widget_set_sensitive(self->appcache_created_entry_, enabled);
183 gtk_widget_set_sensitive(self->appcache_last_accessed_entry_, enabled);
186 void SetIndexedDBDetailsSensitivity(GtkChromeCookieView *self,
188 gtk_widget_set_sensitive(self->indexed_db_origin_entry_, enabled);
189 gtk_widget_set_sensitive(self->indexed_db_size_entry_, enabled);
190 gtk_widget_set_sensitive(self->indexed_db_last_modified_entry_, enabled);
193 void SetLocalStorageItemSensitivity(GtkChromeCookieView* self,
195 gtk_widget_set_sensitive(self->local_storage_item_origin_entry_, enabled);
196 gtk_widget_set_sensitive(self->local_storage_item_key_entry_, enabled);
197 gtk_widget_set_sensitive(self->local_storage_item_value_entry_, enabled);
200 void SetDatabaseAccessedSensitivity(GtkChromeCookieView* self,
202 gtk_widget_set_sensitive(self->database_accessed_origin_entry_, enabled);
203 gtk_widget_set_sensitive(self->database_accessed_name_entry_, enabled);
204 gtk_widget_set_sensitive(self->database_accessed_description_entry_, enabled);
205 gtk_widget_set_sensitive(self->database_accessed_size_entry_, enabled);
208 void SetAppCacheCreatedSensitivity(GtkChromeCookieView* self,
210 gtk_widget_set_sensitive(self->appcache_created_manifest_entry_, enabled);
213 void ClearCookieDetails(GtkChromeCookieView *self) {
214 std::string no_cookie =
215 l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_NONESELECTED);
216 gtk_entry_set_text(GTK_ENTRY(self->cookie_name_entry_),
218 gtk_entry_set_text(GTK_ENTRY(self->cookie_content_entry_),
220 gtk_entry_set_text(GTK_ENTRY(self->cookie_domain_entry_),
222 gtk_entry_set_text(GTK_ENTRY(self->cookie_path_entry_),
224 gtk_entry_set_text(GTK_ENTRY(self->cookie_created_entry_),
226 if (self->cookie_expires_entry_) {
227 gtk_entry_set_text(GTK_ENTRY(self->cookie_expires_entry_),
230 GtkListStore* store = self->cookie_expires_combobox_store_;
232 gtk_list_store_clear(store);
234 gtk_list_store_append(store, &iter);
235 gtk_list_store_set(store, &iter, 0, no_cookie.c_str(), -1);
237 gtk_combo_box_set_active(GTK_COMBO_BOX(self->cookie_expires_combobox_),
240 gtk_entry_set_text(GTK_ENTRY(self->cookie_send_for_entry_),
242 SetCookieDetailsSensitivity(self, FALSE);
245 void UpdateVisibleDetailedInfo(GtkChromeCookieView *self, GtkWidget* table) {
246 SetCookieDetailsSensitivity(self, table == self->cookie_details_table_);
247 SetDatabaseDetailsSensitivity(self, table == self->database_details_table_);
248 SetLocalStorageDetailsSensitivity(self,
249 table == self->local_storage_details_table_);
250 SetAppCacheDetailsSensitivity(self, table == self->appcache_details_table_);
251 SetIndexedDBDetailsSensitivity(self,
252 table == self->indexed_db_details_table_);
253 SetLocalStorageItemSensitivity(self,
254 table == self->local_storage_item_table_);
255 SetDatabaseAccessedSensitivity(self,
256 table == self->database_accessed_table_);
257 SetAppCacheCreatedSensitivity(self,
258 table == self->appcache_created_table_);
260 // Display everything
261 gtk_widget_show(self->table_box_);
262 gtk_widget_show_all(table);
263 // Hide everything that isn't us.
264 if (table != self->cookie_details_table_)
265 gtk_widget_hide(self->cookie_details_table_);
266 if (table != self->database_details_table_)
267 gtk_widget_hide(self->database_details_table_);
268 if (table != self->local_storage_details_table_)
269 gtk_widget_hide(self->local_storage_details_table_);
270 if (table != self->appcache_details_table_)
271 gtk_widget_hide(self->appcache_details_table_);
272 if (table != self->indexed_db_details_table_)
273 gtk_widget_hide(self->indexed_db_details_table_);
274 if (table != self->local_storage_item_table_)
275 gtk_widget_hide(self->local_storage_item_table_);
276 if (table != self->database_accessed_table_)
277 gtk_widget_hide(self->database_accessed_table_);
278 if (table != self->appcache_created_table_)
279 gtk_widget_hide(self->appcache_created_table_);
284 G_DEFINE_TYPE(GtkChromeCookieView, gtk_chrome_cookie_view, GTK_TYPE_FRAME)
286 static void gtk_chrome_cookie_view_class_init(GtkChromeCookieViewClass *klass) {
289 static void gtk_chrome_cookie_view_init(GtkChromeCookieView *self) {
292 void BuildWidgets(GtkChromeCookieView *self, gboolean editable_expiration) {
293 self->table_box_ = gtk_vbox_new(FALSE, 0);
294 gtk_widget_set_no_show_all(self->table_box_, TRUE);
297 self->cookie_details_table_ = gtk_table_new(7, 2, FALSE);
298 gtk_container_add(GTK_CONTAINER(self->table_box_),
299 self->cookie_details_table_);
300 gtk_table_set_col_spacing(GTK_TABLE(self->cookie_details_table_), 0,
304 self->first_label_ = InitDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL,
305 self->cookie_details_table_, &self->cookie_name_entry_);
306 InitDetailRow(row++, IDS_COOKIES_COOKIE_CONTENT_LABEL,
307 self->cookie_details_table_, &self->cookie_content_entry_);
308 InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
309 self->cookie_details_table_, &self->cookie_domain_entry_);
310 InitDetailRow(row++, IDS_COOKIES_COOKIE_PATH_LABEL,
311 self->cookie_details_table_, &self->cookie_path_entry_);
312 InitDetailRow(row++, IDS_COOKIES_COOKIE_SENDFOR_LABEL,
313 self->cookie_details_table_, &self->cookie_send_for_entry_);
314 InitDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL,
315 self->cookie_details_table_, &self->cookie_created_entry_);
316 if (editable_expiration) {
317 InitComboboxRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL,
318 self->cookie_details_table_,
319 &self->cookie_expires_combobox_,
320 &self->cookie_expires_combobox_store_);
322 InitDetailRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL,
323 self->cookie_details_table_, &self->cookie_expires_entry_);
327 self->database_details_table_ = gtk_table_new(4, 2, FALSE);
328 gtk_container_add(GTK_CONTAINER(self->table_box_),
329 self->database_details_table_);
330 gtk_table_set_col_spacing(GTK_TABLE(self->database_details_table_), 0,
333 InitDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL,
334 self->database_details_table_, &self->database_name_entry_);
335 InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL,
336 self->database_details_table_,
337 &self->database_description_entry_);
338 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
339 self->database_details_table_, &self->database_size_entry_);
340 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
341 self->database_details_table_,
342 &self->database_last_modified_entry_);
344 // Local storage details.
345 self->local_storage_details_table_ = gtk_table_new(3, 2, FALSE);
346 gtk_container_add(GTK_CONTAINER(self->table_box_),
347 self->local_storage_details_table_);
348 gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_details_table_), 0,
352 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL,
353 self->local_storage_details_table_,
354 &self->local_storage_origin_entry_);
355 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
356 self->local_storage_details_table_,
357 &self->local_storage_size_entry_);
358 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
359 self->local_storage_details_table_,
360 &self->local_storage_last_modified_entry_);
363 self->appcache_details_table_ = gtk_table_new(4, 2, FALSE);
364 gtk_container_add(GTK_CONTAINER(self->table_box_),
365 self->appcache_details_table_);
366 gtk_table_set_col_spacing(GTK_TABLE(self->appcache_details_table_), 0,
370 InitDetailRow(row++, IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL,
371 self->appcache_details_table_,
372 &self->appcache_manifest_entry_);
373 InitDetailRow(row++, IDS_COOKIES_SIZE_LABEL,
374 self->appcache_details_table_, &self->appcache_size_entry_);
375 InitDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL,
376 self->appcache_details_table_, &self->appcache_created_entry_);
377 InitDetailRow(row++, IDS_COOKIES_LAST_ACCESSED_LABEL,
378 self->appcache_details_table_,
379 &self->appcache_last_accessed_entry_);
381 // IndexedDB details.
382 self->indexed_db_details_table_ = gtk_table_new(4, 2, FALSE);
383 gtk_container_add(GTK_CONTAINER(self->table_box_),
384 self->indexed_db_details_table_);
385 gtk_table_set_col_spacing(GTK_TABLE(self->indexed_db_details_table_), 0,
389 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL,
390 self->indexed_db_details_table_,
391 &self->indexed_db_origin_entry_);
392 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
393 self->indexed_db_details_table_, &self->indexed_db_size_entry_);
394 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
395 self->indexed_db_details_table_,
396 &self->indexed_db_last_modified_entry_);
398 // Local storage item.
399 self->local_storage_item_table_ = gtk_table_new(3, 2, FALSE);
400 gtk_container_add(GTK_CONTAINER(self->table_box_),
401 self->local_storage_item_table_);
402 gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_item_table_), 0,
406 InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
407 self->local_storage_item_table_,
408 &self->local_storage_item_origin_entry_);
409 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_KEY_LABEL,
410 self->local_storage_item_table_,
411 &self->local_storage_item_key_entry_);
412 InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_VALUE_LABEL,
413 self->local_storage_item_table_,
414 &self->local_storage_item_value_entry_);
416 // Database accessed prompt.
417 self->database_accessed_table_ = gtk_table_new(2, 2, FALSE);
418 gtk_container_add(GTK_CONTAINER(self->table_box_),
419 self->database_accessed_table_);
420 gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_item_table_), 0,
424 InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
425 self->database_accessed_table_,
426 &self->database_accessed_origin_entry_);
427 InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_NAME,
428 self->database_accessed_table_,
429 &self->database_accessed_name_entry_);
430 InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL,
431 self->database_accessed_table_,
432 &self->database_accessed_description_entry_);
433 InitDetailRow(row++, IDS_COOKIES_SIZE_LABEL,
434 self->database_accessed_table_,
435 &self->database_accessed_size_entry_);
437 // AppCache created prompt.
438 self->appcache_created_table_ = gtk_table_new(1, 2, FALSE);
439 gtk_container_add(GTK_CONTAINER(self->table_box_),
440 self->appcache_created_table_);
441 gtk_table_set_col_spacing(GTK_TABLE(self->appcache_created_table_), 0,
444 InitDetailRow(row++, IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL,
445 self->appcache_created_table_,
446 &self->appcache_created_manifest_entry_);
448 gtk_frame_set_shadow_type(GTK_FRAME(self), GTK_SHADOW_ETCHED_IN);
449 gtk_container_add(GTK_CONTAINER(self), self->table_box_);
452 GtkWidget* gtk_chrome_cookie_view_new(gboolean editable_expiration) {
453 GtkChromeCookieView* view = GTK_CHROME_COOKIE_VIEW(
454 g_object_new(GTK_TYPE_CHROME_COOKIE_VIEW, NULL));
455 BuildWidgets(view, editable_expiration);
456 g_signal_connect(view, "realize", G_CALLBACK(InitStyles), NULL);
457 return GTK_WIDGET(view);
460 void gtk_chrome_cookie_view_clear(GtkChromeCookieView* self) {
461 UpdateVisibleDetailedInfo(self, self->cookie_details_table_);
462 ClearCookieDetails(self);
465 // Switches the display to showing the passed in cookie.
466 void gtk_chrome_cookie_view_display_cookie(
467 GtkChromeCookieView* self,
468 const std::string& domain,
469 const net::CanonicalCookie& cookie) {
470 UpdateVisibleDetailedInfo(self, self->cookie_details_table_);
472 gtk_entry_set_text(GTK_ENTRY(self->cookie_name_entry_),
473 cookie.Name().c_str());
474 gtk_entry_set_text(GTK_ENTRY(self->cookie_content_entry_),
475 cookie.Value().c_str());
476 gtk_entry_set_text(GTK_ENTRY(self->cookie_domain_entry_),
478 gtk_entry_set_text(GTK_ENTRY(self->cookie_path_entry_),
479 cookie.Path().c_str());
480 gtk_entry_set_text(GTK_ENTRY(self->cookie_created_entry_),
481 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
482 cookie.CreationDate())).c_str());
484 std::string expire_text = cookie.IsPersistent() ?
485 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) :
486 l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_EXPIRES_SESSION);
488 if (self->cookie_expires_entry_) {
489 gtk_entry_set_text(GTK_ENTRY(self->cookie_expires_entry_),
490 expire_text.c_str());
492 GtkListStore* store = self->cookie_expires_combobox_store_;
494 gtk_list_store_clear(store);
496 if (cookie.IsPersistent()) {
497 gtk_list_store_append(store, &iter);
498 gtk_list_store_set(store, &iter, 0, expire_text.c_str(), -1);
501 gtk_list_store_append(store, &iter);
504 l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_EXPIRES_SESSION).c_str(),
507 gtk_combo_box_set_active(GTK_COMBO_BOX(self->cookie_expires_combobox_),
512 GTK_ENTRY(self->cookie_send_for_entry_),
513 l10n_util::GetStringUTF8(cookie.IsSecure() ?
514 IDS_COOKIES_COOKIE_SENDFOR_SECURE :
515 IDS_COOKIES_COOKIE_SENDFOR_ANY).c_str());
516 SetCookieDetailsSensitivity(self, TRUE);
519 void gtk_chrome_cookie_view_display_cookie_string(
520 GtkChromeCookieView* self,
522 const std::string& cookie_line) {
523 net::ParsedCookie pc(cookie_line);
524 net::CanonicalCookie cookie(url, pc);
526 gtk_chrome_cookie_view_display_cookie(
528 pc.HasDomain() ? pc.Domain() : url.host(),
532 // Switches the display to showing the passed in database.
533 void gtk_chrome_cookie_view_display_database(
534 GtkChromeCookieView* self,
535 const BrowsingDataDatabaseHelper::DatabaseInfo& database_info) {
536 UpdateVisibleDetailedInfo(self, self->database_details_table_);
539 GTK_ENTRY(self->database_name_entry_),
540 database_info.database_name.empty() ?
541 l10n_util::GetStringUTF8(
542 IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME).c_str() :
543 database_info.database_name.c_str());
544 gtk_entry_set_text(GTK_ENTRY(self->database_description_entry_),
545 database_info.description.c_str());
546 gtk_entry_set_text(GTK_ENTRY(self->database_size_entry_),
547 UTF16ToUTF8(ui::FormatBytes(database_info.size)).c_str());
548 gtk_entry_set_text(GTK_ENTRY(self->database_last_modified_entry_),
549 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
550 database_info.last_modified)).c_str());
551 SetDatabaseDetailsSensitivity(self, TRUE);
554 // Switches the display to showing the passed in local storage data.
555 void gtk_chrome_cookie_view_display_local_storage(
556 GtkChromeCookieView* self,
557 const BrowsingDataLocalStorageHelper::LocalStorageInfo&
558 local_storage_info) {
559 UpdateVisibleDetailedInfo(self, self->local_storage_details_table_);
561 gtk_entry_set_text(GTK_ENTRY(self->local_storage_origin_entry_),
562 local_storage_info.origin_url.spec().c_str());
563 gtk_entry_set_text(GTK_ENTRY(self->local_storage_size_entry_),
564 UTF16ToUTF8(ui::FormatBytes(
565 local_storage_info.size)).c_str());
566 gtk_entry_set_text(GTK_ENTRY(self->local_storage_last_modified_entry_),
567 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
568 local_storage_info.last_modified)).c_str());
569 SetLocalStorageDetailsSensitivity(self, TRUE);
572 // Switches the display to showing the passed in app cache.
573 void gtk_chrome_cookie_view_display_app_cache(
574 GtkChromeCookieView* self,
575 const appcache::AppCacheInfo& info) {
576 UpdateVisibleDetailedInfo(self, self->appcache_details_table_);
578 gtk_entry_set_text(GTK_ENTRY(self->appcache_manifest_entry_),
579 info.manifest_url.spec().c_str());
580 gtk_entry_set_text(GTK_ENTRY(self->appcache_size_entry_),
581 UTF16ToUTF8(ui::FormatBytes(info.size)).c_str());
582 gtk_entry_set_text(GTK_ENTRY(self->appcache_created_entry_),
583 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
584 info.creation_time)).c_str());
585 gtk_entry_set_text(GTK_ENTRY(self->appcache_last_accessed_entry_),
586 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
587 info.last_access_time)).c_str());
588 SetAppCacheDetailsSensitivity(self, TRUE);
591 // Switches the display to showing the passed in IndexedDB data.
592 void gtk_chrome_cookie_view_display_indexed_db(
593 GtkChromeCookieView* self,
594 const content::IndexedDBInfo& indexed_db_info) {
595 UpdateVisibleDetailedInfo(self, self->indexed_db_details_table_);
597 gtk_entry_set_text(GTK_ENTRY(self->indexed_db_origin_entry_),
598 indexed_db_info.origin_.spec().c_str());
599 gtk_entry_set_text(GTK_ENTRY(self->indexed_db_size_entry_),
600 UTF16ToUTF8(ui::FormatBytes(
601 indexed_db_info.size_)).c_str());
602 gtk_entry_set_text(GTK_ENTRY(self->indexed_db_last_modified_entry_),
603 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
604 indexed_db_info.last_modified_)).c_str());
605 SetLocalStorageDetailsSensitivity(self, TRUE);
608 void gtk_chrome_cookie_view_display_local_storage_item(
609 GtkChromeCookieView* self,
610 const std::string& host,
612 const string16& value) {
613 UpdateVisibleDetailedInfo(self, self->local_storage_item_table_);
615 gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_origin_entry_),
617 gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_key_entry_),
618 UTF16ToUTF8(key).c_str());
619 gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_value_entry_),
620 UTF16ToUTF8(value).c_str());
621 SetLocalStorageItemSensitivity(self, TRUE);
624 void gtk_chrome_cookie_view_display_database_accessed(
625 GtkChromeCookieView* self,
626 const std::string& host,
627 const string16& database_name,
628 const string16& display_name,
629 unsigned long estimated_size) {
630 UpdateVisibleDetailedInfo(self, self->database_accessed_table_);
632 gtk_entry_set_text(GTK_ENTRY(self->database_accessed_origin_entry_),
634 gtk_entry_set_text(GTK_ENTRY(self->database_accessed_name_entry_),
635 UTF16ToUTF8(database_name).c_str());
636 gtk_entry_set_text(GTK_ENTRY(self->database_accessed_description_entry_),
637 UTF16ToUTF8(display_name).c_str());
638 gtk_entry_set_text(GTK_ENTRY(self->database_accessed_size_entry_),
639 UTF16ToUTF8(ui::FormatBytes(estimated_size)).c_str());
640 SetDatabaseAccessedSensitivity(self, TRUE);
643 void gtk_chrome_cookie_view_display_appcache_created(
644 GtkChromeCookieView* self,
645 const GURL& manifest_url) {
646 UpdateVisibleDetailedInfo(self, self->appcache_created_table_);
647 gtk_entry_set_text(GTK_ENTRY(self->appcache_created_manifest_entry_),
648 manifest_url.spec().c_str());
649 SetAppCacheCreatedSensitivity(self, TRUE);
652 bool gtk_chrome_cookie_view_session_expires(GtkChromeCookieView* self) {
653 if (self->cookie_expires_entry_)
656 GtkListStore* store = self->cookie_expires_combobox_store_;
657 int store_size = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
661 DCHECK_EQ(2, store_size);
663 int selected = gtk_combo_box_get_active(GTK_COMBO_BOX(
664 self->cookie_expires_combobox_));
665 return selected == 1;