| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "core/loader/appcache/ApplicationCacheHost.h" | 58 #include "core/loader/appcache/ApplicationCacheHost.h" |
| 59 #include "core/page/Page.h" | 59 #include "core/page/Page.h" |
| 60 #include "core/svg/graphics/SVGImageChromeClient.h" | 60 #include "core/svg/graphics/SVGImageChromeClient.h" |
| 61 #include "core/timing/DOMWindowPerformance.h" | 61 #include "core/timing/DOMWindowPerformance.h" |
| 62 #include "core/timing/Performance.h" | 62 #include "core/timing/Performance.h" |
| 63 #include "platform/Logging.h" | 63 #include "platform/Logging.h" |
| 64 #include "platform/network/ResourceTimingInfo.h" | 64 #include "platform/network/ResourceTimingInfo.h" |
| 65 #include "platform/weborigin/SchemeRegistry.h" | 65 #include "platform/weborigin/SchemeRegistry.h" |
| 66 #include "platform/weborigin/SecurityPolicy.h" | 66 #include "platform/weborigin/SecurityPolicy.h" |
| 67 | 67 |
| 68 #include <algorithm> |
| 69 |
| 68 namespace blink { | 70 namespace blink { |
| 69 | 71 |
| 70 FrameFetchContext::FrameFetchContext(DocumentLoader* loader) | 72 FrameFetchContext::FrameFetchContext(DocumentLoader* loader) |
| 71 : m_document(nullptr) | 73 : m_document(nullptr) |
| 72 , m_documentLoader(loader) | 74 , m_documentLoader(loader) |
| 75 , m_imageFetched(false) |
| 73 { | 76 { |
| 74 } | 77 } |
| 75 | 78 |
| 76 FrameFetchContext::~FrameFetchContext() | 79 FrameFetchContext::~FrameFetchContext() |
| 77 { | 80 { |
| 78 m_document = nullptr; | 81 m_document = nullptr; |
| 79 m_documentLoader = nullptr; | 82 m_documentLoader = nullptr; |
| 80 } | 83 } |
| 81 | 84 |
| 82 LocalFrame* FrameFetchContext::frame() const | 85 LocalFrame* FrameFetchContext::frame() const |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 void FrameFetchContext::countClientHintsResourceWidth() | 654 void FrameFetchContext::countClientHintsResourceWidth() |
| 652 { | 655 { |
| 653 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth); | 656 UseCounter::count(frame(), UseCounter::ClientHintsResourceWidth); |
| 654 } | 657 } |
| 655 | 658 |
| 656 void FrameFetchContext::countClientHintsViewportWidth() | 659 void FrameFetchContext::countClientHintsViewportWidth() |
| 657 { | 660 { |
| 658 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth); | 661 UseCounter::count(frame(), UseCounter::ClientHintsViewportWidth); |
| 659 } | 662 } |
| 660 | 663 |
| 661 bool FrameFetchContext::isLowPriorityIframe() const | |
| 662 { | |
| 663 return !frame()->isMainFrame() && frame()->settings() && frame()->settings()
->lowPriorityIframes(); | |
| 664 } | |
| 665 | |
| 666 bool FrameFetchContext::fetchDeferLateScripts() const | |
| 667 { | |
| 668 return frame()->settings() && frame()->settings()->fetchDeferLateScripts(); | |
| 669 } | |
| 670 | |
| 671 bool FrameFetchContext::fetchIncreaseFontPriority() const | |
| 672 { | |
| 673 return frame()->settings() && frame()->settings()->fetchIncreaseFontPriority
(); | |
| 674 } | |
| 675 | |
| 676 bool FrameFetchContext::fetchIncreaseAsyncScriptPriority() const | |
| 677 { | |
| 678 return frame()->settings() && frame()->settings()->fetchIncreaseAsyncScriptP
riority(); | |
| 679 } | |
| 680 | |
| 681 bool FrameFetchContext::fetchIncreasePriorities() const | 664 bool FrameFetchContext::fetchIncreasePriorities() const |
| 682 { | 665 { |
| 683 return frame()->settings() && frame()->settings()->fetchIncreasePriorities()
; | 666 return frame()->settings() && frame()->settings()->fetchIncreasePriorities()
; |
| 684 } | 667 } |
| 685 | 668 |
| 669 ResourceLoadPriority FrameFetchContext::modifyPriorityForExperiments(ResourceLoa
dPriority priority, Resource::Type type, const FetchRequest& request) |
| 670 { |
| 671 // An image fetch is used to distinguish between "early" and "late" scripts
in a document |
| 672 if (type == Resource::Image) |
| 673 m_imageFetched = true; |
| 674 |
| 675 // If Settings is null, we can't verify any experiments are in force. |
| 676 if (!frame()->settings()) |
| 677 return priority; |
| 678 |
| 679 if (!frame()->isMainFrame() && frame()->settings()->lowPriorityIframes() &&
type == Resource::MainResource) |
| 680 return ResourceLoadPriorityVeryLow; |
| 681 |
| 682 // Async/Defer scripts. |
| 683 if (type == Resource::Script && FetchRequest::LazyLoad == request.defer()) |
| 684 return frame()->settings()->fetchIncreaseAsyncScriptPriority() ? Resourc
eLoadPriorityMedium : ResourceLoadPriorityLow; |
| 685 |
| 686 // Runtime experiment that change how we prioritize resources. |
| 687 // The toggles do not depend on each other and can be flipped individually |
| 688 // though the cumulative result will depend on the interaction between them. |
| 689 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g
pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing |
| 690 |
| 691 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le
vel |
| 692 // and parser-blocking scripts and visible images by 2. |
| 693 // This is used in conjunction with logic on the Chrome side to raise the th
reshold |
| 694 // of "layout-blocking" resources and provide a boost to resources that are
needed |
| 695 // as soon as possible for something currently on the screen. |
| 696 int modifiedPriority = static_cast<int>(priority); |
| 697 if (fetchIncreasePriorities()) { |
| 698 if (type == Resource::CSSStyleSheet || type == Resource::Script || type
== Resource::Font || type == Resource::Image) |
| 699 modifiedPriority++; |
| 700 } |
| 701 |
| 702 if (frame()->settings()->fetchIncreaseFontPriority() && type == Resource::Fo
nt) |
| 703 modifiedPriority++; |
| 704 |
| 705 if (type == Resource::Script) { |
| 706 // Reduce the priority of late-body scripts. |
| 707 if (frame()->settings()->fetchDeferLateScripts() && request.forPreload()
&& m_imageFetched) |
| 708 modifiedPriority--; |
| 709 // Parser-blocking scripts. |
| 710 if (fetchIncreasePriorities() && !request.forPreload()) |
| 711 modifiedPriority++; |
| 712 } |
| 713 |
| 714 // Clamp priority |
| 715 modifiedPriority = std::min(static_cast<int>(ResourceLoadPriorityHighest), s
td::max(static_cast<int>(ResourceLoadPriorityLowest), modifiedPriority)); |
| 716 return static_cast<ResourceLoadPriority>(modifiedPriority); |
| 717 } |
| 686 | 718 |
| 687 DEFINE_TRACE(FrameFetchContext) | 719 DEFINE_TRACE(FrameFetchContext) |
| 688 { | 720 { |
| 689 visitor->trace(m_document); | 721 visitor->trace(m_document); |
| 690 visitor->trace(m_documentLoader); | 722 visitor->trace(m_documentLoader); |
| 691 FetchContext::trace(visitor); | 723 FetchContext::trace(visitor); |
| 692 } | 724 } |
| 693 | 725 |
| 694 } // namespace blink | 726 } // namespace blink |
| OLD | NEW |