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/public/renderer/navigation_state.h" | 10 #include "content/public/renderer/navigation_state.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 } | 49 } |
50 | 50 |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 ContentSettings ContentSettingsObserver::default_settings_; | 56 ContentSettings ContentSettingsObserver::default_settings_; |
57 | 57 |
58 ContentSettingsObserver::ContentSettingsObserver( | 58 ContentSettingsObserver::ContentSettingsObserver( |
59 content::RenderView* render_view) | 59 content::RenderView* render_view, |
60 const ContentSettingsForOneType* image_setting_rules) | |
60 : content::RenderViewObserver(render_view), | 61 : content::RenderViewObserver(render_view), |
61 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 62 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
63 image_setting_rules_(image_setting_rules), | |
62 plugins_temporarily_allowed_(false) { | 64 plugins_temporarily_allowed_(false) { |
63 ClearBlockedContentSettings(); | 65 ClearBlockedContentSettings(); |
64 } | 66 } |
65 | 67 |
66 ContentSettingsObserver::~ContentSettingsObserver() { | 68 ContentSettingsObserver::~ContentSettingsObserver() { |
67 } | 69 } |
68 | 70 |
69 void ContentSettingsObserver::SetContentSettings( | 71 void ContentSettingsObserver::SetContentSettings( |
70 const ContentSettings& settings) { | 72 const ContentSettings& settings) { |
71 current_content_settings_ = settings; | 73 current_content_settings_ = settings; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } | 116 } |
115 | 117 |
116 void ContentSettingsObserver::DidCommitProvisionalLoad( | 118 void ContentSettingsObserver::DidCommitProvisionalLoad( |
117 WebFrame* frame, bool is_new_navigation) { | 119 WebFrame* frame, bool is_new_navigation) { |
118 if (frame->parent()) | 120 if (frame->parent()) |
119 return; // Not a top-level navigation. | 121 return; // Not a top-level navigation. |
120 | 122 |
121 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); | 123 NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
122 if (!state->was_within_same_page()) { | 124 if (!state->was_within_same_page()) { |
123 // 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 |
124 // allowScripts(), allowImages(), allowPlugins() is called for the new page | 126 // allowScripts(), allowImage(), allowPlugins() is called for the new page |
125 // 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 |
126 // flipped from "not blocked" to "blocked". | 128 // flipped from "not blocked" to "blocked". |
127 ClearBlockedContentSettings(); | 129 ClearBlockedContentSettings(); |
128 plugins_temporarily_allowed_ = false; | 130 plugins_temporarily_allowed_ = false; |
129 } | 131 } |
130 | 132 |
131 GURL url = frame->document().url(); | 133 GURL url = frame->document().url(); |
132 | 134 |
133 if (frame->document().securityOrigin().toString() == "null" && | 135 if (frame->document().securityOrigin().toString() == "null" && |
134 !url.SchemeIs(chrome::kFileScheme)) { | 136 !url.SchemeIs(chrome::kFileScheme)) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 bool result = false; | 196 bool result = false; |
195 Send(new ChromeViewHostMsg_AllowFileSystem( | 197 Send(new ChromeViewHostMsg_AllowFileSystem( |
196 routing_id(), GURL(frame->document().securityOrigin().toString()), | 198 routing_id(), GURL(frame->document().securityOrigin().toString()), |
197 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 199 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
198 return result; | 200 return result; |
199 } | 201 } |
200 | 202 |
201 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 203 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
202 bool enabled_per_settings, | 204 bool enabled_per_settings, |
203 const WebURL& image_url) { | 205 const WebURL& image_url) { |
204 if (enabled_per_settings && | 206 DCHECK(image_setting_rules_); |
205 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { | |
206 return true; | |
207 } | |
208 | |
209 if (IsWhitelistedForContentSettings(frame)) | 207 if (IsWhitelistedForContentSettings(frame)) |
210 return true; | 208 return true; |
211 | 209 |
212 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 210 if (frame->document().securityOrigin().isEmpty() || |
213 return false; // Other protocols fall through here. | 211 frame->top()->document().securityOrigin().isEmpty()) { |
Bernhard Bauer
2011/10/17 13:13:19
Nit: If you move this check into the |if (enabled_
marja
2011/10/18 12:23:02
Done.
| |
212 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
213 return false; // Uninitialized document. | |
214 } | |
215 | |
216 bool allow = false; | |
217 GURL top_url(frame->top()->document().securityOrigin().toString()); | |
218 GURL image_gurl(image_url); | |
219 if (enabled_per_settings) { | |
220 ContentSettingsForOneType::const_iterator it; | |
221 for (it = image_setting_rules_->begin(); | |
222 it != image_setting_rules_->end(); ++it) { | |
223 if (it->a.Matches(top_url) && it->b.Matches(image_gurl)) { | |
224 allow = (it->c != CONTENT_SETTING_BLOCK); | |
225 break; | |
226 } | |
227 } | |
228 } | |
229 | |
230 if (!allow) | |
231 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | |
232 return allow; | |
214 } | 233 } |
215 | 234 |
216 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 235 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
217 const WebString& name, | 236 const WebString& name, |
218 const WebSecurityOrigin& origin) { | 237 const WebSecurityOrigin& origin) { |
219 if (frame->document().securityOrigin().isEmpty() || | 238 if (frame->document().securityOrigin().isEmpty() || |
220 frame->top()->document().securityOrigin().isEmpty()) | 239 frame->top()->document().securityOrigin().isEmpty()) |
221 return false; // Uninitialized document. | 240 return false; // Uninitialized document. |
222 | 241 |
223 bool result = false; | 242 bool result = false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 // CONTENT_SETTING_ASK is only valid for cookies. | 310 // CONTENT_SETTING_ASK is only valid for cookies. |
292 return current_content_settings_.settings[settings_type] != | 311 return current_content_settings_.settings[settings_type] != |
293 CONTENT_SETTING_BLOCK; | 312 CONTENT_SETTING_BLOCK; |
294 } | 313 } |
295 | 314 |
296 void ContentSettingsObserver::ClearBlockedContentSettings() { | 315 void ContentSettingsObserver::ClearBlockedContentSettings() { |
297 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 316 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
298 content_blocked_[i] = false; | 317 content_blocked_[i] = false; |
299 cached_storage_permissions_.clear(); | 318 cached_storage_permissions_.clear(); |
300 } | 319 } |
OLD | NEW |