OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "content/public/renderer/document_state.h" | 12 #include "content/public/renderer/document_state.h" |
13 #include "content/public/renderer/navigation_state.h" | 13 #include "content/public/renderer/navigation_state.h" |
14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
18 #include "extensions/common/permissions/permissions_data.h" | 18 #include "extensions/common/permissions/permissions_data.h" |
19 #include "extensions/renderer/dispatcher.h" | 19 #include "extensions/renderer/dispatcher.h" |
20 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" | 20 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" |
21 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
22 #include "third_party/WebKit/public/web/WebDataSource.h" | 22 #include "third_party/WebKit/public/web/WebDataSource.h" |
23 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
24 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
25 #include "third_party/WebKit/public/web/WebFrameClient.h" | 25 #include "third_party/WebKit/public/web/WebFrameClient.h" |
26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
27 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
28 #include "webkit/child/weburlresponse_extradata_impl.h" | |
29 | 28 |
30 #if defined(ENABLE_EXTENSIONS) | 29 #if defined(ENABLE_EXTENSIONS) |
31 #include "chrome/common/extensions/chrome_extension_messages.h" | 30 #include "chrome/common/extensions/chrome_extension_messages.h" |
32 #endif | 31 #endif |
33 | 32 |
34 using blink::WebDataSource; | 33 using blink::WebDataSource; |
35 using blink::WebDocument; | 34 using blink::WebDocument; |
36 using blink::WebFrame; | 35 using blink::WebFrame; |
37 using blink::WebPermissionCallbacks; | 36 using blink::WebPermissionCallbacks; |
38 using blink::WebSecurityOrigin; | 37 using blink::WebSecurityOrigin; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 GURL(frame->top()->document().securityOrigin().toString()))); | 295 GURL(frame->top()->document().securityOrigin().toString()))); |
297 } | 296 } |
298 | 297 |
299 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, | 298 bool ContentSettingsObserver::allowImage(bool enabled_per_settings, |
300 const WebURL& image_url) { | 299 const WebURL& image_url) { |
301 bool allow = enabled_per_settings; | 300 bool allow = enabled_per_settings; |
302 if (enabled_per_settings) { | 301 if (enabled_per_settings) { |
303 if (is_interstitial_page_) | 302 if (is_interstitial_page_) |
304 return true; | 303 return true; |
305 | 304 |
306 WebFrame* frame = render_frame()->GetWebFrame(); | 305 if (IsWhitelistedForContentSettings(render_frame())) |
307 if (IsWhitelistedForContentSettings(frame)) | |
308 return true; | 306 return true; |
309 | 307 |
310 if (content_setting_rules_) { | 308 if (content_setting_rules_) { |
311 GURL secondary_url(image_url); | 309 GURL secondary_url(image_url); |
312 allow = GetContentSettingFromRules( | 310 allow = |
313 content_setting_rules_->image_rules, | 311 GetContentSettingFromRules(content_setting_rules_->image_rules, |
314 frame, secondary_url) != CONTENT_SETTING_BLOCK; | 312 render_frame()->GetWebFrame(), |
| 313 secondary_url) != CONTENT_SETTING_BLOCK; |
315 } | 314 } |
316 } | 315 } |
317 if (!allow) | 316 if (!allow) |
318 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); | 317 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); |
319 return allow; | 318 return allow; |
320 } | 319 } |
321 | 320 |
322 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, | 321 bool ContentSettingsObserver::allowIndexedDB(const WebString& name, |
323 const WebSecurityOrigin& origin) { | 322 const WebSecurityOrigin& origin) { |
324 WebFrame* frame = render_frame()->GetWebFrame(); | 323 WebFrame* frame = render_frame()->GetWebFrame(); |
(...skipping 29 matching lines...) Expand all Loading... |
354 // |IsWhitelistedForContentSettings|; if there is only the default rule | 353 // |IsWhitelistedForContentSettings|; if there is only the default rule |
355 // allowing all scripts, it's quicker this way. | 354 // allowing all scripts, it's quicker this way. |
356 bool allow = true; | 355 bool allow = true; |
357 if (content_setting_rules_) { | 356 if (content_setting_rules_) { |
358 ContentSetting setting = GetContentSettingFromRules( | 357 ContentSetting setting = GetContentSettingFromRules( |
359 content_setting_rules_->script_rules, | 358 content_setting_rules_->script_rules, |
360 frame, | 359 frame, |
361 GURL(frame->document().securityOrigin().toString())); | 360 GURL(frame->document().securityOrigin().toString())); |
362 allow = setting != CONTENT_SETTING_BLOCK; | 361 allow = setting != CONTENT_SETTING_BLOCK; |
363 } | 362 } |
364 allow = allow || IsWhitelistedForContentSettings(frame); | 363 allow = allow || IsWhitelistedForContentSettings(render_frame()); |
365 | 364 |
366 cached_script_permissions_[frame] = allow; | 365 cached_script_permissions_[frame] = allow; |
367 return allow; | 366 return allow; |
368 } | 367 } |
369 | 368 |
370 bool ContentSettingsObserver::allowScriptFromSource( | 369 bool ContentSettingsObserver::allowScriptFromSource( |
371 bool enabled_per_settings, | 370 bool enabled_per_settings, |
372 const blink::WebURL& script_url) { | 371 const blink::WebURL& script_url) { |
373 if (!enabled_per_settings) | 372 if (!enabled_per_settings) |
374 return false; | 373 return false; |
375 if (is_interstitial_page_) | 374 if (is_interstitial_page_) |
376 return true; | 375 return true; |
377 | 376 |
378 bool allow = true; | 377 bool allow = true; |
379 WebFrame* frame = render_frame()->GetWebFrame(); | |
380 if (content_setting_rules_) { | 378 if (content_setting_rules_) { |
381 ContentSetting setting = GetContentSettingFromRules( | 379 ContentSetting setting = |
382 content_setting_rules_->script_rules, | 380 GetContentSettingFromRules(content_setting_rules_->script_rules, |
383 frame, | 381 render_frame()->GetWebFrame(), |
384 GURL(script_url)); | 382 GURL(script_url)); |
385 allow = setting != CONTENT_SETTING_BLOCK; | 383 allow = setting != CONTENT_SETTING_BLOCK; |
386 } | 384 } |
387 return allow || IsWhitelistedForContentSettings(frame); | 385 return allow || IsWhitelistedForContentSettings(render_frame()); |
388 } | 386 } |
389 | 387 |
390 bool ContentSettingsObserver::allowStorage(bool local) { | 388 bool ContentSettingsObserver::allowStorage(bool local) { |
391 WebFrame* frame = render_frame()->GetWebFrame(); | 389 WebFrame* frame = render_frame()->GetWebFrame(); |
392 if (frame->document().securityOrigin().isUnique() || | 390 if (frame->document().securityOrigin().isUnique() || |
393 frame->top()->document().securityOrigin().isUnique()) | 391 frame->top()->document().securityOrigin().isUnique()) |
394 return false; | 392 return false; |
395 bool result = false; | 393 bool result = false; |
396 | 394 |
397 StoragePermissionsKey key( | 395 StoragePermissionsKey key( |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 658 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
661 return NULL; | 659 return NULL; |
662 | 660 |
663 const std::string extension_id = origin.host().utf8().data(); | 661 const std::string extension_id = origin.host().utf8().data(); |
664 if (!extension_dispatcher_->IsExtensionActive(extension_id)) | 662 if (!extension_dispatcher_->IsExtensionActive(extension_id)) |
665 return NULL; | 663 return NULL; |
666 | 664 |
667 return extension_dispatcher_->extensions()->GetByID(extension_id); | 665 return extension_dispatcher_->extensions()->GetByID(extension_id); |
668 } | 666 } |
669 | 667 |
670 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) { | 668 bool ContentSettingsObserver::IsWhitelistedForContentSettings( |
| 669 content::RenderFrame* frame) { |
671 // Whitelist Instant processes. | 670 // Whitelist Instant processes. |
672 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) | 671 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) |
673 return true; | 672 return true; |
674 | 673 |
675 // Whitelist ftp directory listings, as they require JavaScript to function | 674 // Whitelist ftp directory listings, as they require JavaScript to function |
676 // properly. | 675 // properly. |
677 webkit_glue::WebURLResponseExtraDataImpl* extra_data = | 676 if (frame->IsFTPDirectoryListing()) |
678 static_cast<webkit_glue::WebURLResponseExtraDataImpl*>( | |
679 frame->dataSource()->response().extraData()); | |
680 if (extra_data && extra_data->is_ftp_directory_listing()) | |
681 return true; | 677 return true; |
682 return IsWhitelistedForContentSettings(frame->document().securityOrigin(), | 678 |
683 frame->document().url()); | 679 WebFrame* web_frame = frame->GetWebFrame(); |
| 680 return IsWhitelistedForContentSettings(web_frame->document().securityOrigin(), |
| 681 web_frame->document().url()); |
684 } | 682 } |
685 | 683 |
686 bool ContentSettingsObserver::IsWhitelistedForContentSettings( | 684 bool ContentSettingsObserver::IsWhitelistedForContentSettings( |
687 const WebSecurityOrigin& origin, | 685 const WebSecurityOrigin& origin, |
688 const GURL& document_url) { | 686 const GURL& document_url) { |
689 if (document_url == GURL(content::kUnreachableWebDataURL)) | 687 if (document_url == GURL(content::kUnreachableWebDataURL)) |
690 return true; | 688 return true; |
691 | 689 |
692 if (origin.isUnique()) | 690 if (origin.isUnique()) |
693 return false; // Uninitialized document? | 691 return false; // Uninitialized document? |
(...skipping 14 matching lines...) Expand all Loading... |
708 | 706 |
709 // If the scheme is file:, an empty file name indicates a directory listing, | 707 // If the scheme is file:, an empty file name indicates a directory listing, |
710 // which requires JavaScript to function properly. | 708 // which requires JavaScript to function properly. |
711 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { | 709 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { |
712 return document_url.SchemeIs(url::kFileScheme) && | 710 return document_url.SchemeIs(url::kFileScheme) && |
713 document_url.ExtractFileName().empty(); | 711 document_url.ExtractFileName().empty(); |
714 } | 712 } |
715 | 713 |
716 return false; | 714 return false; |
717 } | 715 } |
OLD | NEW |