Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: Source/core/html/HTMLLinkElement.cpp

Issue 1011103002: Allow cross-origin cssRules access to CORS-fetched stylesheet. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: compile fix.. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(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(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
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(CSSStyleSheet* 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 sheet->setAllowRuleAccessFromOrigin(m_owner->document().securityOrigin() );
685 }
686 m_fetchFollowingCORS = false;
687 }
688
676 void LinkStyle::process() 689 void LinkStyle::process()
677 { 690 {
678 ASSERT(m_owner->shouldProcessStyle()); 691 ASSERT(m_owner->shouldProcessStyle());
679 String type = m_owner->typeValue().lower(); 692 String type = m_owner->typeValue().lower();
680 LinkRequestBuilder builder(m_owner); 693 LinkRequestBuilder builder(m_owner);
681 694
682 if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isVal id() && !builder.url().isEmpty()) { 695 if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isVal id() && !builder.url().isEmpty()) {
683 if (!m_owner->shouldLoadLink()) 696 if (!m_owner->shouldLoadLink())
684 return; 697 return;
685 if (!document().securityOrigin()->canDisplay(builder.url())) 698 if (!document().securityOrigin()->canDisplay(builder.url()))
(...skipping 30 matching lines...) Expand all
716 } 729 }
717 730
718 // Don't hold up render tree construction and script execution on styles heets 731 // Don't hold up render tree construction and script execution on styles heets
719 // that are not needed for the rendering at the moment. 732 // that are not needed for the rendering at the moment.
720 bool blocking = mediaQueryMatches && !m_owner->isAlternate(); 733 bool blocking = mediaQueryMatches && !m_owner->isAlternate();
721 addPendingSheet(blocking ? Blocking : NonBlocking); 734 addPendingSheet(blocking ? Blocking : NonBlocking);
722 735
723 // Load stylesheets that are not needed for the rendering immediately wi th low priority. 736 // Load stylesheets that are not needed for the rendering immediately wi th low priority.
724 FetchRequest request = builder.build(blocking); 737 FetchRequest request = builder.build(blocking);
725 AtomicString crossOriginMode = m_owner->fastGetAttribute(HTMLNames::cros soriginAttr); 738 AtomicString crossOriginMode = m_owner->fastGetAttribute(HTMLNames::cros soriginAttr);
726 if (!crossOriginMode.isNull()) 739 if (!crossOriginMode.isNull()) {
727 request.setCrossOriginAccessControl(document().securityOrigin(), cro ssOriginMode); 740 request.setCrossOriginAccessControl(document().securityOrigin(), cro ssOriginMode);
741 setFetchFollowingCORS();
742 }
728 setResource(document().fetcher()->fetchCSSStyleSheet(request)); 743 setResource(document().fetcher()->fetchCSSStyleSheet(request));
729 744
730 if (!resource()) { 745 if (!resource()) {
731 // The request may have been denied if (for example) the stylesheet is local and the document is remote. 746 // The request may have been denied if (for example) the stylesheet is local and the document is remote.
732 m_loading = false; 747 m_loading = false;
733 removePendingSheet(); 748 removePendingSheet();
734 } 749 }
735 } else if (m_sheet) { 750 } else if (m_sheet) {
736 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed 751 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed
737 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get(); 752 RefPtrWillBeRawPtr<StyleSheet> removedSheet = m_sheet.get();
(...skipping 17 matching lines...) Expand all
755 removePendingSheet(); 770 removePendingSheet();
756 } 771 }
757 772
758 DEFINE_TRACE(LinkStyle) 773 DEFINE_TRACE(LinkStyle)
759 { 774 {
760 visitor->trace(m_sheet); 775 visitor->trace(m_sheet);
761 LinkResource::trace(visitor); 776 LinkResource::trace(visitor);
762 } 777 }
763 778
764 } // namespace blink 779 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698