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

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

Issue 166633002: Prefetch @import files from CSS files. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use decoded text for scanning. Created 6 years, 4 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') | Source/core/html/parser/CSSPreloadScanner.h » ('j') | 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 HTMLElement::attributeWillChange(name, oldValue, newValue); 469 HTMLElement::attributeWillChange(name, oldValue, newValue);
470 } 470 }
471 471
472 PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) 472 PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner)
473 { 473 {
474 return adoptPtrWillBeNoop(new LinkStyle(owner)); 474 return adoptPtrWillBeNoop(new LinkStyle(owner));
475 } 475 }
476 476
477 LinkStyle::LinkStyle(HTMLLinkElement* owner) 477 LinkStyle::LinkStyle(HTMLLinkElement* owner)
478 : LinkResource(owner) 478 : LinkResource(owner)
479 , m_preloadScanner(adoptPtr(new CSSPreloadScanner))
480 , m_preloadInput(adoptPtr(new SegmentedString))
481 , m_preloadLength(0)
479 , m_disabledState(Unset) 482 , m_disabledState(Unset)
480 , m_pendingSheetType(None) 483 , m_pendingSheetType(None)
481 , m_loading(false) 484 , m_loading(false)
482 , m_firedLoad(false) 485 , m_firedLoad(false)
483 , m_loadedSheet(false) 486 , m_loadedSheet(false)
484 { 487 {
485 } 488 }
486 489
487 LinkStyle::~LinkStyle() 490 LinkStyle::~LinkStyle()
488 { 491 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); 538 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin());
536 539
537 m_loading = false; 540 m_loading = false;
538 styleSheet->notifyLoadedSheet(cachedStyleSheet); 541 styleSheet->notifyLoadedSheet(cachedStyleSheet);
539 styleSheet->checkLoaded(); 542 styleSheet->checkLoaded();
540 543
541 if (styleSheet->isCacheable()) 544 if (styleSheet->isCacheable())
542 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); 545 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet);
543 } 546 }
544 547
548 void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet)
549 {
550 if (!m_preloadScanner)
551 return;
552
553 PreloadRequestStream pendingPreloads;
554 String sheetText = cachedStyleSheet->sheetText();
555 if (sheetText.length() == m_preloadLength)
556 return;
557
558 m_preloadInput->append(SegmentedString(sheetText.substring(m_preloadLength)) );
559 m_preloadScanner->scan(sheetText.substring(m_preloadLength), *m_preloadInput , pendingPreloads);
560 m_preloadLength = sheetText.length();
abarth-chromium 2014/07/31 14:54:23 Why do you call sheetText.substring(m_preloadLengt
jonnyr 2015/01/05 10:34:52 First of all sorry for the delay in following up o
561
562 OwnPtr<HTMLResourcePreloader> preloader = HTMLResourcePreloader::create(docu ment());
563 preloader->takeAndPreload(pendingPreloads);
564 if (m_preloadScanner->isDoneParsingImports()) {
565 // Note: Although dataRecieved will be called for each packet of data
566 // returned from the network, @import statements are always at the top
567 // of the CSS file. As soon as we reach a part of the CSS file which
568 // is not an @import we can delete our preloader and ignore the rest of
569 // file. If we ever make CSS preloading more complicated (to look for
570 // URLs other than @imports) we will need to re-think this logic.
571 m_preloadScanner.clear();
572 m_preloadInput.clear();
573 }
574 }
575
545 bool LinkStyle::sheetLoaded() 576 bool LinkStyle::sheetLoaded()
546 { 577 {
547 if (!styleSheetIsLoading()) { 578 if (!styleSheetIsLoading()) {
548 removePendingSheet(); 579 removePendingSheet();
549 return true; 580 return true;
550 } 581 }
551 return false; 582 return false;
552 } 583 }
553 584
554 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) 585 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 removePendingSheet(); 772 removePendingSheet();
742 } 773 }
743 774
744 void LinkStyle::trace(Visitor* visitor) 775 void LinkStyle::trace(Visitor* visitor)
745 { 776 {
746 visitor->trace(m_sheet); 777 visitor->trace(m_sheet);
747 LinkResource::trace(visitor); 778 LinkResource::trace(visitor);
748 } 779 }
749 780
750 } // namespace blink 781 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | Source/core/html/parser/CSSPreloadScanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698