summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/rel_list.cc
blob: 6b70a34659228ea817b5cb02379bf3dc5c3738bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/html/rel_list.h"

#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trials.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"

namespace blink {

RelList::RelList(Element* element)
    : DOMTokenList(*element, html_names::kRelAttr) {}

static HashSet<AtomicString>& SupportedTokensLink() {
  // There is a use counter for <link rel="monetization"> but the feature is
  // actually not implemented yet, so "monetization" is not included in the
  // list below. See https://crbug.com/1031476
  DEFINE_STATIC_LOCAL(
      HashSet<AtomicString>, tokens,
      ({
          "preload", "preconnect", "dns-prefetch", "stylesheet", "import",
          "icon", "alternate", "prefetch", "prerender", "next", "manifest",
          "apple-touch-icon", "apple-touch-icon-precomposed", "canonical",
      }));

  return tokens;
}

static HashSet<AtomicString>& SupportedTokensAnchorAndArea() {
  DEFINE_STATIC_LOCAL(HashSet<AtomicString>, tokens,
                      ({
                          "noreferrer", "noopener",
                      }));

  return tokens;
}

bool RelList::ValidateTokenValue(const AtomicString& token_value,
                                 ExceptionState&) const {
  //  https://html.spec.whatwg.org/C/#linkTypes
  if (GetElement().HasTagName(html_names::kLinkTag)) {
    if (SupportedTokensLink().Contains(token_value) ||
        token_value == "modulepreload") {
      return true;
    }
    if (RuntimeEnabledFeatures::SignedExchangeSubresourcePrefetchEnabled(
            GetElement().GetExecutionContext()) &&
        token_value == "allowed-alt-sxg") {
      return true;
    }
    if (RuntimeEnabledFeatures::SubresourceWebBundlesEnabled(
            GetElement().GetExecutionContext()) &&
        token_value == "webbundle") {
      return true;
    }
    if (RuntimeEnabledFeatures::MediaFeedsEnabled(
            GetElement().GetExecutionContext()) &&
        token_value == "media-feed") {
      return true;
    }
  } else if ((GetElement().HasTagName(html_names::kATag) ||
              GetElement().HasTagName(html_names::kAreaTag)) &&
             SupportedTokensAnchorAndArea().Contains(token_value)) {
    return true;
  }
  return false;
}

}  // namespace blink