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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/CrashReport.h"
9 #include "mozilla/dom/Navigator.h"
10 #include "mozilla/dom/ReportingHeader.h"
11 #include "mozilla/dom/ReportDeliver.h"
12 #include "mozilla/JSONStringWriteFuncs.h"
13 #include "nsIPrincipal.h"
14 #include "nsIURIMutator.h"
17 namespace mozilla::dom
{
20 bool CrashReport::Deliver(nsIPrincipal
* aPrincipal
, bool aIsOOM
) {
21 MOZ_ASSERT(aPrincipal
);
23 nsAutoCString endpoint_url
;
24 ReportingHeader::GetEndpointForReport(u
"default"_ns
, aPrincipal
,
26 if (endpoint_url
.IsEmpty()) {
30 nsCString safe_origin_spec
;
31 aPrincipal
->GetExposableSpec(safe_origin_spec
);
33 ReportDeliver::ReportData data
;
34 data
.mType
= u
"crash"_ns
;
35 data
.mGroupName
= u
"default"_ns
;
36 CopyUTF8toUTF16(safe_origin_spec
, data
.mURL
);
37 data
.mCreationTime
= TimeStamp::Now();
39 Navigator::GetUserAgent(nullptr, nullptr, Nothing(), data
.mUserAgent
);
40 data
.mPrincipal
= aPrincipal
;
42 data
.mEndpointURL
= endpoint_url
;
44 JSONStringWriteFunc
<nsCString
> body
;
45 JSONWriter writer
{body
};
49 writer
.StringProperty("reason", "oom");
53 data
.mReportBodyJSON
= std::move(body
).StringRRef();
55 ReportDeliver::Fetch(data
);
59 } // namespace mozilla::dom