2020-02-21 20:40:30 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/CrashReport.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Navigator.h"
|
|
|
|
#include "mozilla/dom/ReportingHeader.h"
|
|
|
|
#include "mozilla/dom/ReportDeliver.h"
|
2020-03-10 02:36:39 +03:00
|
|
|
#include "mozilla/JSONWriter.h"
|
2020-02-21 20:40:30 +03:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIURIMutator.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct StringWriteFunc : public JSONWriteFunc {
|
|
|
|
nsCString& mCString;
|
|
|
|
explicit StringWriteFunc(nsCString& aCString) : mCString(aCString) {}
|
|
|
|
void Write(const char* aStr) override { mCString.Append(aStr); }
|
2020-05-08 19:24:31 +03:00
|
|
|
void Write(const char* aStr, size_t aLen) override {
|
|
|
|
mCString.Append(aStr, aLen);
|
|
|
|
}
|
2020-02-21 20:40:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool CrashReport::Deliver(nsIPrincipal* aPrincipal, bool aIsOOM) {
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
|
|
|
|
nsAutoCString endpoint_url;
|
2020-07-01 11:29:29 +03:00
|
|
|
ReportingHeader::GetEndpointForReport(u"default"_ns, aPrincipal,
|
|
|
|
endpoint_url);
|
2020-02-21 20:40:30 +03:00
|
|
|
if (endpoint_url.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-15 01:04:55 +03:00
|
|
|
nsCString safe_origin_spec;
|
|
|
|
aPrincipal->GetExposableSpec(safe_origin_spec);
|
2020-02-21 20:40:30 +03:00
|
|
|
|
|
|
|
ReportDeliver::ReportData data;
|
2020-07-01 11:29:29 +03:00
|
|
|
data.mType = u"crash"_ns;
|
|
|
|
data.mGroupName = u"default"_ns;
|
2020-02-21 20:40:30 +03:00
|
|
|
data.mURL = NS_ConvertUTF8toUTF16(safe_origin_spec);
|
|
|
|
data.mCreationTime = TimeStamp::Now();
|
|
|
|
|
|
|
|
Navigator::GetUserAgent(nullptr, aPrincipal, false, data.mUserAgent);
|
|
|
|
data.mPrincipal = aPrincipal;
|
|
|
|
data.mFailures = 0;
|
|
|
|
data.mEndpointURL = endpoint_url;
|
|
|
|
|
|
|
|
nsCString body;
|
|
|
|
JSONWriter writer{MakeUnique<StringWriteFunc>(body)};
|
|
|
|
|
|
|
|
writer.Start();
|
|
|
|
if (aIsOOM) {
|
|
|
|
writer.StringProperty("reason", "oom");
|
|
|
|
}
|
|
|
|
writer.End();
|
|
|
|
|
|
|
|
data.mReportBodyJSON = body;
|
|
|
|
|
|
|
|
ReportDeliver::Fetch(data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|