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"
15 FeaturePolicyViolationReportBody::FeaturePolicyViolationReportBody(
16 nsIGlobalObject
* aGlobal
, const nsAString
& aFeatureId
,
17 const nsAString
& aSourceFile
, const Nullable
<int32_t>& aLineNumber
,
18 const Nullable
<int32_t>& aColumnNumber
, const nsAString
& aDisposition
)
19 : ReportBody(aGlobal
),
20 mFeatureId(aFeatureId
),
21 mSourceFile(aSourceFile
),
22 mLineNumber(aLineNumber
),
23 mColumnNumber(aColumnNumber
),
24 mDisposition(aDisposition
) {}
26 FeaturePolicyViolationReportBody::~FeaturePolicyViolationReportBody() = default;
28 JSObject
* FeaturePolicyViolationReportBody::WrapObject(
29 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
30 return FeaturePolicyViolationReportBody_Binding::Wrap(aCx
, this, aGivenProto
);
33 void FeaturePolicyViolationReportBody::GetFeatureId(
34 nsAString
& aFeatureId
) const {
35 aFeatureId
= mFeatureId
;
38 void FeaturePolicyViolationReportBody::GetSourceFile(
39 nsAString
& aSourceFile
) const {
40 aSourceFile
= mSourceFile
;
43 Nullable
<int32_t> FeaturePolicyViolationReportBody::GetLineNumber() const {
47 Nullable
<int32_t> FeaturePolicyViolationReportBody::GetColumnNumber() const {
51 void FeaturePolicyViolationReportBody::GetDisposition(
52 nsAString
& aDisposition
) const {
53 aDisposition
= mDisposition
;
56 void FeaturePolicyViolationReportBody::ToJSON(JSONWriter
& aWriter
) const {
57 aWriter
.StringProperty("featureId", NS_ConvertUTF16toUTF8(mFeatureId
));
59 if (mSourceFile
.IsEmpty()) {
60 aWriter
.NullProperty("sourceFile");
62 aWriter
.StringProperty("sourceFile", NS_ConvertUTF16toUTF8(mSourceFile
));
65 if (mLineNumber
.IsNull()) {
66 aWriter
.NullProperty("lineNumber");
68 aWriter
.IntProperty("lineNumber", mLineNumber
.Value());
71 if (mColumnNumber
.IsNull()) {
72 aWriter
.NullProperty("columnNumber");
74 aWriter
.IntProperty("columnNumber", mColumnNumber
.Value());
77 aWriter
.StringProperty("disposition", NS_ConvertUTF16toUTF8(mDisposition
));
81 } // namespace mozilla