| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. |
| 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) | 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) |
| 7 * Copyright (C) 2011 Google Inc. All rights reserved. | 7 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 if (LinkStyle* link = linkStyle()) | 126 if (LinkStyle* link = linkStyle()) |
| 127 link->setSheetTitle(value); | 127 link->setSheetTitle(value); |
| 128 } | 128 } |
| 129 | 129 |
| 130 HTMLElement::parseAttribute(name, oldValue, value); | 130 HTMLElement::parseAttribute(name, oldValue, value); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool HTMLLinkElement::shouldLoadLink() | 134 bool HTMLLinkElement::shouldLoadLink() |
| 135 { | 135 { |
| 136 return isConnected(); | 136 return isInDocumentTree() || (isConnected() && m_relAttribute.isStyleSheet()
); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool HTMLLinkElement::loadLink(const String& type, const String& as, const Strin
g& media, const KURL& url) | 139 bool HTMLLinkElement::loadLink(const String& type, const String& as, const Strin
g& media, const KURL& url) |
| 140 { | 140 { |
| 141 return m_linkLoader->loadLink(m_relAttribute, crossOriginAttributeValue(fast
GetAttribute(HTMLNames::crossoriginAttr)), type, as, media, url, document(), Net
workHintsInterfaceImpl()); | 141 return m_linkLoader->loadLink(m_relAttribute, crossOriginAttributeValue(fast
GetAttribute(HTMLNames::crossoriginAttr)), type, as, media, url, document(), Net
workHintsInterfaceImpl()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 LinkResource* HTMLLinkElement::linkResourceToProcess() | 144 LinkResource* HTMLLinkElement::linkResourceToProcess() |
| 145 { | 145 { |
| 146 bool visible = isConnected() && !isInShadowTree(); | 146 if (!shouldLoadLink()) { |
| 147 if (!visible) { | |
| 148 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); | 147 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
| 149 return nullptr; | 148 return nullptr; |
| 150 } | 149 } |
| 151 | 150 |
| 152 if (!m_link) { | 151 if (!m_link) { |
| 153 if (m_relAttribute.isImport()) { | 152 if (m_relAttribute.isImport()) { |
| 154 m_link = LinkImport::create(this); | 153 m_link = LinkImport::create(this); |
| 155 } else if (m_relAttribute.isManifest()) { | 154 } else if (m_relAttribute.isManifest()) { |
| 156 m_link = LinkManifest::create(this); | 155 m_link = LinkManifest::create(this); |
| 157 } else if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() && m_relAt
tribute.isServiceWorker()) { | 156 } else if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() && m_relAt
tribute.isServiceWorker()) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (LinkResource* link = linkResourceToProcess()) | 195 if (LinkResource* link = linkResourceToProcess()) |
| 197 link->process(); | 196 link->process(); |
| 198 } | 197 } |
| 199 | 198 |
| 200 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) | 199 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) |
| 201 { | 200 { |
| 202 HTMLElement::insertedInto(insertionPoint); | 201 HTMLElement::insertedInto(insertionPoint); |
| 203 logAddElementIfIsolatedWorldAndInDocument("link", relAttr, hrefAttr); | 202 logAddElementIfIsolatedWorldAndInDocument("link", relAttr, hrefAttr); |
| 204 if (!insertionPoint->isConnected()) | 203 if (!insertionPoint->isConnected()) |
| 205 return InsertionDone; | 204 return InsertionDone; |
| 206 | 205 DCHECK(isConnected()); |
| 207 if (isInShadowTree()) { | 206 if (!shouldLoadLink()) { |
| 207 DCHECK(isInShadowTree()); |
| 208 String message = "HTML element <link> is ignored in shadow tree."; | 208 String message = "HTML element <link> is ignored in shadow tree."; |
| 209 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War
ningMessageLevel, message)); | 209 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War
ningMessageLevel, message)); |
| 210 return InsertionDone; | 210 return InsertionDone; |
| 211 } | 211 } |
| 212 | 212 |
| 213 document().styleEngine().addStyleSheetCandidateNode(this); | 213 document().styleEngine().addStyleSheetCandidateNode(this); |
| 214 | 214 |
| 215 process(); | 215 process(); |
| 216 | 216 |
| 217 if (m_link) | 217 if (m_link) |
| 218 m_link->ownerInserted(); | 218 m_link->ownerInserted(); |
| 219 | 219 |
| 220 return InsertionDone; | 220 return InsertionDone; |
| 221 } | 221 } |
| 222 | 222 |
| 223 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) | 223 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) |
| 224 { | 224 { |
| 225 // Store the result of isInShadowTree() here before Node::removedFrom(..) cl
ears the flags. | 225 // Store the result of isConnected() here before Node::removedFrom(..) clear
s the flags. |
| 226 bool wasInShadowTree = isInShadowTree(); | 226 bool wasConnected = isConnected(); |
| 227 HTMLElement::removedFrom(insertionPoint); | 227 HTMLElement::removedFrom(insertionPoint); |
| 228 if (!insertionPoint->isConnected()) | 228 if (!insertionPoint->isConnected()) |
| 229 return; | 229 return; |
| 230 | 230 |
| 231 m_linkLoader->released(); | 231 m_linkLoader->released(); |
| 232 | 232 |
| 233 if (wasInShadowTree) { | 233 if (!wasConnected) { |
| 234 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); | 234 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
| 235 return; | 235 return; |
| 236 } | 236 } |
| 237 document().styleEngine().removeStyleSheetCandidateNode(this); | 237 document().styleEngine().removeStyleSheetCandidateNode(this); |
| 238 | 238 |
| 239 StyleSheet* removedSheet = sheet(); | 239 StyleSheet* removedSheet = sheet(); |
| 240 | 240 |
| 241 if (m_link) | 241 if (m_link) |
| 242 m_link->ownerRemoved(); | 242 m_link->ownerRemoved(); |
| 243 | 243 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 enum StyleSheetCacheStatus { | 434 enum StyleSheetCacheStatus { |
| 435 StyleSheetNewEntry, | 435 StyleSheetNewEntry, |
| 436 StyleSheetInDiskCache, | 436 StyleSheetInDiskCache, |
| 437 StyleSheetInMemoryCache, | 437 StyleSheetInMemoryCache, |
| 438 StyleSheetCacheStatusCount, | 438 StyleSheetCacheStatusCount, |
| 439 }; | 439 }; |
| 440 | 440 |
| 441 void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const
String& charset, const CSSStyleSheetResource* cachedStyleSheet) | 441 void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const
String& charset, const CSSStyleSheetResource* cachedStyleSheet) |
| 442 { | 442 { |
| 443 if (!m_owner->isInDocumentTree()) { | 443 if (!m_owner->isConnected()) { |
| 444 // While the stylesheet is asynchronously loading, the owner can be move
d out of a document tree. | 444 // While the stylesheet is asynchronously loading, the owner can be disc
onnected from a document. |
| 445 // In that case, cancel any processing on the loaded content. | 445 // In that case, cancel any processing on the loaded content. |
| 446 m_loading = false; | 446 m_loading = false; |
| 447 removePendingSheet(); | 447 removePendingSheet(); |
| 448 if (m_sheet) | 448 if (m_sheet) |
| 449 clearSheet(); | 449 clearSheet(); |
| 450 return; | 450 return; |
| 451 } | 451 } |
| 452 | 452 |
| 453 // See the comment in PendingScript.cpp about why this check is necessary | 453 // See the comment in PendingScript.cpp about why this check is necessary |
| 454 // here, instead of in the resource fetcher. https://crbug.com/500701. | 454 // here, instead of in the resource fetcher. https://crbug.com/500701. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 clearResource(); | 651 clearResource(); |
| 652 clearFetchFollowingCORS(); | 652 clearFetchFollowingCORS(); |
| 653 } | 653 } |
| 654 | 654 |
| 655 if (!m_owner->shouldLoadLink()) | 655 if (!m_owner->shouldLoadLink()) |
| 656 return; | 656 return; |
| 657 | 657 |
| 658 m_loading = true; | 658 m_loading = true; |
| 659 | 659 |
| 660 String title = m_owner->title(); | 660 String title = m_owner->title(); |
| 661 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En
abledViaScript) | 661 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En
abledViaScript && m_owner->isInDocumentTree()) |
| 662 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title
); | 662 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title
); |
| 663 | 663 |
| 664 bool mediaQueryMatches = true; | 664 bool mediaQueryMatches = true; |
| 665 LocalFrame* frame = loadingFrame(); | 665 LocalFrame* frame = loadingFrame(); |
| 666 if (!m_owner->media().isEmpty() && frame) { | 666 if (!m_owner->media().isEmpty() && frame) { |
| 667 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); | 667 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); |
| 668 MediaQueryEvaluator evaluator(frame); | 668 MediaQueryEvaluator evaluator(frame); |
| 669 mediaQueryMatches = evaluator.eval(media); | 669 mediaQueryMatches = evaluator.eval(media); |
| 670 } | 670 } |
| 671 | 671 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 } | 723 } |
| 724 | 724 |
| 725 DEFINE_TRACE(LinkStyle) | 725 DEFINE_TRACE(LinkStyle) |
| 726 { | 726 { |
| 727 visitor->trace(m_sheet); | 727 visitor->trace(m_sheet); |
| 728 LinkResource::trace(visitor); | 728 LinkResource::trace(visitor); |
| 729 ResourceOwner<StyleSheetResource>::trace(visitor); | 729 ResourceOwner<StyleSheetResource>::trace(visitor); |
| 730 } | 730 } |
| 731 | 731 |
| 732 } // namespace blink | 732 } // namespace blink |
| OLD | NEW |