OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/tab_contents/tab_specific_content_settings.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 |
| 9 bool TabSpecificContentSettings::IsContentBlocked( |
| 10 ContentSettingsType content_type) const { |
| 11 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 12 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; |
| 13 DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 14 << "Notifications settings handled by " |
| 15 << "ContentSettingsNotificationsImageModel"; |
| 16 |
| 17 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 18 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| 19 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || |
| 20 content_type == CONTENT_SETTINGS_TYPE_COOKIES || |
| 21 content_type == CONTENT_SETTINGS_TYPE_POPUPS) |
| 22 return content_blocked_[content_type]; |
| 23 |
| 24 NOTREACHED(); |
| 25 return false; |
| 26 } |
| 27 |
| 28 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
| 29 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 30 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 31 content_blocked_[type] = true; |
| 32 if (delegate_) |
| 33 delegate_->OnContentSettingsChange(); |
| 34 } |
| 35 |
| 36 void TabSpecificContentSettings::OnCookieAccessed( |
| 37 const GURL& url, const std::string& cookie_line, bool blocked_by_policy) { |
| 38 net::CookieOptions options; |
| 39 options.set_include_httponly(); |
| 40 if (blocked_by_policy) { |
| 41 blocked_local_shared_objects_.cookies()->SetCookieWithOptions( |
| 42 url, cookie_line, options); |
| 43 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 44 } else { |
| 45 allowed_local_shared_objects_.cookies()->SetCookieWithOptions( |
| 46 url, cookie_line, options); |
| 47 } |
| 48 } |
| 49 |
| 50 void TabSpecificContentSettings::OnLocalStorageAccessed( |
| 51 const GURL& url, bool blocked_by_policy) { |
| 52 if (blocked_by_policy) { |
| 53 blocked_local_shared_objects_.local_storages()->AddLocalStorage(url); |
| 54 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 55 } else { |
| 56 allowed_local_shared_objects_.local_storages()->AddLocalStorage(url); |
| 57 } |
| 58 } |
| 59 |
| 60 void TabSpecificContentSettings::OnWebDatabaseAccessed( |
| 61 const GURL& url, |
| 62 const string16& name, |
| 63 const string16& display_name, |
| 64 unsigned long estimated_size, |
| 65 bool blocked_by_policy) { |
| 66 if (blocked_by_policy) { |
| 67 blocked_local_shared_objects_.databases()->AddDatabase( |
| 68 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name)); |
| 69 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 70 } else { |
| 71 allowed_local_shared_objects_.databases()->AddDatabase( |
| 72 url, UTF16ToUTF8(name), UTF16ToUTF8(display_name)); |
| 73 } |
| 74 } |
| 75 |
| 76 void TabSpecificContentSettings::OnGeolocationPermissionSet( |
| 77 const GURL& requesting_origin, |
| 78 bool allowed) { |
| 79 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin, |
| 80 allowed); |
| 81 if (delegate_) |
| 82 delegate_->OnContentSettingsChange(); |
| 83 } |
| 84 |
| 85 TabSpecificContentSettings::TabSpecificContentSettings( |
| 86 Delegate* delegate, Profile* profile) |
| 87 : allowed_local_shared_objects_(profile), |
| 88 blocked_local_shared_objects_(profile), |
| 89 geolocation_settings_state_(profile), |
| 90 delegate_(NULL) { |
| 91 ClearBlockedContentSettings(); |
| 92 delegate_ = delegate; |
| 93 } |
| 94 |
| 95 void TabSpecificContentSettings::ClearBlockedContentSettings() { |
| 96 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 97 content_blocked_[i] = false; |
| 98 blocked_local_shared_objects_.Reset(); |
| 99 allowed_local_shared_objects_.Reset(); |
| 100 if (delegate_) |
| 101 delegate_->OnContentSettingsChange(); |
| 102 } |
| 103 |
| 104 void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) { |
| 105 content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked; |
| 106 if (delegate_) |
| 107 delegate_->OnContentSettingsChange(); |
| 108 } |
| 109 |
| 110 void TabSpecificContentSettings::GeolocationDidNavigate( |
| 111 const NavigationController::LoadCommittedDetails& details) { |
| 112 geolocation_settings_state_.DidNavigate(details); |
| 113 } |
| 114 |
| 115 TabSpecificContentSettings::LocalSharedObjectsContainer:: |
| 116 LocalSharedObjectsContainer(Profile* profile) |
| 117 : cookies_(new net::CookieMonster(NULL, NULL)), |
| 118 appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), |
| 119 databases_(new CannedBrowsingDataDatabaseHelper(profile)), |
| 120 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { |
| 121 } |
| 122 |
| 123 void TabSpecificContentSettings::LocalSharedObjectsContainer::Reset() { |
| 124 cookies_->DeleteAll(false); |
| 125 appcaches_->Reset(); |
| 126 databases_->Reset(); |
| 127 local_storages_->Reset(); |
| 128 } |
OLD | NEW |