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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 void ContentSettingsObserver::SetContentSettings( | 68 void ContentSettingsObserver::SetContentSettings( |
69 const ContentSettings& settings) { | 69 const ContentSettings& settings) { |
70 current_content_settings_ = settings; | 70 current_content_settings_ = settings; |
71 } | 71 } |
72 | 72 |
73 void ContentSettingsObserver::SetDefaultContentSettings( | 73 void ContentSettingsObserver::SetDefaultContentSettings( |
74 const ContentSettings& settings) { | 74 const ContentSettings& settings) { |
75 default_settings_ = settings; | 75 default_settings_ = settings; |
76 } | 76 } |
77 | 77 |
78 void ContentSettingsObserver::SetImageSettingRules( | |
79 const ContentSettingsForOneType* image_setting_rules) { | |
80 image_setting_rules_ = image_setting_rules; | |
81 } | |
82 | |
78 ContentSetting ContentSettingsObserver::GetContentSetting( | 83 ContentSetting ContentSettingsObserver::GetContentSetting( |
79 ContentSettingsType type) { | 84 ContentSettingsType type) { |
80 // Don't call this for plug-ins. | 85 // Don't call this for plug-ins. |
81 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); | 86 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); |
82 return current_content_settings_.settings[type]; | 87 return current_content_settings_.settings[type]; |
83 } | 88 } |
84 | 89 |
85 void ContentSettingsObserver::DidBlockContentType( | 90 void ContentSettingsObserver::DidBlockContentType( |
86 ContentSettingsType settings_type, | 91 ContentSettingsType settings_type, |
87 const std::string& resource_identifier) { | 92 const std::string& resource_identifier) { |
(...skipping 23 matching lines...) Expand all Loading... | |
111 } | 116 } |
112 | 117 |
113 void ContentSettingsObserver::DidCommitProvisionalLoad( | 118 void ContentSettingsObserver::DidCommitProvisionalLoad( |
114 WebFrame* frame, bool is_new_navigation) { | 119 WebFrame* frame, bool is_new_navigation) { |
115 if (frame->parent()) | 120 if (frame->parent()) |
116 return; // Not a top-level navigation. | 121 return; // Not a top-level navigation. |
117 | 122 |
118 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); | 123 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
119 if (!state->was_within_same_page()) { | 124 if (!state->was_within_same_page()) { |
120 // Clear "block" flags for the new page. This needs to happen before any of | 125 // Clear "block" flags for the new page. This needs to happen before any of |
121 // allowScripts(), allowImages(), allowPlugins() is called for the new page | 126 // allowScripts(), allowImage(), allowPlugins() is called for the new page |
122 // so that these functions can correctly detect that a piece of content | 127 // so that these functions can correctly detect that a piece of content |
123 // flipped from "not blocked" to "blocked". | 128 // flipped from "not blocked" to "blocked". |
124 ClearBlockedContentSettings(); | 129 ClearBlockedContentSettings(); |
125 plugins_temporarily_allowed_ = false; | 130 plugins_temporarily_allowed_ = false; |
126 } | 131 } |
127 | 132 |
128 GURL url = frame->document().url(); | 133 GURL url = frame->document().url(); |
129 | 134 |
130 if (frame->document().securityOrigin().toString() == "null" && | 135 if (frame->document().securityOrigin().toString() == "null" && |
131 !url.SchemeIs(chrome::kFileScheme)) { | 136 !url.SchemeIs(chrome::kFileScheme)) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 bool result = false; | 196 bool result = false; |
192 Send(new ChromeViewHostMsg_AllowFileSystem( | 197 Send(new ChromeViewHostMsg_AllowFileSystem( |
193 routing_id(), GURL(frame->document().securityOrigin().toString()), | 198 routing_id(), GURL(frame->document().securityOrigin().toString()), |
194 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 199 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
195 return result; | 200 return result; |
196 } | 201 } |
197 | 202 |
198 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 203 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
199 bool enabled_per_settings, | 204 bool enabled_per_settings, |
200 const WebURL& image_url) { | 205 const WebURL& image_url) { |
201 if (enabled_per_settings && | |
202 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | |
203 return true; | |
204 } | |
205 | |
206 if (IsWhitelistedForContentSettings(frame)) | 206 if (IsWhitelistedForContentSettings(frame)) |
207 return true; | 207 return true; |
208 | 208 |
209 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 209 bool allow = false; |
Bernhard Bauer
2011/10/20 09:21:53
I think we may want to default to allow?
marja
2011/10/20 11:44:22
Shouldn't we default to enabled_per_settings inste
Bernhard Bauer
2011/10/20 11:58:24
OK (although in practice |enabled_per_settings| is
marja
2011/10/20 14:41:15
Done.
| |
210 return false; // Other protocols fall through here. | 210 GURL top_url(frame->top()->document().securityOrigin().toString()); |
Bernhard Bauer
2011/10/20 09:21:53
Argh, I just noticed that per http://crbug.com/100
marja
2011/10/20 11:44:22
There is the gotcha that "a unique security origin
Bernhard Bauer
2011/10/20 11:58:24
Plus, it means that file:/// content setting patte
marja
2011/10/20 14:41:15
I changed this to be frame->document().url() and p
jochen (gone - plz use gerrit)
2011/10/20 15:32:15
I'd prefer if we'd stick to the security origin. O
Bernhard Bauer
2011/10/20 15:37:09
How would that work if we use the main frame URL?
jochen (gone - plz use gerrit)
2011/10/20 19:01:21
sorry for being unclear, I meant opening the frame
marja
2011/10/21 09:52:58
I uploaded a version which falls back to document.
| |
211 GURL image_gurl(image_url); | |
212 if (image_setting_rules_ && | |
213 !frame->document().securityOrigin().isEmpty() && | |
214 !frame->top()->document().securityOrigin().isEmpty() && | |
215 enabled_per_settings) { | |
216 ContentSettingsForOneType::const_iterator it; | |
217 for (it = image_setting_rules_->begin(); | |
218 it != image_setting_rules_->end(); ++it) { | |
219 if (it->primary_pattern.Matches(top_url) && | |
220 it->secondary_pattern.Matches(image_gurl)) { | |
221 allow = (it->setting != CONTENT_SETTING_BLOCK); | |
222 break; | |
223 } | |
224 } | |
225 } | |
226 | |
227 if (!allow) | |
228 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
229 return allow; | |
211 } | 230 } |
212 | 231 |
213 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 232 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
214 const WebString& name, | 233 const WebString& name, |
215 const WebSecurityOrigin& origin) { | 234 const WebSecurityOrigin& origin) { |
216 if (frame->document().securityOrigin().isEmpty() || | 235 if (frame->document().securityOrigin().isEmpty() || |
217 frame->top()->document().securityOrigin().isEmpty()) | 236 frame->top()->document().securityOrigin().isEmpty()) |
218 return false; // Uninitialized document. | 237 return false; // Uninitialized document. |
219 | 238 |
220 bool result = false; | 239 bool result = false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // CONTENT_SETTING_ASK is only valid for cookies. | 307 // CONTENT_SETTING_ASK is only valid for cookies. |
289 return current_content_settings_.settings[settings_type] != | 308 return current_content_settings_.settings[settings_type] != |
290 CONTENT_SETTING_BLOCK; | 309 CONTENT_SETTING_BLOCK; |
291 } | 310 } |
292 | 311 |
293 void ContentSettingsObserver::ClearBlockedContentSettings() { | 312 void ContentSettingsObserver::ClearBlockedContentSettings() { |
294 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 313 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
295 content_blocked_[i] = false; | 314 content_blocked_[i] = false; |
296 cached_storage_permissions_.clear(); | 315 cached_storage_permissions_.clear(); |
297 } | 316 } |
OLD | NEW |