1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23#ifndef HTMLLinkElement_h 24#define HTMLLinkElement_h 25 26#include "CSSStyleSheet.h" 27#include "CachedResourceClient.h" 28#include "CachedResourceHandle.h" 29#include "HTMLElement.h" 30#include "Timer.h" 31 32namespace WebCore { 33 34class CachedCSSStyleSheet; 35class CachedResource; 36class KURL; 37 38class HTMLLinkElement : public HTMLElement, public CachedResourceClient { 39public: 40 struct RelAttribute { 41 bool m_isStyleSheet; 42 bool m_isIcon; 43 bool m_isAlternate; 44 bool m_isDNSPrefetch; 45#ifdef ANDROID_APPLE_TOUCH_ICON 46 bool m_isTouchIcon; 47 bool m_isPrecomposedTouchIcon; 48#endif 49#if ENABLE(LINK_PREFETCH) 50 bool m_isLinkPrefetch; 51 bool m_isLinkSubresource; 52#endif 53 54 RelAttribute() 55 : m_isStyleSheet(false) 56 , m_isIcon(false) 57 , m_isAlternate(false) 58 , m_isDNSPrefetch(false) 59#if ENABLE(LINK_PREFETCH) 60 , m_isLinkPrefetch(false) 61 , m_isLinkSubresource(false) 62#endif 63 { 64 } 65 }; 66 67 static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, bool createdByParser); 68 virtual ~HTMLLinkElement(); 69 70 KURL href() const; 71 String rel() const; 72 73 virtual String target() const; 74 75 String type() const; 76 77 StyleSheet* sheet() const; 78 79 bool isLoading() const; 80 81 bool isDisabled() const { return m_disabledState == Disabled; } 82 bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript; } 83 bool isIcon() const { return m_relAttribute.m_isIcon; } 84 85private: 86 virtual void parseMappedAttribute(Attribute*); 87 88#if ENABLE(LINK_PREFETCH) 89 void onloadTimerFired(Timer<HTMLLinkElement>*); 90#endif 91 bool checkBeforeLoadEvent(); 92 void process(); 93 static void processCallback(Node*); 94 95 virtual void insertedIntoDocument(); 96 virtual void removedFromDocument(); 97 98 // from CachedResourceClient 99 virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet); 100#if ENABLE(LINK_PREFETCH) 101 virtual void notifyFinished(CachedResource*); 102#endif 103 virtual bool sheetLoaded(); 104 105 bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; } 106 107 void setDisabledState(bool _disabled); 108 109 virtual bool isURLAttribute(Attribute*) const; 110 111public: 112 static void tokenizeRelAttribute(const AtomicString& value, RelAttribute&); 113 114private: 115 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 116 117 virtual void finishParsingChildren(); 118 119 enum PendingSheetType { None, NonBlocking, Blocking }; 120 void addPendingSheet(PendingSheetType); 121 void removePendingSheet(); 122 123private: 124 HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); 125 126 enum DisabledState { 127 Unset, 128 EnabledViaScript, 129 Disabled 130 }; 131 132 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; 133 RefPtr<CSSStyleSheet> m_sheet; 134#if ENABLE(LINK_PREFETCH) 135 CachedResourceHandle<CachedResource> m_cachedLinkResource; 136 Timer<HTMLLinkElement> m_onloadTimer; 137#endif 138 KURL m_url; 139 String m_type; 140 String m_media; 141 DisabledState m_disabledState; 142 RelAttribute m_relAttribute; 143 bool m_loading; 144 bool m_createdByParser; 145 bool m_isInShadowTree; 146 147 PendingSheetType m_pendingSheetType; 148}; 149 150} //namespace 151 152#endif 153