Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: chrome/browser/cocoa/cookie_tree_node.mm

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

Powered by Google App Engine
This is Rietveld 408576698