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