Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/cookies_tree_model.cc

Issue 10790150: Show Flash LSOs for Pepper Flash in cookie dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" 15 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h" 17 #include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
17 #include "chrome/browser/content_settings/cookie_settings.h" 18 #include "chrome/browser/content_settings/cookie_settings.h"
18 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/extension_special_storage_policy.h" 20 #include "chrome/browser/extensions/extension_special_storage_policy.h"
20 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
23 #include "grit/ui_resources.h" 24 #include "grit/ui_resources.h"
24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 25 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
25 #include "net/cookies/canonical_cookie.h" 26 #include "net/cookies/canonical_cookie.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return *this; 247 return *this;
247 } 248 }
248 249
249 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitServerBoundCert( 250 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitServerBoundCert(
250 const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert) { 251 const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert) {
251 Init(TYPE_SERVER_BOUND_CERT); 252 Init(TYPE_SERVER_BOUND_CERT);
252 this->server_bound_cert = server_bound_cert; 253 this->server_bound_cert = server_bound_cert;
253 return *this; 254 return *this;
254 } 255 }
255 256
257 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO(
258 const std::string& flash_lso_domain) {
259 Init(TYPE_FLASH_LSO);
260 this->flash_lso_domain = flash_lso_domain;
261 return *this;
262 }
263
256 /////////////////////////////////////////////////////////////////////////////// 264 ///////////////////////////////////////////////////////////////////////////////
257 // CookieTreeNode, public: 265 // CookieTreeNode, public:
258 266
259 void CookieTreeNode::DeleteStoredObjects() { 267 void CookieTreeNode::DeleteStoredObjects() {
260 std::for_each(children().begin(), 268 std::for_each(children().begin(),
261 children().end(), 269 children().end(),
262 std::mem_fun(&CookieTreeNode::DeleteStoredObjects)); 270 std::mem_fun(&CookieTreeNode::DeleteStoredObjects));
263 } 271 }
264 272
265 CookiesTreeModel* CookieTreeNode::GetModel() const { 273 CookiesTreeModel* CookieTreeNode::GetModel() const {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 : CookieTreeNode(TitleForUrl(url, app_id, name)), 581 : CookieTreeNode(TitleForUrl(url, app_id, name)),
574 cookies_child_(NULL), 582 cookies_child_(NULL),
575 databases_child_(NULL), 583 databases_child_(NULL),
576 local_storages_child_(NULL), 584 local_storages_child_(NULL),
577 session_storages_child_(NULL), 585 session_storages_child_(NULL),
578 appcaches_child_(NULL), 586 appcaches_child_(NULL),
579 indexed_dbs_child_(NULL), 587 indexed_dbs_child_(NULL),
580 file_systems_child_(NULL), 588 file_systems_child_(NULL),
581 quota_child_(NULL), 589 quota_child_(NULL),
582 server_bound_certs_child_(NULL), 590 server_bound_certs_child_(NULL),
591 flash_lso_child_(NULL),
583 app_id_(app_id), 592 app_id_(app_id),
584 app_name_(name), 593 app_name_(name),
585 url_(url), 594 url_(url),
586 canonicalized_host_(CanonicalizeHost(url)) {} 595 canonicalized_host_(CanonicalizeHost(url)) {}
587 596
588 CookieTreeHostNode::~CookieTreeHostNode() {} 597 CookieTreeHostNode::~CookieTreeHostNode() {}
589 598
590 const std::string CookieTreeHostNode::GetHost() const { 599 const std::string CookieTreeHostNode::GetHost() const {
591 const std::string file_origin_node_name( 600 const std::string file_origin_node_name(
592 std::string(chrome::kFileScheme) + content::kStandardSchemeSeparator); 601 std::string(chrome::kFileScheme) + content::kStandardSchemeSeparator);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 675
667 CookieTreeServerBoundCertsNode* 676 CookieTreeServerBoundCertsNode*
668 CookieTreeHostNode::GetOrCreateServerBoundCertsNode() { 677 CookieTreeHostNode::GetOrCreateServerBoundCertsNode() {
669 if (server_bound_certs_child_) 678 if (server_bound_certs_child_)
670 return server_bound_certs_child_; 679 return server_bound_certs_child_;
671 server_bound_certs_child_ = new CookieTreeServerBoundCertsNode; 680 server_bound_certs_child_ = new CookieTreeServerBoundCertsNode;
672 AddChildSortedByTitle(server_bound_certs_child_); 681 AddChildSortedByTitle(server_bound_certs_child_);
673 return server_bound_certs_child_; 682 return server_bound_certs_child_;
674 } 683 }
675 684
685 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode(
686 const std::string& domain) {
687 DCHECK_EQ(GetHost(), domain);
688 if (flash_lso_child_)
689 return flash_lso_child_;
690 flash_lso_child_ = new CookieTreeFlashLSONode(domain);
691 AddChildSortedByTitle(flash_lso_child_);
692 return flash_lso_child_;
693 }
694
676 void CookieTreeHostNode::CreateContentException( 695 void CookieTreeHostNode::CreateContentException(
677 CookieSettings* cookie_settings, ContentSetting setting) const { 696 CookieSettings* cookie_settings, ContentSetting setting) const {
678 DCHECK(setting == CONTENT_SETTING_ALLOW || 697 DCHECK(setting == CONTENT_SETTING_ALLOW ||
679 setting == CONTENT_SETTING_BLOCK || 698 setting == CONTENT_SETTING_BLOCK ||
680 setting == CONTENT_SETTING_SESSION_ONLY); 699 setting == CONTENT_SETTING_SESSION_ONLY);
681 if (CanCreateContentException()) { 700 if (CanCreateContentException()) {
682 cookie_settings->ResetCookieSetting( 701 cookie_settings->ResetCookieSetting(
683 ContentSettingsPattern::FromURLNoWildcard(url_), 702 ContentSettingsPattern::FromURLNoWildcard(url_),
684 ContentSettingsPattern::Wildcard()); 703 ContentSettingsPattern::Wildcard());
685 cookie_settings->SetCookieSetting( 704 cookie_settings->SetCookieSetting(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 825
807 void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) { 826 void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) {
808 DCHECK(new_child); 827 DCHECK(new_child);
809 std::vector<CookieTreeNode*>::iterator iter = 828 std::vector<CookieTreeNode*>::iterator iter =
810 std::lower_bound(children().begin(), children().end(), new_child, 829 std::lower_bound(children().begin(), children().end(), new_child,
811 NodeTitleComparator()); 830 NodeTitleComparator());
812 GetModel()->Add(this, new_child, iter - children().begin()); 831 GetModel()->Add(this, new_child, iter - children().begin());
813 } 832 }
814 833
815 /////////////////////////////////////////////////////////////////////////////// 834 ///////////////////////////////////////////////////////////////////////////////
835 // CookieTreeFlashLSONode
836 CookieTreeFlashLSONode::CookieTreeFlashLSONode(
837 const std::string& domain)
838 : domain_(domain) {}
839 CookieTreeFlashLSONode::~CookieTreeFlashLSONode() {}
840
841 void CookieTreeFlashLSONode::DeleteStoredObjects() {
842 // We are one level below the host node.
843 CookieTreeHostNode* host = static_cast<CookieTreeHostNode*>(parent());
844 CHECK_EQ(host->GetDetailedInfo().node_type,
845 CookieTreeNode::DetailedInfo::TYPE_HOST);
846 LocalDataContainer* container =
847 GetModel()->GetLocalDataContainer(host->app_id());
848 CHECK(container);
849
850 container->flash_lso_helper_->DeleteFlashLSOsForSite(domain_);
851 }
852
853 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const {
854 return DetailedInfo().InitFlashLSO(domain_);
855 }
856
857 ///////////////////////////////////////////////////////////////////////////////
816 // ScopedBatchUpdateNotifier 858 // ScopedBatchUpdateNotifier
817 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( 859 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier(
818 CookiesTreeModel* model, CookieTreeNode* node) 860 CookiesTreeModel* model, CookieTreeNode* node)
819 : model_(model), node_(node), batch_in_progress_(false) { 861 : model_(model), node_(node), batch_in_progress_(false) {
820 } 862 }
821 863
822 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { 864 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() {
823 if (batch_in_progress_) { 865 if (batch_in_progress_) {
824 model_->NotifyObserverTreeNodeChanged(node_); 866 model_->NotifyObserverTreeNodeChanged(node_);
825 model_->NotifyObserverEndBatch(); 867 model_->NotifyObserverEndBatch();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 ScopedBatchUpdateNotifier notifier(this, GetRoot()); 1055 ScopedBatchUpdateNotifier notifier(this, GetRoot());
1014 PopulateQuotaInfoWithFilter(container, &notifier, string16()); 1056 PopulateQuotaInfoWithFilter(container, &notifier, string16());
1015 } 1057 }
1016 1058
1017 void CookiesTreeModel::PopulateServerBoundCertInfo( 1059 void CookiesTreeModel::PopulateServerBoundCertInfo(
1018 LocalDataContainer* container) { 1060 LocalDataContainer* container) {
1019 ScopedBatchUpdateNotifier notifier(this, GetRoot()); 1061 ScopedBatchUpdateNotifier notifier(this, GetRoot());
1020 PopulateServerBoundCertInfoWithFilter(container, &notifier, string16()); 1062 PopulateServerBoundCertInfoWithFilter(container, &notifier, string16());
1021 } 1063 }
1022 1064
1065 void CookiesTreeModel::PopulateFlashLSOInfo(
1066 LocalDataContainer* container) {
1067 ScopedBatchUpdateNotifier notifier(this, GetRoot());
1068 PopulateFlashLSOInfoWithFilter(container, &notifier, string16());
1069 }
1070
1023 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( 1071 void CookiesTreeModel::PopulateAppCacheInfoWithFilter(
1024 LocalDataContainer* container, 1072 LocalDataContainer* container,
1025 ScopedBatchUpdateNotifier* notifier, 1073 ScopedBatchUpdateNotifier* notifier,
1026 const string16& filter) { 1074 const string16& filter) {
1027 using appcache::AppCacheInfo; 1075 using appcache::AppCacheInfo;
1028 typedef std::map<GURL, std::list<AppCacheInfo> > InfoByOrigin; 1076 typedef std::map<GURL, std::list<AppCacheInfo> > InfoByOrigin;
1029 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); 1077 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
1030 1078
1031 if (container->appcache_info_.empty()) 1079 if (container->appcache_info_.empty())
1032 return; 1080 return;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 (UTF8ToUTF16(quota_info->host).find(filter) != string16::npos)) { 1340 (UTF8ToUTF16(quota_info->host).find(filter) != string16::npos)) {
1293 CookieTreeHostNode* host_node = 1341 CookieTreeHostNode* host_node =
1294 root->GetOrCreateHostNode(GURL("http://" + quota_info->host), 1342 root->GetOrCreateHostNode(GURL("http://" + quota_info->host),
1295 container->app_id(), 1343 container->app_id(),
1296 container->app_name()); 1344 container->app_name());
1297 host_node->UpdateOrCreateQuotaNode(quota_info); 1345 host_node->UpdateOrCreateQuotaNode(quota_info);
1298 } 1346 }
1299 } 1347 }
1300 } 1348 }
1301 1349
1350 void CookiesTreeModel::PopulateFlashLSOInfoWithFilter(
1351 LocalDataContainer* container,
1352 ScopedBatchUpdateNotifier* notifier,
1353 const string16& filter) {
1354 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
1355
1356 if (container->flash_lso_domain_list_.empty())
1357 return;
1358
1359 std::string filter_utf8 = UTF16ToUTF8(filter);
1360 notifier->StartBatchUpdate();
1361 for (std::vector<std::string>::iterator it =
1362 container->flash_lso_domain_list_.begin();
1363 it != container->flash_lso_domain_list_.end(); ++it) {
1364 if (!filter_utf8.size() || it->find(filter_utf8) != std::string::npos) {
1365 // Create a fake origin for GetOrCreateHostNode().
1366 GURL origin("http://" + *it);
1367 CookieTreeHostNode* host_node =
1368 root->GetOrCreateHostNode(origin, container->app_id(),
1369 container->app_name());
1370 host_node->GetOrCreateFlashLSONode(*it);
1371 }
1372 }
1373 }
1374
1302 void CookiesTreeModel::NotifyObserverBeginBatch() { 1375 void CookiesTreeModel::NotifyObserverBeginBatch() {
1303 // Only notify the model once if we're batching in a nested manner. 1376 // Only notify the model once if we're batching in a nested manner.
1304 if (batch_update_++ == 0) { 1377 if (batch_update_++ == 0) {
1305 FOR_EACH_OBSERVER(Observer, 1378 FOR_EACH_OBSERVER(Observer,
1306 cookies_observer_list_, 1379 cookies_observer_list_,
1307 TreeModelBeginBatch(this)); 1380 TreeModelBeginBatch(this));
1308 } 1381 }
1309 } 1382 }
1310 1383
1311 void CookiesTreeModel::NotifyObserverEndBatch() { 1384 void CookiesTreeModel::NotifyObserverEndBatch() {
1312 // Only notify the observers if this is the outermost call to EndBatch() if 1385 // Only notify the observers if this is the outermost call to EndBatch() if
1313 // called in a nested manner. 1386 // called in a nested manner.
1314 if (--batch_update_ == 0) { 1387 if (--batch_update_ == 0) {
1315 FOR_EACH_OBSERVER(Observer, 1388 FOR_EACH_OBSERVER(Observer,
1316 cookies_observer_list_, 1389 cookies_observer_list_,
1317 TreeModelEndBatch(this)); 1390 TreeModelEndBatch(this));
1318 } 1391 }
1319 } 1392 }
1320 1393
1321 LocalDataContainer* CookiesTreeModel::GetLocalDataContainer( 1394 LocalDataContainer* CookiesTreeModel::GetLocalDataContainer(
1322 const std::string& app_id) { 1395 const std::string& app_id) {
1323 LocalDataContainer* container = app_data_map_[app_id]; 1396 LocalDataContainer* container = app_data_map_[app_id];
1324 return container; 1397 return container;
1325 } 1398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698