| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/cookies_tree_model.h" | 15 #include "chrome/browser/cookies_tree_model.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/text/bytes_formatting.h" | 18 #include "ui/base/text/bytes_formatting.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kKeyId[] = "id"; | 22 const char kKeyId[] = "id"; |
| 23 const char kKeyTitle[] = "title"; | 23 const char kKeyTitle[] = "title"; |
| 24 const char kKeyIcon[] = "icon"; | 24 const char kKeyIcon[] = "icon"; |
| 25 const char kKeyType[] = "type"; | 25 const char kKeyType[] = "type"; |
| 26 const char kKeyHasChildren[] = "hasChildren"; | 26 const char kKeyHasChildren[] = "hasChildren"; |
| 27 | 27 |
| 28 const char kKeyAppId[] = "appId"; | 28 const char kKeyAppId[] = "appId"; |
| 29 | 29 |
| 30 const char kKeyAppsProtectingThis[] = "appsProtectingThis"; |
| 30 const char kKeyName[] = "name"; | 31 const char kKeyName[] = "name"; |
| 31 const char kKeyContent[] = "content"; | 32 const char kKeyContent[] = "content"; |
| 32 const char kKeyDomain[] = "domain"; | 33 const char kKeyDomain[] = "domain"; |
| 33 const char kKeyPath[] = "path"; | 34 const char kKeyPath[] = "path"; |
| 34 const char kKeySendFor[] = "sendfor"; | 35 const char kKeySendFor[] = "sendfor"; |
| 35 const char kKeyAccessibleToScript[] = "accessibleToScript"; | 36 const char kKeyAccessibleToScript[] = "accessibleToScript"; |
| 36 const char kKeyDesc[] = "desc"; | 37 const char kKeyDesc[] = "desc"; |
| 37 const char kKeySize[] = "size"; | 38 const char kKeySize[] = "size"; |
| 38 const char kKeyOrigin[] = "origin"; | 39 const char kKeyOrigin[] = "origin"; |
| 39 const char kKeyManifest[] = "manifest"; | 40 const char kKeyManifest[] = "manifest"; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 88 |
| 88 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( | 89 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( |
| 89 const CookieTreeNode& node, | 90 const CookieTreeNode& node, |
| 90 base::DictionaryValue* dict) { | 91 base::DictionaryValue* dict) { |
| 91 // Use node's address as an id for WebUI to look it up. | 92 // Use node's address as an id for WebUI to look it up. |
| 92 dict->SetString(kKeyId, GetTreeNodeId(&node)); | 93 dict->SetString(kKeyId, GetTreeNodeId(&node)); |
| 93 dict->SetString(kKeyTitle, node.GetTitle()); | 94 dict->SetString(kKeyTitle, node.GetTitle()); |
| 94 dict->SetBoolean(kKeyHasChildren, !node.empty()); | 95 dict->SetBoolean(kKeyHasChildren, !node.empty()); |
| 95 | 96 |
| 96 switch (node.GetDetailedInfo().node_type) { | 97 switch (node.GetDetailedInfo().node_type) { |
| 97 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: { | 98 case CookieTreeNode::DetailedInfo::TYPE_HOST: { |
| 98 dict->SetString(kKeyType, "origin"); | 99 dict->SetString(kKeyType, "origin"); |
| 99 dict->SetString(kKeyAppId, node.GetDetailedInfo().app_id); | 100 dict->SetString(kKeyAppId, node.GetDetailedInfo().app_id); |
| 100 #if defined(OS_MACOSX) | 101 #if defined(OS_MACOSX) |
| 101 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); | 102 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); |
| 102 #endif | 103 #endif |
| 103 break; | 104 break; |
| 104 } | 105 } |
| 105 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: { | 106 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: { |
| 106 dict->SetString(kKeyType, "cookie"); | 107 dict->SetString(kKeyType, "cookie"); |
| 107 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_ICON"); | 108 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_ICON"); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 base::TimeFormatFriendlyDateAndTime( | 253 base::TimeFormatFriendlyDateAndTime( |
| 253 server_bound_cert.expiration_time()))); | 254 server_bound_cert.expiration_time()))); |
| 254 break; | 255 break; |
| 255 } | 256 } |
| 256 default: | 257 default: |
| 257 #if defined(OS_MACOSX) | 258 #if defined(OS_MACOSX) |
| 258 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); | 259 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); |
| 259 #endif | 260 #endif |
| 260 break; | 261 break; |
| 261 } | 262 } |
| 263 |
| 264 const ExtensionSet* protecting_apps = |
| 265 node.GetModel()->ExtensionsProtectingNode(node); |
| 266 if (protecting_apps && !protecting_apps->is_empty()) { |
| 267 base::ListValue* app_infos = new base::ListValue; |
| 268 for (ExtensionSet::const_iterator it = protecting_apps->begin(); |
| 269 it != protecting_apps->end(); ++it) { |
| 270 base::DictionaryValue* app_info = new base::DictionaryValue(); |
| 271 app_info->SetString(kKeyId, (*it)->id()); |
| 272 app_info->SetString(kKeyName, (*it)->name()); |
| 273 app_infos->Append(app_info); |
| 274 } |
| 275 dict->Set(kKeyAppsProtectingThis, app_infos); |
| 276 } |
| 277 |
| 262 return true; | 278 return true; |
| 263 } | 279 } |
| 264 | 280 |
| 265 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, | 281 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, |
| 266 int start, | 282 int start, |
| 267 int count, | 283 int count, |
| 268 base::ListValue* nodes) { | 284 base::ListValue* nodes) { |
| 269 for (int i = 0; i < count; ++i) { | 285 for (int i = 0; i < count; ++i) { |
| 270 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue); | 286 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue); |
| 271 const CookieTreeNode* child = parent->GetChild(start + i); | 287 const CookieTreeNode* child = parent->GetChild(start + i); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 293 child = id_map_.Lookup(node_id); | 309 child = id_map_.Lookup(node_id); |
| 294 child_index = parent->GetIndexOf(child); | 310 child_index = parent->GetIndexOf(child); |
| 295 if (child_index == -1) | 311 if (child_index == -1) |
| 296 break; | 312 break; |
| 297 | 313 |
| 298 parent = child; | 314 parent = child; |
| 299 } | 315 } |
| 300 | 316 |
| 301 return child_index >= 0 ? child : NULL; | 317 return child_index >= 0 ? child : NULL; |
| 302 } | 318 } |
| OLD | NEW |