| 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 #ifndef CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| 6 #define CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "app/tree_node_model.h" |
| 12 #include "base/scoped_ptr.h" |
| 13 #include "net/base/cookie_monster.h" |
| 14 |
| 15 class CookiesTreeModel; |
| 16 class CookieTreeCookieNode; |
| 17 class CookieTreeCookiesNode; |
| 18 class CookieTreeOriginNode; |
| 19 class Profile; |
| 20 |
| 21 // CookieTreeNode ------------------------------------------------------------- |
| 22 // The base node type in the Cookies + Local Storage options view, from which |
| 23 // all other types are derived. Specialized from TreeNode in that it has a |
| 24 // notion of deleting objects stored in the profile, and being able to have |
| 25 // its children do the same. |
| 26 class CookieTreeNode : public TreeNode<CookieTreeNode> { |
| 27 public: |
| 28 // Used to pull out information for the InfoView (the details display below |
| 29 // the tree control.) |
| 30 struct DetailedInfo { |
| 31 // NodeType corresponds to the various CookieTreeNode types. |
| 32 enum NodeType { |
| 33 TYPE_ROOT, // This is used for CookieTreeRootNode nodes. |
| 34 TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes. |
| 35 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes. |
| 36 TYPE_COOKIE // This is used for CookieTreeCookieNode nodes. |
| 37 }; |
| 38 |
| 39 DetailedInfo(const std::wstring& origin, NodeType node_type, |
| 40 const net::CookieMonster::CookieListPair* cookie) |
| 41 : origin(origin), |
| 42 node_type(node_type), |
| 43 cookie(cookie) {} |
| 44 |
| 45 std::wstring origin; |
| 46 NodeType node_type; |
| 47 const net::CookieMonster::CookieListPair* cookie; |
| 48 }; |
| 49 |
| 50 CookieTreeNode() {} |
| 51 explicit CookieTreeNode(const std::wstring& title) |
| 52 : TreeNode<CookieTreeNode>(title) {} |
| 53 |
| 54 // Delete backend storage for this node, and any children nodes. (E.g. delete |
| 55 // the cookie from CookieMonster, clear the database, and so forth.) |
| 56 virtual void DeleteStoredObjects(); |
| 57 |
| 58 // Gets a pointer back to the associated model for the tree we are in. |
| 59 virtual CookiesTreeModel* GetModel() const; |
| 60 |
| 61 // Returns a struct with detailed information used to populate the details |
| 62 // part of the view. |
| 63 virtual DetailedInfo GetDetailedInfo() const = 0; |
| 64 |
| 65 private: |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode); |
| 68 }; |
| 69 |
| 70 // CookieTreeRootNode --------------------------------------------------------- |
| 71 // The node at the root of the CookieTree that gets inserted into the view. |
| 72 class CookieTreeRootNode : public CookieTreeNode { |
| 73 public: |
| 74 explicit CookieTreeRootNode(CookiesTreeModel* model) : model_(model) {} |
| 75 virtual ~CookieTreeRootNode() {} |
| 76 |
| 77 CookieTreeOriginNode* GetOrCreateOriginNode(const std::wstring& origin); |
| 78 |
| 79 // CookieTreeNode methods: |
| 80 virtual CookiesTreeModel* GetModel() const { return model_; } |
| 81 virtual DetailedInfo GetDetailedInfo() const { |
| 82 return DetailedInfo(std::wstring(), DetailedInfo::TYPE_ROOT, NULL); |
| 83 } |
| 84 private: |
| 85 |
| 86 CookiesTreeModel* model_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode); |
| 89 }; |
| 90 |
| 91 // CookieTreeOriginNode ------------------------------------------------------- |
| 92 class CookieTreeOriginNode : public CookieTreeNode { |
| 93 public: |
| 94 explicit CookieTreeOriginNode(const std::wstring& origin) |
| 95 : CookieTreeNode(origin), cookies_child_(NULL) {} |
| 96 virtual ~CookieTreeOriginNode() {} |
| 97 |
| 98 // CookieTreeNode methods: |
| 99 virtual DetailedInfo GetDetailedInfo() const { |
| 100 return DetailedInfo(GetTitle(), DetailedInfo::TYPE_ORIGIN, NULL); |
| 101 } |
| 102 |
| 103 // CookieTreeOriginNode methods: |
| 104 CookieTreeCookiesNode* GetOrCreateCookiesNode(); |
| 105 private: |
| 106 |
| 107 // A pointer to the COOKIES node. Eventually we will also have database, |
| 108 // appcache, local storage, ..., and when we build up the tree we need to |
| 109 // quickly get a reference to the COOKIES node to add children. Checking each |
| 110 // child and interrogating them to see if they are a COOKIES, APPCACHES, |
| 111 // DATABASES etc node seems less preferable than storing an extra pointer per |
| 112 // origin. |
| 113 CookieTreeCookiesNode* cookies_child_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(CookieTreeOriginNode); |
| 116 }; |
| 117 |
| 118 // CookieTreeCookiesNode ------------------------------------------------------ |
| 119 class CookieTreeCookiesNode : public CookieTreeNode { |
| 120 public: |
| 121 CookieTreeCookiesNode(); |
| 122 virtual ~CookieTreeCookiesNode() {} |
| 123 |
| 124 // CookieTreeNode methods: |
| 125 virtual DetailedInfo GetDetailedInfo() const { |
| 126 return DetailedInfo(GetParent()->GetTitle(), DetailedInfo::TYPE_COOKIES, |
| 127 NULL); |
| 128 } |
| 129 |
| 130 // CookieTreeCookiesNode methods: |
| 131 void AddCookieNode(CookieTreeCookieNode* child); |
| 132 |
| 133 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode); |
| 135 }; |
| 136 |
| 137 class CookieTreeCookieNode : public CookieTreeNode { |
| 138 public: |
| 139 friend class CookieTreeCookiesNode; |
| 140 |
| 141 // Does not take ownership of cookie, and cookie should remain valid at least |
| 142 // as long as the CookieTreeCookieNode is valid. |
| 143 explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); |
| 144 virtual ~CookieTreeCookieNode() {} |
| 145 |
| 146 // CookieTreeNode methods: |
| 147 virtual void DeleteStoredObjects(); |
| 148 virtual DetailedInfo GetDetailedInfo() const { |
| 149 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
| 150 DetailedInfo::TYPE_COOKIE, cookie_); |
| 151 } |
| 152 |
| 153 private: |
| 154 // Comparator functor, takes CookieTreeNode so that we can use it in |
| 155 // lower_bound using children()'s iterators, which are CookieTreeNode*. |
| 156 class CookieNodeComparator { |
| 157 public: |
| 158 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); |
| 159 }; |
| 160 |
| 161 // Cookie_ is not owned by the node, and is expected to remain valid as long |
| 162 // as the CookieTreeCookieNode is valid. |
| 163 net::CookieMonster::CookieListPair* cookie_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); |
| 166 }; |
| 167 |
| 168 |
| 169 class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { |
| 170 public: |
| 171 explicit CookiesTreeModel(Profile* profile); |
| 172 virtual ~CookiesTreeModel() {} |
| 173 |
| 174 // TreeModel methods: |
| 175 // Returns the set of icons for the nodes in the tree. You only need override |
| 176 // this if you don't want to use the default folder icons. |
| 177 virtual void GetIcons(std::vector<SkBitmap>* icons); |
| 178 |
| 179 // Returns the index of the icon to use for |node|. Return -1 to use the |
| 180 // default icon. The index is relative to the list of icons returned from |
| 181 // GetIcons. |
| 182 virtual int GetIconIndex(TreeModelNode* node); |
| 183 |
| 184 // CookiesTreeModel methods: |
| 185 void DeleteCookie(const net::CookieMonster::CookieListPair& cookie); |
| 186 void DeleteAllCookies(); |
| 187 void DeleteCookieNode(CookieTreeCookieNode* cookie_node); |
| 188 |
| 189 private: |
| 190 enum CookieIconIndex { |
| 191 ORIGIN = 0, |
| 192 COOKIE = 1 |
| 193 }; |
| 194 typedef net::CookieMonster::CookieList CookieList; |
| 195 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; |
| 196 |
| 197 void LoadCookies(); |
| 198 |
| 199 // The profile from which this model sources cookies. |
| 200 Profile* profile_; |
| 201 CookieList all_cookies_; |
| 202 |
| 203 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel); |
| 204 }; |
| 205 |
| 206 #endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| 207 |
| OLD | NEW |