Chromium Code Reviews| 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 |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "app/table_model_observer.h" | 13 #include "app/table_model_observer.h" |
| 14 #include "app/tree_node_model.h" | 14 #include "app/tree_node_model.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/linked_ptr.h" | 16 #include "base/linked_ptr.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "chrome/browser/extensions/extensions_service.h" | |
| 18 #include "chrome/browser/in_process_webkit/webkit_context.h" | 19 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 19 #include "chrome/browser/net/chrome_url_request_context.h" | 20 #include "chrome/browser/net/chrome_url_request_context.h" |
| 20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 21 #include "grit/app_resources.h" | 22 #include "grit/app_resources.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 24 #include "net/base/cookie_monster.h" | 25 #include "net/base/cookie_monster.h" |
| 25 #include "net/base/registry_controlled_domain.h" | 26 #include "net/base/registry_controlled_domain.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 | 29 |
| 30 static const char kFileOriginNodeName[] = "file://"; | |
| 29 | 31 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
| 31 // CookieTreeNode, public: | 33 // CookieTreeNode, public: |
| 32 | 34 |
| 33 void CookieTreeNode::DeleteStoredObjects() { | 35 void CookieTreeNode::DeleteStoredObjects() { |
| 34 std::for_each(children().begin(), | 36 std::for_each(children().begin(), |
| 35 children().end(), | 37 children().end(), |
| 36 std::mem_fun(&CookieTreeNode::DeleteStoredObjects)); | 38 std::mem_fun(&CookieTreeNode::DeleteStoredObjects)); |
| 37 } | 39 } |
| 38 | 40 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { | 373 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { |
| 372 // mmargh mmargh mmargh! | 374 // mmargh mmargh mmargh! |
| 373 | 375 |
| 374 // Since we are running on the UI thread don't call GetURLRequestContext(). | 376 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 375 net::CookieMonster* cookie_monster = | 377 net::CookieMonster* cookie_monster = |
| 376 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 378 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 377 | 379 |
| 378 all_cookies_ = cookie_monster->GetAllCookies(); | 380 all_cookies_ = cookie_monster->GetAllCookies(); |
| 379 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 381 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 380 for (CookieList::iterator it = all_cookies_.begin(); | 382 for (CookieList::iterator it = all_cookies_.begin(); |
| 381 it != all_cookies_.end(); | 383 it != all_cookies_.end(); ++it) { |
| 382 ++it) { | 384 std::wstring origin_node_name = UTF8ToWide(it->first); |
| 383 // Get the origin cookie | |
| 384 if (!filter.size() || | 385 if (!filter.size() || |
| 385 (UTF8ToWide(it->first).find(filter) != std::wstring::npos)) { | 386 (origin_node_name.find(filter) != std::wstring::npos)) { |
| 386 CookieTreeOriginNode* origin = | 387 CookieTreeOriginNode* origin_node = |
| 387 root->GetOrCreateOriginNode(UTF8ToWide(it->first)); | 388 root->GetOrCreateOriginNode(origin_node_name); |
| 388 CookieTreeCookiesNode* cookies_node = origin->GetOrCreateCookiesNode(); | 389 CookieTreeCookiesNode* cookies_node = |
| 390 origin_node->GetOrCreateCookiesNode(); | |
| 389 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); | 391 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); |
| 390 cookies_node->AddCookieNode(new_cookie); | 392 cookies_node->AddCookieNode(new_cookie); |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 } | 395 } |
| 394 | 396 |
| 395 void CookiesTreeModel::DeleteAllStoredObjects() { | 397 void CookiesTreeModel::DeleteAllStoredObjects() { |
| 396 CookieTreeNode* root = GetRoot(); | 398 CookieTreeNode* root = GetRoot(); |
| 397 root->DeleteStoredObjects(); | 399 root->DeleteStoredObjects(); |
| 398 int num_children = root->GetChildCount(); | 400 int num_children = root->GetChildCount(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 426 } | 428 } |
| 427 | 429 |
| 428 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( | 430 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( |
| 429 const std::wstring& filter) { | 431 const std::wstring& filter) { |
| 430 if (!appcache_helper_ || appcache_helper_->info_list().empty()) | 432 if (!appcache_helper_ || appcache_helper_->info_list().empty()) |
| 431 return; | 433 return; |
| 432 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 434 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 433 for (AppCacheInfoList::const_iterator info = | 435 for (AppCacheInfoList::const_iterator info = |
| 434 appcache_helper_->info_list().begin(); | 436 appcache_helper_->info_list().begin(); |
| 435 info != appcache_helper_->info_list().end(); ++info) { | 437 info != appcache_helper_->info_list().end(); ++info) { |
| 436 std::wstring host = UTF8ToWide(info->manifest_url.host()); | 438 std::wstring origin_node_name = UTF8ToWide(info->manifest_url.host()); |
| 437 if (filter.empty() || (host.find(filter) != std::wstring::npos)) { | 439 if (filter.empty() || |
| 438 CookieTreeOriginNode* host_node = | 440 (origin_node_name.find(filter) != std::wstring::npos)) { |
| 439 root->GetOrCreateOriginNode(host); | 441 CookieTreeOriginNode* origin_node = |
| 442 root->GetOrCreateOriginNode(origin_node_name); | |
| 440 CookieTreeAppCachesNode* appcaches_node = | 443 CookieTreeAppCachesNode* appcaches_node = |
| 441 host_node->GetOrCreateAppCachesNode(); | 444 origin_node->GetOrCreateAppCachesNode(); |
| 442 appcaches_node->AddAppCacheNode( | 445 appcaches_node->AddAppCacheNode( |
| 443 new CookieTreeAppCacheNode(&(*info))); | 446 new CookieTreeAppCacheNode(&(*info))); |
| 444 } | 447 } |
| 445 } | 448 } |
| 446 NotifyObserverTreeNodeChanged(root); | 449 NotifyObserverTreeNodeChanged(root); |
| 447 } | 450 } |
| 448 | 451 |
| 449 void CookiesTreeModel::OnDatabaseModelInfoLoaded( | 452 void CookiesTreeModel::OnDatabaseModelInfoLoaded( |
| 450 const DatabaseInfoList& database_info) { | 453 const DatabaseInfoList& database_info) { |
| 451 database_info_list_ = database_info; | 454 database_info_list_ = database_info; |
| 452 PopulateDatabaseInfoWithFilter(std::wstring()); | 455 PopulateDatabaseInfoWithFilter(std::wstring()); |
| 453 } | 456 } |
| 454 | 457 |
| 455 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( | 458 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( |
| 456 const std::wstring& filter) { | 459 const std::wstring& filter) { |
| 457 if (database_info_list_.empty()) | 460 if (database_info_list_.empty()) |
| 458 return; | 461 return; |
| 459 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 462 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 460 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); | 463 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); |
| 461 database_info != database_info_list_.end(); | 464 database_info != database_info_list_.end(); |
| 462 ++database_info) { | 465 ++database_info) { |
| 463 std::string origin = database_info->host.empty() ? | 466 // Determine which 'origin' node to place each 'info' in. |
| 464 database_info->origin_identifier : database_info->host; | 467 std::wstring origin_node_name; |
| 468 if (database_info->IsFileSchemeData()) | |
| 469 origin_node_name = UTF8ToWide(kFileOriginNodeName); | |
| 470 else if (database_info->IsExtensionSchemeData()) | |
| 471 origin_node_name = FormExtensionNodeName(database_info->host); | |
| 472 else | |
| 473 origin_node_name = UTF8ToWide(database_info->host); | |
| 474 | |
| 465 if (!filter.size() || | 475 if (!filter.size() || |
| 466 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { | 476 (origin_node_name.find(filter) != std::wstring::npos)) { |
| 467 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( | 477 CookieTreeOriginNode* origin_node = |
| 468 UTF8ToWide(database_info->host)); | 478 root->GetOrCreateOriginNode(origin_node_name); |
| 469 CookieTreeDatabasesNode* databases_node = | 479 CookieTreeDatabasesNode* databases_node = |
| 470 origin_node->GetOrCreateDatabasesNode(); | 480 origin_node->GetOrCreateDatabasesNode(); |
| 471 databases_node->AddDatabaseNode( | 481 databases_node->AddDatabaseNode( |
| 472 new CookieTreeDatabaseNode(&(*database_info))); | 482 new CookieTreeDatabaseNode(&(*database_info))); |
| 473 } | 483 } |
| 474 } | 484 } |
| 475 NotifyObserverTreeNodeChanged(root); | 485 NotifyObserverTreeNodeChanged(root); |
| 476 } | 486 } |
| 477 | 487 |
| 478 void CookiesTreeModel::OnStorageModelInfoLoaded( | 488 void CookiesTreeModel::OnStorageModelInfoLoaded( |
| 479 const LocalStorageInfoList& local_storage_info) { | 489 const LocalStorageInfoList& local_storage_info) { |
| 480 local_storage_info_list_ = local_storage_info; | 490 local_storage_info_list_ = local_storage_info; |
| 481 PopulateLocalStorageInfoWithFilter(std::wstring()); | 491 PopulateLocalStorageInfoWithFilter(std::wstring()); |
| 482 } | 492 } |
| 483 | 493 |
| 484 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( | 494 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( |
| 485 const std::wstring& filter) { | 495 const std::wstring& filter) { |
| 486 if (local_storage_info_list_.empty()) | 496 if (local_storage_info_list_.empty()) |
| 487 return; | 497 return; |
| 488 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 498 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 489 for (LocalStorageInfoList::iterator local_storage_info = | 499 for (LocalStorageInfoList::iterator local_storage_info = |
| 490 local_storage_info_list_.begin(); | 500 local_storage_info_list_.begin(); |
| 491 local_storage_info != local_storage_info_list_.end(); | 501 local_storage_info != local_storage_info_list_.end(); |
| 492 ++local_storage_info) { | 502 ++local_storage_info) { |
| 493 std::string origin = local_storage_info->host.empty() ? | 503 // Determine which 'origin' node to place each 'info' in. |
| 494 local_storage_info->database_identifier : local_storage_info->host; | 504 std::wstring origin_node_name; |
| 505 if (local_storage_info->IsFileSchemeData()) | |
| 506 origin_node_name = UTF8ToWide(kFileOriginNodeName); | |
| 507 else if (local_storage_info->IsExtensionSchemeData()) | |
| 508 origin_node_name = FormExtensionNodeName(local_storage_info->host); | |
| 509 else | |
| 510 origin_node_name = UTF8ToWide(local_storage_info->host); | |
| 511 | |
| 495 if (!filter.size() || | 512 if (!filter.size() || |
| 496 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { | 513 (origin_node_name.find(filter) != std::wstring::npos)) { |
| 497 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( | 514 CookieTreeOriginNode* origin_node = |
| 498 UTF8ToWide(local_storage_info->host)); | 515 root->GetOrCreateOriginNode(origin_node_name); |
| 499 CookieTreeLocalStoragesNode* local_storages_node = | 516 CookieTreeLocalStoragesNode* local_storages_node = |
| 500 origin_node->GetOrCreateLocalStoragesNode(); | 517 origin_node->GetOrCreateLocalStoragesNode(); |
| 501 local_storages_node->AddLocalStorageNode( | 518 local_storages_node->AddLocalStorageNode( |
| 502 new CookieTreeLocalStorageNode(&(*local_storage_info))); | 519 new CookieTreeLocalStorageNode(&(*local_storage_info))); |
| 503 } | 520 } |
| 504 } | 521 } |
| 505 NotifyObserverTreeNodeChanged(root); | 522 NotifyObserverTreeNodeChanged(root); |
| 506 } | 523 } |
| 524 | |
| 525 std::wstring CookiesTreeModel::FormExtensionNodeName( | |
| 526 const std::string& extension_id) { | |
| 527 Extension* extension = | |
| 528 profile_->GetExtensionsService()->GetExtensionById(extension_id, true); | |
| 529 std::wstring extension_name = extension ? | |
| 530 UTF8ToWide(extension->name()) : l10n_util::GetString(IDS_UNKNOWN_PLUGIN_NA ME); | |
|
michaeln
2010/02/27 02:37:56
line length is fixed locally
| |
| 531 | |
| 532 // Since the extension_name will be concatenated with a prefix, we need | |
| 533 // to explicitly set the extension_name to be LTR format if there is no | |
| 534 // strong RTL charater in it. Otherwise, if the prefix is an RTL word, | |
| 535 // the concatenated result might be wrong. For extension named | |
| 536 // "Great Extension!" the concatenated result would be something like | |
| 537 // "!Great Extension :NOISNETXE", in which capital letters "NOISNETXE" | |
| 538 // stand for the Hebrew word for "extension". | |
| 539 l10n_util::AdjustStringForLocaleDirection(extension_name, &extension_name); | |
| 540 return l10n_util::GetStringF(IDS_TASK_MANAGER_EXTENSION_PREFIX, | |
| 541 extension_name); | |
| 542 } | |
| OLD | NEW |