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