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

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

Issue 2110483002: Remove use of CanonicalCookie::Source() from browsing_data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really really fix android? Created 4 years, 5 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
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/browsing_data/cookies_tree_model.h" 5 #include "chrome/browser/browsing_data/cookies_tree_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 if (next_dot == std::string::npos) { 110 if (next_dot == std::string::npos) {
111 retval += host.substr(0, position); 111 retval += host.substr(0, position);
112 break; 112 break;
113 } 113 }
114 retval += host.substr(next_dot + 1, position - (next_dot + 1)); 114 retval += host.substr(next_dot + 1, position - (next_dot + 1));
115 position = next_dot; 115 position = next_dot;
116 } 116 }
117 return retval; 117 return retval;
118 } 118 }
119 119
120 // When creating a cookie tree node from a cookie, strip the port of the
121 // cookie source and treat all non-file:// URLs as http://.
122 GURL CanonicalizeCookieSource(const net::CanonicalCookie& cookie) {
123 GURL url = cookie.Source();
124 if (url.SchemeIsFile())
125 return url;
126
127 url::Replacements<char> replacements;
128 replacements.ClearPort();
129 if (url.SchemeIsCryptographic())
130 replacements.SetScheme("http", url::Component(0, 4));
131
132 return url.GetOrigin().ReplaceComponents(replacements);
133 }
134
135 #if defined(ENABLE_EXTENSIONS) 120 #if defined(ENABLE_EXTENSIONS)
136 bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) { 121 bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) {
137 switch (type) { 122 switch (type) {
138 // Fall through each below cases to return true. 123 // Fall through each below cases to return true.
139 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: 124 case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
140 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: 125 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
141 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: 126 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE:
142 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: 127 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
143 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: 128 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
144 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: 129 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (!batch_in_progress_) { 949 if (!batch_in_progress_) {
965 model_->NotifyObserverBeginBatch(); 950 model_->NotifyObserverBeginBatch();
966 batch_in_progress_ = true; 951 batch_in_progress_ = true;
967 } 952 }
968 } 953 }
969 954
970 /////////////////////////////////////////////////////////////////////////////// 955 ///////////////////////////////////////////////////////////////////////////////
971 // CookiesTreeModel, public: 956 // CookiesTreeModel, public:
972 CookiesTreeModel::CookiesTreeModel( 957 CookiesTreeModel::CookiesTreeModel(
973 LocalDataContainer* data_container, 958 LocalDataContainer* data_container,
974 ExtensionSpecialStoragePolicy* special_storage_policy, 959 ExtensionSpecialStoragePolicy* special_storage_policy)
975 bool group_by_cookie_source)
976 : ui::TreeNodeModel<CookieTreeNode>(new CookieTreeRootNode(this)), 960 : ui::TreeNodeModel<CookieTreeNode>(new CookieTreeRootNode(this)),
977 data_container_(data_container),
978 #if defined(ENABLE_EXTENSIONS) 961 #if defined(ENABLE_EXTENSIONS)
979 special_storage_policy_(special_storage_policy), 962 special_storage_policy_(special_storage_policy),
980 #endif 963 #endif
981 group_by_cookie_source_(group_by_cookie_source) { 964 data_container_(data_container) {
982 data_container_->Init(this); 965 data_container_->Init(this);
983 } 966 }
984 967
985 CookiesTreeModel::~CookiesTreeModel() { 968 CookiesTreeModel::~CookiesTreeModel() {
986 } 969 }
987 970
988 // static 971 // static
989 int CookiesTreeModel::GetSendForMessageID(const net::CanonicalCookie& cookie) { 972 int CookiesTreeModel::GetSendForMessageID(const net::CanonicalCookie& cookie) {
990 if (cookie.IsSecure()) { 973 if (cookie.IsSecure()) {
991 if (cookie.SameSite() != net::CookieSameSite::NO_RESTRICTION) 974 if (cookie.SameSite() != net::CookieSameSite::NO_RESTRICTION)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 1195
1213 void CookiesTreeModel::PopulateCookieInfoWithFilter( 1196 void CookiesTreeModel::PopulateCookieInfoWithFilter(
1214 LocalDataContainer* container, 1197 LocalDataContainer* container,
1215 ScopedBatchUpdateNotifier* notifier, 1198 ScopedBatchUpdateNotifier* notifier,
1216 const base::string16& filter) { 1199 const base::string16& filter) {
1217 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); 1200 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
1218 1201
1219 notifier->StartBatchUpdate(); 1202 notifier->StartBatchUpdate();
1220 for (CookieList::iterator it = container->cookie_list_.begin(); 1203 for (CookieList::iterator it = container->cookie_list_.begin();
1221 it != container->cookie_list_.end(); ++it) { 1204 it != container->cookie_list_.end(); ++it) {
1222 GURL source = CanonicalizeCookieSource(*it); 1205 std::string domain = it->Domain();
1223 if (source.is_empty() || !group_by_cookie_source_) { 1206 if (domain.length() > 1 && domain[0] == '.')
1224 std::string domain = it->Domain(); 1207 domain = domain.substr(1);
1225 if (domain.length() > 1 && domain[0] == '.')
1226 domain = domain.substr(1);
1227 1208
1228 // We treat secure cookies just the same as normal ones. 1209 // Cookies ignore schemes, so group all HTTP and HTTPS cookies together.
1229 source = GURL(std::string(url::kHttpScheme) + 1210 GURL source = GURL(std::string(url::kHttpScheme) +
Bernhard Bauer 2016/07/01 13:30:15 Nit: You could directly initialize |source| here.
mmenke 2016/07/11 18:56:59 Done.
1230 url::kStandardSchemeSeparator + domain + "/"); 1211 url::kStandardSchemeSeparator + domain + "/");
1231 }
1232 if (!source.SchemeIsHTTPOrHTTPS())
1233 continue;
1234 1212
1235 if (filter.empty() || (CookieTreeHostNode::TitleForUrl(source) 1213 if (filter.empty() || (CookieTreeHostNode::TitleForUrl(source)
1236 .find(filter) != base::string16::npos)) { 1214 .find(filter) != base::string16::npos)) {
1237 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(source); 1215 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(source);
1238 CookieTreeCookiesNode* cookies_node = 1216 CookieTreeCookiesNode* cookies_node =
1239 host_node->GetOrCreateCookiesNode(); 1217 host_node->GetOrCreateCookiesNode();
1240 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(it); 1218 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(it);
1241 cookies_node->AddCookieNode(new_cookie); 1219 cookies_node->AddCookieNode(new_cookie);
1242 } 1220 }
1243 } 1221 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 void CookiesTreeModel::MaybeNotifyBatchesEnded() { 1520 void CookiesTreeModel::MaybeNotifyBatchesEnded() {
1543 // Only notify the observers if this is the outermost call to EndBatch() if 1521 // Only notify the observers if this is the outermost call to EndBatch() if
1544 // called in a nested manner. 1522 // called in a nested manner.
1545 if (batches_ended_ == batches_started_ && 1523 if (batches_ended_ == batches_started_ &&
1546 batches_seen_ == batches_expected_) { 1524 batches_seen_ == batches_expected_) {
1547 FOR_EACH_OBSERVER(Observer, 1525 FOR_EACH_OBSERVER(Observer,
1548 cookies_observer_list_, 1526 cookies_observer_list_,
1549 TreeModelEndBatch(this)); 1527 TreeModelEndBatch(this));
1550 } 1528 }
1551 } 1529 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/cookies_tree_model.h ('k') | chrome/browser/browsing_data/cookies_tree_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698