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

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

Issue 2357163002: Setting the link title may change the preferred set. (Closed)
Patch Set: Created 4 years, 3 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 | « third_party/WebKit/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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } else if (name == scopeAttr) { 118 } else if (name == scopeAttr) {
119 m_scope = value; 119 m_scope = value;
120 process(); 120 process();
121 } else if (name == disabledAttr) { 121 } else if (name == disabledAttr) {
122 UseCounter::count(document(), UseCounter::HTMLLinkElementDisabled); 122 UseCounter::count(document(), UseCounter::HTMLLinkElementDisabled);
123 if (LinkStyle* link = linkStyle()) 123 if (LinkStyle* link = linkStyle())
124 link->setDisabledState(!value.isNull()); 124 link->setDisabledState(!value.isNull());
125 } else { 125 } else {
126 if (name == titleAttr) { 126 if (name == titleAttr) {
127 if (LinkStyle* link = linkStyle()) 127 if (LinkStyle* link = linkStyle())
128 link->setSheetTitle(value); 128 link->setSheetTitle(value, StyleEngine::UpdateActiveSheets);
129 } 129 }
130 130
131 HTMLElement::parseAttribute(name, oldValue, value); 131 HTMLElement::parseAttribute(name, oldValue, value);
132 } 132 }
133 } 133 }
134 134
135 bool HTMLLinkElement::shouldLoadLink() 135 bool HTMLLinkElement::shouldLoadLink()
136 { 136 {
137 return isInDocumentTree() || (isConnected() && m_relAttribute.isStyleSheet() ); 137 return isInDocumentTree() || (isConnected() && m_relAttribute.isStyleSheet() );
138 } 138 }
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 467
468 if (StyleSheetContents* restoredSheet = const_cast<CSSStyleSheetResource*>(c achedStyleSheet)->restoreParsedStyleSheet(parserContext)) { 468 if (StyleSheetContents* restoredSheet = const_cast<CSSStyleSheetResource*>(c achedStyleSheet)->restoreParsedStyleSheet(parserContext)) {
469 DCHECK(restoredSheet->isCacheableForResource()); 469 DCHECK(restoredSheet->isCacheableForResource());
470 DCHECK(!restoredSheet->isLoading()); 470 DCHECK(!restoredSheet->isLoading());
471 471
472 if (m_sheet) 472 if (m_sheet)
473 clearSheet(); 473 clearSheet();
474 m_sheet = CSSStyleSheet::create(restoredSheet, m_owner); 474 m_sheet = CSSStyleSheet::create(restoredSheet, m_owner);
475 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); 475 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media()));
476 if (m_owner->isInDocumentTree()) 476 if (m_owner->isInDocumentTree())
477 m_sheet->setTitle(m_owner->title()); 477 setSheetTitle(m_owner->title());
478 setCrossOriginStylesheetStatus(m_sheet.get()); 478 setCrossOriginStylesheetStatus(m_sheet.get());
479 479
480 m_loading = false; 480 m_loading = false;
481 restoredSheet->checkLoaded(); 481 restoredSheet->checkLoaded();
482 482
483 restoredCachedStyleSheetHistogram.count(true); 483 restoredCachedStyleSheetHistogram.count(true);
484 restoredCachedStyleSheet2Histogram.count(StyleSheetInMemoryCache); 484 restoredCachedStyleSheet2Histogram.count(StyleSheetInMemoryCache);
485 return; 485 return;
486 } 486 }
487 restoredCachedStyleSheetHistogram.count(false); 487 restoredCachedStyleSheetHistogram.count(false);
488 StyleSheetCacheStatus cacheStatus = cachedStyleSheet->response().wasCached() ? StyleSheetInDiskCache : StyleSheetNewEntry; 488 StyleSheetCacheStatus cacheStatus = cachedStyleSheet->response().wasCached() ? StyleSheetInDiskCache : StyleSheetNewEntry;
489 restoredCachedStyleSheet2Histogram.count(cacheStatus); 489 restoredCachedStyleSheet2Histogram.count(cacheStatus);
490 490
491 StyleSheetContents* styleSheet = StyleSheetContents::create(href, parserCont ext); 491 StyleSheetContents* styleSheet = StyleSheetContents::create(href, parserCont ext);
492 492
493 if (m_sheet) 493 if (m_sheet)
494 clearSheet(); 494 clearSheet();
495 495
496 m_sheet = CSSStyleSheet::create(styleSheet, m_owner); 496 m_sheet = CSSStyleSheet::create(styleSheet, m_owner);
497 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media())); 497 m_sheet->setMediaQueries(MediaQuerySet::create(m_owner->media()));
498 if (m_owner->isInDocumentTree()) 498 if (m_owner->isInDocumentTree())
499 m_sheet->setTitle(m_owner->title()); 499 setSheetTitle(m_owner->title());
500 setCrossOriginStylesheetStatus(m_sheet.get()); 500 setCrossOriginStylesheetStatus(m_sheet.get());
501 501
502 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().getS ecurityOrigin()); 502 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().getS ecurityOrigin());
503 503
504 m_loading = false; 504 m_loading = false;
505 styleSheet->notifyLoadedSheet(cachedStyleSheet); 505 styleSheet->notifyLoadedSheet(cachedStyleSheet);
506 styleSheet->checkLoaded(); 506 styleSheet->checkLoaded();
507 507
508 if (styleSheet->isCacheableForResource()) 508 if (styleSheet->isCacheableForResource())
509 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); 509 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 clearFetchFollowingCORS(); 655 clearFetchFollowingCORS();
656 } 656 }
657 657
658 if (!m_owner->shouldLoadLink()) 658 if (!m_owner->shouldLoadLink())
659 return; 659 return;
660 660
661 m_loading = true; 661 m_loading = true;
662 662
663 String title = m_owner->title(); 663 String title = m_owner->title();
664 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En abledViaScript && m_owner->isInDocumentTree()) 664 if (!title.isEmpty() && !m_owner->isAlternate() && m_disabledState != En abledViaScript && m_owner->isInDocumentTree())
665 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title ); 665 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title , StyleEngine::DontUpdateActiveSheets);
666 666
667 bool mediaQueryMatches = true; 667 bool mediaQueryMatches = true;
668 LocalFrame* frame = loadingFrame(); 668 LocalFrame* frame = loadingFrame();
669 if (!m_owner->media().isEmpty() && frame) { 669 if (!m_owner->media().isEmpty() && frame) {
670 MediaQuerySet* media = MediaQuerySet::create(m_owner->media()); 670 MediaQuerySet* media = MediaQuerySet::create(m_owner->media());
671 MediaQueryEvaluator evaluator(frame); 671 MediaQueryEvaluator evaluator(frame);
672 mediaQueryMatches = evaluator.eval(media); 672 mediaQueryMatches = evaluator.eval(media);
673 } 673 }
674 674
675 // Don't hold up layout tree construction and script execution on styles heets 675 // Don't hold up layout tree construction and script execution on styles heets
(...skipping 27 matching lines...) Expand all
703 notifyLoadedSheetAndAllCriticalSubresources(Node::ErrorOccurredLoadi ngSubresource); 703 notifyLoadedSheetAndAllCriticalSubresources(Node::ErrorOccurredLoadi ngSubresource);
704 } 704 }
705 } else if (m_sheet) { 705 } else if (m_sheet) {
706 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed 706 // we no longer contain a stylesheet, e.g. perhaps rel or type was chang ed
707 StyleSheet* removedSheet = m_sheet.get(); 707 StyleSheet* removedSheet = m_sheet.get();
708 clearSheet(); 708 clearSheet();
709 document().styleEngine().setNeedsActiveStyleUpdate(removedSheet, FullSty leUpdate); 709 document().styleEngine().setNeedsActiveStyleUpdate(removedSheet, FullSty leUpdate);
710 } 710 }
711 } 711 }
712 712
713 void LinkStyle::setSheetTitle(const String& title) 713 void LinkStyle::setSheetTitle(const String& title, StyleEngine::ActiveSheetsUpda te updateActiveSheets)
714 { 714 {
715 if (m_sheet && m_owner->isInDocumentTree()) 715 if (!m_owner->isInDocumentTree() || !m_owner->relAttribute().isStyleSheet())
716 return;
717
718 if (m_sheet)
716 m_sheet->setTitle(title); 719 m_sheet->setTitle(title);
720
721 if (title.isEmpty() || !isUnset() || m_owner->isAlternate())
722 return;
723
724 KURL href = m_owner->getNonEmptyURLAttribute(hrefAttr);
725 if (href.isValid() && !href.isEmpty())
726 document().styleEngine().setPreferredStylesheetSetNameIfNotSet(title, up dateActiveSheets);
717 } 727 }
718 728
719 void LinkStyle::ownerRemoved() 729 void LinkStyle::ownerRemoved()
720 { 730 {
721 if (m_sheet) 731 if (m_sheet)
722 clearSheet(); 732 clearSheet();
723 733
724 if (styleSheetIsLoading()) 734 if (styleSheetIsLoading())
725 removePendingSheet(); 735 removePendingSheet();
726 } 736 }
727 737
728 DEFINE_TRACE(LinkStyle) 738 DEFINE_TRACE(LinkStyle)
729 { 739 {
730 visitor->trace(m_sheet); 740 visitor->trace(m_sheet);
731 LinkResource::trace(visitor); 741 LinkResource::trace(visitor);
732 ResourceOwner<StyleSheetResource>::trace(visitor); 742 ResourceOwner<StyleSheetResource>::trace(visitor);
733 } 743 }
734 744
735 } // namespace blink 745 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLLinkElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698