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
;
32 MOZ_ASSERT_UNREACHABLE();
33 return FetchPriority::Auto
;
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
;
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
;
56 case nsISupportsPriority::PRIORITY_HIGH
: {
57 aResult
= kPriorityHigh
;
60 case nsISupportsPriority::PRIORITY_NORMAL
: {
61 aResult
= kPriorityNormal
;
64 case nsISupportsPriority::PRIORITY_LOW
: {
65 aResult
= kPriorityLow
;
68 case nsISupportsPriority::PRIORITY_LOWEST
: {
69 aResult
= kPriorityLowest
;
73 aResult
= kPriorityUnknown
;
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
;
91 MOZ_ASSERT_UNREACHABLE();
92 return kFetchPriorityAttributeValueAuto
;
98 void LogPriorityMapping(LazyLogModule
& aLazyLogModule
,
99 FetchPriority aFetchPriority
,
100 int32_t aSupportsPriority
) {
102 nsDependentCString supportsPriority
;
103 SupportsPriorityToString(aSupportsPriority
, supportsPriority
);
104 MOZ_LOG(aLazyLogModule
, LogLevel::Debug
,
105 ("Mapping priority: %s -> %s", ToString(aFetchPriority
),
106 supportsPriority
.get()));
109 } // namespace mozilla::dom