| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { | 43 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 44 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { | 44 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 45 return document_url.SchemeIs(kDirProtocols[i]) && | 45 return document_url.SchemeIs(kDirProtocols[i]) && |
| 46 document_url.ExtractFileName().empty(); | 46 document_url.ExtractFileName().empty(); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 GURL GetOriginOrURL(const WebFrame* frame) { |
| 54 WebString top_origin = frame->top()->document().securityOrigin().toString(); |
| 55 // The the |top_origin| is unique ("null") e.g., for file:// URLs. Use the |
| 56 // document URL as the primary URL in those cases. |
| 57 if (top_origin == "null") |
| 58 return frame->document().url(); |
| 59 return GURL(top_origin); |
| 60 } |
| 61 |
| 53 } // namespace | 62 } // namespace |
| 54 | 63 |
| 55 ContentSettings ContentSettingsObserver::default_settings_; | 64 ContentSettings ContentSettingsObserver::default_settings_; |
| 56 | 65 |
| 57 ContentSettingsObserver::ContentSettingsObserver( | 66 ContentSettingsObserver::ContentSettingsObserver( |
| 58 content::RenderView* render_view) | 67 content::RenderView* render_view) |
| 59 : content::RenderViewObserver(render_view), | 68 : content::RenderViewObserver(render_view), |
| 60 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 69 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
| 61 plugins_temporarily_allowed_(false) { | 70 plugins_temporarily_allowed_(false) { |
| 62 ClearBlockedContentSettings(); | 71 ClearBlockedContentSettings(); |
| 63 } | 72 } |
| 64 | 73 |
| 65 ContentSettingsObserver::~ContentSettingsObserver() { | 74 ContentSettingsObserver::~ContentSettingsObserver() { |
| 66 } | 75 } |
| 67 | 76 |
| 68 void ContentSettingsObserver::SetContentSettings( | 77 void ContentSettingsObserver::SetContentSettings( |
| 69 const ContentSettings& settings) { | 78 const ContentSettings& settings) { |
| 70 current_content_settings_ = settings; | 79 current_content_settings_ = settings; |
| 71 } | 80 } |
| 72 | 81 |
| 73 void ContentSettingsObserver::SetDefaultContentSettings( | 82 void ContentSettingsObserver::SetDefaultContentSettings( |
| 74 const ContentSettings& settings) { | 83 const ContentSettings& settings) { |
| 75 default_settings_ = settings; | 84 default_settings_ = settings; |
| 76 } | 85 } |
| 77 | 86 |
| 87 void ContentSettingsObserver::SetImageSettingRules( |
| 88 const ContentSettingsForOneType* image_setting_rules) { |
| 89 image_setting_rules_ = image_setting_rules; |
| 90 } |
| 91 |
| 78 ContentSetting ContentSettingsObserver::GetContentSetting( | 92 ContentSetting ContentSettingsObserver::GetContentSetting( |
| 79 ContentSettingsType type) { | 93 ContentSettingsType type) { |
| 80 // Don't call this for plug-ins. | 94 // Don't call this for plug-ins. |
| 81 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); | 95 DCHECK_NE(CONTENT_SETTINGS_TYPE_PLUGINS, type); |
| 82 return current_content_settings_.settings[type]; | 96 return current_content_settings_.settings[type]; |
| 83 } | 97 } |
| 84 | 98 |
| 85 void ContentSettingsObserver::DidBlockContentType( | 99 void ContentSettingsObserver::DidBlockContentType( |
| 86 ContentSettingsType settings_type, | 100 ContentSettingsType settings_type, |
| 87 const std::string& resource_identifier) { | 101 const std::string& resource_identifier) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 111 } | 125 } |
| 112 | 126 |
| 113 void ContentSettingsObserver::DidCommitProvisionalLoad( | 127 void ContentSettingsObserver::DidCommitProvisionalLoad( |
| 114 WebFrame* frame, bool is_new_navigation) { | 128 WebFrame* frame, bool is_new_navigation) { |
| 115 if (frame->parent()) | 129 if (frame->parent()) |
| 116 return; // Not a top-level navigation. | 130 return; // Not a top-level navigation. |
| 117 | 131 |
| 118 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); | 132 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
| 119 if (!state->was_within_same_page()) { | 133 if (!state->was_within_same_page()) { |
| 120 // Clear "block" flags for the new page. This needs to happen before any of | 134 // Clear "block" flags for the new page. This needs to happen before any of |
| 121 // allowScripts(), allowImages(), allowPlugins() is called for the new page | 135 // allowScripts(), allowImage(), allowPlugins() is called for the new page |
| 122 // so that these functions can correctly detect that a piece of content | 136 // so that these functions can correctly detect that a piece of content |
| 123 // flipped from "not blocked" to "blocked". | 137 // flipped from "not blocked" to "blocked". |
| 124 ClearBlockedContentSettings(); | 138 ClearBlockedContentSettings(); |
| 125 plugins_temporarily_allowed_ = false; | 139 plugins_temporarily_allowed_ = false; |
| 126 } | 140 } |
| 127 | 141 |
| 128 GURL url = frame->document().url(); | 142 GURL url = frame->document().url(); |
| 129 | 143 |
| 130 if (frame->document().securityOrigin().toString() == "null" && | 144 if (frame->document().securityOrigin().toString() == "null" && |
| 131 !url.SchemeIs(chrome::kFileScheme)) { | 145 !url.SchemeIs(chrome::kFileScheme)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 bool result = false; | 205 bool result = false; |
| 192 Send(new ChromeViewHostMsg_AllowFileSystem( | 206 Send(new ChromeViewHostMsg_AllowFileSystem( |
| 193 routing_id(), GURL(frame->document().securityOrigin().toString()), | 207 routing_id(), GURL(frame->document().securityOrigin().toString()), |
| 194 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 208 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
| 195 return result; | 209 return result; |
| 196 } | 210 } |
| 197 | 211 |
| 198 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 212 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
| 199 bool enabled_per_settings, | 213 bool enabled_per_settings, |
| 200 const WebURL& image_url) { | 214 const WebURL& image_url) { |
| 201 if (enabled_per_settings && | |
| 202 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | |
| 203 return true; | |
| 204 } | |
| 205 | |
| 206 if (IsWhitelistedForContentSettings(frame)) | 215 if (IsWhitelistedForContentSettings(frame)) |
| 207 return true; | 216 return true; |
| 208 | 217 |
| 209 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 218 bool allow = enabled_per_settings; |
| 210 return false; // Other protocols fall through here. | 219 const GURL& primary_url = GetOriginOrURL(frame); |
| 220 GURL secondary_url(image_url); |
| 221 if (image_setting_rules_ && |
| 222 enabled_per_settings) { |
| 223 ContentSettingsForOneType::const_iterator it; |
| 224 for (it = image_setting_rules_->begin(); |
| 225 it != image_setting_rules_->end(); ++it) { |
| 226 if (it->primary_pattern.Matches(primary_url) && |
| 227 it->secondary_pattern.Matches(secondary_url)) { |
| 228 allow = (it->setting != CONTENT_SETTING_BLOCK); |
| 229 break; |
| 230 } |
| 231 } |
| 232 } |
| 233 |
| 234 if (!allow) |
| 235 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
| 236 return allow; |
| 211 } | 237 } |
| 212 | 238 |
| 213 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 239 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
| 214 const WebString& name, | 240 const WebString& name, |
| 215 const WebSecurityOrigin& origin) { | 241 const WebSecurityOrigin& origin) { |
| 216 if (frame->document().securityOrigin().isEmpty() || | 242 if (frame->document().securityOrigin().isEmpty() || |
| 217 frame->top()->document().securityOrigin().isEmpty()) | 243 frame->top()->document().securityOrigin().isEmpty()) |
| 218 return false; // Uninitialized document. | 244 return false; // Uninitialized document. |
| 219 | 245 |
| 220 bool result = false; | 246 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. | 314 // CONTENT_SETTING_ASK is only valid for cookies. |
| 289 return current_content_settings_.settings[settings_type] != | 315 return current_content_settings_.settings[settings_type] != |
| 290 CONTENT_SETTING_BLOCK; | 316 CONTENT_SETTING_BLOCK; |
| 291 } | 317 } |
| 292 | 318 |
| 293 void ContentSettingsObserver::ClearBlockedContentSettings() { | 319 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 294 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 320 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 295 content_blocked_[i] = false; | 321 content_blocked_[i] = false; |
| 296 cached_storage_permissions_.clear(); | 322 cached_storage_permissions_.clear(); |
| 297 } | 323 } |
| OLD | NEW |