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 kKeyProtectedByApps[] = "protectedByApps"; |
28 const char kKeyName[] = "name"; | 29 const char kKeyName[] = "name"; |
29 const char kKeyContent[] = "content"; | 30 const char kKeyContent[] = "content"; |
30 const char kKeyDomain[] = "domain"; | 31 const char kKeyDomain[] = "domain"; |
31 const char kKeyPath[] = "path"; | 32 const char kKeyPath[] = "path"; |
32 const char kKeySendFor[] = "sendfor"; | 33 const char kKeySendFor[] = "sendfor"; |
33 const char kKeyAccessibleToScript[] = "accessibleToScript"; | 34 const char kKeyAccessibleToScript[] = "accessibleToScript"; |
34 const char kKeyDesc[] = "desc"; | 35 const char kKeyDesc[] = "desc"; |
35 const char kKeySize[] = "size"; | 36 const char kKeySize[] = "size"; |
36 const char kKeyOrigin[] = "origin"; | 37 const char kKeyOrigin[] = "origin"; |
37 const char kKeyManifest[] = "manifest"; | 38 const char kKeyManifest[] = "manifest"; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 86 |
86 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( | 87 bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( |
87 const CookieTreeNode& node, | 88 const CookieTreeNode& node, |
88 base::DictionaryValue* dict) { | 89 base::DictionaryValue* dict) { |
89 // Use node's address as an id for WebUI to look it up. | 90 // Use node's address as an id for WebUI to look it up. |
90 dict->SetString(kKeyId, GetTreeNodeId(&node)); | 91 dict->SetString(kKeyId, GetTreeNodeId(&node)); |
91 dict->SetString(kKeyTitle, node.GetTitle()); | 92 dict->SetString(kKeyTitle, node.GetTitle()); |
92 dict->SetBoolean(kKeyHasChildren, !node.empty()); | 93 dict->SetBoolean(kKeyHasChildren, !node.empty()); |
93 | 94 |
94 switch (node.GetDetailedInfo().node_type) { | 95 switch (node.GetDetailedInfo().node_type) { |
95 case CookieTreeNode::DetailedInfo::TYPE_ORIGIN: { | 96 case CookieTreeNode::DetailedInfo::TYPE_HOST: { |
96 dict->SetString(kKeyType, "origin"); | 97 dict->SetString(kKeyType, "origin"); |
97 #if defined(OS_MACOSX) | 98 #if defined(OS_MACOSX) |
98 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); | 99 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); |
99 #endif | 100 #endif |
100 break; | 101 break; |
101 } | 102 } |
102 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: { | 103 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: { |
103 dict->SetString(kKeyType, "cookie"); | 104 dict->SetString(kKeyType, "cookie"); |
104 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_ICON"); | 105 dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_ICON"); |
105 | 106 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 base::TimeFormatFriendlyDateAndTime( | 250 base::TimeFormatFriendlyDateAndTime( |
250 server_bound_cert.expiration_time()))); | 251 server_bound_cert.expiration_time()))); |
251 break; | 252 break; |
252 } | 253 } |
253 default: | 254 default: |
254 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
255 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); | 256 dict->SetString(kKeyIcon, "chrome://theme/IDR_BOOKMARK_BAR_FOLDER"); |
256 #endif | 257 #endif |
257 break; | 258 break; |
258 } | 259 } |
| 260 const ExtensionSet* protecting_apps = |
| 261 node.GetModel()->ExtensionsProtectingNode(node); |
| 262 if (protecting_apps && !protecting_apps->is_empty()) { |
| 263 base::ListValue* app_infos = new base::ListValue; |
| 264 for (ExtensionSet::const_iterator it = |
| 265 protecting_apps->begin(); |
| 266 it != protecting_apps->end(); ++it) { |
| 267 base::DictionaryValue* app_info = new base::DictionaryValue(); |
| 268 app_info->SetString(kKeyId, (*it)->id()); |
| 269 app_info->SetString(kKeyName, (*it)->name()); |
| 270 app_infos->Append(app_info); |
| 271 } |
| 272 dict->Set(kKeyProtectedByApps, app_infos); |
| 273 } |
259 return true; | 274 return true; |
260 } | 275 } |
261 | 276 |
262 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, | 277 void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent, |
263 int start, | 278 int start, |
264 int count, | 279 int count, |
265 base::ListValue* nodes) { | 280 base::ListValue* nodes) { |
266 for (int i = 0; i < count; ++i) { | 281 for (int i = 0; i < count; ++i) { |
267 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue); | 282 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue); |
268 const CookieTreeNode* child = parent->GetChild(start + i); | 283 const CookieTreeNode* child = parent->GetChild(start + i); |
(...skipping 21 matching lines...) Expand all Loading... |
290 child = id_map_.Lookup(node_id); | 305 child = id_map_.Lookup(node_id); |
291 child_index = parent->GetIndexOf(child); | 306 child_index = parent->GetIndexOf(child); |
292 if (child_index == -1) | 307 if (child_index == -1) |
293 break; | 308 break; |
294 | 309 |
295 parent = child; | 310 parent = child; |
296 } | 311 } |
297 | 312 |
298 return child_index >= 0 ? child : NULL; | 313 return child_index >= 0 ? child : NULL; |
299 } | 314 } |
OLD | NEW |