tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CrashReport.cpp (1669B)


      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/. */
      6 
      7 #include "mozilla/dom/CrashReport.h"
      8 
      9 #include "mozilla/JSONStringWriteFuncs.h"
     10 #include "mozilla/dom/Navigator.h"
     11 #include "mozilla/dom/ReportDeliver.h"
     12 #include "mozilla/dom/ReportingHeader.h"
     13 #include "nsIPrincipal.h"
     14 #include "nsIURIMutator.h"
     15 #include "nsString.h"
     16 
     17 namespace mozilla::dom {
     18 
     19 /* static */
     20 bool CrashReport::Deliver(nsIPrincipal* aPrincipal, bool aIsOOM) {
     21  MOZ_ASSERT(aPrincipal);
     22 
     23  nsAutoCString endpoint_url;
     24  ReportingHeader::GetEndpointForReport(u"default"_ns, aPrincipal,
     25                                        endpoint_url);
     26  if (endpoint_url.IsEmpty()) {
     27    return false;
     28  }
     29 
     30  nsCString safe_origin_spec;
     31  aPrincipal->GetExposableSpec(safe_origin_spec);
     32 
     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();
     38 
     39  Navigator::GetUserAgent(nullptr, nullptr, Nothing(), data.mUserAgent);
     40  data.mPrincipal = aPrincipal;
     41  data.mFailures = 0;
     42  data.mEndpointURL = endpoint_url;
     43 
     44  JSONStringWriteFunc<nsCString> body;
     45  JSONWriter writer{body};
     46 
     47  writer.Start();
     48  if (aIsOOM) {
     49    writer.StringProperty("reason", "oom");
     50  }
     51  writer.End();
     52 
     53  data.mReportBodyJSON = std::move(body).StringRRef();
     54 
     55  ReportDeliver::Fetch(data);
     56  return true;
     57 }
     58 
     59 }  // namespace mozilla::dom