diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/parser/HTMLResourcePreloader.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/parser/HTMLResourcePreloader.cpp')
-rw-r--r-- | Source/WebCore/html/parser/HTMLResourcePreloader.cpp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/Source/WebCore/html/parser/HTMLResourcePreloader.cpp b/Source/WebCore/html/parser/HTMLResourcePreloader.cpp index cfd2342b2..623662431 100644 --- a/Source/WebCore/html/parser/HTMLResourcePreloader.cpp +++ b/Source/WebCore/html/parser/HTMLResourcePreloader.cpp @@ -20,7 +20,7 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -35,54 +35,56 @@ namespace WebCore { -bool PreloadRequest::isSafeToSendToAnotherThread() const -{ - return m_initiator.isSafeToSendToAnotherThread() - && m_charset.isSafeToSendToAnotherThread() - && m_resourceURL.isSafeToSendToAnotherThread() - && m_mediaAttribute.isSafeToSendToAnotherThread() - && m_baseURL.isSafeToSendToAnotherThread(); -} - URL PreloadRequest::completeURL(Document& document) { - return document.completeURL(m_resourceURL, m_baseURL.isEmpty() ? document.url() : m_baseURL); + return document.completeURL(m_resourceURL, m_baseURL.isEmpty() ? document.baseURL() : m_baseURL); } CachedResourceRequest PreloadRequest::resourceRequest(Document& document) { ASSERT(isMainThread()); - CachedResourceRequest request(ResourceRequest(completeURL(document))); - request.setInitiator(m_initiator); - // FIXME: It's possible CORS should work for other request types? - if (m_resourceType == CachedResource::Script) - request.mutableResourceRequest().setAllowCookies(m_crossOriginModeAllowsCookies); + bool skipContentSecurityPolicyCheck = false; + if (m_resourceType == CachedResource::Type::Script) + skipContentSecurityPolicyCheck = document.contentSecurityPolicy()->allowScriptWithNonce(m_nonceAttribute); + else if (m_resourceType == CachedResource::Type::CSSStyleSheet) + skipContentSecurityPolicyCheck = document.contentSecurityPolicy()->allowStyleWithNonce(m_nonceAttribute); + + ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); + if (skipContentSecurityPolicyCheck) + options.contentSecurityPolicyImposition = ContentSecurityPolicyImposition::SkipPolicyCheck; + + CachedResourceRequest request { completeURL(document), options }; + request.setInitiator(m_initiator); + String crossOriginMode = m_crossOriginMode; + if (m_moduleScript == ModuleScript::Yes) { + if (crossOriginMode.isNull()) + crossOriginMode = ASCIILiteral("omit"); + } + request.setAsPotentiallyCrossOrigin(crossOriginMode, document); return request; } void HTMLResourcePreloader::preload(PreloadRequestStream requests) { for (auto& request : requests) - preload(std::move(request)); + preload(WTFMove(request)); } -static bool mediaAttributeMatches(Frame* frame, RenderStyle* renderStyle, const String& attributeValue) +static bool mediaAttributeMatches(Document& document, const RenderStyle* renderStyle, const String& attributeValue) { - RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue); - MediaQueryEvaluator mediaQueryEvaluator("screen", frame, renderStyle); - return mediaQueryEvaluator.eval(mediaQueries.get()); + auto mediaQueries = MediaQuerySet::create(attributeValue); + return MediaQueryEvaluator { "screen", document, renderStyle }.evaluate(mediaQueries.get()); } void HTMLResourcePreloader::preload(std::unique_ptr<PreloadRequest> preload) { ASSERT(m_document.frame()); ASSERT(m_document.renderView()); - if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document.frame(), &m_document.renderView()->style(), preload->media())) + if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document, &m_document.renderView()->style(), preload->media())) return; - CachedResourceRequest request = preload->resourceRequest(m_document); - m_document.cachedResourceLoader()->preload(preload->resourceType(), request, preload->charset()); + m_document.cachedResourceLoader().preload(preload->resourceType(), preload->resourceRequest(m_document)); } |