Chromium Code Reviews| 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 return adoptPtrWillBeNoop(new LinkStyle(owner)); | 482 return adoptPtrWillBeNoop(new LinkStyle(owner)); |
| 483 } | 483 } |
| 484 | 484 |
| 485 LinkStyle::LinkStyle(HTMLLinkElement* owner) | 485 LinkStyle::LinkStyle(HTMLLinkElement* owner) |
| 486 : LinkResource(owner) | 486 : LinkResource(owner) |
| 487 , m_disabledState(Unset) | 487 , m_disabledState(Unset) |
| 488 , m_pendingSheetType(None) | 488 , m_pendingSheetType(None) |
| 489 , m_loading(false) | 489 , m_loading(false) |
| 490 , m_firedLoad(false) | 490 , m_firedLoad(false) |
| 491 , m_loadedSheet(false) | 491 , m_loadedSheet(false) |
| 492 , m_fetchFollowingCORS(false) | |
| 492 { | 493 { |
| 493 } | 494 } |
| 494 | 495 |
| 495 LinkStyle::~LinkStyle() | 496 LinkStyle::~LinkStyle() |
| 496 { | 497 { |
| 497 #if !ENABLE(OILPAN) | 498 #if !ENABLE(OILPAN) |
| 498 if (m_sheet) | 499 if (m_sheet) |
| 499 m_sheet->clearOwnerNode(); | 500 m_sheet->clearOwnerNode(); |
| 500 #endif | 501 #endif |
| 501 } | 502 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 526 | 527 |
| 527 if (RefPtrWillBeRawPtr<StyleSheetContents> restoredSheet = const_cast<CSSSty leSheetResource*>(cachedStyleSheet)->restoreParsedStyleSheet(parserContext)) { | 528 if (RefPtrWillBeRawPtr<StyleSheetContents> restoredSheet = const_cast<CSSSty leSheetResource*>(cachedStyleSheet)->restoreParsedStyleSheet(parserContext)) { |
| 528 ASSERT(restoredSheet->isCacheable()); | 529 ASSERT(restoredSheet->isCacheable()); |
| 529 ASSERT(!restoredSheet->isLoading()); | 530 ASSERT(!restoredSheet->isLoading()); |
| 530 | 531 |
| 531 if (m_sheet) | 532 if (m_sheet) |
| 532 clearSheet(); | 533 clearSheet(); |
| 533 m_sheet = CSSStyleSheet::create(restoredSheet, m_owner); | 534 m_sheet = CSSStyleSheet::create(restoredSheet, m_owner); |
| 534 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); | 535 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); |
| 535 m_sheet->setTitle(m_owner->title()); | 536 m_sheet->setTitle(m_owner->title()); |
| 537 setCrossOriginStylesheetStatus(baseURL, m_sheet.get()); | |
| 536 | 538 |
| 537 m_loading = false; | 539 m_loading = false; |
| 538 restoredSheet->checkLoaded(); | 540 restoredSheet->checkLoaded(); |
| 539 return; | 541 return; |
| 540 } | 542 } |
| 541 | 543 |
| 542 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea te(href, parserContext); | 544 RefPtrWillBeRawPtr<StyleSheetContents> styleSheet = StyleSheetContents::crea te(href, parserContext); |
| 543 | 545 |
| 544 if (m_sheet) | 546 if (m_sheet) |
| 545 clearSheet(); | 547 clearSheet(); |
| 546 | 548 |
| 547 m_sheet = CSSStyleSheet::create(styleSheet, m_owner); | 549 m_sheet = CSSStyleSheet::create(styleSheet, m_owner); |
| 548 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); | 550 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); |
| 549 m_sheet->setTitle(m_owner->title()); | 551 m_sheet->setTitle(m_owner->title()); |
| 552 setCrossOriginStylesheetStatus(baseURL, m_sheet.get()); | |
| 550 | 553 |
| 551 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); | 554 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); |
| 552 | 555 |
| 553 m_loading = false; | 556 m_loading = false; |
| 554 styleSheet->notifyLoadedSheet(cachedStyleSheet); | 557 styleSheet->notifyLoadedSheet(cachedStyleSheet); |
| 555 styleSheet->checkLoaded(); | 558 styleSheet->checkLoaded(); |
| 556 | 559 |
| 557 if (styleSheet->isCacheable()) | 560 if (styleSheet->isCacheable()) |
| 558 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); | 561 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); |
| 559 } | 562 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 if (!m_sheet && m_disabledState == EnabledViaScript) { | 669 if (!m_sheet && m_disabledState == EnabledViaScript) { |
| 667 if (m_owner->shouldProcessStyle()) | 670 if (m_owner->shouldProcessStyle()) |
| 668 process(); | 671 process(); |
| 669 } else { | 672 } else { |
| 670 // FIXME: We don't have enough knowledge here to know if we should c all addedStyleSheet() or removedStyleSheet(). | 673 // FIXME: We don't have enough knowledge here to know if we should c all addedStyleSheet() or removedStyleSheet(). |
| 671 m_owner->document().styleResolverChanged(); | 674 m_owner->document().styleResolverChanged(); |
| 672 } | 675 } |
| 673 } | 676 } |
| 674 } | 677 } |
| 675 | 678 |
| 679 void LinkStyle::setCrossOriginStylesheetStatus(const KURL& baseURL, CSSStyleShee t* sheet) | |
| 680 { | |
| 681 if (m_fetchFollowingCORS && resource() && !resource()->errorOccurred()) { | |
| 682 // Record the security origin the CORS access check succeeded at, if cro ss origin. | |
| 683 // Only origins that are script accessible to it may access the styleshe et's rules. | |
| 684 if (!m_owner->document().securityOrigin()->canRequest(baseURL)) | |
|
Mike West
2015/03/17 20:05:46
I'm not sure it's useful to check canRequest here,
sof
2015/03/17 21:52:15
Yes, it serves no purpose to do this check here (n
| |
| 685 sheet->setAllowRuleAccessFromOrigin(m_owner->document().securityOrig in()); | |
| 686 } | |
| 687 m_fetchFollowingCORS = false; | |
| 688 } | |
| 689 | |
| 676 void LinkStyle::process() | 690 void LinkStyle::process() |
| 677 { | 691 { |
| 678 ASSERT(m_owner->shouldProcessStyle()); | 692 ASSERT(m_owner->shouldProcessStyle()); |
| 679 String type = m_owner->typeValue().lower(); | 693 String type = m_owner->typeValue().lower(); |
| 680 LinkRequestBuilder builder(m_owner); | 694 LinkRequestBuilder builder(m_owner); |
| 681 | 695 |
| 682 if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isVal id() && !builder.url().isEmpty()) { | 696 if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isVal id() && !builder.url().isEmpty()) { |
| 683 if (!m_owner->shouldLoadLink()) | 697 if (!m_owner->shouldLoadLink()) |
| 684 return; | 698 return; |
| 685 if (!document().securityOrigin()->canDisplay(builder.url())) | 699 if (!document().securityOrigin()->canDisplay(builder.url())) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 716 } | 730 } |
| 717 | 731 |
| 718 // Don't hold up render tree construction and script execution on styles heets | 732 // Don't hold up render tree construction and script execution on styles heets |
| 719 // that are not needed for the rendering at the moment. | 733 // that are not needed for the rendering at the moment. |
| 720 bool blocking = mediaQueryMatches && !m_owner->isAlternate(); | 734 bool blocking = mediaQueryMatches && !m_owner->isAlternate(); |
| 721 addPendingSheet(blocking ? Blocking : NonBlocking); | 735 addPendingSheet(blocking ? Blocking : NonBlocking); |
| 722 | 736 |
| 723 // Load stylesheets that are not needed for the rendering immediately wi th low priority. | 737 // Load stylesheets that are not needed for the rendering immediately wi th low priority. |
| 724 FetchRequest request = builder.build(blocking); | 738 FetchRequest request = builder.build(blocking); |
| 725 AtomicString crossOriginMode = m_owner->fastGetAttribute(HTMLNames::cros soriginAttr); | 739 AtomicString crossOriginMode = m_owner->fastGetAttribute(HTMLNames::cros soriginAttr); |
| 726 if (!crossOriginMode.isNull()) | 740 if (!crossOriginMode.isNull()) { |
| 727 request.setCrossOriginAccessControl(document().securityOrigin(), cro ssOriginMode); | 741 request.setCrossOriginAccessControl(document().securityOrigin(), cro ssOriginMode); |
| 742 setFetchFollowingCORS(); | |
| 743 } | |
| 728 setResource(document().fetcher()->fetchCSSStyleSheet(request)); | 744 setResource(document().fetcher()->fetchCSSStyleSheet(request)); |
| 729 | 745 |
| 730 if (!resource()) { | 746 if (!resource()) { |
| 731 // The request may have been denied if (for example) the stylesheet is local and the document is remote. | 747 // The request may have been denied if (for example) the stylesheet is local and the document is remote. |
| 732 m_loading = false; | 748 m_loading = false; |
| 733 removePendingSheet(); | 749 removePendingSheet(); |
| 734 } | 750 } |
| 735 } else if (m_sheet) { | 751 } else if (m_sheet) { |
| 736 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed | 752 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed |
| 737 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get(); | 753 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 755 removePendingSheet(); | 771 removePendingSheet(); |
| 756 } | 772 } |
| 757 | 773 |
| 758 DEFINE_TRACE(LinkStyle) | 774 DEFINE_TRACE(LinkStyle) |
| 759 { | 775 { |
| 760 visitor->trace(m_sheet); | 776 visitor->trace(m_sheet); |
| 761 LinkResource::trace(visitor); | 777 LinkResource::trace(visitor); |
| 762 } | 778 } |
| 763 | 779 |
| 764 } // namespace blink | 780 } // namespace blink |
| OLD | NEW |