| 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 |
| 6 * reserved. |
| 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) | 7 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) |
| 7 * Copyright (C) 2011 Google Inc. All rights reserved. | 8 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 8 * | 9 * |
| 9 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 11 * modify it under the terms of the GNU Library General Public |
| 11 * License as published by the Free Software Foundation; either | 12 * License as published by the Free Software Foundation; either |
| 12 * version 2 of the License, or (at your option) any later version. | 13 * version 2 of the License, or (at your option) any later version. |
| 13 * | 14 * |
| 14 * This library is distributed in the hope that it will be useful, | 15 * This library is distributed in the hope that it will be useful, |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 214 |
| 214 process(); | 215 process(); |
| 215 | 216 |
| 216 if (m_link) | 217 if (m_link) |
| 217 m_link->ownerInserted(); | 218 m_link->ownerInserted(); |
| 218 | 219 |
| 219 return InsertionDone; | 220 return InsertionDone; |
| 220 } | 221 } |
| 221 | 222 |
| 222 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) { | 223 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) { |
| 223 // Store the result of isConnected() here before Node::removedFrom(..) clears
the flags. | 224 // Store the result of isConnected() here before Node::removedFrom(..) clears |
| 225 // the flags. |
| 224 bool wasConnected = isConnected(); | 226 bool wasConnected = isConnected(); |
| 225 HTMLElement::removedFrom(insertionPoint); | 227 HTMLElement::removedFrom(insertionPoint); |
| 226 if (!insertionPoint->isConnected()) | 228 if (!insertionPoint->isConnected()) |
| 227 return; | 229 return; |
| 228 | 230 |
| 229 m_linkLoader->released(); | 231 m_linkLoader->released(); |
| 230 | 232 |
| 231 if (!wasConnected) { | 233 if (!wasConnected) { |
| 232 DCHECK(!linkStyle() || !linkStyle()->hasSheet()); | 234 DCHECK(!linkStyle() || !linkStyle()->hasSheet()); |
| 233 return; | 235 return; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 StyleSheetInMemoryCache, | 409 StyleSheetInMemoryCache, |
| 408 StyleSheetCacheStatusCount, | 410 StyleSheetCacheStatusCount, |
| 409 }; | 411 }; |
| 410 | 412 |
| 411 void LinkStyle::setCSSStyleSheet( | 413 void LinkStyle::setCSSStyleSheet( |
| 412 const String& href, | 414 const String& href, |
| 413 const KURL& baseURL, | 415 const KURL& baseURL, |
| 414 const String& charset, | 416 const String& charset, |
| 415 const CSSStyleSheetResource* cachedStyleSheet) { | 417 const CSSStyleSheetResource* cachedStyleSheet) { |
| 416 if (!m_owner->isConnected()) { | 418 if (!m_owner->isConnected()) { |
| 417 // While the stylesheet is asynchronously loading, the owner can be disconne
cted from a document. | 419 // While the stylesheet is asynchronously loading, the owner can be |
| 420 // disconnected from a document. |
| 418 // In that case, cancel any processing on the loaded content. | 421 // In that case, cancel any processing on the loaded content. |
| 419 m_loading = false; | 422 m_loading = false; |
| 420 removePendingSheet(); | 423 removePendingSheet(); |
| 421 if (m_sheet) | 424 if (m_sheet) |
| 422 clearSheet(); | 425 clearSheet(); |
| 423 return; | 426 return; |
| 424 } | 427 } |
| 425 | 428 |
| 426 // See the comment in PendingScript.cpp about why this check is necessary | 429 // See the comment in PendingScript.cpp about why this check is necessary |
| 427 // here, instead of in the resource fetcher. https://crbug.com/500701. | 430 // here, instead of in the resource fetcher. https://crbug.com/500701. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 564 } |
| 562 | 565 |
| 563 m_owner->document().styleEngine().removePendingSheet(*m_owner, | 566 m_owner->document().styleEngine().removePendingSheet(*m_owner, |
| 564 m_styleEngineContext); | 567 m_styleEngineContext); |
| 565 } | 568 } |
| 566 | 569 |
| 567 void LinkStyle::setDisabledState(bool disabled) { | 570 void LinkStyle::setDisabledState(bool disabled) { |
| 568 LinkStyle::DisabledState oldDisabledState = m_disabledState; | 571 LinkStyle::DisabledState oldDisabledState = m_disabledState; |
| 569 m_disabledState = disabled ? Disabled : EnabledViaScript; | 572 m_disabledState = disabled ? Disabled : EnabledViaScript; |
| 570 if (oldDisabledState != m_disabledState) { | 573 if (oldDisabledState != m_disabledState) { |
| 571 // If we change the disabled state while the sheet is still loading, then we
have to | 574 // If we change the disabled state while the sheet is still loading, then we |
| 572 // perform three checks: | 575 // have to perform three checks: |
| 573 if (styleSheetIsLoading()) { | 576 if (styleSheetIsLoading()) { |
| 574 // Check #1: The sheet becomes disabled while loading. | 577 // Check #1: The sheet becomes disabled while loading. |
| 575 if (m_disabledState == Disabled) | 578 if (m_disabledState == Disabled) |
| 576 removePendingSheet(); | 579 removePendingSheet(); |
| 577 | 580 |
| 578 // Check #2: An alternate sheet becomes enabled while it is still loading. | 581 // Check #2: An alternate sheet becomes enabled while it is still loading. |
| 579 if (m_owner->relAttribute().isAlternate() && | 582 if (m_owner->relAttribute().isAlternate() && |
| 580 m_disabledState == EnabledViaScript) | 583 m_disabledState == EnabledViaScript) |
| 581 addPendingSheet(Blocking); | 584 addPendingSheet(Blocking); |
| 582 | 585 |
| 583 // Check #3: A main sheet becomes enabled while it was still loading and | 586 // Check #3: A main sheet becomes enabled while it was still loading and |
| 584 // after it was disabled via script. It takes really terrible code to make
this | 587 // after it was disabled via script. It takes really terrible code to make |
| 585 // happen (a double toggle for no reason essentially). This happens on | 588 // this happen (a double toggle for no reason essentially). This happens |
| 586 // virtualplastic.net, which manages to do about 12 enable/disables on onl
y 3 | 589 // on virtualplastic.net, which manages to do about 12 enable/disables on |
| 587 // sheets. :) | 590 // only 3 sheets. :) |
| 588 if (!m_owner->relAttribute().isAlternate() && | 591 if (!m_owner->relAttribute().isAlternate() && |
| 589 m_disabledState == EnabledViaScript && oldDisabledState == Disabled) | 592 m_disabledState == EnabledViaScript && oldDisabledState == Disabled) |
| 590 addPendingSheet(Blocking); | 593 addPendingSheet(Blocking); |
| 591 | 594 |
| 592 // If the sheet is already loading just bail. | 595 // If the sheet is already loading just bail. |
| 593 return; | 596 return; |
| 594 } | 597 } |
| 595 | 598 |
| 596 if (m_sheet) { | 599 if (m_sheet) { |
| 597 m_sheet->setDisabled(disabled); | 600 m_sheet->setDisabled(disabled); |
| 598 return; | 601 return; |
| 599 } | 602 } |
| 600 | 603 |
| 601 if (m_disabledState == EnabledViaScript && m_owner->shouldProcessStyle()) | 604 if (m_disabledState == EnabledViaScript && m_owner->shouldProcessStyle()) |
| 602 process(); | 605 process(); |
| 603 } | 606 } |
| 604 } | 607 } |
| 605 | 608 |
| 606 void LinkStyle::setCrossOriginStylesheetStatus(CSSStyleSheet* sheet) { | 609 void LinkStyle::setCrossOriginStylesheetStatus(CSSStyleSheet* sheet) { |
| 607 if (m_fetchFollowingCORS && resource() && !resource()->errorOccurred()) { | 610 if (m_fetchFollowingCORS && resource() && !resource()->errorOccurred()) { |
| 608 // Record the security origin the CORS access check succeeded at, if cross o
rigin. | 611 // Record the security origin the CORS access check succeeded at, if cross |
| 609 // Only origins that are script accessible to it may access the stylesheet's
rules. | 612 // origin. Only origins that are script accessible to it may access the |
| 613 // stylesheet's rules. |
| 610 sheet->setAllowRuleAccessFromOrigin( | 614 sheet->setAllowRuleAccessFromOrigin( |
| 611 m_owner->document().getSecurityOrigin()); | 615 m_owner->document().getSecurityOrigin()); |
| 612 } | 616 } |
| 613 m_fetchFollowingCORS = false; | 617 m_fetchFollowingCORS = false; |
| 614 } | 618 } |
| 615 | 619 |
| 616 void LinkStyle::process() { | 620 void LinkStyle::process() { |
| 617 DCHECK(m_owner->shouldProcessStyle()); | 621 DCHECK(m_owner->shouldProcessStyle()); |
| 618 String type = m_owner->typeValue().lower(); | 622 String type = m_owner->typeValue().lower(); |
| 619 String as = m_owner->asValue().lower(); | 623 String as = m_owner->asValue().lower(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 title, StyleEngine::DontUpdateActiveSheets); | 662 title, StyleEngine::DontUpdateActiveSheets); |
| 659 | 663 |
| 660 bool mediaQueryMatches = true; | 664 bool mediaQueryMatches = true; |
| 661 LocalFrame* frame = loadingFrame(); | 665 LocalFrame* frame = loadingFrame(); |
| 662 if (!m_owner->media().isEmpty() && frame) { | 666 if (!m_owner->media().isEmpty() && frame) { |
| 663 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); | 667 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); |
| 664 MediaQueryEvaluator evaluator(frame); | 668 MediaQueryEvaluator evaluator(frame); |
| 665 mediaQueryMatches = evaluator.eval(media); | 669 mediaQueryMatches = evaluator.eval(media); |
| 666 } | 670 } |
| 667 | 671 |
| 668 // Don't hold up layout tree construction and script execution on stylesheet
s | 672 // Don't hold up layout tree construction and script execution on |
| 669 // that are not needed for the layout at the moment. | 673 // stylesheets that are not needed for the layout at the moment. |
| 670 bool blocking = mediaQueryMatches && !m_owner->isAlternate() && | 674 bool blocking = mediaQueryMatches && !m_owner->isAlternate() && |
| 671 m_owner->isCreatedByParser(); | 675 m_owner->isCreatedByParser(); |
| 672 addPendingSheet(blocking ? Blocking : NonBlocking); | 676 addPendingSheet(blocking ? Blocking : NonBlocking); |
| 673 | 677 |
| 674 // Load stylesheets that are not needed for the layout immediately with low
priority. | 678 // Load stylesheets that are not needed for the layout immediately with low |
| 675 // When the link element is created by scripts, load the stylesheets asynchr
onously but in high priority. | 679 // priority. When the link element is created by scripts, load the |
| 680 // stylesheets asynchronously but in high priority. |
| 676 bool lowPriority = !mediaQueryMatches || m_owner->isAlternate(); | 681 bool lowPriority = !mediaQueryMatches || m_owner->isAlternate(); |
| 677 FetchRequest request = builder.build(lowPriority); | 682 FetchRequest request = builder.build(lowPriority); |
| 678 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue( | 683 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue( |
| 679 m_owner->fastGetAttribute(HTMLNames::crossoriginAttr)); | 684 m_owner->fastGetAttribute(HTMLNames::crossoriginAttr)); |
| 680 if (crossOrigin != CrossOriginAttributeNotSet) { | 685 if (crossOrigin != CrossOriginAttributeNotSet) { |
| 681 request.setCrossOriginAccessControl(document().getSecurityOrigin(), | 686 request.setCrossOriginAccessControl(document().getSecurityOrigin(), |
| 682 crossOrigin); | 687 crossOrigin); |
| 683 setFetchFollowingCORS(); | 688 setFetchFollowingCORS(); |
| 684 } | 689 } |
| 685 | 690 |
| 686 String integrityAttr = m_owner->fastGetAttribute(HTMLNames::integrityAttr); | 691 String integrityAttr = m_owner->fastGetAttribute(HTMLNames::integrityAttr); |
| 687 if (!integrityAttr.isEmpty()) { | 692 if (!integrityAttr.isEmpty()) { |
| 688 IntegrityMetadataSet metadataSet; | 693 IntegrityMetadataSet metadataSet; |
| 689 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadataSet); | 694 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadataSet); |
| 690 request.setIntegrityMetadata(metadataSet); | 695 request.setIntegrityMetadata(metadataSet); |
| 691 } | 696 } |
| 692 setResource(CSSStyleSheetResource::fetch(request, document().fetcher())); | 697 setResource(CSSStyleSheetResource::fetch(request, document().fetcher())); |
| 693 | 698 |
| 694 if (m_loading && !resource()) { | 699 if (m_loading && !resource()) { |
| 695 // The request may have been denied if (for example) the stylesheet is loc
al and the document is remote, or if there was a Content Security Policy Failure
. | 700 // The request may have been denied if (for example) the stylesheet is |
| 696 // setCSSStyleSheet() can be called synchronuosly in setResource() and thu
s resource() is null and |m_loading| is false in such cases even if the request
succeeds. | 701 // local and the document is remote, or if there was a Content Security |
| 702 // Policy Failure. setCSSStyleSheet() can be called synchronuosly in |
| 703 // setResource() and thus resource() is null and |m_loading| is false in |
| 704 // such cases even if the request succeeds. |
| 697 m_loading = false; | 705 m_loading = false; |
| 698 removePendingSheet(); | 706 removePendingSheet(); |
| 699 notifyLoadedSheetAndAllCriticalSubresources( | 707 notifyLoadedSheetAndAllCriticalSubresources( |
| 700 Node::ErrorOccurredLoadingSubresource); | 708 Node::ErrorOccurredLoadingSubresource); |
| 701 } | 709 } |
| 702 } else if (m_sheet) { | 710 } else if (m_sheet) { |
| 703 // we no longer contain a stylesheet, e.g. perhaps rel or type was changed | 711 // we no longer contain a stylesheet, e.g. perhaps rel or type was changed |
| 704 StyleSheet* removedSheet = m_sheet.get(); | 712 StyleSheet* removedSheet = m_sheet.get(); |
| 705 clearSheet(); | 713 clearSheet(); |
| 706 document().styleEngine().setNeedsActiveStyleUpdate(removedSheet, | 714 document().styleEngine().setNeedsActiveStyleUpdate(removedSheet, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 734 removePendingSheet(); | 742 removePendingSheet(); |
| 735 } | 743 } |
| 736 | 744 |
| 737 DEFINE_TRACE(LinkStyle) { | 745 DEFINE_TRACE(LinkStyle) { |
| 738 visitor->trace(m_sheet); | 746 visitor->trace(m_sheet); |
| 739 LinkResource::trace(visitor); | 747 LinkResource::trace(visitor); |
| 740 ResourceOwner<StyleSheetResource>::trace(visitor); | 748 ResourceOwner<StyleSheetResource>::trace(visitor); |
| 741 } | 749 } |
| 742 | 750 |
| 743 } // namespace blink | 751 } // namespace blink |
| OLD | NEW |