Chromium Code Reviews| 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 = enabled_per_settings; |
| 210 return false; // Other protocols fall through here. | 210 |
| 211 WebString top_origin = frame->top()->document().securityOrigin().toString(); | |
| 212 GURL page_url(frame->document().url()); | |
| 213 GURL primary_url; | |
| 214 // For file:// URLs, the top_origin is unique ("null"). Use the file:// URL as | |
| 215 // the primary URL. | |
| 216 if (top_origin == "null" && page_url.SchemeIsFile()) | |
|
Bernhard Bauer
2011/10/21 10:10:10
Are there other cases where we might want to use t
marja
2011/10/21 10:25:05
How about this version: use the doc url always whe
Bernhard Bauer
2011/10/21 10:57:35
I guess both versions serve the file URL use case,
| |
| 217 primary_url = page_url; | |
| 218 else | |
| 219 primary_url = GURL(top_origin); | |
| 220 | |
| 221 GURL secondary_url(image_url); | |
| 222 if (image_setting_rules_ && | |
| 223 enabled_per_settings) { | |
| 224 ContentSettingsForOneType::const_iterator it; | |
| 225 for (it = image_setting_rules_->begin(); | |
| 226 it != image_setting_rules_->end(); ++it) { | |
| 227 if (it->primary_pattern.Matches(primary_url) && | |
| 228 it->secondary_pattern.Matches(secondary_url)) { | |
| 229 allow = (it->setting != CONTENT_SETTING_BLOCK); | |
| 230 break; | |
| 231 } | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 if (!allow) | |
| 236 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
| 237 return allow; | |
| 211 } | 238 } |
| 212 | 239 |
| 213 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 240 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
| 214 const WebString& name, | 241 const WebString& name, |
| 215 const WebSecurityOrigin& origin) { | 242 const WebSecurityOrigin& origin) { |
| 216 if (frame->document().securityOrigin().isEmpty() || | 243 if (frame->document().securityOrigin().isEmpty() || |
| 217 frame->top()->document().securityOrigin().isEmpty()) | 244 frame->top()->document().securityOrigin().isEmpty()) |
| 218 return false; // Uninitialized document. | 245 return false; // Uninitialized document. |
| 219 | 246 |
| 220 bool result = false; | 247 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. | 315 // CONTENT_SETTING_ASK is only valid for cookies. |
| 289 return current_content_settings_.settings[settings_type] != | 316 return current_content_settings_.settings[settings_type] != |
| 290 CONTENT_SETTING_BLOCK; | 317 CONTENT_SETTING_BLOCK; |
| 291 } | 318 } |
| 292 | 319 |
| 293 void ContentSettingsObserver::ClearBlockedContentSettings() { | 320 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 294 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 321 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 295 content_blocked_[i] = false; | 322 content_blocked_[i] = false; |
| 296 cached_storage_permissions_.clear(); | 323 cached_storage_permissions_.clear(); |
| 297 } | 324 } |
| OLD | NEW |