blob: a4642a4087d1ef49a9c0fe7a760444308ede8d83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/cocoa/cookie_tree_node.h"
#include "app/l10n_util_mac.h"
#import "base/i18n/time_formatting.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
#include "grit/generated_resources.h"
@implementation CocoaCookieTreeNode
- (id)initWithNode:(CookieTreeNode*)node {
if ((self = [super init])) {
DCHECK(node);
treeNode_ = node;
[self rebuild];
}
return self;
}
- (void)rebuild {
title_.reset([base::SysWideToNSString(treeNode_->GetTitle()) retain]);
children_.reset();
nodeType_ = kCocoaCookieTreeNodeTypeFolder;
CookieTreeNode::DetailedInfo info = treeNode_->GetDetailedInfo();
CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type;
if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) {
nodeType_ = kCocoaCookieTreeNodeTypeCookie;
net::CookieMonster::CanonicalCookie cookie = info.cookie->second;
name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]);
title_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]);
content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]);
path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]);
domain_.reset([base::SysWideToNSString(info.origin) retain]);
if (cookie.DoesExpire()) {
expires_.reset([base::SysWideToNSString(
base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) retain]);
} else {
expires_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]);
}
created_.reset([base::SysWideToNSString(
base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) retain]);
if (cookie.IsSecure()) {
sendFor_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]);
} else {
sendFor_.reset([l10n_util::GetNSStringWithFixup(
IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]);
}
} else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE) {
const BrowsingDataLocalStorageHelper::LocalStorageInfo* storageInfo =
info.local_storage_info;
nodeType_ = kCocoaCookieTreeNodeTypeLocalStorage;
domain_.reset([base::SysUTF8ToNSString(storageInfo->origin) retain]);
fileSize_.reset([base::SysWideToNSString(FormatBytes(storageInfo->size,
GetByteDisplayUnits(storageInfo->size), true)) retain]);
lastModified_.reset([base::SysWideToNSString(
base::TimeFormatFriendlyDateAndTime(
storageInfo->last_modified)) retain]);
}
}
- (NSString*)title {
return title_.get();
}
- (CocoaCookieTreeNodeType)nodeType {
return nodeType_;
}
- (TreeModelNode*)treeNode {
return treeNode_;
}
- (NSMutableArray*)mutableChildren {
if (!children_.get()) {
const int childCount = treeNode_->GetChildCount();
children_.reset([[NSMutableArray alloc] initWithCapacity:childCount]);
for (int i = 0; i < childCount; ++i) {
CookieTreeNode* child = treeNode_->GetChild(i);
scoped_nsobject<CocoaCookieTreeNode> childNode(
[[CocoaCookieTreeNode alloc] initWithNode:child]);
[children_ addObject:childNode.get()];
}
}
return children_.get();
}
- (NSArray*)children {
return [self mutableChildren];
}
- (BOOL)isLeaf {
return nodeType_ != kCocoaCookieTreeNodeTypeFolder;
}
- (NSString*)description {
NSString* format =
@"<CocoaCookieTreeNode @ %p (title=%@, nodeType=%d, childCount=%u)";
return [NSString stringWithFormat:format, self, [self title],
[self nodeType], [[self children] count]];
}
#pragma mark Cookie Accessors
- (NSString*)name {
return name_.get();
}
- (NSString*)content {
return content_.get();
}
- (NSString*)domain {
return domain_.get();
}
- (NSString*)path {
return path_.get();
}
- (NSString*)sendFor {
return sendFor_.get();
}
- (NSString*)created {
return created_.get();
}
- (NSString*)expires {
return expires_.get();
}
#pragma mark Local Storage Accessors
- (NSString*)fileSize {
return fileSize_.get();
}
- (NSString*)lastModified {
return lastModified_.get();
}
@end
|