| 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 #include "chrome/browser/cookies_tree_model.h" | 5 #include "chrome/browser/cookies_tree_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 break; | 217 break; |
| 218 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: | 218 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: |
| 219 return COOKIE; | 219 return COOKIE; |
| 220 break; | 220 break; |
| 221 default: | 221 default: |
| 222 return -1; | 222 return -1; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void CookiesTreeModel::LoadCookies() { | 226 void CookiesTreeModel::LoadCookies() { |
| 227 LoadCookiesWithFilter(L""); |
| 228 } |
| 229 |
| 230 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { |
| 227 // mmargh mmargh mmargh! | 231 // mmargh mmargh mmargh! |
| 228 | 232 |
| 229 // Since we are running on the UI thread don't call GetURLRequestContext(). | 233 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 230 net::CookieMonster* cookie_monster = | 234 net::CookieMonster* cookie_monster = |
| 231 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 235 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 232 | 236 |
| 233 all_cookies_ = cookie_monster->GetAllCookies(); | 237 all_cookies_ = cookie_monster->GetAllCookies(); |
| 234 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 238 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 235 for (CookieList::iterator it = all_cookies_.begin(); | 239 for (CookieList::iterator it = all_cookies_.begin(); |
| 236 it != all_cookies_.end(); | 240 it != all_cookies_.end(); |
| 237 ++it) { | 241 ++it) { |
| 238 // Get the origin cookie | 242 // Get the origin cookie |
| 239 CookieTreeOriginNode* origin = | 243 if (!filter.size() || |
| 240 root->GetOrCreateOriginNode(UTF8ToWide(it->first)); | 244 (UTF8ToWide(it->first).find(filter) != std::wstring::npos)) { |
| 241 CookieTreeCookiesNode* cookies_node = origin->GetOrCreateCookiesNode(); | 245 CookieTreeOriginNode* origin = |
| 242 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); | 246 root->GetOrCreateOriginNode(UTF8ToWide(it->first)); |
| 243 cookies_node->AddCookieNode(new_cookie); | 247 CookieTreeCookiesNode* cookies_node = origin->GetOrCreateCookiesNode(); |
| 248 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); |
| 249 cookies_node->AddCookieNode(new_cookie); |
| 250 } |
| 244 } | 251 } |
| 245 } | 252 } |
| 246 | 253 |
| 247 void CookiesTreeModel::DeleteCookie( | 254 void CookiesTreeModel::DeleteCookie( |
| 248 const net::CookieMonster::CookieListPair& cookie) { | 255 const net::CookieMonster::CookieListPair& cookie) { |
| 249 // notify CookieMonster that we should delete this cookie | 256 // notify CookieMonster that we should delete this cookie |
| 250 // Since we are running on the UI thread don't call GetURLRequestContext(). | 257 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 251 net::CookieMonster* monster = | 258 net::CookieMonster* monster = |
| 252 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 259 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 253 // We have stored a copy of all the cookies in the model, and our model is | 260 // We have stored a copy of all the cookies in the model, and our model is |
| 254 // never re-calculated. Thus, we just need to delete the nodes from our | 261 // never re-calculated. Thus, we just need to delete the nodes from our |
| 255 // model, and tell CookieMonster to delete the cookies. We can keep the | 262 // model, and tell CookieMonster to delete the cookies. We can keep the |
| 256 // vector storing the cookies in-tact and not delete from there (that would | 263 // vector storing the cookies in-tact and not delete from there (that would |
| 257 // invalidate our pointers), and the fact that it contains semi out-of-date | 264 // invalidate our pointers), and the fact that it contains semi out-of-date |
| 258 // data is not problematic as we don't re-build the model based on that. | 265 // data is not problematic as we don't re-build the model based on that. |
| 259 monster->DeleteCookie(cookie.first, cookie.second, true); | 266 monster->DeleteCookie(cookie.first, cookie.second, true); |
| 260 } | 267 } |
| 261 | 268 |
| 262 void CookiesTreeModel::DeleteAllCookies() { | 269 void CookiesTreeModel::DeleteAllCookies() { |
| 263 CookieTreeNode* root = GetRoot(); | 270 CookieTreeNode* root = GetRoot(); |
| 264 root->DeleteStoredObjects(); | 271 root->DeleteStoredObjects(); |
| 265 int num_children = root->GetChildCount(); | 272 int num_children = root->GetChildCount(); |
| 266 for (int i = num_children - 1; i >= 0; --i) { | 273 for (int i = num_children - 1; i >= 0; --i) |
| 267 delete Remove(root, i); | 274 delete Remove(root, i); |
| 268 } | |
| 269 LoadCookies(); | 275 LoadCookies(); |
| 270 NotifyObserverTreeNodeChanged(root); | 276 NotifyObserverTreeNodeChanged(root); |
| 271 } | 277 } |
| 272 | 278 |
| 273 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { | 279 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { |
| 274 cookie_node->DeleteStoredObjects(); | 280 cookie_node->DeleteStoredObjects(); |
| 275 // find the parent and index | 281 // find the parent and index |
| 276 CookieTreeNode* parent_node = cookie_node->GetParent(); | 282 CookieTreeNode* parent_node = cookie_node->GetParent(); |
| 277 int cookie_node_index = parent_node->IndexOfChild(cookie_node); | 283 int cookie_node_index = parent_node->IndexOfChild(cookie_node); |
| 278 delete Remove(parent_node, cookie_node_index); | 284 delete Remove(parent_node, cookie_node_index); |
| 279 } | 285 } |
| 286 |
| 287 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { |
| 288 CookieTreeNode* root = GetRoot(); |
| 289 int num_children = root->GetChildCount(); |
| 290 for (int i = num_children - 1; i >= 0; --i) |
| 291 delete Remove(root, i); |
| 292 LoadCookiesWithFilter(filter); |
| 293 NotifyObserverTreeNodeChanged(root); |
| 294 } |
| OLD | NEW |