Bug 1873144 - Disabled test_conformance__textures__misc__texture-npot-video.html...
[gecko.git] / dom / reporting / CrashReport.cpp
blob9cfd5340d535d09e2d1c952588d72ba52c9b24d1
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"
15 #include "nsString.h"
17 namespace mozilla::dom {
19 /* static */
20 bool CrashReport::Deliver(nsIPrincipal* aPrincipal, bool aIsOOM) {
21 MOZ_ASSERT(aPrincipal);
23 nsAutoCString endpoint_url;
24 ReportingHeader::GetEndpointForReport(u"default"_ns, aPrincipal,
25 endpoint_url);
26 if (endpoint_url.IsEmpty()) {
27 return false;
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;
41 data.mFailures = 0;
42 data.mEndpointURL = endpoint_url;
44 JSONStringWriteFunc<nsCString> body;
45 JSONWriter writer{body};
47 writer.Start();
48 if (aIsOOM) {
49 writer.StringProperty("reason", "oom");
51 writer.End();
53 data.mReportBodyJSON = std::move(body).StringRRef();
55 ReportDeliver::Fetch(data);
56 return true;
59 } // namespace mozilla::dom