summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/trustedtypes/trusted_type_policy.h
blob: af13e11476cba4d9bc46fb2ce6fcb60c03b034f6 (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
// 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_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TRUSTEDTYPES_TRUSTED_TYPE_POLICY_H_

#include "third_party/blink/renderer/bindings/core/v8/v8_trusted_type_policy_options.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "v8/include/v8.h"

namespace blink {

class ExceptionState;
class TrustedHTML;
class TrustedScript;
class TrustedScriptURL;

class CORE_EXPORT TrustedTypePolicy final : public ScriptWrappable {
  DEFINE_WRAPPERTYPEINFO();

 public:
  TrustedTypePolicy(const String& policy_name, TrustedTypePolicyOptions*);

  TrustedHTML* CreateHTML(v8::Isolate*,
                          const String&,
                          const HeapVector<ScriptValue>&,
                          ExceptionState&);
  TrustedScript* CreateScript(v8::Isolate*,
                              const String&,
                              const HeapVector<ScriptValue>&,
                              ExceptionState&);
  TrustedScriptURL* CreateScriptURL(v8::Isolate*,
                                    const String&,
                                    const HeapVector<ScriptValue>&,
                                    ExceptionState&);

  // IDL generates calls with ScriptState*, which contains the Isolate*.
  // These methods all call the Isolate* variant.
  TrustedHTML* createHTML(ScriptState*,
                          const String&,
                          const HeapVector<ScriptValue>&,
                          ExceptionState&);
  TrustedScript* createScript(ScriptState*,
                              const String&,
                              const HeapVector<ScriptValue>&,
                              ExceptionState&);
  TrustedScriptURL* createScriptURL(ScriptState*,
                                    const String&,
                                    const HeapVector<ScriptValue>&,
                                    ExceptionState&);

  bool HasCreateHTML();
  bool HasCreateScript();
  bool HasCreateScriptURL();

  String name() const;

  void Trace(Visitor*) const override;

 private:
  String name_;
  Member<TrustedTypePolicyOptions> policy_options_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_TRUSTEDTYPES_TRUSTED_TYPE_POLICY_H_