summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/trustedtypes/trusted_type_policy_factory.h
blob: 88a6a37c249d8993bdcf0944534a70bc97c8c9cf (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
// Copyright 2018 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TRUSTEDTYPES_TRUSTED_TYPE_POLICY_FACTORY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TRUSTEDTYPES_TRUSTED_TYPE_POLICY_FACTORY_H_

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_type_policy_options.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

class ExceptionState;
class LocalFrame;
class ScriptState;
class ScriptValue;
class TrustedTypePolicy;

class CORE_EXPORT TrustedTypePolicyFactory final : public ScriptWrappable,
                                                   public DOMWindowClient {
  DEFINE_WRAPPERTYPEINFO();
  USING_GARBAGE_COLLECTED_MIXIN(TrustedTypePolicyFactory);

 public:
  static TrustedTypePolicyFactory* Create(LocalFrame* frame) {
    return MakeGarbageCollected<TrustedTypePolicyFactory>(frame);
  }

  explicit TrustedTypePolicyFactory(LocalFrame*);

  // TrustedTypePolicyFactory.idl
  TrustedTypePolicy* createPolicy(const String&,
                                  const TrustedTypePolicyOptions*,
                                  bool exposed,
                                  ExceptionState&);

  TrustedTypePolicy* getExposedPolicy(const String&);

  Vector<String> getPolicyNames() const;

  bool isHTML(ScriptState*, const ScriptValue&);
  bool isScript(ScriptState*, const ScriptValue&);
  bool isScriptURL(ScriptState*, const ScriptValue&);
  bool isURL(ScriptState*, const ScriptValue&);

  void Trace(blink::Visitor*) override;

 private:
  const WrapperTypeInfo* GetWrapperTypeInfoFromScriptValue(ScriptState*,
                                                           const ScriptValue&);

  HeapHashMap<String, Member<TrustedTypePolicy>> policy_map_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_TRUSTEDTYPES_TRUSTED_TYPE_POLICY_FACTORY_H_