| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/cookie_tree_node.h" |
| 6 |
| 7 #include "app/l10n_util_mac.h" |
| 8 #import "base/i18n/time_formatting.h" |
| 9 #include "base/sys_string_conversions.h" |
| 10 #include "grit/generated_resources.h" |
| 11 |
| 12 @implementation CocoaCookieTreeNode |
| 13 |
| 14 - (id)initWithNode:(CookieTreeNode*)node { |
| 15 if ((self = [super init])) { |
| 16 DCHECK(node); |
| 17 treeNode_ = node; |
| 18 |
| 19 const int childCount = node->GetChildCount(); |
| 20 children_.reset([[NSMutableArray alloc] initWithCapacity:childCount]); |
| 21 for (int i = 0; i < childCount; ++i) { |
| 22 CookieTreeNode* child = node->GetChild(i); |
| 23 scoped_nsobject<CocoaCookieTreeNode> childNode( |
| 24 [[CocoaCookieTreeNode alloc] initWithNode:child]); |
| 25 [children_ addObject:childNode.get()]; |
| 26 } |
| 27 |
| 28 [self rebuild]; |
| 29 } |
| 30 return self; |
| 31 } |
| 32 |
| 33 - (void)rebuild { |
| 34 title_.reset([base::SysWideToNSString(treeNode_->GetTitle()) retain]); |
| 35 isCookie_ = NO; |
| 36 |
| 37 CookieTreeNode::DetailedInfo info = treeNode_->GetDetailedInfo(); |
| 38 if (info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { |
| 39 isCookie_ = YES; |
| 40 net::CookieMonster::CanonicalCookie cookie = info.cookie->second; |
| 41 |
| 42 name_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); |
| 43 title_.reset([base::SysUTF8ToNSString(cookie.Name()) retain]); |
| 44 content_.reset([base::SysUTF8ToNSString(cookie.Value()) retain]); |
| 45 path_.reset([base::SysUTF8ToNSString(cookie.Path()) retain]); |
| 46 domain_.reset([base::SysWideToNSString(info.origin) retain]); |
| 47 |
| 48 if (cookie.DoesExpire()) { |
| 49 expires_.reset([base::SysWideToNSString( |
| 50 base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) retain]); |
| 51 } else { |
| 52 expires_.reset([l10n_util::GetNSStringWithFixup( |
| 53 IDS_COOKIES_COOKIE_EXPIRES_SESSION) retain]); |
| 54 } |
| 55 |
| 56 created_.reset([base::SysWideToNSString( |
| 57 base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())) retain]); |
| 58 |
| 59 if (cookie.IsSecure()) { |
| 60 sendFor_.reset([l10n_util::GetNSStringWithFixup( |
| 61 IDS_COOKIES_COOKIE_SENDFOR_SECURE) retain]); |
| 62 } else { |
| 63 sendFor_.reset([l10n_util::GetNSStringWithFixup( |
| 64 IDS_COOKIES_COOKIE_SENDFOR_ANY) retain]); |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 69 - (BOOL)isLeaf { |
| 70 return (treeNode_->GetChildCount() == 0); |
| 71 } |
| 72 |
| 73 - (NSString*)title { |
| 74 return title_.get(); |
| 75 } |
| 76 |
| 77 - (NSMutableArray*)children { |
| 78 return children_.get(); |
| 79 } |
| 80 |
| 81 - (TreeModelNode*)treeNode { |
| 82 return treeNode_; |
| 83 } |
| 84 |
| 85 #pragma mark Cookie Accessors |
| 86 |
| 87 - (BOOL)isCookie { |
| 88 return isCookie_; |
| 89 } |
| 90 |
| 91 - (NSString*)name { |
| 92 return name_.get(); |
| 93 } |
| 94 |
| 95 - (NSString*)content { |
| 96 return content_.get(); |
| 97 } |
| 98 |
| 99 - (NSString*)domain { |
| 100 return domain_.get(); |
| 101 } |
| 102 |
| 103 - (NSString*)path { |
| 104 return path_.get(); |
| 105 } |
| 106 |
| 107 - (NSString*)sendFor { |
| 108 return sendFor_.get(); |
| 109 } |
| 110 |
| 111 - (NSString*)created { |
| 112 return created_.get(); |
| 113 } |
| 114 |
| 115 - (NSString*)expires { |
| 116 return expires_.get(); |
| 117 } |
| 118 |
| 119 @end |
| OLD | NEW |