| Index: third_party/WebKit/Source/core/loader/LinkLoader.cpp
|
| diff --git a/third_party/WebKit/Source/core/loader/LinkLoader.cpp b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
|
| index 024c8177dbb1de369c84d132dbdd11f993c98b45..eace1084ca99919acbc1cf86b2bbcee23779587e 100644
|
| --- a/third_party/WebKit/Source/core/loader/LinkLoader.cpp
|
| +++ b/third_party/WebKit/Source/core/loader/LinkLoader.cpp
|
| @@ -31,6 +31,8 @@
|
|
|
| #include "core/loader/LinkLoader.h"
|
|
|
| +#include "core/css/MediaList.h"
|
| +#include "core/css/MediaQueryEvaluator.h"
|
| #include "core/dom/Document.h"
|
| #include "core/fetch/FetchInitiatorTypeNames.h"
|
| #include "core/fetch/FetchRequest.h"
|
| @@ -40,6 +42,7 @@
|
| #include "core/frame/UseCounter.h"
|
| #include "core/html/CrossOriginAttribute.h"
|
| #include "core/html/LinkRelAttribute.h"
|
| +#include "core/html/parser/HTMLPreloadScanner.h"
|
| #include "core/inspector/ConsoleMessage.h"
|
| #include "core/loader/DocumentLoader.h"
|
| #include "core/loader/LinkHeader.h"
|
| @@ -246,7 +249,7 @@ static bool isSupportedType(Resource::Type resourceType, const String& mimeType)
|
| }
|
|
|
| static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KURL& href, Document& document, const String& as, const String& mimeType,
|
| - CrossOriginAttributeValue crossOrigin, LinkCaller caller, bool& errorOccurred)
|
| + const String& media, CrossOriginAttributeValue crossOrigin, LinkCaller caller, bool& errorOccurred, ViewportDescription* viewportDescription)
|
| {
|
| if (!document.loader() || !relAttribute.isLinkPreload())
|
| return nullptr;
|
| @@ -258,6 +261,17 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
|
| return nullptr;
|
| }
|
|
|
| + if (!media.isEmpty()) {
|
| + RefPtrWillBeRawPtr<MediaValues> mediaValues = MediaValues::createDynamicIfFrameExists(document.frame());
|
| + if (viewportDescription)
|
| + mediaValues->overrideViewportDimensions(viewportDescription->maxWidth.getFloatValue(), viewportDescription->maxHeight.getFloatValue());
|
| +
|
| + // Preload only if media matches
|
| + RefPtrWillBeRawPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media);
|
| + MediaQueryEvaluator evaluator(*mediaValues);
|
| + if (!evaluator.eval(mediaQueries.get()))
|
| + return nullptr;
|
| + }
|
| if (caller == LinkCalledFromHeader)
|
| UseCounter::count(document, UseCounter::LinkHeaderPreload);
|
| Resource::Type resourceType;
|
| @@ -286,9 +300,10 @@ static Resource* preloadIfNeeded(const LinkRelAttribute& relAttribute, const KUR
|
| return document.loader()->startPreload(resourceType, linkRequest);
|
| }
|
|
|
| -bool LinkLoader::loadLinkFromHeader(const String& headerValue, const KURL& baseURL, Document* document, const NetworkHintsInterface& networkHintsInterface, CanLoadResources canLoadResources)
|
| +bool LinkLoader::loadLinkFromHeader(const String& headerValue, const KURL& baseURL, Document* document, const NetworkHintsInterface& networkHintsInterface,
|
| + CanLoadResources canLoadResources, ViewportDescriptionWrapper* viewportDescriptionWrapper)
|
| {
|
| - if (!document)
|
| + if (!document || headerValue.isEmpty())
|
| return false;
|
| LinkHeaderSet headerSet(headerValue);
|
| for (auto& header : headerSet) {
|
| @@ -306,15 +321,18 @@ bool LinkLoader::loadLinkFromHeader(const String& headerValue, const KURL& baseU
|
| }
|
| if (canLoadResources != DoNotLoadResources) {
|
| bool errorOccurred = false;
|
| - if (RuntimeEnabledFeatures::linkPreloadEnabled())
|
| - preloadIfNeeded(relAttribute, url, *document, header.as(), header.mimeType(), header.crossOrigin(), LinkCalledFromHeader, errorOccurred);
|
| + if (RuntimeEnabledFeatures::linkPreloadEnabled()) {
|
| + ViewportDescription* viewportDescription = (viewportDescriptionWrapper && viewportDescriptionWrapper->set) ? &(viewportDescriptionWrapper->description) : nullptr;
|
| + preloadIfNeeded(relAttribute, url, *document, header.as(), header.mimeType(), header.media(), header.crossOrigin(), LinkCalledFromHeader, errorOccurred, viewportDescription);
|
| + }
|
| }
|
| // TODO(yoav): Add more supported headers as needed.
|
| }
|
| return true;
|
| }
|
|
|
| -bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttributeValue crossOrigin, const String& type, const String& as, const KURL& href, Document& document, const NetworkHintsInterface& networkHintsInterface)
|
| +bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttributeValue crossOrigin, const String& type,
|
| + const String& as, const String& media, const KURL& href, Document& document, const NetworkHintsInterface& networkHintsInterface)
|
| {
|
| // TODO(yoav): Do all links need to load only after they're in document???
|
|
|
| @@ -326,7 +344,7 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, CrossOriginAttri
|
|
|
| bool errorOccurred = false;
|
| if (m_client->shouldLoadLink())
|
| - createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, document, as, type, crossOrigin, LinkCalledFromMarkup, errorOccurred));
|
| + createLinkPreloadResourceClient(preloadIfNeeded(relAttribute, href, document, as, type, media, crossOrigin, LinkCalledFromMarkup, errorOccurred, nullptr));
|
| if (errorOccurred)
|
| m_linkLoadingErrorTimer.startOneShot(0, BLINK_FROM_HERE);
|
|
|
|
|