| 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" |
| 12 #include "chrome/browser/browsing_data_database_helper.h" | 13 #include "chrome/browser/browsing_data_database_helper.h" |
| 13 #include "chrome/browser/browsing_data_file_system_helper.h" | 14 #include "chrome/browser/browsing_data_file_system_helper.h" |
| 14 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 15 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
| 15 #include "chrome/browser/browsing_data_local_storage_helper.h" | 16 #include "chrome/browser/browsing_data_local_storage_helper.h" |
| 16 #include "chrome/browser/content_settings/content_settings_details.h" | 17 #include "chrome/browser/content_settings/content_settings_details.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 18 #include "chrome/browser/cookies_tree_model.h" | 19 #include "chrome/browser/cookies_tree_model.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/render_messages.h" | 22 #include "chrome/common/render_messages.h" |
| 22 #include "content/browser/renderer_host/render_process_host.h" | 23 #include "content/browser/renderer_host/render_process_host.h" |
| 23 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 24 #include "content/browser/tab_contents/navigation_details.h" | 25 #include "content/browser/tab_contents/navigation_details.h" |
| 25 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
| 26 #include "content/browser/tab_contents/tab_contents_delegate.h" | 27 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 27 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
| 28 #include "content/common/view_messages.h" | 29 #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 cookies_->GetAllCookies().empty() && | 39 return appcaches_->empty() && |
| 40 appcaches_->empty() && | 40 cookies_->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 allowed_local_shared_objects_(tab->profile()), | 50 allowed_local_shared_objects_(tab->profile()), |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 NotificationService::NoDetails()); | 231 NotificationService::NoDetails()); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 void TabSpecificContentSettings::OnCookiesRead( | 235 void TabSpecificContentSettings::OnCookiesRead( |
| 236 const GURL& url, | 236 const GURL& url, |
| 237 const net::CookieList& cookie_list, | 237 const net::CookieList& cookie_list, |
| 238 bool blocked_by_policy) { | 238 bool blocked_by_policy) { |
| 239 if (cookie_list.empty()) | 239 if (cookie_list.empty()) |
| 240 return; | 240 return; |
| 241 LocalSharedObjectsContainer& container = blocked_by_policy ? | 241 if (blocked_by_policy) { |
| 242 blocked_local_shared_objects_ : allowed_local_shared_objects_; | 242 blocked_local_shared_objects_.cookies()->AddReadCookie( |
| 243 typedef net::CookieList::const_iterator cookie_iterator; | 243 url, cookie_list); |
| 244 for (cookie_iterator cookie = cookie_list.begin(); | 244 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 245 cookie != cookie_list.end(); ++cookie) { | 245 } else { |
| 246 container.cookies()->SetCookieWithDetails(url, | 246 allowed_local_shared_objects_.cookies()->AddReadCookie( |
| 247 cookie->Name(), | 247 url, cookie_list); |
| 248 cookie->Value(), | 248 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); |
| 249 cookie->Domain(), | |
| 250 cookie->Path(), | |
| 251 cookie->ExpiryDate(), | |
| 252 cookie->IsSecure(), | |
| 253 cookie->IsHttpOnly()); | |
| 254 } | 249 } |
| 255 if (blocked_by_policy) | |
| 256 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | |
| 257 else | |
| 258 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); | |
| 259 } | 250 } |
| 260 | 251 |
| 261 void TabSpecificContentSettings::OnCookieChanged( | 252 void TabSpecificContentSettings::OnCookieChanged( |
| 262 const GURL& url, | 253 const GURL& url, |
| 263 const std::string& cookie_line, | 254 const std::string& cookie_line, |
| 264 const net::CookieOptions& options, | 255 const net::CookieOptions& options, |
| 265 bool blocked_by_policy) { | 256 bool blocked_by_policy) { |
| 266 if (blocked_by_policy) { | 257 if (blocked_by_policy) { |
| 267 blocked_local_shared_objects_.cookies()->SetCookieWithOptions( | 258 blocked_local_shared_objects_.cookies()->AddChangeCookie( |
| 268 url, cookie_line, options); | 259 url, cookie_line, options); |
| 269 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 260 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 270 } else { | 261 } else { |
| 271 allowed_local_shared_objects_.cookies()->SetCookieWithOptions( | 262 allowed_local_shared_objects_.cookies()->AddChangeCookie( |
| 272 url, cookie_line, options); | 263 url, cookie_line, options); |
| 273 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); | 264 OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); |
| 274 } | 265 } |
| 275 } | 266 } |
| 276 | 267 |
| 277 void TabSpecificContentSettings::OnIndexedDBAccessed( | 268 void TabSpecificContentSettings::OnIndexedDBAccessed( |
| 278 const GURL& url, | 269 const GURL& url, |
| 279 const string16& description, | 270 const string16& description, |
| 280 bool blocked_by_policy) { | 271 bool blocked_by_policy) { |
| 281 if (blocked_by_policy) { | 272 if (blocked_by_policy) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 tab_contents()->profile()->GetHostContentSettingsMap(); | 467 tab_contents()->profile()->GetHostContentSettingsMap(); |
| 477 Send(new ViewMsg_SetDefaultContentSettings( | 468 Send(new ViewMsg_SetDefaultContentSettings( |
| 478 map->GetDefaultContentSettings())); | 469 map->GetDefaultContentSettings())); |
| 479 Send(new ViewMsg_SetContentSettingsForCurrentURL( | 470 Send(new ViewMsg_SetContentSettingsForCurrentURL( |
| 480 entry_url, map->GetContentSettings(entry_url, entry_url))); | 471 entry_url, map->GetContentSettings(entry_url, entry_url))); |
| 481 } | 472 } |
| 482 } | 473 } |
| 483 | 474 |
| 484 TabSpecificContentSettings::LocalSharedObjectsContainer:: | 475 TabSpecificContentSettings::LocalSharedObjectsContainer:: |
| 485 LocalSharedObjectsContainer(Profile* profile) | 476 LocalSharedObjectsContainer(Profile* profile) |
| 486 : cookies_(new net::CookieMonster(NULL, NULL)), | 477 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), |
| 487 appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), | 478 cookies_(new CannedBrowsingDataCookieHelper(profile)), |
| 488 databases_(new CannedBrowsingDataDatabaseHelper(profile)), | 479 databases_(new CannedBrowsingDataDatabaseHelper(profile)), |
| 489 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), | 480 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), |
| 490 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)), | 481 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(profile)), |
| 491 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), | 482 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), |
| 492 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { | 483 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { |
| 493 cookies_->SetCookieableSchemes( | |
| 494 net::CookieMonster::kDefaultCookieableSchemes, | |
| 495 net::CookieMonster::kDefaultCookieableSchemesCount); | |
| 496 cookies_->SetKeepExpiredCookies(); | |
| 497 } | 484 } |
| 498 | 485 |
| 499 TabSpecificContentSettings::LocalSharedObjectsContainer:: | 486 TabSpecificContentSettings::LocalSharedObjectsContainer:: |
| 500 ~LocalSharedObjectsContainer() { | 487 ~LocalSharedObjectsContainer() { |
| 501 } | 488 } |
| 502 | 489 |
| 503 void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { | 490 void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { |
| 504 cookies_ = new net::CookieMonster(NULL, NULL); | |
| 505 cookies_->SetCookieableSchemes( | |
| 506 net::CookieMonster::kDefaultCookieableSchemes, | |
| 507 net::CookieMonster::kDefaultCookieableSchemesCount); | |
| 508 cookies_->SetKeepExpiredCookies(); | |
| 509 appcaches_->Reset(); | 491 appcaches_->Reset(); |
| 492 cookies_->Reset(); |
| 510 databases_->Reset(); | 493 databases_->Reset(); |
| 511 file_systems_->Reset(); | 494 file_systems_->Reset(); |
| 512 indexed_dbs_->Reset(); | 495 indexed_dbs_->Reset(); |
| 513 local_storages_->Reset(); | 496 local_storages_->Reset(); |
| 514 session_storages_->Reset(); | 497 session_storages_->Reset(); |
| 515 } | 498 } |
| 516 | 499 |
| 517 CookiesTreeModel* | 500 CookiesTreeModel* |
| 518 TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() { | 501 TabSpecificContentSettings::LocalSharedObjectsContainer::GetCookiesTreeModel() { |
| 519 return new CookiesTreeModel(cookies_, | 502 return new CookiesTreeModel(cookies_->Clone(), |
| 520 databases_->Clone(), | 503 databases_->Clone(), |
| 521 local_storages_->Clone(), | 504 local_storages_->Clone(), |
| 522 session_storages_->Clone(), | 505 session_storages_->Clone(), |
| 523 appcaches_->Clone(), | 506 appcaches_->Clone(), |
| 524 indexed_dbs_->Clone(), | 507 indexed_dbs_->Clone(), |
| 525 file_systems_->Clone(), | 508 file_systems_->Clone(), |
| 526 true); | 509 true); |
| 527 } | 510 } |
| OLD | NEW |