| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" | 5 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/cookies_tree_model.h" | 12 #include "chrome/browser/cookies_tree_model.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/text/bytes_formatting.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 static const char kKeyId[] = "id"; | 19 static const char kKeyId[] = "id"; |
| 19 static const char kKeyTitle[] = "title"; | 20 static const char kKeyTitle[] = "title"; |
| 20 static const char kKeyIcon[] = "icon"; | 21 static const char kKeyIcon[] = "icon"; |
| 21 static const char kKeyType[] = "type"; | 22 static const char kKeyType[] = "type"; |
| 22 static const char kKeyHasChildren[] = "hasChildren"; | 23 static const char kKeyHasChildren[] = "hasChildren"; |
| 23 | 24 |
| 24 static const char kKeyName[] = "name"; | 25 static const char kKeyName[] = "name"; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 111 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 111 | 112 |
| 112 const BrowsingDataDatabaseHelper::DatabaseInfo& database_info = | 113 const BrowsingDataDatabaseHelper::DatabaseInfo& database_info = |
| 113 *node.GetDetailedInfo().database_info; | 114 *node.GetDetailedInfo().database_info; |
| 114 | 115 |
| 115 dict->SetString(kKeyName, database_info.database_name.empty() ? | 116 dict->SetString(kKeyName, database_info.database_name.empty() ? |
| 116 l10n_util::GetStringUTF8(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) : | 117 l10n_util::GetStringUTF8(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) : |
| 117 database_info.database_name); | 118 database_info.database_name); |
| 118 dict->SetString(kKeyDesc, database_info.description); | 119 dict->SetString(kKeyDesc, database_info.description); |
| 119 dict->SetString(kKeySize, | 120 dict->SetString(kKeySize, |
| 120 FormatBytes(database_info.size, | 121 ui::FormatBytes(database_info.size, |
| 121 GetByteDisplayUnits(database_info.size), | 122 ui::DATA_UNITS_NATURAL, |
| 122 true)); | 123 true)); |
| 123 dict->SetString(kKeyModified, UTF16ToUTF8( | 124 dict->SetString(kKeyModified, UTF16ToUTF8( |
| 124 base::TimeFormatFriendlyDateAndTime(database_info.last_modified))); | 125 base::TimeFormatFriendlyDateAndTime(database_info.last_modified))); |
| 125 | 126 |
| 126 break; | 127 break; |
| 127 } | 128 } |
| 128 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: { | 129 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: { |
| 129 dict->SetString(kKeyType, "local_storage"); | 130 dict->SetString(kKeyType, "local_storage"); |
| 130 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 131 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 131 | 132 |
| 132 const BrowsingDataLocalStorageHelper::LocalStorageInfo& | 133 const BrowsingDataLocalStorageHelper::LocalStorageInfo& |
| 133 local_storage_info = *node.GetDetailedInfo().local_storage_info; | 134 local_storage_info = *node.GetDetailedInfo().local_storage_info; |
| 134 | 135 |
| 135 dict->SetString(kKeyOrigin, local_storage_info.origin); | 136 dict->SetString(kKeyOrigin, local_storage_info.origin); |
| 136 dict->SetString(kKeySize, | 137 dict->SetString(kKeySize, |
| 137 FormatBytes(local_storage_info.size, | 138 ui::FormatBytes(local_storage_info.size, |
| 138 GetByteDisplayUnits(local_storage_info.size), | 139 ui::DATA_UNITS_NATURAL, |
| 139 true)); | 140 true)); |
| 140 dict->SetString(kKeyModified, UTF16ToUTF8( | 141 dict->SetString(kKeyModified, UTF16ToUTF8( |
| 141 base::TimeFormatFriendlyDateAndTime( | 142 base::TimeFormatFriendlyDateAndTime( |
| 142 local_storage_info.last_modified))); | 143 local_storage_info.last_modified))); |
| 143 | 144 |
| 144 break; | 145 break; |
| 145 } | 146 } |
| 146 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: { | 147 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: { |
| 147 dict->SetString(kKeyType, "app_cache"); | 148 dict->SetString(kKeyType, "app_cache"); |
| 148 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 149 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 149 | 150 |
| 150 const appcache::AppCacheInfo& appcache_info = | 151 const appcache::AppCacheInfo& appcache_info = |
| 151 *node.GetDetailedInfo().appcache_info; | 152 *node.GetDetailedInfo().appcache_info; |
| 152 | 153 |
| 153 dict->SetString(kKeyManifest, appcache_info.manifest_url.spec()); | 154 dict->SetString(kKeyManifest, appcache_info.manifest_url.spec()); |
| 154 dict->SetString(kKeySize, | 155 dict->SetString(kKeySize, |
| 155 FormatBytes(appcache_info.size, | 156 ui::FormatBytes(appcache_info.size, |
| 156 GetByteDisplayUnits(appcache_info.size), | 157 ui::DATA_UNITS_NATURAL, |
| 157 true)); | 158 true)); |
| 158 dict->SetString(kKeyCreated, UTF16ToUTF8( | 159 dict->SetString(kKeyCreated, UTF16ToUTF8( |
| 159 base::TimeFormatFriendlyDateAndTime(appcache_info.creation_time))); | 160 base::TimeFormatFriendlyDateAndTime(appcache_info.creation_time))); |
| 160 dict->SetString(kKeyAccessed, UTF16ToUTF8( | 161 dict->SetString(kKeyAccessed, UTF16ToUTF8( |
| 161 base::TimeFormatFriendlyDateAndTime(appcache_info.last_access_time))); | 162 base::TimeFormatFriendlyDateAndTime(appcache_info.last_access_time))); |
| 162 | 163 |
| 163 break; | 164 break; |
| 164 } | 165 } |
| 165 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: { | 166 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: { |
| 166 dict->SetString(kKeyType, "indexed_db"); | 167 dict->SetString(kKeyType, "indexed_db"); |
| 167 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 168 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 168 | 169 |
| 169 const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info = | 170 const BrowsingDataIndexedDBHelper::IndexedDBInfo& indexed_db_info = |
| 170 *node.GetDetailedInfo().indexed_db_info; | 171 *node.GetDetailedInfo().indexed_db_info; |
| 171 | 172 |
| 172 dict->SetString(kKeyOrigin, indexed_db_info.origin); | 173 dict->SetString(kKeyOrigin, indexed_db_info.origin); |
| 173 dict->SetString(kKeySize, | 174 dict->SetString(kKeySize, |
| 174 FormatBytes(indexed_db_info.size, | 175 ui::FormatBytes(indexed_db_info.size, |
| 175 GetByteDisplayUnits(indexed_db_info.size), | 176 ui::DATA_UNITS_NATURAL, |
| 176 true)); | 177 true)); |
| 177 dict->SetString(kKeyModified, UTF16ToUTF8( | 178 dict->SetString(kKeyModified, UTF16ToUTF8( |
| 178 base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified))); | 179 base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified))); |
| 179 | 180 |
| 180 break; | 181 break; |
| 181 } | 182 } |
| 182 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: { | 183 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: { |
| 183 dict->SetString(kKeyType, "file_system"); | 184 dict->SetString(kKeyType, "file_system"); |
| 184 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); | 185 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON"); |
| 185 | 186 |
| 186 const BrowsingDataFileSystemHelper::FileSystemInfo& file_system_info = | 187 const BrowsingDataFileSystemHelper::FileSystemInfo& file_system_info = |
| 187 *node.GetDetailedInfo().file_system_info; | 188 *node.GetDetailedInfo().file_system_info; |
| 188 | 189 |
| 189 dict->SetString(kKeyOrigin, file_system_info.origin.spec()); | 190 dict->SetString(kKeyOrigin, file_system_info.origin.spec()); |
| 190 dict->SetString(kKeyPersistent, | 191 dict->SetString(kKeyPersistent, |
| 191 file_system_info.has_persistent ? | 192 file_system_info.has_persistent ? |
| 192 UTF16ToUTF8(FormatBytes( | 193 UTF16ToUTF8(ui::FormatBytes( |
| 193 file_system_info.usage_persistent, | 194 file_system_info.usage_persistent, |
| 194 GetByteDisplayUnits( | 195 ui::DATA_UNITS_NATURAL, |
| 195 file_system_info.usage_persistent), | |
| 196 true)) : | 196 true)) : |
| 197 l10n_util::GetStringUTF8( | 197 l10n_util::GetStringUTF8( |
| 198 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); | 198 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); |
| 199 dict->SetString(kKeyTemporary, | 199 dict->SetString(kKeyTemporary, |
| 200 file_system_info.has_temporary ? | 200 file_system_info.has_temporary ? |
| 201 UTF16ToUTF8(FormatBytes( | 201 UTF16ToUTF8(ui::FormatBytes( |
| 202 file_system_info.usage_temporary, | 202 file_system_info.usage_temporary, |
| 203 GetByteDisplayUnits( | 203 ui::DATA_UNITS_NATURAL, |
| 204 file_system_info.usage_temporary), | |
| 205 true)) : | 204 true)) : |
| 206 l10n_util::GetStringUTF8( | 205 l10n_util::GetStringUTF8( |
| 207 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); | 206 IDS_COOKIES_FILE_SYSTEM_USAGE_NONE)); |
| 208 break; | 207 break; |
| 209 } | 208 } |
| 210 default: | 209 default: |
| 211 #if defined(OS_MACOSX) | 210 #if defined(OS_MACOSX) |
| 212 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); | 211 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); |
| 213 #endif | 212 #endif |
| 214 break; | 213 break; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 243 if (child_index == -1) | 242 if (child_index == -1) |
| 244 break; | 243 break; |
| 245 | 244 |
| 246 parent = child; | 245 parent = child; |
| 247 } | 246 } |
| 248 | 247 |
| 249 return child_index >= 0 ? child : NULL; | 248 return child_index >= 0 ? child : NULL; |
| 250 } | 249 } |
| 251 | 250 |
| 252 } // namespace cookies_tree_model_util | 251 } // namespace cookies_tree_model_util |
| OLD | NEW |