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