| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 ContentSettings ContentSettingsObserver::default_settings_; | 55 ContentSettings ContentSettingsObserver::default_settings_; |
| 56 | 56 |
| 57 ContentSettingsObserver::ContentSettingsObserver( | 57 ContentSettingsObserver::ContentSettingsObserver( |
| 58 content::RenderView* render_view) | 58 content::RenderView* render_view, |
| 59 const ContentSettingsForOneType* image_setting_rules) |
| 59 : content::RenderViewObserver(render_view), | 60 : content::RenderViewObserver(render_view), |
| 60 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 61 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
| 62 image_setting_rules_(image_setting_rules), |
| 61 plugins_temporarily_allowed_(false) { | 63 plugins_temporarily_allowed_(false) { |
| 62 ClearBlockedContentSettings(); | 64 ClearBlockedContentSettings(); |
| 63 } | 65 } |
| 64 | 66 |
| 65 ContentSettingsObserver::~ContentSettingsObserver() { | 67 ContentSettingsObserver::~ContentSettingsObserver() { |
| 66 } | 68 } |
| 67 | 69 |
| 68 void ContentSettingsObserver::SetContentSettings( | 70 void ContentSettingsObserver::SetContentSettings( |
| 69 const ContentSettings& settings) { | 71 const ContentSettings& settings) { |
| 70 current_content_settings_ = settings; | 72 current_content_settings_ = settings; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 115 } |
| 114 | 116 |
| 115 void ContentSettingsObserver::DidCommitProvisionalLoad( | 117 void ContentSettingsObserver::DidCommitProvisionalLoad( |
| 116 WebFrame* frame, bool is_new_navigation) { | 118 WebFrame* frame, bool is_new_navigation) { |
| 117 if (frame->parent()) | 119 if (frame->parent()) |
| 118 return; // Not a top-level navigation. | 120 return; // Not a top-level navigation. |
| 119 | 121 |
| 120 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); | 122 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
| 121 if (!state->was_within_same_page()) { | 123 if (!state->was_within_same_page()) { |
| 122 // Clear "block" flags for the new page. This needs to happen before any of | 124 // Clear "block" flags for the new page. This needs to happen before any of |
| 123 // allowScripts(), allowImages(), allowPlugins() is called for the new page | 125 // allowScripts(), allowImage(), allowPlugins() is called for the new page |
| 124 // so that these functions can correctly detect that a piece of content | 126 // so that these functions can correctly detect that a piece of content |
| 125 // flipped from "not blocked" to "blocked". | 127 // flipped from "not blocked" to "blocked". |
| 126 ClearBlockedContentSettings(); | 128 ClearBlockedContentSettings(); |
| 127 plugins_temporarily_allowed_ = false; | 129 plugins_temporarily_allowed_ = false; |
| 128 } | 130 } |
| 129 | 131 |
| 130 GURL url = frame->document().url(); | 132 GURL url = frame->document().url(); |
| 131 | 133 |
| 132 if (frame->document().securityOrigin().toString() == "null" && | 134 if (frame->document().securityOrigin().toString() == "null" && |
| 133 !url.SchemeIs(chrome::kFileScheme)) { | 135 !url.SchemeIs(chrome::kFileScheme)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 bool result = false; | 195 bool result = false; |
| 194 Send(new ChromeViewHostMsg_AllowFileSystem( | 196 Send(new ChromeViewHostMsg_AllowFileSystem( |
| 195 routing_id(), GURL(frame->document().securityOrigin().toString()), | 197 routing_id(), GURL(frame->document().securityOrigin().toString()), |
| 196 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 198 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
| 197 return result; | 199 return result; |
| 198 } | 200 } |
| 199 | 201 |
| 200 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 202 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
| 201 bool enabled_per_settings, | 203 bool enabled_per_settings, |
| 202 const WebURL& image_url) { | 204 const WebURL& image_url) { |
| 203 if (enabled_per_settings && | 205 DCHECK(image_setting_rules_); |
| 204 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | |
| 205 return true; | |
| 206 } | |
| 207 | |
| 208 if (IsWhitelistedForContentSettings(frame)) | 206 if (IsWhitelistedForContentSettings(frame)) |
| 209 return true; | 207 return true; |
| 210 | 208 |
| 211 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 209 bool allow = false; |
| 212 return false; // Other protocols fall through here. | 210 GURL top_url(frame->top()->document().securityOrigin().toString()); |
| 211 GURL image_gurl(image_url); |
| 212 if (!frame->document().securityOrigin().isEmpty() && |
| 213 !frame->top()->document().securityOrigin().isEmpty() && |
| 214 enabled_per_settings) { |
| 215 ContentSettingsForOneType::const_iterator it; |
| 216 for (it = image_setting_rules_->begin(); |
| 217 it != image_setting_rules_->end(); ++it) { |
| 218 if (it->primary_pattern.Matches(top_url) && |
| 219 it->secondary_pattern.Matches(image_gurl)) { |
| 220 allow = (it->setting != CONTENT_SETTING_BLOCK); |
| 221 break; |
| 222 } |
| 223 } |
| 224 } |
| 225 |
| 226 if (!allow) |
| 227 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
| 228 return allow; |
| 213 } | 229 } |
| 214 | 230 |
| 215 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 231 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
| 216 const WebString& name, | 232 const WebString& name, |
| 217 const WebSecurityOrigin& origin) { | 233 const WebSecurityOrigin& origin) { |
| 218 if (frame->document().securityOrigin().isEmpty() || | 234 if (frame->document().securityOrigin().isEmpty() || |
| 219 frame->top()->document().securityOrigin().isEmpty()) | 235 frame->top()->document().securityOrigin().isEmpty()) |
| 220 return false; // Uninitialized document. | 236 return false; // Uninitialized document. |
| 221 | 237 |
| 222 bool result = false; | 238 bool result = false; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // CONTENT_SETTING_ASK is only valid for cookies. | 306 // CONTENT_SETTING_ASK is only valid for cookies. |
| 291 return current_content_settings_.settings[settings_type] != | 307 return current_content_settings_.settings[settings_type] != |
| 292 CONTENT_SETTING_BLOCK; | 308 CONTENT_SETTING_BLOCK; |
| 293 } | 309 } |
| 294 | 310 |
| 295 void ContentSettingsObserver::ClearBlockedContentSettings() { | 311 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 296 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 312 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 297 content_blocked_[i] = false; | 313 content_blocked_[i] = false; |
| 298 cached_storage_permissions_.clear(); | 314 cached_storage_permissions_.clear(); |
| 299 } | 315 } |
| OLD | NEW |