OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 local_storage_info_(local_storage_info) { | 167 local_storage_info_(local_storage_info) { |
168 } | 168 } |
169 | 169 |
170 void CookieTreeLocalStorageNode::DeleteStoredObjects() { | 170 void CookieTreeLocalStorageNode::DeleteStoredObjects() { |
171 GetModel()->local_storage_helper_->DeleteLocalStorageFile( | 171 GetModel()->local_storage_helper_->DeleteLocalStorageFile( |
172 local_storage_info_->file_path); | 172 local_storage_info_->file_path); |
173 } | 173 } |
174 | 174 |
175 /////////////////////////////////////////////////////////////////////////////// | 175 /////////////////////////////////////////////////////////////////////////////// |
176 // CookieTreeRootNode, public: | 176 // CookieTreeRootNode, public: |
| 177 |
177 CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode( | 178 CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode( |
178 const std::wstring& origin) { | 179 const GURL& url) { |
179 // Strip the leading dot if it exists. | 180 CookieTreeOriginNode origin_node(url); |
180 std::wstring rewritten_origin = origin; | |
181 if (origin.length() >= 1 && origin[0] == '.') | |
182 rewritten_origin = origin.substr(1); | |
183 | |
184 CookieTreeOriginNode rewritten_origin_node(rewritten_origin); | |
185 | 181 |
186 // First see if there is an existing match. | 182 // First see if there is an existing match. |
187 std::vector<CookieTreeNode*>::iterator origin_node_iterator = | 183 std::vector<CookieTreeNode*>::iterator origin_node_iterator = |
188 lower_bound(children().begin(), | 184 lower_bound(children().begin(), |
189 children().end(), | 185 children().end(), |
190 &rewritten_origin_node, | 186 &origin_node, |
191 OriginNodeComparator()); | 187 OriginNodeComparator()); |
192 | 188 |
193 if (origin_node_iterator != children().end() && rewritten_origin == | 189 if (origin_node_iterator != children().end() && |
| 190 CookieTreeOriginNode::TitleForUrl(url) == |
194 (*origin_node_iterator)->GetTitle()) | 191 (*origin_node_iterator)->GetTitle()) |
195 return static_cast<CookieTreeOriginNode*>(*origin_node_iterator); | 192 return static_cast<CookieTreeOriginNode*>(*origin_node_iterator); |
196 // Node doesn't exist, create a new one and insert it into the (ordered) | 193 // Node doesn't exist, create a new one and insert it into the (ordered) |
197 // children. | 194 // children. |
198 CookieTreeOriginNode* retval = new CookieTreeOriginNode(rewritten_origin); | 195 CookieTreeOriginNode* retval = new CookieTreeOriginNode(url); |
199 DCHECK(model_); | 196 DCHECK(model_); |
200 model_->Add(this, (origin_node_iterator - children().begin()), retval); | 197 model_->Add(this, (origin_node_iterator - children().begin()), retval); |
201 return retval; | 198 return retval; |
202 } | 199 } |
203 | 200 |
204 /////////////////////////////////////////////////////////////////////////////// | 201 /////////////////////////////////////////////////////////////////////////////// |
205 // CookieTreeOriginNode, public: | 202 // CookieTreeOriginNode, public: |
206 | 203 |
| 204 // static |
| 205 std::wstring CookieTreeOriginNode::TitleForUrl( |
| 206 const GURL& url) { |
| 207 return UTF8ToWide(url.SchemeIsFile() ? kFileOriginNodeName : url.host()); |
| 208 } |
| 209 |
| 210 CookieTreeOriginNode::CookieTreeOriginNode(const GURL& url) |
| 211 : CookieTreeNode(TitleForUrl(url)), |
| 212 cookies_child_(NULL), |
| 213 databases_child_(NULL), |
| 214 local_storages_child_(NULL), |
| 215 appcaches_child_(NULL), |
| 216 url_(url) {} |
| 217 |
| 218 |
207 CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() { | 219 CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() { |
208 if (cookies_child_) | 220 if (cookies_child_) |
209 return cookies_child_; | 221 return cookies_child_; |
210 cookies_child_ = new CookieTreeCookiesNode; | 222 cookies_child_ = new CookieTreeCookiesNode; |
211 AddChildSortedByTitle(cookies_child_); | 223 AddChildSortedByTitle(cookies_child_); |
212 return cookies_child_; | 224 return cookies_child_; |
213 } | 225 } |
214 | 226 |
215 CookieTreeDatabasesNode* CookieTreeOriginNode::GetOrCreateDatabasesNode() { | 227 CookieTreeDatabasesNode* CookieTreeOriginNode::GetOrCreateDatabasesNode() { |
216 if (databases_child_) | 228 if (databases_child_) |
(...skipping 14 matching lines...) Expand all Loading... |
231 | 243 |
232 CookieTreeAppCachesNode* CookieTreeOriginNode::GetOrCreateAppCachesNode() { | 244 CookieTreeAppCachesNode* CookieTreeOriginNode::GetOrCreateAppCachesNode() { |
233 if (appcaches_child_) | 245 if (appcaches_child_) |
234 return appcaches_child_; | 246 return appcaches_child_; |
235 appcaches_child_ = new CookieTreeAppCachesNode; | 247 appcaches_child_ = new CookieTreeAppCachesNode; |
236 AddChildSortedByTitle(appcaches_child_); | 248 AddChildSortedByTitle(appcaches_child_); |
237 return appcaches_child_; | 249 return appcaches_child_; |
238 } | 250 } |
239 | 251 |
240 void CookieTreeOriginNode::CreateContentException( | 252 void CookieTreeOriginNode::CreateContentException( |
241 HostContentSettingsMap* content_settings, ContentSetting setting) { | 253 HostContentSettingsMap* content_settings, ContentSetting setting) const { |
242 std::wstring title(GetTitle()); | 254 if (CanCreateContentException()) { |
243 content_settings->AddExceptionForURL(GURL(WideToUTF16(title)), | 255 content_settings->AddExceptionForURL(url_, |
244 CONTENT_SETTINGS_TYPE_COOKIES, | 256 CONTENT_SETTINGS_TYPE_COOKIES, |
245 setting); | 257 setting); |
| 258 } |
| 259 } |
| 260 |
| 261 bool CookieTreeOriginNode::CanCreateContentException() const { |
| 262 return !url_.SchemeIsFile(); |
246 } | 263 } |
247 | 264 |
248 /////////////////////////////////////////////////////////////////////////////// | 265 /////////////////////////////////////////////////////////////////////////////// |
249 // CookieTreeCookiesNode, public: | 266 // CookieTreeCookiesNode, public: |
250 | 267 |
251 CookieTreeCookiesNode::CookieTreeCookiesNode() | 268 CookieTreeCookiesNode::CookieTreeCookiesNode() |
252 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) { | 269 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) { |
253 } | 270 } |
254 | 271 |
255 /////////////////////////////////////////////////////////////////////////////// | 272 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 LoadCookiesWithFilter(std::wstring()); | 394 LoadCookiesWithFilter(std::wstring()); |
378 } | 395 } |
379 | 396 |
380 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { | 397 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { |
381 // mmargh mmargh mmargh! | 398 // mmargh mmargh mmargh! |
382 | 399 |
383 all_cookies_ = cookie_monster_->GetAllCookies(); | 400 all_cookies_ = cookie_monster_->GetAllCookies(); |
384 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 401 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
385 for (CookieList::iterator it = all_cookies_.begin(); | 402 for (CookieList::iterator it = all_cookies_.begin(); |
386 it != all_cookies_.end(); ++it) { | 403 it != all_cookies_.end(); ++it) { |
387 std::wstring origin_node_name = UTF8ToWide(it->first); | 404 std::string origin_host = it->first; |
| 405 if (origin_host.length() > 1 && origin_host[0] == '.') |
| 406 origin_host = it->first.substr(1); |
| 407 // We treat secure cookies just the same as normal ones. |
| 408 GURL origin(std::string(chrome::kHttpScheme) + |
| 409 chrome::kStandardSchemeSeparator + origin_host + "/"); |
388 if (!filter.size() || | 410 if (!filter.size() || |
389 (origin_node_name.find(filter) != std::wstring::npos)) { | 411 (CookieTreeOriginNode::TitleForUrl(origin).find(filter) != |
| 412 std::string::npos)) { |
390 CookieTreeOriginNode* origin_node = | 413 CookieTreeOriginNode* origin_node = |
391 root->GetOrCreateOriginNode(origin_node_name); | 414 root->GetOrCreateOriginNode(origin); |
392 CookieTreeCookiesNode* cookies_node = | 415 CookieTreeCookiesNode* cookies_node = |
393 origin_node->GetOrCreateCookiesNode(); | 416 origin_node->GetOrCreateCookiesNode(); |
394 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); | 417 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); |
395 cookies_node->AddCookieNode(new_cookie); | 418 cookies_node->AddCookieNode(new_cookie); |
396 } | 419 } |
397 } | 420 } |
398 } | 421 } |
399 | 422 |
400 void CookiesTreeModel::DeleteAllStoredObjects() { | 423 void CookiesTreeModel::DeleteAllStoredObjects() { |
401 NotifyObserverBeginBatch(); | 424 NotifyObserverBeginBatch(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 485 |
463 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 486 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
464 NotifyObserverBeginBatch(); | 487 NotifyObserverBeginBatch(); |
465 for (InfoByOrigin::const_iterator origin = | 488 for (InfoByOrigin::const_iterator origin = |
466 appcache_info_->infos_by_origin.begin(); | 489 appcache_info_->infos_by_origin.begin(); |
467 origin != appcache_info_->infos_by_origin.end(); ++origin) { | 490 origin != appcache_info_->infos_by_origin.end(); ++origin) { |
468 std::wstring origin_node_name = UTF8ToWide(origin->first.host()); | 491 std::wstring origin_node_name = UTF8ToWide(origin->first.host()); |
469 if (filter.empty() || | 492 if (filter.empty() || |
470 (origin_node_name.find(filter) != std::wstring::npos)) { | 493 (origin_node_name.find(filter) != std::wstring::npos)) { |
471 CookieTreeOriginNode* origin_node = | 494 CookieTreeOriginNode* origin_node = |
472 root->GetOrCreateOriginNode(origin_node_name); | 495 root->GetOrCreateOriginNode(origin->first); |
473 CookieTreeAppCachesNode* appcaches_node = | 496 CookieTreeAppCachesNode* appcaches_node = |
474 origin_node->GetOrCreateAppCachesNode(); | 497 origin_node->GetOrCreateAppCachesNode(); |
475 | 498 |
476 for (AppCacheInfoVector::const_iterator info = origin->second.begin(); | 499 for (AppCacheInfoVector::const_iterator info = origin->second.begin(); |
477 info != origin->second.end(); ++info) { | 500 info != origin->second.end(); ++info) { |
478 appcaches_node->AddAppCacheNode( | 501 appcaches_node->AddAppCacheNode( |
479 new CookieTreeAppCacheNode(&(*info))); | 502 new CookieTreeAppCacheNode(&(*info))); |
480 } | 503 } |
481 } | 504 } |
482 } | 505 } |
483 NotifyObserverTreeNodeChanged(root); | 506 NotifyObserverTreeNodeChanged(root); |
484 NotifyObserverEndBatch(); | 507 NotifyObserverEndBatch(); |
485 } | 508 } |
486 | 509 |
487 void CookiesTreeModel::OnDatabaseModelInfoLoaded( | 510 void CookiesTreeModel::OnDatabaseModelInfoLoaded( |
488 const DatabaseInfoList& database_info) { | 511 const DatabaseInfoList& database_info) { |
489 database_info_list_ = database_info; | 512 database_info_list_ = database_info; |
490 PopulateDatabaseInfoWithFilter(std::wstring()); | 513 PopulateDatabaseInfoWithFilter(std::wstring()); |
491 } | 514 } |
492 | 515 |
493 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( | 516 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( |
494 const std::wstring& filter) { | 517 const std::wstring& filter) { |
495 if (database_info_list_.empty()) | 518 if (database_info_list_.empty()) |
496 return; | 519 return; |
497 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 520 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
498 NotifyObserverBeginBatch(); | 521 NotifyObserverBeginBatch(); |
499 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); | 522 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); |
500 database_info != database_info_list_.end(); | 523 database_info != database_info_list_.end(); |
501 ++database_info) { | 524 ++database_info) { |
502 // Determine which 'origin' node to place each 'info' in. | 525 GURL origin(database_info->origin); |
503 std::wstring origin_node_name; | |
504 if (database_info->IsFileSchemeData()) | |
505 origin_node_name = UTF8ToWide(kFileOriginNodeName); | |
506 else | |
507 origin_node_name = UTF8ToWide(database_info->host); | |
508 | 526 |
509 if (!filter.size() || | 527 if (!filter.size() || |
510 (origin_node_name.find(filter) != std::wstring::npos)) { | 528 (CookieTreeOriginNode::TitleForUrl(origin).find(filter) != |
| 529 std::wstring::npos)) { |
511 CookieTreeOriginNode* origin_node = | 530 CookieTreeOriginNode* origin_node = |
512 root->GetOrCreateOriginNode(origin_node_name); | 531 root->GetOrCreateOriginNode(origin); |
513 CookieTreeDatabasesNode* databases_node = | 532 CookieTreeDatabasesNode* databases_node = |
514 origin_node->GetOrCreateDatabasesNode(); | 533 origin_node->GetOrCreateDatabasesNode(); |
515 databases_node->AddDatabaseNode( | 534 databases_node->AddDatabaseNode( |
516 new CookieTreeDatabaseNode(&(*database_info))); | 535 new CookieTreeDatabaseNode(&(*database_info))); |
517 } | 536 } |
518 } | 537 } |
519 NotifyObserverTreeNodeChanged(root); | 538 NotifyObserverTreeNodeChanged(root); |
520 NotifyObserverEndBatch(); | 539 NotifyObserverEndBatch(); |
521 } | 540 } |
522 | 541 |
523 void CookiesTreeModel::OnStorageModelInfoLoaded( | 542 void CookiesTreeModel::OnStorageModelInfoLoaded( |
524 const LocalStorageInfoList& local_storage_info) { | 543 const LocalStorageInfoList& local_storage_info) { |
525 local_storage_info_list_ = local_storage_info; | 544 local_storage_info_list_ = local_storage_info; |
526 PopulateLocalStorageInfoWithFilter(std::wstring()); | 545 PopulateLocalStorageInfoWithFilter(std::wstring()); |
527 } | 546 } |
528 | 547 |
529 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( | 548 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( |
530 const std::wstring& filter) { | 549 const std::wstring& filter) { |
531 if (local_storage_info_list_.empty()) | 550 if (local_storage_info_list_.empty()) |
532 return; | 551 return; |
533 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 552 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
534 NotifyObserverBeginBatch(); | 553 NotifyObserverBeginBatch(); |
535 for (LocalStorageInfoList::iterator local_storage_info = | 554 for (LocalStorageInfoList::iterator local_storage_info = |
536 local_storage_info_list_.begin(); | 555 local_storage_info_list_.begin(); |
537 local_storage_info != local_storage_info_list_.end(); | 556 local_storage_info != local_storage_info_list_.end(); |
538 ++local_storage_info) { | 557 ++local_storage_info) { |
539 // Determine which 'origin' node to place each 'info' in. | 558 GURL origin(local_storage_info->origin); |
540 std::wstring origin_node_name; | |
541 if (local_storage_info->IsFileSchemeData()) | |
542 origin_node_name = UTF8ToWide(kFileOriginNodeName); | |
543 else | |
544 origin_node_name = UTF8ToWide(local_storage_info->host); | |
545 | 559 |
546 if (!filter.size() || | 560 if (!filter.size() || |
547 (origin_node_name.find(filter) != std::wstring::npos)) { | 561 (CookieTreeOriginNode::TitleForUrl(origin).find(filter) != |
| 562 std::wstring::npos)) { |
548 CookieTreeOriginNode* origin_node = | 563 CookieTreeOriginNode* origin_node = |
549 root->GetOrCreateOriginNode(origin_node_name); | 564 root->GetOrCreateOriginNode(origin); |
550 CookieTreeLocalStoragesNode* local_storages_node = | 565 CookieTreeLocalStoragesNode* local_storages_node = |
551 origin_node->GetOrCreateLocalStoragesNode(); | 566 origin_node->GetOrCreateLocalStoragesNode(); |
552 local_storages_node->AddLocalStorageNode( | 567 local_storages_node->AddLocalStorageNode( |
553 new CookieTreeLocalStorageNode(&(*local_storage_info))); | 568 new CookieTreeLocalStorageNode(&(*local_storage_info))); |
554 } | 569 } |
555 } | 570 } |
556 NotifyObserverTreeNodeChanged(root); | 571 NotifyObserverTreeNodeChanged(root); |
557 NotifyObserverEndBatch(); | 572 NotifyObserverEndBatch(); |
558 } | 573 } |
559 | 574 |
560 void CookiesTreeModel::NotifyObserverBeginBatch() { | 575 void CookiesTreeModel::NotifyObserverBeginBatch() { |
561 // Only notify the model once if we're batching in a nested manner. | 576 // Only notify the model once if we're batching in a nested manner. |
562 if (batch_update_++ == 0) { | 577 if (batch_update_++ == 0) { |
563 FOR_EACH_OBSERVER(Observer, | 578 FOR_EACH_OBSERVER(Observer, |
564 cookies_observer_list_, | 579 cookies_observer_list_, |
565 TreeModelBeginBatch(this)); | 580 TreeModelBeginBatch(this)); |
566 } | 581 } |
567 } | 582 } |
568 | 583 |
569 void CookiesTreeModel::NotifyObserverEndBatch() { | 584 void CookiesTreeModel::NotifyObserverEndBatch() { |
570 // Only notify the observers if this is the outermost call to EndBatch() if | 585 // Only notify the observers if this is the outermost call to EndBatch() if |
571 // called in a nested manner. | 586 // called in a nested manner. |
572 if (--batch_update_ == 0) { | 587 if (--batch_update_ == 0) { |
573 FOR_EACH_OBSERVER(Observer, | 588 FOR_EACH_OBSERVER(Observer, |
574 cookies_observer_list_, | 589 cookies_observer_list_, |
575 TreeModelEndBatch(this)); | 590 TreeModelEndBatch(this)); |
576 } | 591 } |
577 } | 592 } |
OLD | NEW |