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/document_state.h" | 9 #include "content/public/renderer/document_state.h" |
10 #include "content/public/renderer/navigation_state.h" | 10 #include "content/public/renderer/navigation_state.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 using WebKit::WebURL; | 25 using WebKit::WebURL; |
26 using WebKit::WebView; | 26 using WebKit::WebView; |
27 using content::DocumentState; | 27 using content::DocumentState; |
28 using content::NavigationState; | 28 using content::NavigationState; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // True if |frame| contains content that is white-listed for content settings. | 32 // True if |frame| contains content that is white-listed for content settings. |
33 static bool IsWhitelistedForContentSettings(WebFrame* frame) { | 33 static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
34 WebSecurityOrigin origin = frame->document().securityOrigin(); | 34 WebSecurityOrigin origin = frame->document().securityOrigin(); |
35 if (origin.isEmpty()) | 35 if (origin.isUnique()) |
36 return false; // Uninitialized document? | 36 return false; // Uninitialized document? |
37 | 37 |
38 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) | 38 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
39 return true; // Browser UI elements should still work. | 39 return true; // Browser UI elements should still work. |
40 | 40 |
41 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) | 41 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) |
42 return true; // DevTools UI elements should still work. | 42 return true; // DevTools UI elements should still work. |
43 | 43 |
44 // If the scheme is ftp: or file:, an empty file name indicates a directory | 44 // If the scheme is ftp: or file:, an empty file name indicates a directory |
45 // listing, which requires JavaScript to function properly. | 45 // listing, which requires JavaScript to function properly. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // If we start failing this DCHECK, please makes sure we don't regress | 154 // If we start failing this DCHECK, please makes sure we don't regress |
155 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 | 155 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 |
156 DCHECK(frame->document().securityOrigin().toString() == "null" || | 156 DCHECK(frame->document().securityOrigin().toString() == "null" || |
157 !url.SchemeIs(chrome::kDataScheme)); | 157 !url.SchemeIs(chrome::kDataScheme)); |
158 } | 158 } |
159 | 159 |
160 bool ContentSettingsObserver::AllowDatabase(WebFrame* frame, | 160 bool ContentSettingsObserver::AllowDatabase(WebFrame* frame, |
161 const WebString& name, | 161 const WebString& name, |
162 const WebString& display_name, | 162 const WebString& display_name, |
163 unsigned long estimated_size) { | 163 unsigned long estimated_size) { |
164 if (frame->document().securityOrigin().isEmpty() || | 164 if (frame->document().securityOrigin().isUnique() || |
165 frame->top()->document().securityOrigin().isEmpty()) | 165 frame->top()->document().securityOrigin().isUnique()) |
166 return false; // Uninitialized document. | 166 return false; |
167 | 167 |
168 bool result = false; | 168 bool result = false; |
169 Send(new ChromeViewHostMsg_AllowDatabase( | 169 Send(new ChromeViewHostMsg_AllowDatabase( |
170 routing_id(), GURL(frame->document().securityOrigin().toString()), | 170 routing_id(), GURL(frame->document().securityOrigin().toString()), |
171 GURL(frame->top()->document().securityOrigin().toString()), | 171 GURL(frame->top()->document().securityOrigin().toString()), |
172 name, display_name, &result)); | 172 name, display_name, &result)); |
173 return result; | 173 return result; |
174 } | 174 } |
175 | 175 |
176 bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) { | 176 bool ContentSettingsObserver::AllowFileSystem(WebFrame* frame) { |
177 if (frame->document().securityOrigin().isEmpty() || | 177 if (frame->document().securityOrigin().isUnique() || |
178 frame->top()->document().securityOrigin().isEmpty()) | 178 frame->top()->document().securityOrigin().isUnique()) |
179 return false; // Uninitialized document. | 179 return false; |
180 | 180 |
181 bool result = false; | 181 bool result = false; |
182 Send(new ChromeViewHostMsg_AllowFileSystem( | 182 Send(new ChromeViewHostMsg_AllowFileSystem( |
183 routing_id(), GURL(frame->document().securityOrigin().toString()), | 183 routing_id(), GURL(frame->document().securityOrigin().toString()), |
184 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 184 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
185 return result; | 185 return result; |
186 } | 186 } |
187 | 187 |
188 bool ContentSettingsObserver::AllowImage(WebFrame* frame, | 188 bool ContentSettingsObserver::AllowImage(WebFrame* frame, |
189 bool enabled_per_settings, | 189 bool enabled_per_settings, |
(...skipping 10 matching lines...) Expand all Loading... |
200 } | 200 } |
201 | 201 |
202 if (!allow) | 202 if (!allow) |
203 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 203 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
204 return allow; | 204 return allow; |
205 } | 205 } |
206 | 206 |
207 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, | 207 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, |
208 const WebString& name, | 208 const WebString& name, |
209 const WebSecurityOrigin& origin) { | 209 const WebSecurityOrigin& origin) { |
210 if (frame->document().securityOrigin().isEmpty() || | 210 if (frame->document().securityOrigin().isUnique() || |
211 frame->top()->document().securityOrigin().isEmpty()) | 211 frame->top()->document().securityOrigin().isUnique()) |
212 return false; // Uninitialized document. | 212 return false; |
213 | 213 |
214 bool result = false; | 214 bool result = false; |
215 Send(new ChromeViewHostMsg_AllowIndexedDB( | 215 Send(new ChromeViewHostMsg_AllowIndexedDB( |
216 routing_id(), GURL(frame->document().securityOrigin().toString()), | 216 routing_id(), GURL(frame->document().securityOrigin().toString()), |
217 GURL(frame->top()->document().securityOrigin().toString()), | 217 GURL(frame->top()->document().securityOrigin().toString()), |
218 name, &result)); | 218 name, &result)); |
219 return result; | 219 return result; |
220 } | 220 } |
221 | 221 |
222 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, | 222 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 ContentSetting setting = GetContentSettingFromRules( | 263 ContentSetting setting = GetContentSettingFromRules( |
264 content_setting_rules_->script_rules, | 264 content_setting_rules_->script_rules, |
265 frame, | 265 frame, |
266 GURL(script_url)); | 266 GURL(script_url)); |
267 allow = setting != CONTENT_SETTING_BLOCK; | 267 allow = setting != CONTENT_SETTING_BLOCK; |
268 } | 268 } |
269 return allow || IsWhitelistedForContentSettings(frame); | 269 return allow || IsWhitelistedForContentSettings(frame); |
270 } | 270 } |
271 | 271 |
272 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { | 272 bool ContentSettingsObserver::AllowStorage(WebFrame* frame, bool local) { |
273 if (frame->document().securityOrigin().isEmpty() || | 273 if (frame->document().securityOrigin().isUnique() || |
274 frame->top()->document().securityOrigin().isEmpty()) | 274 frame->top()->document().securityOrigin().isUnique()) |
275 return false; // Uninitialized document. | 275 return false; |
276 bool result = false; | 276 bool result = false; |
277 | 277 |
278 StoragePermissionsKey key( | 278 StoragePermissionsKey key( |
279 GURL(frame->document().securityOrigin().toString()), local); | 279 GURL(frame->document().securityOrigin().toString()), local); |
280 std::map<StoragePermissionsKey, bool>::const_iterator permissions = | 280 std::map<StoragePermissionsKey, bool>::const_iterator permissions = |
281 cached_storage_permissions_.find(key); | 281 cached_storage_permissions_.find(key); |
282 if (permissions != cached_storage_permissions_.end()) | 282 if (permissions != cached_storage_permissions_.end()) |
283 return permissions->second; | 283 return permissions->second; |
284 | 284 |
285 Send(new ChromeViewHostMsg_AllowDOMStorage( | 285 Send(new ChromeViewHostMsg_AllowDOMStorage( |
(...skipping 16 matching lines...) Expand all Loading... |
302 void ContentSettingsObserver::OnLoadBlockedPlugins() { | 302 void ContentSettingsObserver::OnLoadBlockedPlugins() { |
303 plugins_temporarily_allowed_ = true; | 303 plugins_temporarily_allowed_ = true; |
304 } | 304 } |
305 | 305 |
306 void ContentSettingsObserver::ClearBlockedContentSettings() { | 306 void ContentSettingsObserver::ClearBlockedContentSettings() { |
307 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 307 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
308 content_blocked_[i] = false; | 308 content_blocked_[i] = false; |
309 cached_storage_permissions_.clear(); | 309 cached_storage_permissions_.clear(); |
310 cached_script_permissions_.clear(); | 310 cached_script_permissions_.clear(); |
311 } | 311 } |
OLD | NEW |