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

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

Issue 10092013: Display third party cookies and site data counts in the WebsiteSettings UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 8 years, 8 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/browsing_data_cookie_helper.h" 5 #include "chrome/browser/browsing_data_cookie_helper.h"
6 6
7 #include "utility"
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stl_util.h"
10 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
12 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/base/registry_controlled_domain.h"
13 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
14 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
15 19
16 using content::BrowserThread; 20 using content::BrowserThread;
17 21
18 BrowsingDataCookieHelper::BrowsingDataCookieHelper(Profile* profile) 22 BrowsingDataCookieHelper::BrowsingDataCookieHelper(Profile* profile)
19 : is_fetching_(false), 23 : is_fetching_(false),
20 profile_(profile), 24 profile_(profile),
21 request_context_getter_(profile->GetRequestContext()) { 25 request_context_getter_(profile->GetRequestContext()) {
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 cookie_monster->DeleteCanonicalCookieAsync( 90 cookie_monster->DeleteCanonicalCookieAsync(
87 cookie, net::CookieMonster::DeleteCookieCallback()); 91 cookie, net::CookieMonster::DeleteCookieCallback());
88 } 92 }
89 } 93 }
90 94
91 CannedBrowsingDataCookieHelper::CannedBrowsingDataCookieHelper( 95 CannedBrowsingDataCookieHelper::CannedBrowsingDataCookieHelper(
92 Profile* profile) 96 Profile* profile)
93 : BrowsingDataCookieHelper(profile) { 97 : BrowsingDataCookieHelper(profile) {
94 } 98 }
95 99
96 CannedBrowsingDataCookieHelper::~CannedBrowsingDataCookieHelper() {} 100 CannedBrowsingDataCookieHelper::~CannedBrowsingDataCookieHelper() {
101 Reset();
102 }
97 103
98 CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() { 104 CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
100 CannedBrowsingDataCookieHelper* clone = 106 CannedBrowsingDataCookieHelper* clone =
101 new CannedBrowsingDataCookieHelper(profile()); 107 new CannedBrowsingDataCookieHelper(profile());
102 108
103 clone->cookie_list_ = cookie_list_; 109 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin();
110 it != origin_cookie_list_map_.end();
111 ++it) {
112 net::CookieList* cookies = clone->GetCookiesFor(it->first);
113 cookies->insert(cookies->begin(), it->second->begin(), it->second->end());
114 }
104 return clone; 115 return clone;
105 } 116 }
106 117
107 void CannedBrowsingDataCookieHelper::AddReadCookies( 118 void CannedBrowsingDataCookieHelper::AddReadCookies(
119 const GURL& frame_url,
108 const GURL& url, 120 const GURL& url,
109 const net::CookieList& cookie_list) { 121 const net::CookieList& cookie_list) {
110 typedef net::CookieList::const_iterator cookie_iterator; 122 typedef net::CookieList::const_iterator cookie_iterator;
111 for (cookie_iterator add_cookie = cookie_list.begin(); 123 for (cookie_iterator add_cookie = cookie_list.begin();
112 add_cookie != cookie_list.end(); ++add_cookie) { 124 add_cookie != cookie_list.end(); ++add_cookie) {
113 DeleteMetchingCookie(*add_cookie); 125 AddCookie(frame_url, *add_cookie);
114 cookie_list_.push_back(*add_cookie);
115 } 126 }
116 } 127 }
117 128
118 void CannedBrowsingDataCookieHelper::AddChangedCookie( 129 void CannedBrowsingDataCookieHelper::AddChangedCookie(
130 const GURL& frame_url,
119 const GURL& url, 131 const GURL& url,
120 const std::string& cookie_line, 132 const std::string& cookie_line,
121 const net::CookieOptions& options) { 133 const net::CookieOptions& options) {
122 typedef net::CookieList::iterator cookie_iterator; 134 net::CookieMonster::ParsedCookie parsed_cookie(cookie_line);
123 135 if (options.exclude_httponly() && parsed_cookie.IsHttpOnly()) {
124 net::CookieMonster::ParsedCookie pc(cookie_line);
125 if (options.exclude_httponly() && pc.IsHttpOnly()) {
126 // Return if a Javascript cookie illegally specified the HTTP only flag. 136 // Return if a Javascript cookie illegally specified the HTTP only flag.
127 return; 137 return;
128 } 138 }
129 139
130 scoped_ptr<net::CookieMonster::CanonicalCookie> cc; 140 scoped_ptr<net::CookieMonster::CanonicalCookie> cookie;
bauerb at google 2012/04/27 16:12:50 You can immediately initialize |cookie| with the n
markusheintz_ 2012/05/10 16:32:36 Done.
131 // This fails to create a canonical cookie, if the normalized cookie domain 141 // This fails to create a canonical cookie, if the normalized cookie domain
132 // form cookie line and the url don't have the same domain+registry, or url 142 // form cookie line and the url don't have the same domain+registry, or url
133 // host isn't cookie domain or one of its subdomains. 143 // host isn't cookie domain or one of its subdomains.
134 cc.reset(net::CookieMonster::CanonicalCookie::Create(url, pc)); 144 cookie.reset(net::CookieMonster::CanonicalCookie::Create(url, parsed_cookie));
135 145
136 if (cc.get()) { 146 if (cookie.get())
137 DeleteMetchingCookie(*cc); 147 AddCookie(frame_url, *cookie);
138 cookie_list_.push_back(*cc);
139 }
140 } 148 }
141 149
142 void CannedBrowsingDataCookieHelper::Reset() { 150 void CannedBrowsingDataCookieHelper::Reset() {
143 cookie_list_.clear(); 151 STLDeleteContainerPairSecondPointers(origin_cookie_list_map_.begin(),
152 origin_cookie_list_map_.end());
153 origin_cookie_list_map_.clear();
144 } 154 }
145 155
146 bool CannedBrowsingDataCookieHelper::empty() const { 156 bool CannedBrowsingDataCookieHelper::empty() const {
147 return cookie_list_.empty(); 157 for (OriginCookieListMap::const_iterator it =
158 origin_cookie_list_map_.begin();
159 it != origin_cookie_list_map_.end();
160 ++it) {
161 if (!it->second->empty())
162 return false;
163 }
164 return true;
148 } 165 }
149 166
167
150 size_t CannedBrowsingDataCookieHelper::GetCookieCount() const { 168 size_t CannedBrowsingDataCookieHelper::GetCookieCount() const {
151 return cookie_list_.size(); 169 size_t count = 0;
170 for (OriginCookieListMap::const_iterator it = origin_cookie_list_map_.begin();
171 it != origin_cookie_list_map_.end();
172 ++it) {
173 count += it->second->size();
174 }
175 return count;
152 } 176 }
153 177
178
154 void CannedBrowsingDataCookieHelper::StartFetching( 179 void CannedBrowsingDataCookieHelper::StartFetching(
155 const net::CookieMonster::GetCookieListCallback& callback) { 180 const net::CookieMonster::GetCookieListCallback& callback) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
157 callback.Run(cookie_list_); 182 net::CookieList cookie_list;
183 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin();
184 it != origin_cookie_list_map_.end();
185 ++it) {
186 cookie_list.insert(cookie_list.begin(),
187 it->second->begin(),
188 it->second->end());
189 }
190 callback.Run(cookie_list);
158 } 191 }
159 192
160 bool CannedBrowsingDataCookieHelper::DeleteMetchingCookie( 193 bool CannedBrowsingDataCookieHelper::DeleteMatchingCookie(
161 const net::CookieMonster::CanonicalCookie& add_cookie) { 194 const net::CookieMonster::CanonicalCookie& add_cookie,
195 net::CookieList* cookie_list) {
162 typedef net::CookieList::iterator cookie_iterator; 196 typedef net::CookieList::iterator cookie_iterator;
163 for (cookie_iterator cookie = cookie_list_.begin(); 197 for (cookie_iterator cookie = cookie_list->begin();
164 cookie != cookie_list_.end(); ++cookie) { 198 cookie != cookie_list->end(); ++cookie) {
165 if (cookie->Name() == add_cookie.Name() && 199 if (cookie->Name() == add_cookie.Name() &&
166 cookie->Domain() == add_cookie.Domain()&& 200 cookie->Domain() == add_cookie.Domain()&&
167 cookie->Path() == add_cookie.Path()) { 201 cookie->Path() == add_cookie.Path()) {
168 cookie_list_.erase(cookie); 202 cookie_list->erase(cookie);
169 return true; 203 return true;
170 } 204 }
171 } 205 }
172 return false; 206 return false;
173 } 207 }
208
209 net::CookieList* CannedBrowsingDataCookieHelper::GetCookiesFor(
210 const GURL& first_party_origin) {
211 OriginCookieListMap::iterator it =
212 origin_cookie_list_map_.find(first_party_origin);
213 if (it == origin_cookie_list_map_.end()) {
214 net::CookieList* cookies = new net::CookieList();
215 origin_cookie_list_map_.insert(
216 std::pair<GURL, net::CookieList*>(first_party_origin, cookies));
217 return cookies;
218 }
219 return it->second;
220 }
221
222 void CannedBrowsingDataCookieHelper::AddCookie(
223 const GURL& frame_url,
224 const net::CookieMonster::CanonicalCookie& cookie) {
225 net::CookieList* cookie_list =
226 GetCookiesFor(frame_url.GetOrigin());
227 DeleteMatchingCookie(cookie, cookie_list);
228 cookie_list->push_back(cookie);
229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698