This source file includes following definitions.
- prerenderRelTypesFromRelAttribute
- m_linkLoadingErrorTimer
- linkLoadTimerFired
- linkLoadingErrorTimerFired
- notifyFinished
- didStartPrerender
- didStopPrerender
- didSendLoadForPrerender
- didSendDOMContentLoadedForPrerender
- loadLink
- released
#include "config.h"
#include "core/loader/LinkLoader.h"
#include "FetchInitiatorTypeNames.h"
#include "core/dom/Document.h"
#include "core/fetch/FetchRequest.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/frame/Settings.h"
#include "core/html/LinkRelAttribute.h"
#include "core/loader/PrerenderHandle.h"
#include "platform/Prerender.h"
#include "platform/network/DNS.h"
namespace WebCore {
static unsigned prerenderRelTypesFromRelAttribute(const LinkRelAttribute& relAttribute)
{
unsigned result = 0;
if (relAttribute.isLinkPrerender())
result |= PrerenderRelTypePrerender;
if (relAttribute.isLinkNext())
result |= PrerenderRelTypeNext;
return result;
}
LinkLoader::LinkLoader(LinkLoaderClient* client)
: m_client(client)
, m_linkLoadTimer(this, &LinkLoader::linkLoadTimerFired)
, m_linkLoadingErrorTimer(this, &LinkLoader::linkLoadingErrorTimerFired)
{
}
LinkLoader::~LinkLoader()
{
}
void LinkLoader::linkLoadTimerFired(Timer<LinkLoader>* timer)
{
ASSERT_UNUSED(timer, timer == &m_linkLoadTimer);
m_client->linkLoaded();
}
void LinkLoader::linkLoadingErrorTimerFired(Timer<LinkLoader>* timer)
{
ASSERT_UNUSED(timer, timer == &m_linkLoadingErrorTimer);
m_client->linkLoadingErrored();
}
void LinkLoader::notifyFinished(Resource* resource)
{
ASSERT(this->resource() == resource);
if (resource->errorOccurred())
m_linkLoadingErrorTimer.startOneShot(0, FROM_HERE);
else
m_linkLoadTimer.startOneShot(0, FROM_HERE);
clearResource();
}
void LinkLoader::didStartPrerender()
{
m_client->didStartLinkPrerender();
}
void LinkLoader::didStopPrerender()
{
m_client->didStopLinkPrerender();
}
void LinkLoader::didSendLoadForPrerender()
{
m_client->didSendLoadForLinkPrerender();
}
void LinkLoader::didSendDOMContentLoadedForPrerender()
{
m_client->didSendDOMContentLoadedForLinkPrerender();
}
bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const AtomicString& crossOriginMode, const String& type, const KURL& href, Document& document)
{
if (relAttribute.isDNSPrefetch()) {
Settings* settings = document.settings();
if (settings && settings->dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty())
prefetchDNS(href.host());
}
if ((relAttribute.isLinkPrefetch() || relAttribute.isLinkSubresource()) && href.isValid() && document.frame()) {
if (!m_client->shouldLoadLink())
return false;
Resource::Type type = relAttribute.isLinkSubresource() ? Resource::LinkSubresource : Resource::LinkPrefetch;
FetchRequest linkRequest(ResourceRequest(document.completeURL(href)), FetchInitiatorTypeNames::link);
if (!crossOriginMode.isNull())
linkRequest.setCrossOriginAccessControl(document.securityOrigin(), crossOriginMode);
setResource(document.fetcher()->fetchLinkResource(type, linkRequest));
}
if (const unsigned prerenderRelTypes = prerenderRelTypesFromRelAttribute(relAttribute)) {
if (!m_prerender) {
m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes);
} else if (m_prerender->url() != href) {
m_prerender->cancel();
m_prerender = PrerenderHandle::create(document, this, href, prerenderRelTypes);
}
} else if (m_prerender) {
m_prerender->cancel();
m_prerender.clear();
}
return true;
}
void LinkLoader::released()
{
if (m_prerender) {
m_prerender->cancel();
m_prerender.clear();
}
}
}