OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/tab_specific_content_settings.h" | 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browsing_data_appcache_helper.h" | 11 #include "chrome/browser/browsing_data_appcache_helper.h" |
12 #include "chrome/browser/browsing_data_cookie_helper.h" | |
13 #include "chrome/browser/browsing_data_database_helper.h" | 12 #include "chrome/browser/browsing_data_database_helper.h" |
14 #include "chrome/browser/browsing_data_file_system_helper.h" | 13 #include "chrome/browser/browsing_data_file_system_helper.h" |
15 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 14 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
16 #include "chrome/browser/browsing_data_local_storage_helper.h" | 15 #include "chrome/browser/browsing_data_local_storage_helper.h" |
17 #include "chrome/browser/content_settings/content_settings_details.h" | 16 #include "chrome/browser/content_settings/content_settings_details.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
19 #include "chrome/browser/cookies_tree_model.h" | 18 #include "chrome/browser/cookies_tree_model.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
23 #include "content/browser/renderer_host/render_process_host.h" | 22 #include "content/browser/renderer_host/render_process_host.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 23 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/browser/tab_contents/navigation_details.h" | 24 #include "content/browser/tab_contents/navigation_details.h" |
26 #include "content/browser/tab_contents/tab_contents.h" | 25 #include "content/browser/tab_contents/tab_contents.h" |
27 #include "content/browser/tab_contents/tab_contents_delegate.h" | 26 #include "content/browser/tab_contents/tab_contents_delegate.h" |
28 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
29 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 29 #include "net/base/cookie_monster.h" |
30 #include "webkit/fileapi/file_system_types.h" | 30 #include "webkit/fileapi/file_system_types.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 typedef std::list<TabSpecificContentSettings*> TabSpecificList; | 33 typedef std::list<TabSpecificContentSettings*> TabSpecificList; |
34 static base::LazyInstance<TabSpecificList> g_tab_specific( | 34 static base::LazyInstance<TabSpecificList> g_tab_specific( |
35 base::LINKER_INITIALIZED); | 35 base::LINKER_INITIALIZED); |
36 } | 36 } |
37 | 37 |
38 bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const { | 38 bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const { |
39 return appcaches_->empty() && | 39 return cookies_->GetAllCookies().empty() && |
40 cookies_->empty() && | 40 appcaches_->empty() && |
41 databases_->empty() && | 41 databases_->empty() && |
42 file_systems_->empty() && | 42 file_systems_->empty() && |
43 indexed_dbs_->empty() && | 43 indexed_dbs_->empty() && |
44 local_storages_->empty() && | 44 local_storages_->empty() && |
45 session_storages_->empty(); | 45 session_storages_->empty(); |
46 } | 46 } |
47 | 47 |
48 TabSpecificContentSettings::TabSpecificContentSettings(TabContents* tab) | 48 TabSpecificContentSettings::TabSpecificContentSettings(TabContents* tab) |
49 : TabContentsObserver(tab), | 49 : TabContentsObserver(tab), |
50 profile_(Profile::FromBrowserContext(tab->browser_context())), | 50 profile_(Profile::FromBrowserContext(tab->browser_context())), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 NotificationService::NoDetails()); | 232 NotificationService::NoDetails()); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void TabSpecificContentSettings::OnCookiesRead( | 236 void TabSpecificContentSettings::OnCookiesRead( |
237 const GURL& url, | 237 const GURL& url, |
238 const net::CookieList& cookie_list, | 238 const net::CookieList& cookie_list, |
239 bool blocked_by_policy) { | 239 bool blocked_by_policy) { |
240 if (cookie_list.empty()) | 240 if (cookie_list.empty()) |
241 return; | 241 return; |
242 if (blocked_by_policy) { | 242 LocalSharedObjectsContainer& container = blocked_by_policy ? |
243 blocked_local_shared_objects_.cookies()->AddReadCookies( | 243 blocked_local_shared_objects_ : allowed_local_shared_objects_; |
244 url, cookie_list); | 244 typedef net::CookieList::const_iterator cookie_iterator; |
| 245 for (cookie_iterator cookie = cookie_list.begin(); |
| 246 cookie != cookie_list.end(); ++cookie) { |
| 247 container.cookies()->SetCookieWithDetails(url, |
| 248 cookie->Name(), |
| 249 cookie->Value(), |
| 250 cookie->Domain(), |
| 251 cookie->Path(), |
| 252 cookie->ExpiryDate(), |
| 253 cookie->IsSecure(), |
| 254 cookie->IsHttpOnly()); |
| 255 } |
| 256 if (blocked_by_policy) |
245 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 257 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
246 } else { | 258 else |
247 allowed_local_shared_objects_.cookies()->AddReadCookies( | |
248 url, cookie_list); | |
249 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); | 259 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); |
250 } | |
251 } | 260 } |
252 | 261 |
253 void TabSpecificContentSettings::OnCookieChanged( | 262 void TabSpecificContentSettings::OnCookieChanged( |
254 const GURL& url, | 263 const GURL& url, |
255 const std::string& cookie_line, | 264 const std::string& cookie_line, |
256 const net::CookieOptions& options, | 265 const net::CookieOptions& options, |
257 bool blocked_by_policy) { | 266 bool blocked_by_policy) { |
258 if (blocked_by_policy) { | 267 if (blocked_by_policy) { |
259 blocked_local_shared_objects_.cookies()->AddChangedCookie( | 268 blocked_local_shared_objects_.cookies()->SetCookieWithOptions( |
260 url, cookie_line, options); | 269 url, cookie_line, options); |
261 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 270 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
262 } else { | 271 } else { |
263 allowed_local_shared_objects_.cookies()->AddChangedCookie( | 272 allowed_local_shared_objects_.cookies()->SetCookieWithOptions( |
264 url, cookie_line, options); | 273 url, cookie_line, options); |
265 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); | 274 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); |
266 } | 275 } |
267 } | 276 } |
268 | 277 |
269 void TabSpecificContentSettings::OnIndexedDBAccessed( | 278 void TabSpecificContentSettings::OnIndexedDBAccessed( |
270 const GURL& url, | 279 const GURL& url, |
271 const string16& description, | 280 const string16& description, |
272 bool blocked_by_policy) { | 281 bool blocked_by_policy) { |
273 if (blocked_by_policy) { | 282 if (blocked_by_policy) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 479 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
471 Send(new ViewMsg_SetDefaultContentSettings( | 480 Send(new ViewMsg_SetDefaultContentSettings( |
472 map->GetDefaultContentSettings())); | 481 map->GetDefaultContentSettings())); |
473 Send(new ViewMsg_SetContentSettingsForCurrentURL( | 482 Send(new ViewMsg_SetContentSettingsForCurrentURL( |
474 entry_url, map->GetContentSettings(entry_url, entry_url))); | 483 entry_url, map->GetContentSettings(entry_url, entry_url))); |
475 } | 484 } |
476 } | 485 } |
477 | 486 |
478 TabSpecificContentSettings::LocalSharedObjectsContainer:: | 487 TabSpecificContentSettings::LocalSharedObjectsContainer:: |
479 LocalSharedObjectsContainer(Profile* profile) | 488 LocalSharedObjectsContainer(Profile* profile) |
480 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), | 489 : cookies_(new net::CookieMonster(NULL, NULL)), |
481 cookies_(new CannedBrowsingDataCookieHelper(profile)), | 490 appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), |
482 databases_(new CannedBrowsingDataDatabaseHelper(profile)), | 491 databases_(new CannedBrowsingDataDatabaseHelper(profile)), |
483 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), | 492 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), |
484 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)), | 493 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)), |
485 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), | 494 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), |
486 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { | 495 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { |
| 496 cookies_->SetCookieableSchemes( |
| 497 net::CookieMonster::kDefaultCookieableSchemes, |
| 498 net::CookieMonster::kDefaultCookieableSchemesCount); |
| 499 cookies_->SetKeepExpiredCookies(); |
487 } | 500 } |
488 | 501 |
489 TabSpecificContentSettings::LocalSharedObjectsContainer:: | 502 TabSpecificContentSettings::LocalSharedObjectsContainer:: |
490 ~LocalSharedObjectsContainer() { | 503 ~LocalSharedObjectsContainer() { |
491 } | 504 } |
492 | 505 |
493 void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { | 506 void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { |
| 507 cookies_ = new net::CookieMonster(NULL, NULL); |
| 508 cookies_->SetCookieableSchemes( |
| 509 net::CookieMonster::kDefaultCookieableSchemes, |
| 510 net::CookieMonster::kDefaultCookieableSchemesCount); |
| 511 cookies_->SetKeepExpiredCookies(); |
494 appcaches_->Reset(); | 512 appcaches_->Reset(); |
495 cookies_->Reset(); | |
496 databases_->Reset(); | 513 databases_->Reset(); |
497 file_systems_->Reset(); | 514 file_systems_->Reset(); |
498 indexed_dbs_->Reset(); | 515 indexed_dbs_->Reset(); |
499 local_storages_->Reset(); | 516 local_storages_->Reset(); |
500 session_storages_->Reset(); | 517 session_storages_->Reset(); |
501 } | 518 } |
502 | 519 |
503 CookiesTreeModel* | 520 CookiesTreeModel* |
504 TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() { | 521 TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() { |
505 return new CookiesTreeModel(cookies_->Clone(), | 522 return new CookiesTreeModel(cookies_, |
506 databases_->Clone(), | 523 databases_->Clone(), |
507 local_storages_->Clone(), | 524 local_storages_->Clone(), |
508 session_storages_->Clone(), | 525 session_storages_->Clone(), |
509 appcaches_->Clone(), | 526 appcaches_->Clone(), |
510 indexed_dbs_->Clone(), | 527 indexed_dbs_->Clone(), |
511 file_systems_->Clone(), | 528 file_systems_->Clone(), |
512 true); | 529 true); |
513 } | 530 } |
OLD | NEW |