1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORT_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORT_H_
7 
8 #include "third_party/blink/renderer/core/core_export.h"
9 #include "third_party/blink/renderer/core/frame/report_body.h"
10 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
11 
12 namespace blink {
13 
14 // The constants are implemented as static members of a class to have an unique
15 // address and not violate ODR.
16 struct CORE_EXPORT ReportType {
17   static constexpr const char kCSPViolation[] = "csp-violation";
18   static constexpr const char kCoopAccessViolation[] = "coop-access-violation";
19   static constexpr const char kDeprecation[] = "deprecation";
20   static constexpr const char kDocumentPolicyViolation[] =
21       "document-policy-violation";
22   static constexpr const char kFeaturePolicyViolation[] =
23       "permissions-policy-violation";
24   static constexpr const char kIntervention[] = "intervention";
25 };
26 
27 class CORE_EXPORT Report : public ScriptWrappable {
28   DEFINE_WRAPPERTYPEINFO();
29 
30  public:
Report(const String & type,const String & url,ReportBody * body)31   Report(const String& type, const String& url, ReportBody* body)
32       : type_(type), url_(url), body_(body) {
33     DCHECK(!type.IsNull());
34   }
35 
36   ~Report() override = default;
37 
type()38   String type() const { return type_; }
url()39   String url() const { return url_; }
body()40   ReportBody* body() const { return body_; }
41 
Trace(Visitor * visitor)42   void Trace(Visitor* visitor) const override {
43     visitor->Trace(body_);
44     ScriptWrappable::Trace(visitor);
45   }
46 
47   ScriptValue toJSON(ScriptState* script_state) const;
48 
49   // Provides a hash-like value for identifying reports with same content.
50   // Collision of match id is possible.
51   unsigned MatchId() const;
52 
53  private:
54   const String type_;
55   const String url_;
56   Member<ReportBody> body_;
57 };
58 
59 }  // namespace blink
60 
61 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORT_H_
62