Home | History | Annotate | Download | only in gtk
      1 // Copyright (c) 2011 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/gtk_chrome_cookie_view.h"
      6 
      7 #include "base/i18n/time_formatting.h"
      8 #include "base/utf_string_conversions.h"
      9 #include "chrome/browser/ui/gtk/gtk_util.h"
     10 #include "grit/generated_resources.h"
     11 #include "ui/base/l10n/l10n_util.h"
     12 
     13 namespace {
     14 
     15 void InitBrowserDetailStyle(GtkWidget* entry, GtkStyle* label_style,
     16                             GtkStyle* dialog_style) {
     17   gtk_widget_modify_fg(entry, GTK_STATE_NORMAL,
     18                        &label_style->fg[GTK_STATE_NORMAL]);
     19   gtk_widget_modify_fg(entry, GTK_STATE_INSENSITIVE,
     20                        &label_style->fg[GTK_STATE_INSENSITIVE]);
     21   // GTK_NO_WINDOW widgets like GtkLabel don't draw their own background, so we
     22   // combine the normal or insensitive foreground of the label style with the
     23   // normal background of the window style to achieve the "normal label" and
     24   // "insensitive label" colors.
     25   gtk_widget_modify_base(entry, GTK_STATE_NORMAL,
     26                          &dialog_style->bg[GTK_STATE_NORMAL]);
     27   gtk_widget_modify_base(entry, GTK_STATE_INSENSITIVE,
     28                          &dialog_style->bg[GTK_STATE_NORMAL]);
     29 }
     30 
     31 GtkWidget* InitRowLabel(int row, int label_id, GtkWidget* details_table) {
     32   GtkWidget* name_label = gtk_label_new(
     33       l10n_util::GetStringUTF8(label_id).c_str());
     34   gtk_misc_set_alignment(GTK_MISC(name_label), 1, 0.5);
     35   gtk_table_attach(GTK_TABLE(details_table), name_label,
     36                    0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
     37 
     38   return name_label;
     39 }
     40 
     41 GtkWidget* InitDetailRow(int row, int label_id,
     42                          GtkWidget* details_table, GtkWidget** entry) {
     43   GtkWidget* name_label = InitRowLabel(row, label_id, details_table);
     44 
     45   *entry = gtk_entry_new();
     46   gtk_entry_set_editable(GTK_ENTRY(*entry), FALSE);
     47   gtk_entry_set_has_frame(GTK_ENTRY(*entry), FALSE);
     48   gtk_table_attach_defaults(GTK_TABLE(details_table), *entry,
     49                             1, 2, row, row + 1);
     50 
     51   return name_label;
     52 }
     53 
     54 GtkWidget* InitComboboxRow(int row, int label_id,
     55                            GtkWidget* details_table,
     56                            GtkWidget** combobox,
     57                            GtkListStore** store) {
     58   GtkWidget* name_label = InitRowLabel(row, label_id, details_table);
     59 
     60   *store = gtk_list_store_new(1, G_TYPE_STRING);
     61   *combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(*store));
     62   g_object_unref(*store);
     63 
     64   GtkCellRenderer* cell = gtk_cell_renderer_text_new();
     65   gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(*combobox), cell, TRUE);
     66   gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(*combobox), cell,
     67                                   "text", 0, NULL);
     68 
     69   GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
     70   gtk_box_pack_start(GTK_BOX(hbox), *combobox, FALSE, FALSE, 0);
     71 
     72   gtk_table_attach_defaults(GTK_TABLE(details_table), hbox,
     73                             1, 2, row, row + 1);
     74 
     75   return name_label;
     76 }
     77 
     78 void InitStyles(GtkChromeCookieView *self) {
     79   GtkStyle* label_style = gtk_widget_get_style(self->first_label_);
     80   GtkStyle* dialog_style = gtk_widget_get_style(GTK_WIDGET(self));
     81 
     82   // Cookie details.
     83   InitBrowserDetailStyle(self->cookie_name_entry_, label_style, dialog_style);
     84   InitBrowserDetailStyle(self->cookie_content_entry_, label_style,
     85                          dialog_style);
     86   InitBrowserDetailStyle(self->cookie_domain_entry_, label_style, dialog_style);
     87   InitBrowserDetailStyle(self->cookie_path_entry_, label_style, dialog_style);
     88   InitBrowserDetailStyle(self->cookie_send_for_entry_, label_style,
     89                          dialog_style);
     90   InitBrowserDetailStyle(self->cookie_created_entry_, label_style,
     91                          dialog_style);
     92   if (self->cookie_expires_entry_) {
     93     InitBrowserDetailStyle(self->cookie_expires_entry_, label_style,
     94                            dialog_style);
     95   }
     96 
     97   // Database details.
     98   InitBrowserDetailStyle(self->database_name_entry_, label_style, dialog_style);
     99   InitBrowserDetailStyle(self->database_description_entry_, label_style,
    100                          dialog_style);
    101   InitBrowserDetailStyle(self->database_size_entry_, label_style, dialog_style);
    102   InitBrowserDetailStyle(self->database_last_modified_entry_, label_style,
    103                          dialog_style);
    104 
    105   // Local storage details.
    106   InitBrowserDetailStyle(self->local_storage_origin_entry_, label_style,
    107                          dialog_style);
    108   InitBrowserDetailStyle(self->local_storage_size_entry_, label_style,
    109                          dialog_style);
    110   InitBrowserDetailStyle(self->local_storage_last_modified_entry_, label_style,
    111                          dialog_style);
    112 
    113   // AppCache details.
    114   InitBrowserDetailStyle(self->appcache_manifest_entry_, label_style,
    115                          dialog_style);
    116   InitBrowserDetailStyle(self->appcache_size_entry_, label_style, dialog_style);
    117   InitBrowserDetailStyle(self->appcache_created_entry_, label_style,
    118                          dialog_style);
    119   InitBrowserDetailStyle(self->appcache_last_accessed_entry_, label_style,
    120                          dialog_style);
    121 
    122   // Local storage item.
    123   InitBrowserDetailStyle(self->local_storage_item_origin_entry_, label_style,
    124                          dialog_style);
    125   InitBrowserDetailStyle(self->local_storage_item_key_entry_, label_style,
    126                          dialog_style);
    127   InitBrowserDetailStyle(self->local_storage_item_value_entry_, label_style,
    128                          dialog_style);
    129 
    130   // Database accessed item.
    131   InitBrowserDetailStyle(self->database_accessed_origin_entry_, label_style,
    132                          dialog_style);
    133   InitBrowserDetailStyle(self->database_accessed_name_entry_, label_style,
    134                          dialog_style);
    135   InitBrowserDetailStyle(self->database_accessed_description_entry_,
    136                          label_style, dialog_style);
    137   InitBrowserDetailStyle(self->database_accessed_size_entry_, label_style,
    138                          dialog_style);
    139 
    140   // AppCache created item.
    141   InitBrowserDetailStyle(self->appcache_created_manifest_entry_, label_style,
    142                          dialog_style);
    143 }
    144 
    145 void SetCookieDetailsSensitivity(GtkChromeCookieView *self,
    146                                  gboolean enabled) {
    147   gtk_widget_set_sensitive(self->cookie_name_entry_, enabled);
    148   gtk_widget_set_sensitive(self->cookie_content_entry_, enabled);
    149   gtk_widget_set_sensitive(self->cookie_domain_entry_, enabled);
    150   gtk_widget_set_sensitive(self->cookie_path_entry_, enabled);
    151   gtk_widget_set_sensitive(self->cookie_send_for_entry_, enabled);
    152   gtk_widget_set_sensitive(self->cookie_created_entry_, enabled);
    153   if (self->cookie_expires_entry_)
    154     gtk_widget_set_sensitive(self->cookie_expires_entry_, enabled);
    155   else
    156     gtk_widget_set_sensitive(self->cookie_expires_combobox_, enabled);
    157 }
    158 
    159 void SetDatabaseDetailsSensitivity(GtkChromeCookieView *self,
    160                                    gboolean enabled) {
    161   gtk_widget_set_sensitive(self->database_name_entry_, enabled);
    162   gtk_widget_set_sensitive(self->database_description_entry_, enabled);
    163   gtk_widget_set_sensitive(self->database_size_entry_, enabled);
    164   gtk_widget_set_sensitive(self->database_last_modified_entry_, enabled);
    165 }
    166 
    167 void SetLocalStorageDetailsSensitivity(GtkChromeCookieView *self,
    168                                        gboolean enabled) {
    169   gtk_widget_set_sensitive(self->local_storage_origin_entry_, enabled);
    170   gtk_widget_set_sensitive(self->local_storage_size_entry_, enabled);
    171   gtk_widget_set_sensitive(self->local_storage_last_modified_entry_, enabled);
    172 }
    173 
    174 void SetAppCacheDetailsSensitivity(GtkChromeCookieView *self,
    175                                    gboolean enabled) {
    176   gtk_widget_set_sensitive(self->appcache_manifest_entry_, enabled);
    177   gtk_widget_set_sensitive(self->appcache_size_entry_, enabled);
    178   gtk_widget_set_sensitive(self->appcache_created_entry_, enabled);
    179   gtk_widget_set_sensitive(self->appcache_last_accessed_entry_, enabled);
    180 }
    181 
    182 void SetIndexedDBDetailsSensitivity(GtkChromeCookieView *self,
    183                                     gboolean enabled) {
    184   gtk_widget_set_sensitive(self->indexed_db_origin_entry_, enabled);
    185   gtk_widget_set_sensitive(self->indexed_db_size_entry_, enabled);
    186   gtk_widget_set_sensitive(self->indexed_db_last_modified_entry_, enabled);
    187 }
    188 
    189 void SetLocalStorageItemSensitivity(GtkChromeCookieView* self,
    190                                     gboolean enabled) {
    191   gtk_widget_set_sensitive(self->local_storage_item_origin_entry_, enabled);
    192   gtk_widget_set_sensitive(self->local_storage_item_key_entry_, enabled);
    193   gtk_widget_set_sensitive(self->local_storage_item_value_entry_, enabled);
    194 }
    195 
    196 void SetDatabaseAccessedSensitivity(GtkChromeCookieView* self,
    197                                     gboolean enabled) {
    198   gtk_widget_set_sensitive(self->database_accessed_origin_entry_, enabled);
    199   gtk_widget_set_sensitive(self->database_accessed_name_entry_, enabled);
    200   gtk_widget_set_sensitive(self->database_accessed_description_entry_, enabled);
    201   gtk_widget_set_sensitive(self->database_accessed_size_entry_, enabled);
    202 }
    203 
    204 void SetAppCacheCreatedSensitivity(GtkChromeCookieView* self,
    205                                    gboolean enabled) {
    206   gtk_widget_set_sensitive(self->appcache_created_manifest_entry_, enabled);
    207 }
    208 
    209 void ClearCookieDetails(GtkChromeCookieView *self) {
    210   std::string no_cookie =
    211       l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_NONESELECTED);
    212   gtk_entry_set_text(GTK_ENTRY(self->cookie_name_entry_),
    213                      no_cookie.c_str());
    214   gtk_entry_set_text(GTK_ENTRY(self->cookie_content_entry_),
    215                      no_cookie.c_str());
    216   gtk_entry_set_text(GTK_ENTRY(self->cookie_domain_entry_),
    217                      no_cookie.c_str());
    218   gtk_entry_set_text(GTK_ENTRY(self->cookie_path_entry_),
    219                      no_cookie.c_str());
    220   gtk_entry_set_text(GTK_ENTRY(self->cookie_created_entry_),
    221                      no_cookie.c_str());
    222   if (self->cookie_expires_entry_) {
    223     gtk_entry_set_text(GTK_ENTRY(self->cookie_expires_entry_),
    224                        no_cookie.c_str());
    225   } else {
    226     GtkListStore* store = self->cookie_expires_combobox_store_;
    227     GtkTreeIter iter;
    228     gtk_list_store_clear(store);
    229 
    230     gtk_list_store_append(store, &iter);
    231     gtk_list_store_set(store, &iter, 0, no_cookie.c_str(), -1);
    232 
    233     gtk_combo_box_set_active(GTK_COMBO_BOX(self->cookie_expires_combobox_),
    234                              0);
    235   }
    236   gtk_entry_set_text(GTK_ENTRY(self->cookie_send_for_entry_),
    237                      no_cookie.c_str());
    238   SetCookieDetailsSensitivity(self, FALSE);
    239 }
    240 
    241 void UpdateVisibleDetailedInfo(GtkChromeCookieView *self, GtkWidget* table) {
    242   SetCookieDetailsSensitivity(self, table == self->cookie_details_table_);
    243   SetDatabaseDetailsSensitivity(self, table == self->database_details_table_);
    244   SetLocalStorageDetailsSensitivity(self,
    245       table == self->local_storage_details_table_);
    246   SetAppCacheDetailsSensitivity(self, table == self->appcache_details_table_);
    247   SetIndexedDBDetailsSensitivity(self,
    248       table == self->indexed_db_details_table_);
    249   SetLocalStorageItemSensitivity(self,
    250       table == self->local_storage_item_table_);
    251   SetDatabaseAccessedSensitivity(self,
    252       table == self->database_accessed_table_);
    253   SetAppCacheCreatedSensitivity(self,
    254       table == self->appcache_created_table_);
    255 
    256   // Display everything
    257   gtk_widget_show(self->table_box_);
    258   gtk_widget_show_all(table);
    259   // Hide everything that isn't us.
    260   if (table != self->cookie_details_table_)
    261     gtk_widget_hide(self->cookie_details_table_);
    262   if (table != self->database_details_table_)
    263     gtk_widget_hide(self->database_details_table_);
    264   if (table != self->local_storage_details_table_)
    265     gtk_widget_hide(self->local_storage_details_table_);
    266   if (table != self->appcache_details_table_)
    267     gtk_widget_hide(self->appcache_details_table_);
    268   if (table != self->indexed_db_details_table_)
    269     gtk_widget_hide(self->indexed_db_details_table_);
    270   if (table != self->local_storage_item_table_)
    271     gtk_widget_hide(self->local_storage_item_table_);
    272   if (table != self->database_accessed_table_)
    273     gtk_widget_hide(self->database_accessed_table_);
    274   if (table != self->appcache_created_table_)
    275     gtk_widget_hide(self->appcache_created_table_);
    276 }
    277 
    278 }  // namespace
    279 
    280 G_DEFINE_TYPE(GtkChromeCookieView, gtk_chrome_cookie_view, GTK_TYPE_FRAME)
    281 
    282 static void gtk_chrome_cookie_view_class_init(GtkChromeCookieViewClass *klass) {
    283 }
    284 
    285 static void gtk_chrome_cookie_view_init(GtkChromeCookieView *self) {
    286 }
    287 
    288 void BuildWidgets(GtkChromeCookieView *self, gboolean editable_expiration) {
    289   self->table_box_ = gtk_vbox_new(FALSE, 0);
    290   gtk_widget_set_no_show_all(self->table_box_, TRUE);
    291 
    292   // Cookie details.
    293   self->cookie_details_table_ = gtk_table_new(7, 2, FALSE);
    294   gtk_container_add(GTK_CONTAINER(self->table_box_),
    295                     self->cookie_details_table_);
    296   gtk_table_set_col_spacing(GTK_TABLE(self->cookie_details_table_), 0,
    297                             gtk_util::kLabelSpacing);
    298 
    299   int row = 0;
    300   self->first_label_ = InitDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL,
    301                 self->cookie_details_table_, &self->cookie_name_entry_);
    302   InitDetailRow(row++, IDS_COOKIES_COOKIE_CONTENT_LABEL,
    303                 self->cookie_details_table_, &self->cookie_content_entry_);
    304   InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
    305                 self->cookie_details_table_, &self->cookie_domain_entry_);
    306   InitDetailRow(row++, IDS_COOKIES_COOKIE_PATH_LABEL,
    307                 self->cookie_details_table_, &self->cookie_path_entry_);
    308   InitDetailRow(row++, IDS_COOKIES_COOKIE_SENDFOR_LABEL,
    309                 self->cookie_details_table_, &self->cookie_send_for_entry_);
    310   InitDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL,
    311                 self->cookie_details_table_, &self->cookie_created_entry_);
    312   if (editable_expiration) {
    313     InitComboboxRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL,
    314                     self->cookie_details_table_,
    315                     &self->cookie_expires_combobox_,
    316                     &self->cookie_expires_combobox_store_);
    317   } else {
    318     InitDetailRow(row++, IDS_COOKIES_COOKIE_EXPIRES_LABEL,
    319                   self->cookie_details_table_, &self->cookie_expires_entry_);
    320   }
    321 
    322   // Database details.
    323   self->database_details_table_ = gtk_table_new(4, 2, FALSE);
    324   gtk_container_add(GTK_CONTAINER(self->table_box_),
    325                     self->database_details_table_);
    326   gtk_table_set_col_spacing(GTK_TABLE(self->database_details_table_), 0,
    327                             gtk_util::kLabelSpacing);
    328 
    329   InitDetailRow(row++, IDS_COOKIES_COOKIE_NAME_LABEL,
    330                 self->database_details_table_, &self->database_name_entry_);
    331   InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL,
    332                 self->database_details_table_,
    333                 &self->database_description_entry_);
    334   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
    335                 self->database_details_table_, &self->database_size_entry_);
    336   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
    337                 self->database_details_table_,
    338                 &self->database_last_modified_entry_);
    339 
    340   // Local storage details.
    341   self->local_storage_details_table_ = gtk_table_new(3, 2, FALSE);
    342   gtk_container_add(GTK_CONTAINER(self->table_box_),
    343                     self->local_storage_details_table_);
    344   gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_details_table_), 0,
    345                             gtk_util::kLabelSpacing);
    346 
    347   row = 0;
    348   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL,
    349                 self->local_storage_details_table_,
    350                 &self->local_storage_origin_entry_);
    351   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
    352                 self->local_storage_details_table_,
    353                 &self->local_storage_size_entry_);
    354   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
    355                 self->local_storage_details_table_,
    356                 &self->local_storage_last_modified_entry_);
    357 
    358   // AppCache details.
    359   self->appcache_details_table_ = gtk_table_new(4, 2, FALSE);
    360   gtk_container_add(GTK_CONTAINER(self->table_box_),
    361                     self->appcache_details_table_);
    362   gtk_table_set_col_spacing(GTK_TABLE(self->appcache_details_table_), 0,
    363                             gtk_util::kLabelSpacing);
    364 
    365   row = 0;
    366   InitDetailRow(row++, IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL,
    367                 self->appcache_details_table_,
    368                 &self->appcache_manifest_entry_);
    369   InitDetailRow(row++, IDS_COOKIES_SIZE_LABEL,
    370                 self->appcache_details_table_, &self->appcache_size_entry_);
    371   InitDetailRow(row++, IDS_COOKIES_COOKIE_CREATED_LABEL,
    372                 self->appcache_details_table_, &self->appcache_created_entry_);
    373   InitDetailRow(row++, IDS_COOKIES_LAST_ACCESSED_LABEL,
    374                 self->appcache_details_table_,
    375                 &self->appcache_last_accessed_entry_);
    376 
    377   // IndexedDB details.
    378   self->indexed_db_details_table_ = gtk_table_new(4, 2, FALSE);
    379   gtk_container_add(GTK_CONTAINER(self->table_box_),
    380                     self->indexed_db_details_table_);
    381   gtk_table_set_col_spacing(GTK_TABLE(self->indexed_db_details_table_), 0,
    382                             gtk_util::kLabelSpacing);
    383 
    384   row = 0;
    385   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL,
    386                 self->indexed_db_details_table_,
    387                 &self->indexed_db_origin_entry_);
    388   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL,
    389                 self->indexed_db_details_table_, &self->indexed_db_size_entry_);
    390   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL,
    391                 self->indexed_db_details_table_,
    392                 &self->indexed_db_last_modified_entry_);
    393 
    394   // Local storage item.
    395   self->local_storage_item_table_ = gtk_table_new(3, 2, FALSE);
    396   gtk_container_add(GTK_CONTAINER(self->table_box_),
    397                     self->local_storage_item_table_);
    398   gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_item_table_), 0,
    399                             gtk_util::kLabelSpacing);
    400 
    401   row = 0;
    402   InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
    403                 self->local_storage_item_table_,
    404                 &self->local_storage_item_origin_entry_);
    405   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_KEY_LABEL,
    406                 self->local_storage_item_table_,
    407                 &self->local_storage_item_key_entry_);
    408   InitDetailRow(row++, IDS_COOKIES_LOCAL_STORAGE_VALUE_LABEL,
    409                 self->local_storage_item_table_,
    410                 &self->local_storage_item_value_entry_);
    411 
    412   // Database accessed prompt.
    413   self->database_accessed_table_ = gtk_table_new(2, 2, FALSE);
    414   gtk_container_add(GTK_CONTAINER(self->table_box_),
    415                     self->database_accessed_table_);
    416   gtk_table_set_col_spacing(GTK_TABLE(self->local_storage_item_table_), 0,
    417                             gtk_util::kLabelSpacing);
    418 
    419   row = 0;
    420   InitDetailRow(row++, IDS_COOKIES_COOKIE_DOMAIN_LABEL,
    421                 self->database_accessed_table_,
    422                 &self->database_accessed_origin_entry_);
    423   InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_NAME,
    424                 self->database_accessed_table_,
    425                 &self->database_accessed_name_entry_);
    426   InitDetailRow(row++, IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL,
    427                 self->database_accessed_table_,
    428                 &self->database_accessed_description_entry_);
    429   InitDetailRow(row++, IDS_COOKIES_SIZE_LABEL,
    430                 self->database_accessed_table_,
    431                 &self->database_accessed_size_entry_);
    432 
    433   // AppCache created prompt.
    434   self->appcache_created_table_ = gtk_table_new(1, 2, FALSE);
    435   gtk_container_add(GTK_CONTAINER(self->table_box_),
    436                     self->appcache_created_table_);
    437   gtk_table_set_col_spacing(GTK_TABLE(self->appcache_created_table_), 0,
    438                             gtk_util::kLabelSpacing);
    439   row = 0;
    440   InitDetailRow(row++, IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL,
    441                 self->appcache_created_table_,
    442                 &self->appcache_created_manifest_entry_);
    443 
    444   gtk_frame_set_shadow_type(GTK_FRAME(self), GTK_SHADOW_ETCHED_IN);
    445   gtk_container_add(GTK_CONTAINER(self), self->table_box_);
    446 }
    447 
    448 GtkWidget* gtk_chrome_cookie_view_new(gboolean editable_expiration) {
    449   GtkChromeCookieView* view = GTK_CHROME_COOKIE_VIEW(
    450       g_object_new(GTK_TYPE_CHROME_COOKIE_VIEW, NULL));
    451   BuildWidgets(view, editable_expiration);
    452   g_signal_connect(view, "realize", G_CALLBACK(InitStyles), NULL);
    453   return GTK_WIDGET(view);
    454 }
    455 
    456 void gtk_chrome_cookie_view_clear(GtkChromeCookieView* self) {
    457   UpdateVisibleDetailedInfo(self, self->cookie_details_table_);
    458   ClearCookieDetails(self);
    459 }
    460 
    461 // Switches the display to showing the passed in cookie.
    462 void gtk_chrome_cookie_view_display_cookie(
    463     GtkChromeCookieView* self,
    464     const std::string& domain,
    465     const net::CookieMonster::CanonicalCookie& cookie) {
    466   UpdateVisibleDetailedInfo(self, self->cookie_details_table_);
    467 
    468   gtk_entry_set_text(GTK_ENTRY(self->cookie_name_entry_),
    469                      cookie.Name().c_str());
    470   gtk_entry_set_text(GTK_ENTRY(self->cookie_content_entry_),
    471                      cookie.Value().c_str());
    472   gtk_entry_set_text(GTK_ENTRY(self->cookie_domain_entry_),
    473                      domain.c_str());
    474   gtk_entry_set_text(GTK_ENTRY(self->cookie_path_entry_),
    475                      cookie.Path().c_str());
    476   gtk_entry_set_text(GTK_ENTRY(self->cookie_created_entry_),
    477                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    478                          cookie.CreationDate())).c_str());
    479 
    480   std::string expire_text = cookie.DoesExpire() ?
    481       UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) :
    482       l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_EXPIRES_SESSION);
    483 
    484   if (self->cookie_expires_entry_) {
    485     gtk_entry_set_text(GTK_ENTRY(self->cookie_expires_entry_),
    486                        expire_text.c_str());
    487   } else {
    488     GtkListStore* store = self->cookie_expires_combobox_store_;
    489     GtkTreeIter iter;
    490     gtk_list_store_clear(store);
    491 
    492     if (cookie.DoesExpire()) {
    493       gtk_list_store_append(store, &iter);
    494       gtk_list_store_set(store, &iter, 0, expire_text.c_str(), -1);
    495     }
    496 
    497     gtk_list_store_append(store, &iter);
    498     gtk_list_store_set(
    499         store, &iter, 0,
    500         l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_EXPIRES_SESSION).c_str(),
    501         -1);
    502 
    503     gtk_combo_box_set_active(GTK_COMBO_BOX(self->cookie_expires_combobox_),
    504                              0);
    505   }
    506 
    507   gtk_entry_set_text(
    508       GTK_ENTRY(self->cookie_send_for_entry_),
    509       l10n_util::GetStringUTF8(cookie.IsSecure() ?
    510                                IDS_COOKIES_COOKIE_SENDFOR_SECURE :
    511                                IDS_COOKIES_COOKIE_SENDFOR_ANY).c_str());
    512   SetCookieDetailsSensitivity(self, TRUE);
    513 }
    514 
    515 void gtk_chrome_cookie_view_display_cookie_string(
    516     GtkChromeCookieView* self,
    517     const GURL& url,
    518     const std::string& cookie_line) {
    519   net::CookieMonster::ParsedCookie pc(cookie_line);
    520   net::CookieMonster::CanonicalCookie cookie(url, pc);
    521 
    522   gtk_chrome_cookie_view_display_cookie(
    523       self,
    524       pc.HasDomain() ? pc.Domain() : url.host(),
    525       cookie);
    526 }
    527 
    528 // Switches the display to showing the passed in database.
    529 void gtk_chrome_cookie_view_display_database(
    530     GtkChromeCookieView* self,
    531     const BrowsingDataDatabaseHelper::DatabaseInfo& database_info) {
    532   UpdateVisibleDetailedInfo(self, self->database_details_table_);
    533 
    534   gtk_entry_set_text(
    535       GTK_ENTRY(self->database_name_entry_),
    536       database_info.database_name.empty() ?
    537           l10n_util::GetStringUTF8(
    538               IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME).c_str() :
    539           database_info.database_name.c_str());
    540   gtk_entry_set_text(GTK_ENTRY(self->database_description_entry_),
    541                      database_info.description.c_str());
    542   gtk_entry_set_text(GTK_ENTRY(self->database_size_entry_),
    543                      UTF16ToUTF8(FormatBytes(
    544                          database_info.size,
    545                          GetByteDisplayUnits(database_info.size),
    546                          true)).c_str());
    547   gtk_entry_set_text(GTK_ENTRY(self->database_last_modified_entry_),
    548                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    549                          database_info.last_modified)).c_str());
    550   SetDatabaseDetailsSensitivity(self, TRUE);
    551 }
    552 
    553 // Switches the display to showing the passed in local storage data.
    554 void gtk_chrome_cookie_view_display_local_storage(
    555     GtkChromeCookieView* self,
    556     const BrowsingDataLocalStorageHelper::LocalStorageInfo&
    557     local_storage_info) {
    558   UpdateVisibleDetailedInfo(self, self->local_storage_details_table_);
    559 
    560   gtk_entry_set_text(GTK_ENTRY(self->local_storage_origin_entry_),
    561                      local_storage_info.origin.c_str());
    562   gtk_entry_set_text(GTK_ENTRY(self->local_storage_size_entry_),
    563                      UTF16ToUTF8(FormatBytes(
    564                          local_storage_info.size,
    565                          GetByteDisplayUnits(local_storage_info.size),
    566                          true)).c_str());
    567   gtk_entry_set_text(GTK_ENTRY(self->local_storage_last_modified_entry_),
    568                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    569                          local_storage_info.last_modified)).c_str());
    570   SetLocalStorageDetailsSensitivity(self, TRUE);
    571 }
    572 
    573 // Switches the display to showing the passed in app cache.
    574 void gtk_chrome_cookie_view_display_app_cache(
    575     GtkChromeCookieView* self,
    576     const appcache::AppCacheInfo& info) {
    577   UpdateVisibleDetailedInfo(self, self->appcache_details_table_);
    578 
    579   gtk_entry_set_text(GTK_ENTRY(self->appcache_manifest_entry_),
    580                      info.manifest_url.spec().c_str());
    581   gtk_entry_set_text(GTK_ENTRY(self->appcache_size_entry_),
    582                      UTF16ToUTF8(FormatBytes(
    583                          info.size,
    584                          GetByteDisplayUnits(info.size),
    585                          true)).c_str());
    586   gtk_entry_set_text(GTK_ENTRY(self->appcache_created_entry_),
    587                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    588                          info.creation_time)).c_str());
    589   gtk_entry_set_text(GTK_ENTRY(self->appcache_last_accessed_entry_),
    590                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    591                          info.last_access_time)).c_str());
    592   SetAppCacheDetailsSensitivity(self, TRUE);
    593 }
    594 
    595 // Switches the display to showing the passed in IndexedDB data.
    596 void gtk_chrome_cookie_view_display_indexed_db(
    597     GtkChromeCookieView* self,
    598     const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info) {
    599   UpdateVisibleDetailedInfo(self, self->indexed_db_details_table_);
    600 
    601   gtk_entry_set_text(GTK_ENTRY(self->indexed_db_origin_entry_),
    602                      indexed_db_info.origin.c_str());
    603   gtk_entry_set_text(GTK_ENTRY(self->indexed_db_size_entry_),
    604                      UTF16ToUTF8(FormatBytes(
    605                          indexed_db_info.size,
    606                          GetByteDisplayUnits(indexed_db_info.size),
    607                          true)).c_str());
    608   gtk_entry_set_text(GTK_ENTRY(self->indexed_db_last_modified_entry_),
    609                      UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
    610                          indexed_db_info.last_modified)).c_str());
    611   SetLocalStorageDetailsSensitivity(self, TRUE);
    612 }
    613 
    614 void gtk_chrome_cookie_view_display_local_storage_item(
    615     GtkChromeCookieView* self,
    616     const std::string& host,
    617     const string16& key,
    618     const string16& value) {
    619   UpdateVisibleDetailedInfo(self, self->local_storage_item_table_);
    620 
    621   gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_origin_entry_),
    622                      host.c_str());
    623   gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_key_entry_),
    624                      UTF16ToUTF8(key).c_str());
    625   gtk_entry_set_text(GTK_ENTRY(self->local_storage_item_value_entry_),
    626                      UTF16ToUTF8(value).c_str());
    627   SetLocalStorageItemSensitivity(self, TRUE);
    628 }
    629 
    630 void gtk_chrome_cookie_view_display_database_accessed(
    631     GtkChromeCookieView* self,
    632     const std::string& host,
    633     const string16& database_name,
    634     const string16& display_name,
    635     unsigned long estimated_size) {
    636   UpdateVisibleDetailedInfo(self, self->database_accessed_table_);
    637 
    638   gtk_entry_set_text(GTK_ENTRY(self->database_accessed_origin_entry_),
    639                      host.c_str());
    640   gtk_entry_set_text(GTK_ENTRY(self->database_accessed_name_entry_),
    641                      UTF16ToUTF8(database_name).c_str());
    642   gtk_entry_set_text(GTK_ENTRY(self->database_accessed_description_entry_),
    643                      UTF16ToUTF8(display_name).c_str());
    644   gtk_entry_set_text(GTK_ENTRY(self->database_accessed_size_entry_),
    645                      UTF16ToUTF8(FormatBytes(
    646                          estimated_size,
    647                          GetByteDisplayUnits(estimated_size),
    648                          true)).c_str());
    649   SetDatabaseAccessedSensitivity(self, TRUE);
    650 }
    651 
    652 void gtk_chrome_cookie_view_display_appcache_created(
    653     GtkChromeCookieView* self,
    654     const GURL& manifest_url) {
    655   UpdateVisibleDetailedInfo(self, self->appcache_created_table_);
    656   gtk_entry_set_text(GTK_ENTRY(self->appcache_created_manifest_entry_),
    657                      manifest_url.spec().c_str());
    658   SetAppCacheCreatedSensitivity(self, TRUE);
    659 }
    660 
    661 bool gtk_chrome_cookie_view_session_expires(GtkChromeCookieView* self) {
    662   if (self->cookie_expires_entry_)
    663     return false;
    664 
    665   GtkListStore* store = self->cookie_expires_combobox_store_;
    666   int store_size = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
    667   if (store_size == 1)
    668     return false;
    669 
    670   DCHECK_EQ(2, store_size);
    671 
    672   int selected = gtk_combo_box_get_active(GTK_COMBO_BOX(
    673       self->cookie_expires_combobox_));
    674   return selected == 1;
    675 }
    676