Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad()) ; | 426 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad()) ; |
| 427 resource->setOptions(request.options()); | 427 resource->setOptions(request.options()); |
| 428 resource->setDataBufferingPolicy(BufferData); | 428 resource->setDataBufferingPolicy(BufferData); |
| 429 resource->responseReceived(response); | 429 resource->responseReceived(response); |
| 430 if (substituteData.content()->size()) | 430 if (substituteData.content()->size()) |
| 431 resource->setResourceBuffer(substituteData.content()); | 431 resource->setResourceBuffer(substituteData.content()); |
| 432 resource->finish(); | 432 resource->finish(); |
| 433 memoryCache()->add(resource.get()); | 433 memoryCache()->add(resource.get()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool ResourceFetcher::checkInsecureContent(Resource::Type type, const KURL& url, LocalFrame* frame, MixedContentBlockingTreatment treatment) const | |
| 437 { | |
| 438 if (treatment == TreatAsDefaultForType) { | |
| 439 switch (type) { | |
| 440 case Resource::XSLStyleSheet: | |
| 441 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | |
| 442 case Resource::Script: | |
| 443 case Resource::SVGDocument: | |
| 444 case Resource::CSSStyleSheet: | |
| 445 case Resource::ImportResource: | |
| 446 // These resource can inject script into the current document (Scrip t, | |
| 447 // XSL) or exfiltrate the content of the current document (CSS). | |
| 448 treatment = TreatAsActiveContent; | |
| 449 break; | |
| 450 | |
| 451 case Resource::Font: | |
| 452 case Resource::TextTrack: | |
| 453 // These resources are passive, but mixed usage is low enough that w e | |
| 454 // can block them in a mixed context. | |
| 455 treatment = TreatAsActiveContent; | |
| 456 break; | |
| 457 | |
| 458 case Resource::Raw: | |
| 459 case Resource::Image: | |
| 460 case Resource::Media: | |
| 461 // These resources can corrupt only the frame's pixels. | |
| 462 treatment = TreatAsPassiveContent; | |
| 463 break; | |
| 464 | |
| 465 case Resource::MainResource: | |
| 466 case Resource::LinkPrefetch: | |
| 467 case Resource::LinkSubresource: | |
| 468 // These cannot affect the current document. | |
| 469 treatment = TreatAsAlwaysAllowedContent; | |
| 470 break; | |
| 471 } | |
| 472 } | |
| 473 | |
| 474 // No frame, no mixed content. | |
| 475 if (!frame) | |
| 476 return true; | |
| 477 | |
| 478 if (treatment == TreatAsActiveContent) { | |
| 479 if (!frame->loader().mixedContentChecker()->canRunInsecureContent(frame- >document()->securityOrigin(), url)) | |
| 480 return false; | |
| 481 } else if (treatment == TreatAsPassiveContent) { | |
| 482 if (!frame->loader().mixedContentChecker()->canDisplayInsecureContent(fr ame->document()->securityOrigin(), url)) | |
| 483 return false; | |
| 484 if (MixedContentChecker::isMixedContent(frame->document()->securityOrigi n(), url) || MixedContentChecker::isMixedContent(toLocalFrame(frame->tree().top( ))->document()->securityOrigin(), url)) { | |
| 485 switch (type) { | |
| 486 case Resource::Raw: | |
| 487 UseCounter::count(frame->document(), UseCounter::MixedContentRaw ); | |
| 488 break; | |
| 489 | |
| 490 case Resource::Image: | |
| 491 UseCounter::count(frame->document(), UseCounter::MixedContentIma ge); | |
| 492 break; | |
| 493 | |
| 494 case Resource::Media: | |
| 495 UseCounter::count(frame->document(), UseCounter::MixedContentMed ia); | |
| 496 break; | |
| 497 | |
| 498 default: | |
| 499 ASSERT_NOT_REACHED(); | |
| 500 } | |
| 501 } | |
| 502 } else { | |
| 503 ASSERT(treatment == TreatAsAlwaysAllowedContent); | |
| 504 } | |
| 505 return true; | |
| 506 } | |
| 507 | |
| 508 bool ResourceFetcher::canRequest(Resource::Type type, const ResourceRequest& res ourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forPre load, FetchRequest::OriginRestriction originRestriction) const | 436 bool ResourceFetcher::canRequest(Resource::Type type, const ResourceRequest& res ourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forPre load, FetchRequest::OriginRestriction originRestriction) const |
| 509 { | 437 { |
| 510 SecurityOrigin* securityOrigin = options.securityOrigin.get(); | 438 SecurityOrigin* securityOrigin = options.securityOrigin.get(); |
| 511 if (!securityOrigin && document()) | 439 if (!securityOrigin && document()) |
| 512 securityOrigin = document()->securityOrigin(); | 440 securityOrigin = document()->securityOrigin(); |
| 513 | 441 |
| 514 if (originRestriction != FetchRequest::NoOriginRestriction && securityOrigin && !securityOrigin->canDisplay(url)) { | 442 if (originRestriction != FetchRequest::NoOriginRestriction && securityOrigin && !securityOrigin->canDisplay(url)) { |
| 515 if (!forPreload) | 443 if (!forPreload) |
| 516 context().reportLocalLoadFailed(url); | 444 context().reportLocalLoadFailed(url); |
| 517 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a llowed by SecurityOrigin::canDisplay"); | 445 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a llowed by SecurityOrigin::canDisplay"); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 break; | 543 break; |
| 616 } | 544 } |
| 617 | 545 |
| 618 // SVG Images have unique security rules that prevent all subresource reques ts | 546 // SVG Images have unique security rules that prevent all subresource reques ts |
| 619 // except for data urls. | 547 // except for data urls. |
| 620 if (type != Resource::MainResource) { | 548 if (type != Resource::MainResource) { |
| 621 if (frame() && frame()->chromeClient().isSVGImageChromeClient() && !url. protocolIsData()) | 549 if (frame() && frame()->chromeClient().isSVGImageChromeClient() && !url. protocolIsData()) |
| 622 return false; | 550 return false; |
| 623 } | 551 } |
| 624 | 552 |
| 625 // Last of all, check for insecure content. We do this last so that when | 553 // Last of all, check for mixed content. We do this last so that when |
| 626 // folks block insecure content with a CSP policy, they don't get a warning. | 554 // folks block mixed content with a CSP policy, they don't get a warning. |
| 627 // They'll still get a warning in the console about CSP blocking the load. | 555 // They'll still get a warning in the console about CSP blocking the load. |
| 628 | 556 |
| 629 // If we're loading the main resource of a subframe, ensure that we treat th e resource as active | 557 // If we're loading the main resource of a subframe, ensure that we treat th e resource as active |
|
sof
2014/09/11 09:34:42
Do you need to adjust this comment to fit what's n
Mike West
2014/09/11 09:49:35
I do need to drop that bit of the comment. Thanks
| |
| 630 // content for the purposes of mixed content checks, and that we check again st the parent of the | 558 // content for the purposes of mixed content checks, and that we check again st the parent of the |
| 631 // active frame, rather than the frame itself. | 559 // active frame, rather than the frame itself. |
| 632 LocalFrame* effectiveFrame = frame(); | 560 LocalFrame* effectiveFrame = frame(); |
| 633 MixedContentBlockingTreatment effectiveTreatment = options.mixedContentBlock ingTreatment; | |
| 634 if (resourceRequest.frameType() == WebURLRequest::FrameTypeNested) { | 561 if (resourceRequest.frameType() == WebURLRequest::FrameTypeNested) { |
| 635 effectiveTreatment = TreatAsActiveContent; | |
| 636 // FIXME: Deal with RemoteFrames. | 562 // FIXME: Deal with RemoteFrames. |
| 637 if (frame()->tree().parent()->isLocalFrame()) | 563 if (frame()->tree().parent()->isLocalFrame()) |
| 638 effectiveFrame = toLocalFrame(frame()->tree().parent()); | 564 effectiveFrame = toLocalFrame(frame()->tree().parent()); |
| 639 } | 565 } |
| 640 | 566 |
| 641 // FIXME: Should we consider forPreload here? | 567 return !MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques t, url); |
| 642 if (!checkInsecureContent(type, url, effectiveFrame, effectiveTreatment)) { | |
| 643 ASSERT(MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReq uest, url)); | |
| 644 return false; | |
| 645 } | |
| 646 | |
| 647 ASSERT(!MixedContentChecker::shouldBlockFetch(effectiveFrame, resourceReques t, url)); | |
| 648 return true; | |
| 649 } | 568 } |
| 650 | 569 |
| 651 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour ceOrigin, const KURL& url) const | 570 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour ceOrigin, const KURL& url) const |
| 652 { | 571 { |
| 653 // Redirects can change the response URL different from one of request. | 572 // Redirects can change the response URL different from one of request. |
| 654 if (!canRequest(resource->type(), resource->resourceRequest(), url, resource ->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestrict ionForType)) | 573 if (!canRequest(resource->type(), resource->resourceRequest(), url, resource ->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultOriginRestrict ionForType)) |
| 655 return false; | 574 return false; |
| 656 | 575 |
| 657 if (!sourceOrigin && document()) | 576 if (!sourceOrigin && document()) |
| 658 sourceOrigin = document()->securityOrigin(); | 577 sourceOrigin = document()->securityOrigin(); |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 | 1490 |
| 1572 void ResourceFetcher::trace(Visitor* visitor) | 1491 void ResourceFetcher::trace(Visitor* visitor) |
| 1573 { | 1492 { |
| 1574 visitor->trace(m_document); | 1493 visitor->trace(m_document); |
| 1575 visitor->trace(m_loaders); | 1494 visitor->trace(m_loaders); |
| 1576 visitor->trace(m_multipartLoaders); | 1495 visitor->trace(m_multipartLoaders); |
| 1577 ResourceLoaderHost::trace(visitor); | 1496 ResourceLoaderHost::trace(visitor); |
| 1578 } | 1497 } |
| 1579 | 1498 |
| 1580 } | 1499 } |
| OLD | NEW |