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

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: Fixed according to comments. 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))
479 , m_disabledState(Unset) 481 , m_disabledState(Unset)
480 , m_pendingSheetType(None) 482 , m_pendingSheetType(None)
481 , m_loading(false) 483 , m_loading(false)
482 , m_firedLoad(false) 484 , m_firedLoad(false)
483 , m_loadedSheet(false) 485 , m_loadedSheet(false)
484 { 486 {
485 } 487 }
486 488
487 LinkStyle::~LinkStyle() 489 LinkStyle::~LinkStyle()
488 { 490 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); 537 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin());
536 538
537 m_loading = false; 539 m_loading = false;
538 styleSheet->notifyLoadedSheet(cachedStyleSheet); 540 styleSheet->notifyLoadedSheet(cachedStyleSheet);
539 styleSheet->checkLoaded(); 541 styleSheet->checkLoaded();
540 542
541 if (styleSheet->isCacheable()) 543 if (styleSheet->isCacheable())
542 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); 544 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet);
543 } 545 }
544 546
547 void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet, cons t char* data, int length)
548 {
549 if (!m_preloadScanner)
550 return;
551
552 PreloadRequestStream pendingPreloads;
553 m_preloadInput->append(SegmentedString(String(data, length)));
abarth-chromium 2014/07/29 16:43:52 How can you take a const char* and make a String o
554 m_preloadScanner->scan(data, *m_preloadInput, pendingPreloads);
555
556 OwnPtr<HTMLResourcePreloader> preloader = HTMLResourcePreloader::create(docu ment());
557 preloader->takeAndPreload(pendingPreloads);
558 if (m_preloadScanner->isDoneParsingImports()) {
559 // Note: Although dataRecieved will be called for each packet of data
560 // returned from the network, @import statements are always at the top
561 // of the CSS file. As soon as we reach a part of the CSS file which
562 // is not an @import we can delete our preloader and ignore the rest of
563 // file. If we ever make CSS preloading more complicated (to look for
564 // URLs other than @imports) we will need to re-think this logic.
565 m_preloadScanner.clear();
566 m_preloadInput.clear();
567 }
568 }
569
545 bool LinkStyle::sheetLoaded() 570 bool LinkStyle::sheetLoaded()
546 { 571 {
547 if (!styleSheetIsLoading()) { 572 if (!styleSheetIsLoading()) {
548 removePendingSheet(); 573 removePendingSheet();
549 return true; 574 return true;
550 } 575 }
551 return false; 576 return false;
552 } 577 }
553 578
554 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) 579 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 removePendingSheet(); 766 removePendingSheet();
742 } 767 }
743 768
744 void LinkStyle::trace(Visitor* visitor) 769 void LinkStyle::trace(Visitor* visitor)
745 { 770 {
746 visitor->trace(m_sheet); 771 visitor->trace(m_sheet);
747 LinkResource::trace(visitor); 772 LinkResource::trace(visitor);
748 } 773 }
749 774
750 } // namespace blink 775 } // 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