Index: Source/core/html/HTMLLinkElement.cpp |
diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp |
index 3f0ee3011bec9228bff6af757356f62347576c65..1b00709f0fd1caab149b2bd5ad65ec1e85007497 100644 |
--- a/Source/core/html/HTMLLinkElement.cpp |
+++ b/Source/core/html/HTMLLinkElement.cpp |
@@ -34,9 +34,11 @@ |
#include "core/css/resolver/StyleResolver.h" |
#include "core/dom/Attribute.h" |
#include "core/dom/Document.h" |
+#include "core/dom/DocumentFragment.h" |
#include "core/dom/DocumentStyleSheetCollection.h" |
#include "core/dom/Event.h" |
#include "core/dom/EventSender.h" |
+#include "core/html/HTMLImportsController.h" |
#include "core/loader/FrameLoader.h" |
#include "core/loader/cache/CachedCSSStyleSheet.h" |
#include "core/loader/cache/CachedResourceLoader.h" |
@@ -135,7 +137,7 @@ bool HTMLLinkElement::shouldLoadLink() |
return continueLoad; |
} |
-LinkStyle* HTMLLinkElement::linkStyleToProcess() |
+LinkResource* HTMLLinkElement::linkResourceToProcess() |
{ |
bool visible = inDocument() && !m_isInShadowTree; |
if (!visible) { |
@@ -144,17 +146,43 @@ LinkStyle* HTMLLinkElement::linkStyleToProcess() |
} |
if (!m_link) { |
- m_link = adoptPtr(new LinkStyle(this)); |
- if (fastHasAttribute(disabledAttr)) |
- m_link->setDisabledState(true); |
+ if (m_relAttribute.isImport() && RuntimeEnabledFeatures::htmlImportsEnabled()) |
+ m_link = LinkImport::create(this); |
+ else { |
+ RefPtr<LinkStyle> link = LinkStyle::create(this); |
+ if (fastHasAttribute(disabledAttr)) |
+ link->setDisabledState(true); |
+ m_link = link.release(); |
+ } |
} |
return m_link.get(); |
} |
+LinkStyle* HTMLLinkElement::linkStyle() const |
+{ |
+ if (!m_link || m_link->type() != LinkResource::Style) |
+ return 0; |
+ return static_cast<LinkStyle*>(m_link.get()); |
+} |
+ |
+LinkImport* HTMLLinkElement::linkImport() const |
+{ |
+ if (!m_link || m_link->type() != LinkResource::Import) |
+ return 0; |
+ return static_cast<LinkImport*>(m_link.get()); |
+} |
+ |
+DocumentFragment* HTMLLinkElement::import() const |
+{ |
+ if (LinkImport* link = linkImport()) |
+ return linkImport()->importedFragment(); |
+ return 0; |
+} |
+ |
void HTMLLinkElement::process() |
{ |
- if (LinkStyle* link = linkStyleToProcess()) |
+ if (LinkResource* link = linkResourceToProcess()) |
link->process(); |
} |
@@ -188,8 +216,8 @@ void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) |
} |
document()->styleSheetCollection()->removeStyleSheetCandidateNode(this); |
- if (LinkStyle* link = linkStyle()) |
- link->ownerRemoved(); |
+ if (m_link) |
+ m_link->ownerRemoved(); |
if (document()->renderer()) |
document()->styleResolverChanged(DeferRecalcStyle); |
@@ -334,8 +362,13 @@ void HTMLLinkElement::setSizes(const String& value) |
} |
+PassRefPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
+{ |
+ return adoptRef(new LinkStyle(owner)); |
+} |
+ |
LinkStyle::LinkStyle(HTMLLinkElement* owner) |
- : m_owner(owner) |
+ : LinkResource(owner) |
, m_disabledState(Unset) |
, m_pendingSheetType(None) |
, m_loading(false) |
@@ -511,24 +544,20 @@ void LinkStyle::process() |
{ |
ASSERT(m_owner->shouldProcessStyle()); |
String type = m_owner->typeValue().lower(); |
- KURL url = m_owner->getNonEmptyURLAttribute(hrefAttr); |
+ LinkRequestBuilder builder(m_owner); |
- if (m_owner->relAttribute().iconType() != InvalidIcon && url.isValid() && !url.isEmpty()) { |
+ if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isValid() && !builder.url().isEmpty()) { |
if (!m_owner->shouldLoadLink()) |
return; |
if (document()->frame()) |
document()->frame()->loader()->didChangeIcons(m_owner->relAttribute().iconType()); |
} |
- if (!m_owner->loadLink(type, url)) |
+ if (!m_owner->loadLink(type, builder.url())) |
return; |
if ((m_disabledState != Disabled) && m_owner->relAttribute().isStyleSheet() |
- && document()->frame() && url.isValid()) { |
- |
- String charset = m_owner->getAttribute(charsetAttr); |
- if (charset.isEmpty() && document()->frame()) |
- charset = document()->charset(); |
+ && document()->frame() && builder.url().isValid()) { |
if (m_cachedSheet) { |
removePendingSheet(); |
@@ -555,8 +584,7 @@ void LinkStyle::process() |
addPendingSheet(blocking ? Blocking : NonBlocking); |
// Load stylesheets that are not needed for the rendering immediately with low priority. |
- ResourceLoadPriority priority = blocking ? ResourceLoadPriorityUnresolved : ResourceLoadPriorityVeryLow; |
- CachedResourceRequest request(ResourceRequest(document()->completeURL(url)), m_owner->localName(), charset, priority); |
+ CachedResourceRequest request = builder.build(blocking); |
m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet(request); |
if (m_cachedSheet) |