tor-browser

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

ReportingUtils.cpp (1385B)


      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/ReportingUtils.h"
      8 
      9 #include "mozilla/dom/Report.h"
     10 #include "mozilla/dom/ReportBody.h"
     11 #include "mozilla/dom/ReportDeliver.h"
     12 #include "mozilla/ipc/BackgroundChild.h"
     13 #include "mozilla/ipc/BackgroundUtils.h"
     14 #include "mozilla/ipc/PBackgroundChild.h"
     15 #include "nsAtom.h"
     16 #include "nsIGlobalObject.h"
     17 
     18 namespace mozilla::dom {
     19 
     20 /* static */
     21 void ReportingUtils::Report(nsIGlobalObject* aGlobal, nsAtom* aType,
     22                            const nsAString& aGroupName, const nsAString& aURL,
     23                            ReportBody* aBody) {
     24  MOZ_ASSERT(aGlobal);
     25  MOZ_ASSERT(aBody);
     26 
     27  nsDependentAtomString type(aType);
     28 
     29  RefPtr<mozilla::dom::Report> report =
     30      new mozilla::dom::Report(aGlobal, type, aURL, aBody);
     31  aGlobal->BroadcastReport(report);
     32 
     33  if (!NS_IsMainThread()) {
     34    return;
     35  }
     36 
     37  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
     38  if (!window) {
     39    return;
     40  }
     41 
     42  // Send the report to the server.
     43  ReportDeliver::Record(window, type, aGroupName, aURL, aBody);
     44 }
     45 
     46 }  // namespace mozilla::dom