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/renderer/content_settings_observer.h" | 5 #include "chrome/renderer/content_settings_observer.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
9 #include "content/public/renderer/navigation_state.h" | 9 #include "content/public/renderer/navigation_state.h" |
10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 ContentSettings ContentSettingsObserver::default_settings_; | 64 ContentSettings ContentSettingsObserver::default_settings_; |
65 | 65 |
66 ContentSettingsObserver::ContentSettingsObserver( | 66 ContentSettingsObserver::ContentSettingsObserver( |
67 content::RenderView* render_view) | 67 content::RenderView* render_view) |
68 : content::RenderViewObserver(render_view), | 68 : content::RenderViewObserver(render_view), |
69 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 69 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
70 content_setting_rules_(NULL), | |
70 plugins_temporarily_allowed_(false) { | 71 plugins_temporarily_allowed_(false) { |
71 ClearBlockedContentSettings(); | 72 ClearBlockedContentSettings(); |
72 } | 73 } |
73 | 74 |
74 ContentSettingsObserver::~ContentSettingsObserver() { | 75 ContentSettingsObserver::~ContentSettingsObserver() { |
75 } | 76 } |
76 | 77 |
77 void ContentSettingsObserver::SetContentSettings( | 78 void ContentSettingsObserver::SetContentSettings( |
78 const ContentSettings& settings) { | 79 const ContentSettings& settings) { |
79 current_content_settings_ = settings; | 80 current_content_settings_ = settings; |
80 } | 81 } |
81 | 82 |
82 void ContentSettingsObserver::SetDefaultContentSettings( | 83 void ContentSettingsObserver::SetDefaultContentSettings( |
83 const ContentSettings& settings) { | 84 const ContentSettings& settings) { |
84 default_settings_ = settings; | 85 default_settings_ = settings; |
85 } | 86 } |
86 | 87 |
87 void ContentSettingsObserver::SetImageSettingRules( | 88 void ContentSettingsObserver::SetContentSettingRules( |
88 const ContentSettingsForOneType* image_setting_rules) { | 89 const ContentSettingsForOneType* content_setting_rules) { |
89 image_setting_rules_ = image_setting_rules; | 90 content_setting_rules_ = content_setting_rules; |
90 } | 91 } |
91 | 92 |
92 ContentSetting ContentSettingsObserver::GetContentSetting( | 93 ContentSetting ContentSettingsObserver::GetContentSetting( |
93 ContentSettingsType type) { | 94 ContentSettingsType type) { |
94 // Don't call this for plug-ins. | 95 // Don't call this for plug-ins. |
95 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); | 96 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); |
96 return current_content_settings_.settings[type]; | 97 return current_content_settings_.settings[type]; |
97 } | 98 } |
98 | 99 |
99 void ContentSettingsObserver::DidBlockContentType( | 100 void ContentSettingsObserver::DidBlockContentType( |
(...skipping 25 matching lines...) Expand all Loading... | |
125 } | 126 } |
126 | 127 |
127 void ContentSettingsObserver::DidCommitProvisionalLoad( | 128 void ContentSettingsObserver::DidCommitProvisionalLoad( |
128 WebFrame* frame, bool is_new_navigation) { | 129 WebFrame* frame, bool is_new_navigation) { |
129 if (frame->parent()) | 130 if (frame->parent()) |
130 return; // Not a top-level navigation. | 131 return; // Not a top-level navigation. |
131 | 132 |
132 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); | 133 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
133 if (!state->was_within_same_page()) { | 134 if (!state->was_within_same_page()) { |
134 // Clear "block" flags for the new page. This needs to happen before any of | 135 // Clear "block" flags for the new page. This needs to happen before any of |
135 // allowScripts(), allowImage(), allowPlugins() is called for the new page | 136 // |AllowScript()|, |AllowScriptFromSource()|, |AllowImage()|, or |
136 // so that these functions can correctly detect that a piece of content | 137 // |AllowPlugins()| is called for the new page so that these functions can |
137 // flipped from "not blocked" to "blocked". | 138 // correctly detect that a piece of content flipped from "not blocked" to |
139 // "blocked". | |
138 ClearBlockedContentSettings(); | 140 ClearBlockedContentSettings(); |
139 plugins_temporarily_allowed_ = false; | 141 plugins_temporarily_allowed_ = false; |
140 } | 142 } |
141 | 143 |
142 GURL url = frame->document().url(); | 144 GURL url = frame->document().url(); |
143 | 145 |
144 if (frame->document().securityOrigin().toString() == "null" && | 146 if (frame->document().securityOrigin().toString() == "null" && |
145 !url.SchemeIs(chrome::kFileScheme)) { | 147 !url.SchemeIs(chrome::kFileScheme)) { |
146 // The Frame has a unique security origin. Instead of granting the frame | 148 // The Frame has a unique security origin. Instead of granting the frame |
147 // privileges based on it's URL, we fall back to the default content | 149 // privileges based on it's URL, we fall back to the default content |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 213 |
212 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 214 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
213 bool enabled_per_settings, | 215 bool enabled_per_settings, |
214 const WebURL& image_url) { | 216 const WebURL& image_url) { |
215 if (IsWhitelistedForContentSettings(frame)) | 217 if (IsWhitelistedForContentSettings(frame)) |
216 return true; | 218 return true; |
217 | 219 |
218 bool allow = enabled_per_settings; | 220 bool allow = enabled_per_settings; |
219 const GURL& primary_url = GetOriginOrURL(frame); | 221 const GURL& primary_url = GetOriginOrURL(frame); |
220 GURL secondary_url(image_url); | 222 GURL secondary_url(image_url); |
221 if (image_setting_rules_ && | 223 if (content_setting_rules_ && |
222 enabled_per_settings) { | 224 enabled_per_settings) { |
225 const ContentSettingsForOneType& image_setting_rules = | |
226 content_setting_rules_[CONTENT_SETTINGS_TYPE_IMAGES]; | |
223 ContentSettingsForOneType::const_iterator it; | 227 ContentSettingsForOneType::const_iterator it; |
224 for (it = image_setting_rules_->begin(); | 228 for (it = image_setting_rules.begin(); |
225 it != image_setting_rules_->end(); ++it) { | 229 it != image_setting_rules.end(); ++it) { |
226 if (it->primary_pattern.Matches(primary_url) && | 230 if (it->primary_pattern.Matches(primary_url) && |
227 it->secondary_pattern.Matches(secondary_url)) { | 231 it->secondary_pattern.Matches(secondary_url)) { |
228 allow = (it->setting != CONTENT_SETTING_BLOCK); | 232 allow = (it->setting != CONTENT_SETTING_BLOCK); |
229 break; | 233 break; |
230 } | 234 } |
231 } | 235 } |
232 } | 236 } |
233 | 237 |
234 if (!allow) | 238 if (!allow) |
235 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 239 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
(...skipping 16 matching lines...) Expand all Loading... | |
252 } | 256 } |
253 | 257 |
254 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, | 258 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, |
255 bool enabled_per_settings) { | 259 bool enabled_per_settings) { |
256 return enabled_per_settings; | 260 return enabled_per_settings; |
257 } | 261 } |
258 | 262 |
259 bool ContentSettingsObserver::AllowScript(WebFrame* frame, | 263 bool ContentSettingsObserver::AllowScript(WebFrame* frame, |
260 bool enabled_per_settings) { | 264 bool enabled_per_settings) { |
261 if (enabled_per_settings && | 265 if (enabled_per_settings && |
262 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { | 266 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { |
jochen (gone - plz use gerrit)
2011/11/02 09:25:05
can you also update this to take frame->top and fr
Bernhard Bauer
2011/11/02 09:57:14
How are they going to interact?
jochen (gone - plz use gerrit)
2011/11/02 10:40:48
allowScripts checks whether a given security origi
marja
2011/11/02 14:46:35
Using the top document's security origin as primar
jochen (gone - plz use gerrit)
2011/11/02 19:19:00
right
marja
2011/11/02 22:16:01
Done, in that case.
| |
263 return true; | 267 return true; |
264 } | 268 } |
265 | 269 |
266 if (IsWhitelistedForContentSettings(frame)) | 270 if (IsWhitelistedForContentSettings(frame)) |
267 return true; | 271 return true; |
268 | 272 |
269 return false; // Other protocols fall through here. | 273 return false; // Other protocols fall through here. |
270 } | 274 } |
271 | 275 |
276 bool ContentSettingsObserver::AllowScriptFromSource( | |
277 WebFrame* frame, | |
278 bool enabled_per_settings, | |
279 const WebKit::WebURL& script_url) { | |
280 if (!enabled_per_settings) | |
281 return false; | |
282 if (IsWhitelistedForContentSettings(frame)) | |
283 return true; | |
284 | |
285 if (content_setting_rules_) { | |
286 const ContentSettingsForOneType& script_setting_rules = | |
287 content_setting_rules_[CONTENT_SETTINGS_TYPE_JAVASCRIPT]; | |
288 const GURL& primary_url = GetOriginOrURL(frame); | |
289 GURL secondary_url(script_url); | |
290 ContentSettingsForOneType::const_iterator it; | |
291 for (it = script_setting_rules.begin(); | |
292 it != script_setting_rules.end(); ++it) { | |
293 if (it->primary_pattern.Matches(primary_url) && | |
294 it->secondary_pattern.Matches(secondary_url)) { | |
295 return (it->setting != CONTENT_SETTING_BLOCK); | |
296 } | |
297 } | |
298 } | |
299 return true; | |
300 } | |
301 | |
272 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { | 302 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { |
273 if (frame->document().securityOrigin().isEmpty() || | 303 if (frame->document().securityOrigin().isEmpty() || |
274 frame->top()->document().securityOrigin().isEmpty()) | 304 frame->top()->document().securityOrigin().isEmpty()) |
275 return false; // Uninitialized document. | 305 return false; // Uninitialized document. |
276 bool result = false; | 306 bool result = false; |
277 | 307 |
278 StoragePermissionsKey key( | 308 StoragePermissionsKey key( |
279 GURL(frame->document().securityOrigin().toString()), local); | 309 GURL(frame->document().securityOrigin().toString()), local); |
280 std::map<StoragePermissionsKey, bool>::const_iterator permissions = | 310 std::map<StoragePermissionsKey, bool>::const_iterator permissions = |
281 cached_storage_permissions_.find(key); | 311 cached_storage_permissions_.find(key); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 // CONTENT_SETTING_ASK is only valid for cookies. | 344 // CONTENT_SETTING_ASK is only valid for cookies. |
315 return current_content_settings_.settings[settings_type] != | 345 return current_content_settings_.settings[settings_type] != |
316 CONTENT_SETTING_BLOCK; | 346 CONTENT_SETTING_BLOCK; |
317 } | 347 } |
318 | 348 |
319 void ContentSettingsObserver::ClearBlockedContentSettings() { | 349 void ContentSettingsObserver::ClearBlockedContentSettings() { |
320 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 350 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
321 content_blocked_[i] = false; | 351 content_blocked_[i] = false; |
322 cached_storage_permissions_.clear(); | 352 cached_storage_permissions_.clear(); |
323 } | 353 } |
OLD | NEW |