1 // Copyright (c) 2011 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.
5 #import "chrome/browser/ui/cocoa/content_settings/cookie_tree_node.h"
7 #include "base/strings/sys_string_conversions.h"
9 @implementation CocoaCookieTreeNode
11 - (id)initWithNode:(CookieTreeNode*)node {
12 if ((self = [super init])) {
21 title_.reset([base::SysUTF16ToNSString(treeNode_->GetTitle()) retain]);
23 // The tree node assumes ownership of the cookie details object
24 details_.reset([[CocoaCookieDetails createFromCookieTreeNode:(treeNode_)]
32 - (CocoaCookieDetailsType)nodeType {
33 return [details_.get() type];
36 - (ui::TreeModelNode*)treeNode {
40 - (NSMutableArray*)mutableChildren {
41 if (!children_.get()) {
42 const int childCount = treeNode_->child_count();
43 children_.reset([[NSMutableArray alloc] initWithCapacity:childCount]);
44 for (int i = 0; i < childCount; ++i) {
45 CookieTreeNode* child = treeNode_->GetChild(i);
46 base::scoped_nsobject<CocoaCookieTreeNode> childNode(
47 [[CocoaCookieTreeNode alloc] initWithNode:child]);
48 [children_ addObject:childNode.get()];
51 return children_.get();
54 - (NSArray*)children {
55 return [self mutableChildren];
59 return [self nodeType] != kCocoaCookieDetailsTypeFolder;
62 - (NSString*)description {
64 @"<CocoaCookieTreeNode @ %p (title=%@, nodeType=%d, childCount=%u)";
65 return [NSString stringWithFormat:format, self, [self title],
66 [self nodeType], [[self children] count]];
69 - (CocoaCookieDetails*)details {