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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 ContentSettings ContentSettingsObserver::default_settings_; | 54 ContentSettings ContentSettingsObserver::default_settings_; |
55 | 55 |
56 ContentSettingsObserver::ContentSettingsObserver(RenderView* render_view) | 56 ContentSettingsObserver::ContentSettingsObserver( |
57 RenderView* render_view, ContentSettingRules* image_setting_rules) | |
57 : RenderViewObserver(render_view), | 58 : RenderViewObserver(render_view), |
58 RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 59 RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
60 image_setting_rules_(image_setting_rules), | |
59 plugins_temporarily_allowed_(false) { | 61 plugins_temporarily_allowed_(false) { |
60 ClearBlockedContentSettings(); | 62 ClearBlockedContentSettings(); |
61 } | 63 } |
62 | 64 |
63 ContentSettingsObserver::~ContentSettingsObserver() { | 65 ContentSettingsObserver::~ContentSettingsObserver() { |
64 } | 66 } |
65 | 67 |
66 void ContentSettingsObserver::SetContentSettings( | 68 void ContentSettingsObserver::SetContentSettings( |
67 const ContentSettings& settings) { | 69 const ContentSettings& settings) { |
68 current_content_settings_ = settings; | 70 current_content_settings_ = settings; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 191 |
190 bool result = false; | 192 bool result = false; |
191 Send(new ChromeViewHostMsg_AllowFileSystem( | 193 Send(new ChromeViewHostMsg_AllowFileSystem( |
192 routing_id(), GURL(frame->document().securityOrigin().toString()), | 194 routing_id(), GURL(frame->document().securityOrigin().toString()), |
193 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 195 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
194 return result; | 196 return result; |
195 } | 197 } |
196 | 198 |
197 bool ContentSettingsObserver::AllowImages(WebFrame* frame, | 199 bool ContentSettingsObserver::AllowImages(WebFrame* frame, |
198 bool enabled_per_settings) { | 200 bool enabled_per_settings) { |
199 if (enabled_per_settings && | |
200 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | |
201 return true; | |
202 } | |
203 | |
204 if (IsWhitelistedForContentSettings(frame)) | 201 if (IsWhitelistedForContentSettings(frame)) |
205 return true; | 202 return true; |
206 | 203 |
204 if (frame->document().securityOrigin().isEmpty() || | |
205 frame->top()->document().securityOrigin().isEmpty()) { | |
206 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
207 return false; // Uninitialized document. | |
208 } | |
209 | |
210 if (enabled_per_settings) { | |
211 ContentSettingRules::const_iterator it; | |
212 for (it = image_setting_rules_->begin(); | |
213 it != image_setting_rules_->end(); ++it) { | |
214 if (it->a.Matches(GURL(frame->document().securityOrigin().toString())) && | |
215 it->b.Matches( | |
216 GURL(frame->top()->document().securityOrigin().toString()))) { | |
217 bool allow = (it->c != CONTENT_SETTING_BLOCK); | |
Bernhard Bauer
2011/09/15 12:52:19
You already have a call to DidBlockContentType bel
marja
2011/09/15 16:00:03
Done.
| |
218 if (!allow) | |
219 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
220 return allow; | |
221 } | |
222 } | |
223 } | |
224 | |
207 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 225 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
208 return false; // Other protocols fall through here. | 226 return false; // Other protocols fall through here. |
209 } | 227 } |
210 | 228 |
211 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 229 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
212 const WebString& name, | 230 const WebString& name, |
213 const WebSecurityOrigin& origin) { | 231 const WebSecurityOrigin& origin) { |
214 if (frame->document().securityOrigin().isEmpty() || | 232 if (frame->document().securityOrigin().isEmpty() || |
215 frame->top()->document().securityOrigin().isEmpty()) | 233 frame->top()->document().securityOrigin().isEmpty()) |
216 return false; // Uninitialized document. | 234 return false; // Uninitialized document. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 // CONTENT_SETTING_ASK is only valid for cookies. | 304 // CONTENT_SETTING_ASK is only valid for cookies. |
287 return current_content_settings_.settings[settings_type] != | 305 return current_content_settings_.settings[settings_type] != |
288 CONTENT_SETTING_BLOCK; | 306 CONTENT_SETTING_BLOCK; |
289 } | 307 } |
290 | 308 |
291 void ContentSettingsObserver::ClearBlockedContentSettings() { | 309 void ContentSettingsObserver::ClearBlockedContentSettings() { |
292 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 310 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
293 content_blocked_[i] = false; | 311 content_blocked_[i] = false; |
294 cached_storage_permissions_.clear(); | 312 cached_storage_permissions_.clear(); |
295 } | 313 } |
OLD | NEW |