Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / FetchPriority.cpp
blob259c05c6c3136d9f4a4d5be010daef85479e20c8
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/. */
7 #include "mozilla/dom/FetchPriority.h"
9 #include "mozilla/Assertions.h"
10 #include "mozilla/Logging.h"
11 #include "mozilla/dom/RequestBinding.h"
12 #include "nsISupportsPriority.h"
13 #include "nsStringFwd.h"
15 namespace mozilla::dom {
16 const char* kFetchPriorityAttributeValueHigh = "high";
17 const char* kFetchPriorityAttributeValueLow = "low";
18 const char* kFetchPriorityAttributeValueAuto = "auto";
20 FetchPriority ToFetchPriority(RequestPriority aRequestPriority) {
21 switch (aRequestPriority) {
22 case RequestPriority::High: {
23 return FetchPriority::High;
25 case RequestPriority::Low: {
26 return FetchPriority::Low;
28 case RequestPriority::Auto: {
29 return FetchPriority::Auto;
31 default: {
32 MOZ_ASSERT_UNREACHABLE();
33 return FetchPriority::Auto;
38 #ifdef DEBUG
39 constexpr auto kPriorityHighest = "PRIORITY_HIGHEST"_ns;
40 constexpr auto kPriorityHigh = "PRIORITY_HIGH"_ns;
41 constexpr auto kPriorityNormal = "PRIORITY_NORMAL"_ns;
42 constexpr auto kPriorityLow = "PRIORITY_LOW"_ns;
43 constexpr auto kPriorityLowest = "PRIORITY_LOWEST"_ns;
44 constexpr auto kPriorityUnknown = "UNKNOWN"_ns;
46 /**
47 * See <nsISupportsPriority.idl>.
49 static void SupportsPriorityToString(int32_t aSupportsPriority,
50 nsACString& aResult) {
51 switch (aSupportsPriority) {
52 case nsISupportsPriority::PRIORITY_HIGHEST: {
53 aResult = kPriorityHighest;
54 break;
56 case nsISupportsPriority::PRIORITY_HIGH: {
57 aResult = kPriorityHigh;
58 break;
60 case nsISupportsPriority::PRIORITY_NORMAL: {
61 aResult = kPriorityNormal;
62 break;
64 case nsISupportsPriority::PRIORITY_LOW: {
65 aResult = kPriorityLow;
66 break;
68 case nsISupportsPriority::PRIORITY_LOWEST: {
69 aResult = kPriorityLowest;
70 break;
72 default: {
73 aResult = kPriorityUnknown;
74 break;
79 static const char* ToString(FetchPriority aFetchPriority) {
80 switch (aFetchPriority) {
81 case FetchPriority::Auto: {
82 return kFetchPriorityAttributeValueAuto;
84 case FetchPriority::Low: {
85 return kFetchPriorityAttributeValueLow;
87 case FetchPriority::High: {
88 return kFetchPriorityAttributeValueHigh;
90 default: {
91 MOZ_ASSERT_UNREACHABLE();
92 return kFetchPriorityAttributeValueAuto;
96 #endif // DEBUG
98 void LogPriorityMapping(LazyLogModule& aLazyLogModule,
99 FetchPriority aFetchPriority,
100 int32_t aSupportsPriority) {
101 #ifdef DEBUG
102 nsDependentCString supportsPriority;
103 SupportsPriorityToString(aSupportsPriority, supportsPriority);
104 MOZ_LOG(aLazyLogModule, LogLevel::Debug,
105 ("Mapping priority: %s -> %s", ToString(aFetchPriority),
106 supportsPriority.get()));
107 #endif // DEBUG
109 } // namespace mozilla::dom