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 28 matching lines...) Expand all Loading... | |
| 39 #include "core/events/EventSender.h" | 39 #include "core/events/EventSender.h" |
| 40 #include "core/fetch/CSSStyleSheetResource.h" | 40 #include "core/fetch/CSSStyleSheetResource.h" |
| 41 #include "core/fetch/FetchRequest.h" | 41 #include "core/fetch/FetchRequest.h" |
| 42 #include "core/fetch/ResourceFetcher.h" | 42 #include "core/fetch/ResourceFetcher.h" |
| 43 #include "core/frame/FrameView.h" | 43 #include "core/frame/FrameView.h" |
| 44 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
| 45 #include "core/frame/SubresourceIntegrity.h" | 45 #include "core/frame/SubresourceIntegrity.h" |
| 46 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 47 #include "core/html/LinkManifest.h" | 47 #include "core/html/LinkManifest.h" |
| 48 #include "core/html/imports/LinkImport.h" | 48 #include "core/html/imports/LinkImport.h" |
| 49 #include "core/html/parser/CompactHTMLToken.h" | |
| 49 #include "core/loader/FrameLoader.h" | 50 #include "core/loader/FrameLoader.h" |
| 50 #include "core/loader/FrameLoaderClient.h" | 51 #include "core/loader/FrameLoaderClient.h" |
| 51 #include "core/rendering/style/StyleInheritedData.h" | 52 #include "core/rendering/style/StyleInheritedData.h" |
| 52 #include "platform/RuntimeEnabledFeatures.h" | 53 #include "platform/RuntimeEnabledFeatures.h" |
| 53 #include "wtf/StdLibExtras.h" | 54 #include "wtf/StdLibExtras.h" |
| 54 | 55 |
| 55 namespace blink { | 56 namespace blink { |
| 56 | 57 |
| 57 using namespace HTMLNames; | 58 using namespace HTMLNames; |
| 58 | 59 |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 HTMLElement::attributeWillChange(name, oldValue, newValue); | 474 HTMLElement::attributeWillChange(name, oldValue, newValue); |
| 474 } | 475 } |
| 475 | 476 |
| 476 PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) | 477 PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
| 477 { | 478 { |
| 478 return adoptPtrWillBeNoop(new LinkStyle(owner)); | 479 return adoptPtrWillBeNoop(new LinkStyle(owner)); |
| 479 } | 480 } |
| 480 | 481 |
| 481 LinkStyle::LinkStyle(HTMLLinkElement* owner) | 482 LinkStyle::LinkStyle(HTMLLinkElement* owner) |
| 482 : LinkResource(owner) | 483 : LinkResource(owner) |
| 484 , m_token(adoptPtr(new HTMLToken)) | |
| 485 , m_tokenizer(HTMLTokenizer::create(m_options)) | |
| 486 , m_preloadScanner(adoptPtr(new CSSPreloadScanner)) | |
| 487 , m_preloadLength(0) | |
| 483 , m_disabledState(Unset) | 488 , m_disabledState(Unset) |
| 484 , m_pendingSheetType(None) | 489 , m_pendingSheetType(None) |
| 485 , m_loading(false) | 490 , m_loading(false) |
| 486 , m_firedLoad(false) | 491 , m_firedLoad(false) |
| 487 , m_loadedSheet(false) | 492 , m_loadedSheet(false) |
| 488 { | 493 { |
| 494 // The tokenizer uses RAWTEXTState to identify the origin of a request. | |
| 495 // This state is also used while handling CSS prefetch in the html parser. | |
| 496 m_tokenizer->setState(HTMLTokenizer::RAWTEXTState); | |
| 489 } | 497 } |
| 490 | 498 |
| 491 LinkStyle::~LinkStyle() | 499 LinkStyle::~LinkStyle() |
| 492 { | 500 { |
| 493 #if !ENABLE(OILPAN) | 501 #if !ENABLE(OILPAN) |
| 494 if (m_sheet) | 502 if (m_sheet) |
| 495 m_sheet->clearOwnerNode(); | 503 m_sheet->clearOwnerNode(); |
| 496 #endif | 504 #endif |
| 497 } | 505 } |
| 498 | 506 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); | 555 styleSheet->parseAuthorStyleSheet(cachedStyleSheet, m_owner->document().secu rityOrigin()); |
| 548 | 556 |
| 549 m_loading = false; | 557 m_loading = false; |
| 550 styleSheet->notifyLoadedSheet(cachedStyleSheet); | 558 styleSheet->notifyLoadedSheet(cachedStyleSheet); |
| 551 styleSheet->checkLoaded(); | 559 styleSheet->checkLoaded(); |
| 552 | 560 |
| 553 if (styleSheet->isCacheable()) | 561 if (styleSheet->isCacheable()) |
| 554 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); | 562 const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleShe et(styleSheet); |
| 555 } | 563 } |
| 556 | 564 |
| 565 void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet) | |
| 566 { | |
| 567 if (!m_preloadScanner) | |
|
Yoav Weiss
2015/01/05 13:18:44
Maybe a comment saying that the absence of m_prelo
jonnyr
2015/01/06 00:13:06
Done.
| |
| 568 return; | |
| 569 | |
| 570 PreloadRequestStream pendingPreloads; | |
| 571 String sheetText = cachedStyleSheet->sheetText(); | |
| 572 if (sheetText.length() == m_preloadLength) | |
| 573 return; | |
| 574 | |
| 575 m_input.append(sheetText.substring(m_preloadLength)); | |
| 576 | |
| 577 while (true) { | |
| 578 | |
|
Yoav Weiss
2015/01/05 13:18:44
Why not merge the if condition into the while loop
jonnyr
2015/01/06 00:13:06
Done.
| |
| 579 if (!m_tokenizer->nextToken(m_input.current(), *m_token)) | |
| 580 break; // We've reached the end of our current input. | |
| 581 | |
| 582 { | |
| 583 CompactHTMLToken token(m_token.get(), TextPosition(m_input.current() .currentLine(), m_input.current().currentColumn())); | |
| 584 m_preloadScanner->scan(token.data(), m_input.current(), pendingPrelo ads); | |
| 585 } | |
| 586 m_token->clear(); | |
| 587 } | |
| 588 | |
| 589 m_preloadLength = sheetText.length(); | |
| 590 | |
| 591 OwnPtr<HTMLResourcePreloader> preloader = HTMLResourcePreloader::create(docu ment()); | |
| 592 preloader->takeAndPreload(pendingPreloads); | |
| 593 if (m_preloadScanner->isDoneParsingImports()) { | |
| 594 // Note: Although dataRecieved will be called for each packet of data | |
| 595 // returned from the network, @import statements are always at the top | |
| 596 // of the CSS file. As soon as we reach a part of the CSS file which | |
| 597 // is not an @import we can delete our preloader and ignore the rest of | |
| 598 // file. If we ever make CSS preloading more complicated (to look for | |
| 599 // URLs other than @imports) we will need to re-think this logic. | |
| 600 m_preloadScanner.clear(); | |
| 601 m_tokenizer.clear(); | |
| 602 m_token.clear(); | |
| 603 } | |
| 604 } | |
| 605 | |
| 557 bool LinkStyle::sheetLoaded() | 606 bool LinkStyle::sheetLoaded() |
| 558 { | 607 { |
| 559 if (!styleSheetIsLoading()) { | 608 if (!styleSheetIsLoading()) { |
| 560 removePendingSheet(); | 609 removePendingSheet(); |
| 561 return true; | 610 return true; |
| 562 } | 611 } |
| 563 return false; | 612 return false; |
| 564 } | 613 } |
| 565 | 614 |
| 566 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) | 615 void LinkStyle::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 removePendingSheet(); | 800 removePendingSheet(); |
| 752 } | 801 } |
| 753 | 802 |
| 754 void LinkStyle::trace(Visitor* visitor) | 803 void LinkStyle::trace(Visitor* visitor) |
| 755 { | 804 { |
| 756 visitor->trace(m_sheet); | 805 visitor->trace(m_sheet); |
| 757 LinkResource::trace(visitor); | 806 LinkResource::trace(visitor); |
| 758 } | 807 } |
| 759 | 808 |
| 760 } // namespace blink | 809 } // namespace blink |
| OLD | NEW |