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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
207 if (isInShadowTree()) { | 206 if (isConnected() && !shouldLoadLink()) { |
kochi
2016/07/26 05:35:06
Does insertionPoint->isConnected() on line 203 gua
hayato
2016/07/26 06:04:32
Good point.
I have added DCHECK()s around here.
| |
208 String message = "HTML element <link> is ignored in shadow tree."; | 207 String message = "HTML element <link> is ignored in shadow tree."; |
209 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War ningMessageLevel, message)); | 208 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, War ningMessageLevel, message)); |
210 return InsertionDone; | 209 return InsertionDone; |
211 } | 210 } |
212 | 211 |
213 document().styleEngine().addStyleSheetCandidateNode(this); | 212 document().styleEngine().addStyleSheetCandidateNode(this); |
214 | 213 |
215 process(); | 214 process(); |
216 | 215 |
217 if (m_link) | 216 if (m_link) |
218 m_link->ownerInserted(); | 217 m_link->ownerInserted(); |
219 | 218 |
220 return InsertionDone; | 219 return InsertionDone; |
221 } | 220 } |
222 | 221 |
223 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) | 222 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) |
224 { | 223 { |
225 // Store the result of isInShadowTree() here before Node::removedFrom(..) cl ears the flags. | 224 // Store the result of isConnected() here before Node::removedFrom(..) clear s the flags. |
226 bool wasInShadowTree = isInShadowTree(); | 225 bool wasConnected = isConnected(); |
227 HTMLElement::removedFrom(insertionPoint); | 226 HTMLElement::removedFrom(insertionPoint); |
228 if (!insertionPoint->isConnected()) | 227 if (!insertionPoint->isConnected()) |
229 return; | 228 return; |
230 | 229 |
231 m_linkLoader->released(); | 230 m_linkLoader->released(); |
232 | 231 |
233 if (wasInShadowTree) { | 232 if (!wasConnected) { |
234 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); | 233 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
235 return; | 234 return; |
236 } | 235 } |
237 document().styleEngine().removeStyleSheetCandidateNode(this); | 236 document().styleEngine().removeStyleSheetCandidateNode(this); |
238 | 237 |
239 StyleSheet* removedSheet = sheet(); | 238 StyleSheet* removedSheet = sheet(); |
240 | 239 |
241 if (m_link) | 240 if (m_link) |
242 m_link->ownerRemoved(); | 241 m_link->ownerRemoved(); |
243 | 242 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 | 432 |
434 enum StyleSheetCacheStatus { | 433 enum StyleSheetCacheStatus { |
435 StyleSheetNewEntry, | 434 StyleSheetNewEntry, |
436 StyleSheetInDiskCache, | 435 StyleSheetInDiskCache, |
437 StyleSheetInMemoryCache, | 436 StyleSheetInMemoryCache, |
438 StyleSheetCacheStatusCount, | 437 StyleSheetCacheStatusCount, |
439 }; | 438 }; |
440 | 439 |
441 void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CSSStyleSheetResource* cachedStyleSheet) | 440 void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CSSStyleSheetResource* cachedStyleSheet) |
442 { | 441 { |
443 if (!m_owner->isInDocumentTree()) { | 442 if (!m_owner->isConnected()) { |
444 // While the stylesheet is asynchronously loading, the owner can be move d out of a document tree. | 443 // 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. | 444 // In that case, cancel any processing on the loaded content. |
446 m_loading = false; | 445 m_loading = false; |
447 removePendingSheet(); | 446 removePendingSheet(); |
448 if (m_sheet) | 447 if (m_sheet) |
449 clearSheet(); | 448 clearSheet(); |
450 return; | 449 return; |
451 } | 450 } |
452 | 451 |
453 // See the comment in PendingScript.cpp about why this check is necessary | 452 // See the comment in PendingScript.cpp about why this check is necessary |
454 // here, instead of in the resource fetcher. https://crbug.com/500701. | 453 // here, instead of in the resource fetcher. https://crbug.com/500701. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 return; | 655 return; |
657 | 656 |
658 m_loading = true; | 657 m_loading = true; |
659 | 658 |
660 String title = m_owner->title(); | 659 String title = m_owner->title(); |
661 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En abledViaScript) | 660 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En abledViaScript) |
662 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title ); | 661 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title ); |
663 | 662 |
664 bool mediaQueryMatches = true; | 663 bool mediaQueryMatches = true; |
665 LocalFrame* frame = loadingFrame(); | 664 LocalFrame* frame = loadingFrame(); |
666 if (!m_owner->media().isEmpty() && frame && frame->document()) { | 665 // MediaQuery is valid only in a document tree. |
kochi
2016/07/26 05:35:06
Is this a TODO, or defined in any spec?
hayato
2016/07/26 06:04:32
Ops. That was my misunderstanding. I though this a
| |
666 if (m_owner->isInDocumentTree() && !m_owner->media().isEmpty() && frame && frame->document()) { | |
667 RefPtr<ComputedStyle> documentStyle = StyleResolver::styleForDocumen t(*frame->document()); | 667 RefPtr<ComputedStyle> documentStyle = StyleResolver::styleForDocumen t(*frame->document()); |
668 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); | 668 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); |
669 MediaQueryEvaluator evaluator(frame); | 669 MediaQueryEvaluator evaluator(frame); |
670 mediaQueryMatches = evaluator.eval(media); | 670 mediaQueryMatches = evaluator.eval(media); |
671 } | 671 } |
672 | 672 |
673 // Don't hold up layout tree construction and script execution on styles heets | 673 // Don't hold up layout tree construction and script execution on styles heets |
674 // that are not needed for the layout at the moment. | 674 // that are not needed for the layout at the moment. |
675 bool blocking = mediaQueryMatches && !m_owner->isAlternate() && m_owner- >isCreatedByParser(); | 675 bool blocking = mediaQueryMatches && !m_owner->isAlternate() && m_owner- >isCreatedByParser(); |
676 addPendingSheet(blocking ? Blocking : NonBlocking); | 676 addPendingSheet(blocking ? Blocking : NonBlocking); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 } | 724 } |
725 | 725 |
726 DEFINE_TRACE(LinkStyle) | 726 DEFINE_TRACE(LinkStyle) |
727 { | 727 { |
728 visitor->trace(m_sheet); | 728 visitor->trace(m_sheet); |
729 LinkResource::trace(visitor); | 729 LinkResource::trace(visitor); |
730 ResourceOwner<StyleSheetResource>::trace(visitor); | 730 ResourceOwner<StyleSheetResource>::trace(visitor); |
731 } | 731 } |
732 | 732 |
733 } // namespace blink | 733 } // namespace blink |
OLD | NEW |