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/FeaturePolicyViolationReportBody.h"
9 #include "mozilla/JSONWriter.h"
10 #include "mozilla/dom/FeaturePolicyBinding.h"
12 namespace mozilla::dom
{
14 FeaturePolicyViolationReportBody::FeaturePolicyViolationReportBody(
15 nsIGlobalObject
* aGlobal
, const nsAString
& aFeatureId
,
16 const nsACString
& aSourceFile
, const Nullable
<int32_t>& aLineNumber
,
17 const Nullable
<int32_t>& aColumnNumber
, const nsAString
& aDisposition
)
18 : ReportBody(aGlobal
),
19 mFeatureId(aFeatureId
),
20 mSourceFile(aSourceFile
),
21 mLineNumber(aLineNumber
),
22 mColumnNumber(aColumnNumber
),
23 mDisposition(aDisposition
) {}
25 FeaturePolicyViolationReportBody::~FeaturePolicyViolationReportBody() = default;
27 JSObject
* FeaturePolicyViolationReportBody::WrapObject(
28 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
29 return FeaturePolicyViolationReportBody_Binding::Wrap(aCx
, this, aGivenProto
);
32 void FeaturePolicyViolationReportBody::GetFeatureId(
33 nsAString
& aFeatureId
) const {
34 aFeatureId
= mFeatureId
;
37 void FeaturePolicyViolationReportBody::GetSourceFile(
38 nsACString
& aSourceFile
) const {
39 aSourceFile
= mSourceFile
;
42 Nullable
<int32_t> FeaturePolicyViolationReportBody::GetLineNumber() const {
46 Nullable
<int32_t> FeaturePolicyViolationReportBody::GetColumnNumber() const {
50 void FeaturePolicyViolationReportBody::GetDisposition(
51 nsAString
& aDisposition
) const {
52 aDisposition
= mDisposition
;
55 void FeaturePolicyViolationReportBody::ToJSON(JSONWriter
& aWriter
) const {
56 aWriter
.StringProperty("featureId", NS_ConvertUTF16toUTF8(mFeatureId
));
58 if (mSourceFile
.IsEmpty()) {
59 aWriter
.NullProperty("sourceFile");
61 aWriter
.StringProperty("sourceFile", mSourceFile
);
64 if (mLineNumber
.IsNull()) {
65 aWriter
.NullProperty("lineNumber");
67 aWriter
.IntProperty("lineNumber", mLineNumber
.Value());
70 if (mColumnNumber
.IsNull()) {
71 aWriter
.NullProperty("columnNumber");
73 aWriter
.IntProperty("columnNumber", mColumnNumber
.Value());
76 aWriter
.StringProperty("disposition", NS_ConvertUTF16toUTF8(mDisposition
));
79 } // namespace mozilla::dom