| 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/common/database_messages.h" | 9 #include "content/common/database_messages.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 ContentSettingsType type) { | 77 ContentSettingsType type) { |
| 78 if (type == CONTENT_SETTINGS_TYPE_PLUGINS && | 78 if (type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 79 plugins_temporarily_allowed_) { | 79 plugins_temporarily_allowed_) { |
| 80 return CONTENT_SETTING_ALLOW; | 80 return CONTENT_SETTING_ALLOW; |
| 81 } | 81 } |
| 82 return current_content_settings_.settings[type]; | 82 return current_content_settings_.settings[type]; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void ContentSettingsObserver::DidBlockContentType( | 85 void ContentSettingsObserver::DidBlockContentType( |
| 86 ContentSettingsType settings_type, | 86 ContentSettingsType settings_type, |
| 87 const std::string& resource_identifier) { | 87 const std::string& resource_identifier, |
| 88 // Always send a message when |resource_identifier| is not empty, to tell the | 88 ContentSetting setting) { |
| 89 // browser which resource was blocked (otherwise the browser will only show | 89 content_blocked_[settings_type] = true; |
| 90 // the first resource to be blocked, and none that are blocked at a later | 90 Send(new ViewHostMsg_ContentBlocked(routing_id(), settings_type, |
| 91 // time). | 91 resource_identifier, setting)); |
| 92 if (!content_blocked_[settings_type] || !resource_identifier.empty()) { | |
| 93 content_blocked_[settings_type] = true; | |
| 94 Send(new ViewHostMsg_ContentBlocked(routing_id(), settings_type, | |
| 95 resource_identifier)); | |
| 96 } | |
| 97 } | 92 } |
| 98 | 93 |
| 99 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { | 94 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { |
| 100 bool handled = true; | 95 bool handled = true; |
| 101 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 96 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
| 102 // Don't swallow LoadBlockedPlugins messages, as they're sent to every | 97 // Don't swallow LoadBlockedPlugins messages, as they're sent to every |
| 103 // blocked plugin. | 98 // blocked plugin. |
| 104 IPC_MESSAGE_HANDLER_GENERIC(ViewMsg_LoadBlockedPlugins, | 99 IPC_MESSAGE_HANDLER_GENERIC(ViewMsg_LoadBlockedPlugins, |
| 105 OnLoadBlockedPlugins(); handled = false) | 100 OnLoadBlockedPlugins(); handled = false) |
| 106 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, | 101 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 bool ContentSettingsObserver::AllowImages(WebFrame* frame, | 192 bool ContentSettingsObserver::AllowImages(WebFrame* frame, |
| 198 bool enabled_per_settings) { | 193 bool enabled_per_settings) { |
| 199 if (enabled_per_settings && | 194 if (enabled_per_settings && |
| 200 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | 195 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { |
| 201 return true; | 196 return true; |
| 202 } | 197 } |
| 203 | 198 |
| 204 if (IsWhitelistedForContentSettings(frame)) | 199 if (IsWhitelistedForContentSettings(frame)) |
| 205 return true; | 200 return true; |
| 206 | 201 |
| 207 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 202 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string(), |
| 203 CONTENT_SETTING_BLOCK); |
| 208 return false; // Other protocols fall through here. | 204 return false; // Other protocols fall through here. |
| 209 } | 205 } |
| 210 | 206 |
| 211 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 207 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
| 212 const WebString& name, | 208 const WebString& name, |
| 213 const WebSecurityOrigin& origin) { | 209 const WebSecurityOrigin& origin) { |
| 214 if (frame->document().securityOrigin().isEmpty() || | 210 if (frame->document().securityOrigin().isEmpty() || |
| 215 frame->top()->document().securityOrigin().isEmpty()) | 211 frame->top()->document().securityOrigin().isEmpty()) |
| 216 return false; // Uninitialized document. | 212 return false; // Uninitialized document. |
| 217 | 213 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 Send(new ViewHostMsg_AllowDOMStorage( | 253 Send(new ViewHostMsg_AllowDOMStorage( |
| 258 routing_id(), GURL(frame->document().securityOrigin().toString()), | 254 routing_id(), GURL(frame->document().securityOrigin().toString()), |
| 259 GURL(frame->top()->document().securityOrigin().toString()), | 255 GURL(frame->top()->document().securityOrigin().toString()), |
| 260 local ? DOM_STORAGE_LOCAL : DOM_STORAGE_SESSION, | 256 local ? DOM_STORAGE_LOCAL : DOM_STORAGE_SESSION, |
| 261 &result)); | 257 &result)); |
| 262 cached_storage_permissions_[key] = result; | 258 cached_storage_permissions_[key] = result; |
| 263 return result; | 259 return result; |
| 264 } | 260 } |
| 265 | 261 |
| 266 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { | 262 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { |
| 267 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); | 263 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
| 264 CONTENT_SETTING_BLOCK); |
| 268 } | 265 } |
| 269 | 266 |
| 270 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { | 267 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { |
| 271 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); | 268 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), |
| 269 CONTENT_SETTING_BLOCK); |
| 272 } | 270 } |
| 273 | 271 |
| 274 void ContentSettingsObserver::OnSetContentSettingsForLoadingURL( | 272 void ContentSettingsObserver::OnSetContentSettingsForLoadingURL( |
| 275 const GURL& url, | 273 const GURL& url, |
| 276 const ContentSettings& content_settings) { | 274 const ContentSettings& content_settings) { |
| 277 host_content_settings_[url] = content_settings; | 275 host_content_settings_[url] = content_settings; |
| 278 } | 276 } |
| 279 | 277 |
| 280 void ContentSettingsObserver::OnLoadBlockedPlugins() { | 278 void ContentSettingsObserver::OnLoadBlockedPlugins() { |
| 281 plugins_temporarily_allowed_ = true; | 279 plugins_temporarily_allowed_ = true; |
| 282 } | 280 } |
| 283 | 281 |
| 284 bool ContentSettingsObserver::AllowContentType( | 282 bool ContentSettingsObserver::AllowContentType( |
| 285 ContentSettingsType settings_type) { | 283 ContentSettingsType settings_type) { |
| 286 // CONTENT_SETTING_ASK is only valid for cookies. | 284 // CONTENT_SETTING_ASK is only valid for cookies. |
| 287 return current_content_settings_.settings[settings_type] != | 285 return current_content_settings_.settings[settings_type] != |
| 288 CONTENT_SETTING_BLOCK; | 286 CONTENT_SETTING_BLOCK; |
| 289 } | 287 } |
| 290 | 288 |
| 291 void ContentSettingsObserver::ClearBlockedContentSettings() { | 289 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 292 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 290 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 293 content_blocked_[i] = false; | 291 content_blocked_[i] = false; |
| 294 cached_storage_permissions_.clear(); | 292 cached_storage_permissions_.clear(); |
| 295 } | 293 } |
| OLD | NEW |