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/document_state.h" | 9 #include "content/public/renderer/document_state.h" |
10 #include "content/public/renderer/navigation_state.h" | 10 #include "content/public/renderer/navigation_state.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return CONTENT_SETTING_DEFAULT; | 61 return CONTENT_SETTING_DEFAULT; |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
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 content_setting_rules_(NULL), |
71 plugins_temporarily_allowed_(false) { | 71 plugins_temporarily_allowed_(false), |
| 72 is_interstitial_page_(false) { |
72 ClearBlockedContentSettings(); | 73 ClearBlockedContentSettings(); |
73 } | 74 } |
74 | 75 |
75 ContentSettingsObserver::~ContentSettingsObserver() { | 76 ContentSettingsObserver::~ContentSettingsObserver() { |
76 } | 77 } |
77 | 78 |
78 void ContentSettingsObserver::SetContentSettingRules( | 79 void ContentSettingsObserver::SetContentSettingRules( |
79 const RendererContentSettingRules* content_setting_rules) { | 80 const RendererContentSettingRules* content_setting_rules) { |
80 content_setting_rules_ = content_setting_rules; | 81 content_setting_rules_ = content_setting_rules; |
81 } | 82 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 bool result = false; | 156 bool result = false; |
156 Send(new ChromeViewHostMsg_AllowFileSystem( | 157 Send(new ChromeViewHostMsg_AllowFileSystem( |
157 routing_id(), GURL(frame->document().securityOrigin().toString()), | 158 routing_id(), GURL(frame->document().securityOrigin().toString()), |
158 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 159 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
159 return result; | 160 return result; |
160 } | 161 } |
161 | 162 |
162 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 163 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
163 bool enabled_per_settings, | 164 bool enabled_per_settings, |
164 const WebURL& image_url) { | 165 const WebURL& image_url) { |
| 166 if (is_interstitial_page_) |
| 167 return true; |
165 if (IsWhitelistedForContentSettings(frame)) | 168 if (IsWhitelistedForContentSettings(frame)) |
166 return true; | 169 return true; |
167 | 170 |
168 bool allow = enabled_per_settings; | 171 bool allow = enabled_per_settings; |
169 if (content_setting_rules_ && enabled_per_settings) { | 172 if (content_setting_rules_ && enabled_per_settings) { |
170 GURL secondary_url(image_url); | 173 GURL secondary_url(image_url); |
171 allow = GetContentSettingFromRules( | 174 allow = GetContentSettingFromRules( |
172 content_setting_rules_->image_rules, | 175 content_setting_rules_->image_rules, |
173 frame, secondary_url) != CONTENT_SETTING_BLOCK; | 176 frame, secondary_url) != CONTENT_SETTING_BLOCK; |
174 } | 177 } |
(...skipping 18 matching lines...) Expand all Loading... |
193 return result; | 196 return result; |
194 } | 197 } |
195 | 198 |
196 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, | 199 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, |
197 bool enabled_per_settings) { | 200 bool enabled_per_settings) { |
198 return enabled_per_settings; | 201 return enabled_per_settings; |
199 } | 202 } |
200 | 203 |
201 bool ContentSettingsObserver::AllowScript(WebFrame* frame, | 204 bool ContentSettingsObserver::AllowScript(WebFrame* frame, |
202 bool enabled_per_settings) { | 205 bool enabled_per_settings) { |
| 206 if (is_interstitial_page_) |
| 207 return true; |
203 if (!enabled_per_settings) | 208 if (!enabled_per_settings) |
204 return false; | 209 return false; |
205 | 210 |
206 std::map<WebFrame*, bool>::const_iterator it = | 211 std::map<WebFrame*, bool>::const_iterator it = |
207 cached_script_permissions_.find(frame); | 212 cached_script_permissions_.find(frame); |
208 if (it != cached_script_permissions_.end()) | 213 if (it != cached_script_permissions_.end()) |
209 return it->second; | 214 return it->second; |
210 | 215 |
211 // Evaluate the content setting rules before | 216 // Evaluate the content setting rules before |
212 // |IsWhitelistedForContentSettings|; if there is only the default rule | 217 // |IsWhitelistedForContentSettings|; if there is only the default rule |
213 // allowing all scripts, it's quicker this way. | 218 // allowing all scripts, it's quicker this way. |
214 bool allow = true; | 219 bool allow = true; |
215 if (content_setting_rules_) { | 220 if (content_setting_rules_) { |
216 ContentSetting setting = GetContentSettingFromRules( | 221 ContentSetting setting = GetContentSettingFromRules( |
217 content_setting_rules_->script_rules, | 222 content_setting_rules_->script_rules, |
218 frame, | 223 frame, |
219 GURL(frame->document().securityOrigin().toString())); | 224 GURL(frame->document().securityOrigin().toString())); |
220 allow = setting != CONTENT_SETTING_BLOCK; | 225 allow = setting != CONTENT_SETTING_BLOCK; |
221 } | 226 } |
222 allow = allow || IsWhitelistedForContentSettings(frame); | 227 allow = allow || IsWhitelistedForContentSettings(frame); |
223 | 228 |
224 cached_script_permissions_[frame] = allow; | 229 cached_script_permissions_[frame] = allow; |
225 return allow; | 230 return allow; |
226 } | 231 } |
227 | 232 |
228 bool ContentSettingsObserver::AllowScriptFromSource( | 233 bool ContentSettingsObserver::AllowScriptFromSource( |
229 WebFrame* frame, | 234 WebFrame* frame, |
230 bool enabled_per_settings, | 235 bool enabled_per_settings, |
231 const WebKit::WebURL& script_url) { | 236 const WebKit::WebURL& script_url) { |
| 237 if (is_interstitial_page_) |
| 238 return true; |
232 if (!enabled_per_settings) | 239 if (!enabled_per_settings) |
233 return false; | 240 return false; |
234 | 241 |
235 bool allow = true; | 242 bool allow = true; |
236 if (content_setting_rules_) { | 243 if (content_setting_rules_) { |
237 ContentSetting setting = GetContentSettingFromRules( | 244 ContentSetting setting = GetContentSettingFromRules( |
238 content_setting_rules_->script_rules, | 245 content_setting_rules_->script_rules, |
239 frame, | 246 frame, |
240 GURL(script_url)); | 247 GURL(script_url)); |
241 allow = setting != CONTENT_SETTING_BLOCK; | 248 allow = setting != CONTENT_SETTING_BLOCK; |
(...skipping 23 matching lines...) Expand all Loading... |
265 } | 272 } |
266 | 273 |
267 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { | 274 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { |
268 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); | 275 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
269 } | 276 } |
270 | 277 |
271 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { | 278 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { |
272 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); | 279 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
273 } | 280 } |
274 | 281 |
| 282 void ContentSettingsObserver::SetAsInterstitial() { |
| 283 is_interstitial_page_ = true; |
| 284 } |
| 285 |
275 void ContentSettingsObserver::OnLoadBlockedPlugins() { | 286 void ContentSettingsObserver::OnLoadBlockedPlugins() { |
276 plugins_temporarily_allowed_ = true; | 287 plugins_temporarily_allowed_ = true; |
277 } | 288 } |
278 | 289 |
279 void ContentSettingsObserver::ClearBlockedContentSettings() { | 290 void ContentSettingsObserver::ClearBlockedContentSettings() { |
280 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 291 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
281 content_blocked_[i] = false; | 292 content_blocked_[i] = false; |
282 cached_storage_permissions_.clear(); | 293 cached_storage_permissions_.clear(); |
283 cached_script_permissions_.clear(); | 294 cached_script_permissions_.clear(); |
284 } | 295 } |
(...skipping 26 matching lines...) Expand all Loading... |
311 const char* kDirProtocols[] = { chrome::kFtpScheme, chrome::kFileScheme }; | 322 const char* kDirProtocols[] = { chrome::kFtpScheme, chrome::kFileScheme }; |
312 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { | 323 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
313 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { | 324 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
314 return document_url.SchemeIs(kDirProtocols[i]) && | 325 return document_url.SchemeIs(kDirProtocols[i]) && |
315 document_url.ExtractFileName().empty(); | 326 document_url.ExtractFileName().empty(); |
316 } | 327 } |
317 } | 328 } |
318 | 329 |
319 return false; | 330 return false; |
320 } | 331 } |
OLD | NEW |