StylePreloadKind.h (1845B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_css_StylePreloadKind_h 8 #define mozilla_css_StylePreloadKind_h 9 10 #include <stdint.h> 11 12 namespace mozilla::css { 13 14 enum class StylePreloadKind : uint8_t { 15 // Not a preload. 16 None, 17 // An speculative load from the parser for a <link rel="stylesheet"> or 18 // @import stylesheet. 19 FromParser, 20 // A preload (speculative or not) for a <link rel="preload" as="style"> 21 // element. 22 FromLinkRelPreloadElement, 23 // A preload for a "Link" rel=preload response header. 24 FromLinkRelPreloadHeader, 25 // A preload from an early-hints header. 26 FromEarlyHintsHeader, 27 }; 28 29 inline bool IsLinkRelPreloadOrEarlyHint(StylePreloadKind aKind) { 30 return aKind == StylePreloadKind::FromLinkRelPreloadElement || 31 aKind == StylePreloadKind::FromLinkRelPreloadHeader || 32 aKind == StylePreloadKind::FromEarlyHintsHeader; 33 } 34 35 inline bool ShouldAssumeStandardsMode(StylePreloadKind aKind) { 36 switch (aKind) { 37 case StylePreloadKind::FromLinkRelPreloadHeader: 38 case StylePreloadKind::FromEarlyHintsHeader: 39 // For header preloads we guess non-quirks, because otherwise it is 40 // useless for modern pages. 41 // 42 // Link element preload is generally good because the speculative html 43 // parser deals with quirks mode properly. 44 return true; 45 case StylePreloadKind::None: 46 case StylePreloadKind::FromParser: 47 case StylePreloadKind::FromLinkRelPreloadElement: 48 break; 49 } 50 return false; 51 } 52 53 } // namespace mozilla::css 54 55 #endif // mozilla_css_StylePreloadKind_h