| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 5 #ifndef CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| 6 #define CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 6 #define CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "app/tree_node_model.h" | 11 #include "app/tree_node_model.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 13 #include "net/base/cookie_monster.h" | 14 #include "net/base/cookie_monster.h" |
| 14 | 15 |
| 15 class CookiesTreeModel; | 16 class CookiesTreeModel; |
| 17 class CookieTreeLocalStorageNode; |
| 18 class CookieTreeLocalStoragesNode; |
| 16 class CookieTreeCookieNode; | 19 class CookieTreeCookieNode; |
| 17 class CookieTreeCookiesNode; | 20 class CookieTreeCookiesNode; |
| 18 class CookieTreeOriginNode; | 21 class CookieTreeOriginNode; |
| 19 class Profile; | 22 class Profile; |
| 20 | 23 |
| 21 // CookieTreeNode ------------------------------------------------------------- | 24 // CookieTreeNode ------------------------------------------------------------- |
| 22 // The base node type in the Cookies + Local Storage options view, from which | 25 // 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 | 26 // 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 | 27 // notion of deleting objects stored in the profile, and being able to have |
| 25 // its children do the same. | 28 // its children do the same. |
| 26 class CookieTreeNode : public TreeNode<CookieTreeNode> { | 29 class CookieTreeNode : public TreeNode<CookieTreeNode> { |
| 27 public: | 30 public: |
| 28 // Used to pull out information for the InfoView (the details display below | 31 // Used to pull out information for the InfoView (the details display below |
| 29 // the tree control.) | 32 // the tree control.) |
| 30 struct DetailedInfo { | 33 struct DetailedInfo { |
| 31 // NodeType corresponds to the various CookieTreeNode types. | 34 // NodeType corresponds to the various CookieTreeNode types. |
| 32 enum NodeType { | 35 enum NodeType { |
| 33 TYPE_ROOT, // This is used for CookieTreeRootNode nodes. | 36 TYPE_ROOT, // This is used for CookieTreeRootNode nodes. |
| 34 TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes. | 37 TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes. |
| 35 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes. | 38 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes. |
| 36 TYPE_COOKIE // This is used for CookieTreeCookieNode nodes. | 39 TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes. |
| 40 TYPE_LOCAL_STORAGES, // This is used for CookieTreeLocalStoragesNode. |
| 41 TYPE_LOCAL_STORAGE, // This is used for CookieTreeLocalStorageNode. |
| 37 }; | 42 }; |
| 38 | 43 |
| 39 DetailedInfo(const std::wstring& origin, NodeType node_type, | 44 DetailedInfo(const std::wstring& origin, NodeType node_type, |
| 40 const net::CookieMonster::CookieListPair* cookie) | 45 const net::CookieMonster::CookieListPair* cookie, |
| 46 const BrowsingDataLocalStorageHelper::LocalStorageInfo* |
| 47 local_storage_info) |
| 41 : origin(origin), | 48 : origin(origin), |
| 42 node_type(node_type), | 49 node_type(node_type), |
| 43 cookie(cookie) {} | 50 cookie(cookie), |
| 51 local_storage_info(local_storage_info) { |
| 52 if (node_type == TYPE_LOCAL_STORAGE) |
| 53 DCHECK(local_storage_info); |
| 54 } |
| 44 | 55 |
| 45 std::wstring origin; | 56 std::wstring origin; |
| 46 NodeType node_type; | 57 NodeType node_type; |
| 47 const net::CookieMonster::CookieListPair* cookie; | 58 const net::CookieMonster::CookieListPair* cookie; |
| 59 const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info; |
| 48 }; | 60 }; |
| 49 | 61 |
| 50 CookieTreeNode() {} | 62 CookieTreeNode() {} |
| 51 explicit CookieTreeNode(const std::wstring& title) | 63 explicit CookieTreeNode(const std::wstring& title) |
| 52 : TreeNode<CookieTreeNode>(title) {} | 64 : TreeNode<CookieTreeNode>(title) {} |
| 53 | 65 |
| 54 // Delete backend storage for this node, and any children nodes. (E.g. delete | 66 // Delete backend storage for this node, and any children nodes. (E.g. delete |
| 55 // the cookie from CookieMonster, clear the database, and so forth.) | 67 // the cookie from CookieMonster, clear the database, and so forth.) |
| 56 virtual void DeleteStoredObjects(); | 68 virtual void DeleteStoredObjects(); |
| 57 | 69 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 class CookieTreeRootNode : public CookieTreeNode { | 84 class CookieTreeRootNode : public CookieTreeNode { |
| 73 public: | 85 public: |
| 74 explicit CookieTreeRootNode(CookiesTreeModel* model) : model_(model) {} | 86 explicit CookieTreeRootNode(CookiesTreeModel* model) : model_(model) {} |
| 75 virtual ~CookieTreeRootNode() {} | 87 virtual ~CookieTreeRootNode() {} |
| 76 | 88 |
| 77 CookieTreeOriginNode* GetOrCreateOriginNode(const std::wstring& origin); | 89 CookieTreeOriginNode* GetOrCreateOriginNode(const std::wstring& origin); |
| 78 | 90 |
| 79 // CookieTreeNode methods: | 91 // CookieTreeNode methods: |
| 80 virtual CookiesTreeModel* GetModel() const { return model_; } | 92 virtual CookiesTreeModel* GetModel() const { return model_; } |
| 81 virtual DetailedInfo GetDetailedInfo() const { | 93 virtual DetailedInfo GetDetailedInfo() const { |
| 82 return DetailedInfo(std::wstring(), DetailedInfo::TYPE_ROOT, NULL); | 94 return DetailedInfo(std::wstring(), DetailedInfo::TYPE_ROOT, NULL, NULL); |
| 83 } | 95 } |
| 84 private: | 96 private: |
| 85 | 97 |
| 86 CookiesTreeModel* model_; | 98 CookiesTreeModel* model_; |
| 87 | 99 |
| 88 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode); | 100 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode); |
| 89 }; | 101 }; |
| 90 | 102 |
| 91 // CookieTreeOriginNode ------------------------------------------------------- | 103 // CookieTreeOriginNode ------------------------------------------------------- |
| 92 class CookieTreeOriginNode : public CookieTreeNode { | 104 class CookieTreeOriginNode : public CookieTreeNode { |
| 93 public: | 105 public: |
| 94 explicit CookieTreeOriginNode(const std::wstring& origin) | 106 explicit CookieTreeOriginNode(const std::wstring& origin) |
| 95 : CookieTreeNode(origin), cookies_child_(NULL) {} | 107 : CookieTreeNode(origin), cookies_child_(NULL), |
| 108 local_storages_child_(NULL) {} |
| 96 virtual ~CookieTreeOriginNode() {} | 109 virtual ~CookieTreeOriginNode() {} |
| 97 | 110 |
| 98 // CookieTreeNode methods: | 111 // CookieTreeNode methods: |
| 99 virtual DetailedInfo GetDetailedInfo() const { | 112 virtual DetailedInfo GetDetailedInfo() const { |
| 100 return DetailedInfo(GetTitle(), DetailedInfo::TYPE_ORIGIN, NULL); | 113 return DetailedInfo(GetTitle(), DetailedInfo::TYPE_ORIGIN, NULL, NULL); |
| 101 } | 114 } |
| 102 | 115 |
| 103 // CookieTreeOriginNode methods: | 116 // CookieTreeOriginNode methods: |
| 104 CookieTreeCookiesNode* GetOrCreateCookiesNode(); | 117 CookieTreeCookiesNode* GetOrCreateCookiesNode(); |
| 118 CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode(); |
| 119 |
| 105 private: | 120 private: |
| 106 | 121 |
| 107 // A pointer to the COOKIES node. Eventually we will also have database, | 122 // 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 | 123 // 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 | 124 // 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, | 125 // 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 | 126 // DATABASES etc node seems less preferable than storing an extra pointer per |
| 112 // origin. | 127 // origin. |
| 113 CookieTreeCookiesNode* cookies_child_; | 128 CookieTreeCookiesNode* cookies_child_; |
| 129 CookieTreeLocalStoragesNode* local_storages_child_; |
| 114 | 130 |
| 115 DISALLOW_COPY_AND_ASSIGN(CookieTreeOriginNode); | 131 DISALLOW_COPY_AND_ASSIGN(CookieTreeOriginNode); |
| 116 }; | 132 }; |
| 117 | 133 |
| 118 // CookieTreeCookiesNode ------------------------------------------------------ | 134 // CookieTreeCookiesNode ------------------------------------------------------ |
| 119 class CookieTreeCookiesNode : public CookieTreeNode { | 135 class CookieTreeCookiesNode : public CookieTreeNode { |
| 120 public: | 136 public: |
| 121 CookieTreeCookiesNode(); | 137 CookieTreeCookiesNode(); |
| 122 virtual ~CookieTreeCookiesNode() {} | 138 virtual ~CookieTreeCookiesNode() {} |
| 123 | 139 |
| 124 // CookieTreeNode methods: | 140 // CookieTreeNode methods: |
| 125 virtual DetailedInfo GetDetailedInfo() const { | 141 virtual DetailedInfo GetDetailedInfo() const { |
| 126 return DetailedInfo(GetParent()->GetTitle(), DetailedInfo::TYPE_COOKIES, | 142 return DetailedInfo(GetParent()->GetTitle(), DetailedInfo::TYPE_COOKIES, |
| 127 NULL); | 143 NULL, NULL); |
| 128 } | 144 } |
| 129 | 145 |
| 130 // CookieTreeCookiesNode methods: | 146 // CookieTreeCookiesNode methods: |
| 131 void AddCookieNode(CookieTreeCookieNode* child); | 147 void AddCookieNode(CookieTreeCookieNode* child); |
| 132 | 148 |
| 133 private: | 149 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode); | 150 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode); |
| 135 }; | 151 }; |
| 136 | 152 |
| 137 class CookieTreeCookieNode : public CookieTreeNode { | 153 class CookieTreeCookieNode : public CookieTreeNode { |
| 138 public: | 154 public: |
| 139 friend class CookieTreeCookiesNode; | 155 friend class CookieTreeCookiesNode; |
| 140 | 156 |
| 141 // Does not take ownership of cookie, and cookie should remain valid at least | 157 // Does not take ownership of cookie, and cookie should remain valid at least |
| 142 // as long as the CookieTreeCookieNode is valid. | 158 // as long as the CookieTreeCookieNode is valid. |
| 143 explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); | 159 explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); |
| 144 virtual ~CookieTreeCookieNode() {} | 160 virtual ~CookieTreeCookieNode() {} |
| 145 | 161 |
| 146 // CookieTreeNode methods: | 162 // CookieTreeNode methods: |
| 147 virtual void DeleteStoredObjects(); | 163 virtual void DeleteStoredObjects(); |
| 148 virtual DetailedInfo GetDetailedInfo() const { | 164 virtual DetailedInfo GetDetailedInfo() const { |
| 149 return DetailedInfo(GetParent()->GetParent()->GetTitle(), | 165 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
| 150 DetailedInfo::TYPE_COOKIE, cookie_); | 166 DetailedInfo::TYPE_COOKIE, cookie_, NULL); |
| 151 } | 167 } |
| 152 | 168 |
| 153 private: | 169 private: |
| 154 // Comparator functor, takes CookieTreeNode so that we can use it in | 170 // Comparator functor, takes CookieTreeNode so that we can use it in |
| 155 // lower_bound using children()'s iterators, which are CookieTreeNode*. | 171 // lower_bound using children()'s iterators, which are CookieTreeNode*. |
| 156 class CookieNodeComparator { | 172 class CookieNodeComparator { |
| 157 public: | 173 public: |
| 158 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); | 174 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); |
| 159 }; | 175 }; |
| 160 | 176 |
| 161 // Cookie_ is not owned by the node, and is expected to remain valid as long | 177 // Cookie_ is not owned by the node, and is expected to remain valid as long |
| 162 // as the CookieTreeCookieNode is valid. | 178 // as the CookieTreeCookieNode is valid. |
| 163 net::CookieMonster::CookieListPair* cookie_; | 179 net::CookieMonster::CookieListPair* cookie_; |
| 164 | 180 |
| 165 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); | 181 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); |
| 166 }; | 182 }; |
| 167 | 183 |
| 184 // CookieTreeLocalStoragesNode ------------------------------------------------- |
| 185 class CookieTreeLocalStoragesNode : public CookieTreeNode { |
| 186 public: |
| 187 CookieTreeLocalStoragesNode(); |
| 188 virtual ~CookieTreeLocalStoragesNode() {} |
| 189 |
| 190 // CookieTreeNode methods: |
| 191 virtual DetailedInfo GetDetailedInfo() const { |
| 192 return DetailedInfo(GetParent()->GetTitle(), |
| 193 DetailedInfo::TYPE_LOCAL_STORAGES, |
| 194 NULL, |
| 195 NULL); |
| 196 } |
| 197 |
| 198 // CookieTreeStoragesNode methods: |
| 199 void AddLocalStorageNode(CookieTreeLocalStorageNode* child); |
| 200 |
| 201 private: |
| 202 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode); |
| 203 }; |
| 204 |
| 205 class CookieTreeLocalStorageNode : public CookieTreeNode { |
| 206 public: |
| 207 friend class CookieTreeLocalStoragesNode; |
| 208 |
| 209 // Does not take ownership of local_storage_info, and local_storage_info |
| 210 // should remain valid at least as long as the CookieTreeStorageNode is valid. |
| 211 explicit CookieTreeLocalStorageNode( |
| 212 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info); |
| 213 virtual ~CookieTreeLocalStorageNode() {} |
| 214 |
| 215 // CookieTreeStorageNode methods: |
| 216 virtual void DeleteStoredObjects(); |
| 217 virtual DetailedInfo GetDetailedInfo() const { |
| 218 return DetailedInfo(GetParent()->GetParent()->GetTitle(), |
| 219 DetailedInfo::TYPE_LOCAL_STORAGE, NULL, |
| 220 local_storage_info_); |
| 221 } |
| 222 |
| 223 private: |
| 224 // Comparator functor, takes CookieTreeNode so that we can use it in |
| 225 // lower_bound using children()'s iterators, which are CookieTreeNode*. |
| 226 class CookieNodeComparator { |
| 227 public: |
| 228 bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs); |
| 229 }; |
| 230 |
| 231 // local_storage_info_ is not owned by the node, and is expected to remain |
| 232 // valid as long as the CookieTreeLocalStorageNode is valid. |
| 233 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info_; |
| 234 |
| 235 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode); |
| 236 }; |
| 168 | 237 |
| 169 class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { | 238 class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { |
| 170 public: | 239 public: |
| 171 explicit CookiesTreeModel(Profile* profile); | 240 CookiesTreeModel( |
| 172 virtual ~CookiesTreeModel() {} | 241 Profile* profile, |
| 242 BrowsingDataLocalStorageHelper* browsing_data_local_storage_helper); |
| 243 virtual ~CookiesTreeModel(); |
| 173 | 244 |
| 174 // TreeModel methods: | 245 // TreeModel methods: |
| 175 // Returns the set of icons for the nodes in the tree. You only need override | 246 // 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. | 247 // this if you don't want to use the default folder icons. |
| 177 virtual void GetIcons(std::vector<SkBitmap>* icons); | 248 virtual void GetIcons(std::vector<SkBitmap>* icons); |
| 178 | 249 |
| 179 // Returns the index of the icon to use for |node|. Return -1 to use the | 250 // 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 | 251 // default icon. The index is relative to the list of icons returned from |
| 181 // GetIcons. | 252 // GetIcons. |
| 182 virtual int GetIconIndex(TreeModelNode* node); | 253 virtual int GetIconIndex(TreeModelNode* node); |
| 183 | 254 |
| 184 // CookiesTreeModel methods: | 255 // CookiesTreeModel methods: |
| 185 void DeleteCookie(const net::CookieMonster::CookieListPair& cookie); | 256 void DeleteCookie(const net::CookieMonster::CookieListPair& cookie); |
| 186 void DeleteAllCookies(); | 257 void DeleteAllCookies(); |
| 187 void DeleteCookieNode(CookieTreeNode* cookie_node); | 258 void DeleteCookieNode(CookieTreeNode* cookie_node); |
| 259 void DeleteLocalStorage(const FilePath& file_path); |
| 260 void DeleteAllLocalStorage(); |
| 188 | 261 |
| 189 // Filter the origins to only display matched results. | 262 // Filter the origins to only display matched results. |
| 190 void UpdateSearchResults(const std::wstring& filter); | 263 void UpdateSearchResults(const std::wstring& filter); |
| 191 | 264 |
| 192 private: | 265 private: |
| 193 enum CookieIconIndex { | 266 enum CookieIconIndex { |
| 194 ORIGIN = 0, | 267 ORIGIN = 0, |
| 195 COOKIE = 1 | 268 COOKIE = 1, |
| 269 LOCAL_STORAGE = 2, |
| 196 }; | 270 }; |
| 197 typedef net::CookieMonster::CookieList CookieList; | 271 typedef net::CookieMonster::CookieList CookieList; |
| 198 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; | 272 typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; |
| 273 typedef std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> |
| 274 LocalStorageInfoList; |
| 199 | 275 |
| 200 void LoadCookies(); | 276 void LoadCookies(); |
| 201 void LoadCookiesWithFilter(const std::wstring& filter); | 277 void LoadCookiesWithFilter(const std::wstring& filter); |
| 202 | 278 |
| 279 void OnStorageModelInfoLoaded(const LocalStorageInfoList& local_storage_info); |
| 280 |
| 281 void PopulateLocalStorageInfoWithFilter(const std::wstring& filter); |
| 282 |
| 203 // The profile from which this model sources cookies. | 283 // The profile from which this model sources cookies. |
| 204 Profile* profile_; | 284 Profile* profile_; |
| 205 CookieList all_cookies_; | 285 CookieList all_cookies_; |
| 206 | 286 |
| 287 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_; |
| 288 LocalStorageInfoList local_storage_info_list_; |
| 289 |
| 207 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel); | 290 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel); |
| 208 }; | 291 }; |
| 209 | 292 |
| 210 #endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_ | 293 #endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_ |
| OLD | NEW |