| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "core/frame/csp/ContentSecurityPolicy.h" | 49 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 50 #include "core/page/FrameTree.h" | 50 #include "core/page/FrameTree.h" |
| 51 #include "core/page/Page.h" | 51 #include "core/page/Page.h" |
| 52 #include "core/frame/Settings.h" | 52 #include "core/frame/Settings.h" |
| 53 #include "core/inspector/ConsoleMessage.h" | 53 #include "core/inspector/ConsoleMessage.h" |
| 54 #include "platform/Logging.h" | 54 #include "platform/Logging.h" |
| 55 #include "platform/UserGestureIndicator.h" | 55 #include "platform/UserGestureIndicator.h" |
| 56 #include "platform/mhtml/ArchiveResource.h" | 56 #include "platform/mhtml/ArchiveResource.h" |
| 57 #include "platform/mhtml/ArchiveResourceCollection.h" | 57 #include "platform/mhtml/ArchiveResourceCollection.h" |
| 58 #include "platform/mhtml/MHTMLArchive.h" | 58 #include "platform/mhtml/MHTMLArchive.h" |
| 59 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" |
| 59 #include "platform/plugins/PluginData.h" | 60 #include "platform/plugins/PluginData.h" |
| 60 #include "platform/weborigin/SchemeRegistry.h" | 61 #include "platform/weborigin/SchemeRegistry.h" |
| 61 #include "platform/weborigin/SecurityPolicy.h" | 62 #include "platform/weborigin/SecurityPolicy.h" |
| 62 #include "public/platform/Platform.h" | 63 #include "public/platform/Platform.h" |
| 63 #include "public/platform/WebMimeRegistry.h" | 64 #include "public/platform/WebMimeRegistry.h" |
| 64 #include "public/platform/WebThreadedDataReceiver.h" | 65 #include "public/platform/WebThreadedDataReceiver.h" |
| 65 #include "wtf/Assertions.h" | 66 #include "wtf/Assertions.h" |
| 66 #include "wtf/text/WTFString.h" | 67 #include "wtf/text/WTFString.h" |
| 67 | 68 |
| 68 namespace blink { | 69 namespace blink { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (!canShowMIMEType(m_response.mimeType(), m_frame->page())) | 417 if (!canShowMIMEType(m_response.mimeType(), m_frame->page())) |
| 417 return false; | 418 return false; |
| 418 | 419 |
| 419 // Prevent remote web archives from loading because they can claim to be fro
m any domain and thus avoid cross-domain security checks. | 420 // Prevent remote web archives from loading because they can claim to be fro
m any domain and thus avoid cross-domain security checks. |
| 420 if (equalIgnoringCase("multipart/related", m_response.mimeType()) && !Scheme
Registry::shouldTreatURLSchemeAsLocal(m_request.url().protocol())) | 421 if (equalIgnoringCase("multipart/related", m_response.mimeType()) && !Scheme
Registry::shouldTreatURLSchemeAsLocal(m_request.url().protocol())) |
| 421 return false; | 422 return false; |
| 422 | 423 |
| 423 return true; | 424 return true; |
| 424 } | 425 } |
| 425 | 426 |
| 427 void DocumentLoader::cancelLoadAfterXFrameOptionsOrCSPDenied(const ResourceRespo
nse& response) |
| 428 { |
| 429 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame, this, ma
inResourceIdentifier(), response); |
| 430 |
| 431 frame()->document()->enforceSandboxFlags(SandboxOrigin); |
| 432 if (FrameOwner* owner = frame()->owner()) |
| 433 owner->dispatchLoad(); |
| 434 |
| 435 // The load event might have detached this frame. In that case, the load wil
l already have been cancelled during detach. |
| 436 if (frameLoader()) |
| 437 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); |
| 438 return; |
| 439 } |
| 440 |
| 426 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse
& response) | 441 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse
& response) |
| 427 { | 442 { |
| 428 ASSERT_UNUSED(resource, m_mainResource == resource); | 443 ASSERT_UNUSED(resource, m_mainResource == resource); |
| 429 RefPtr<DocumentLoader> protect(this); | 444 RefPtr<DocumentLoader> protect(this); |
| 430 | 445 |
| 431 m_applicationCacheHost->didReceiveResponseForMainResource(response); | 446 m_applicationCacheHost->didReceiveResponseForMainResource(response); |
| 432 | 447 |
| 433 // The memory cache doesn't understand the application cache or its caching
rules. So if a main resource is served | 448 // The memory cache doesn't understand the application cache or its caching
rules. So if a main resource is served |
| 434 // from the application cache, ensure we don't save the result for future us
e. All responses loaded | 449 // from the application cache, ensure we don't save the result for future us
e. All responses loaded |
| 435 // from appcache will have a non-zero appCacheID(). | 450 // from appcache will have a non-zero appCacheID(). |
| 436 if (response.appCacheID()) | 451 if (response.appCacheID()) |
| 437 memoryCache()->remove(m_mainResource.get()); | 452 memoryCache()->remove(m_mainResource.get()); |
| 438 | 453 |
| 439 DEFINE_STATIC_LOCAL(AtomicString, xFrameOptionHeader, ("x-frame-options", At
omicString::ConstructFromLiteral)); | 454 DEFINE_STATIC_LOCAL(AtomicString, xFrameOptionHeader, ("x-frame-options", At
omicString::ConstructFromLiteral)); |
| 440 HTTPHeaderMap::const_iterator it = response.httpHeaderFields().find(xFrameOp
tionHeader); | 455 HTTPHeaderMap::const_iterator it = response.httpHeaderFields().find(xFrameOp
tionHeader); |
| 441 if (it != response.httpHeaderFields().end()) { | 456 if (it != response.httpHeaderFields().end()) { |
| 442 String content = it->value; | 457 String content = it->value; |
| 443 ASSERT(m_mainResource); | 458 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response
.url(), mainResourceIdentifier())) { |
| 444 unsigned long identifier = mainResourceIdentifier(); | |
| 445 ASSERT(identifier); | |
| 446 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response
.url(), identifier)) { | |
| 447 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame,
this, identifier, response); | |
| 448 String message = "Refused to display '" + response.url().elidedStrin
g() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'."; | 459 String message = "Refused to display '" + response.url().elidedStrin
g() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'."; |
| 449 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(SecurityMessageSource, ErrorMessageLevel, message); | 460 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(SecurityMessageSource, ErrorMessageLevel, message); |
| 450 consoleMessage->setRequestIdentifier(identifier); | 461 consoleMessage->setRequestIdentifier(mainResourceIdentifier()); |
| 451 frame()->document()->addConsoleMessage(consoleMessage.release()); | 462 frame()->document()->addConsoleMessage(consoleMessage.release()); |
| 452 frame()->document()->enforceSandboxFlags(SandboxOrigin); | |
| 453 if (FrameOwner* owner = frame()->owner()) | |
| 454 owner->dispatchLoad(); | |
| 455 | 463 |
| 456 // The load event might have detached this frame. In that case, the
load will already have been cancelled during detach. | 464 cancelLoadAfterXFrameOptionsOrCSPDenied(response); |
| 457 if (frameLoader()) | |
| 458 cancelMainResourceLoad(ResourceError::cancelledError(m_request.u
rl())); | |
| 459 return; | 465 return; |
| 460 } | 466 } |
| 461 } | 467 } |
| 462 | 468 |
| 469 m_contentSecurityPolicy = ContentSecurityPolicy::create(); |
| 470 m_contentSecurityPolicy->setOverrideURLForSelf(response.url()); |
| 471 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponseHead
ers(response)); |
| 472 if (!m_contentSecurityPolicy->allowAncestors(m_frame)) { |
| 473 cancelLoadAfterXFrameOptionsOrCSPDenied(response); |
| 474 return; |
| 475 } |
| 476 |
| 463 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); | 477 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); |
| 464 | 478 |
| 465 m_response = response; | 479 m_response = response; |
| 466 | 480 |
| 467 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->dataBufferin
gPolicy() != BufferData) | 481 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->dataBufferin
gPolicy() != BufferData) |
| 468 m_mainResource->setDataBufferingPolicy(BufferData); | 482 m_mainResource->setDataBufferingPolicy(BufferData); |
| 469 | 483 |
| 470 if (!shouldContinueForResponse()) { | 484 if (!shouldContinueForResponse()) { |
| 471 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main
Resource->identifier(), m_response); | 485 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main
Resource->identifier(), m_response); |
| 472 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); | 486 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR
L() | 829 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR
L() |
| 816 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn
it& init, const String& source, Document* ownerDocument) | 830 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn
it& init, const String& source, Document* ownerDocument) |
| 817 { | 831 { |
| 818 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri
ter->encoding() : emptyAtom, true); | 832 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri
ter->encoding() : emptyAtom, true); |
| 819 if (!source.isNull()) | 833 if (!source.isNull()) |
| 820 m_writer->appendReplacingData(source); | 834 m_writer->appendReplacingData(source); |
| 821 endWriting(m_writer.get()); | 835 endWriting(m_writer.get()); |
| 822 } | 836 } |
| 823 | 837 |
| 824 } // namespace blink | 838 } // namespace blink |
| OLD | NEW |