tor-browser

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

ReportingObserver.h (2133B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_ReportingObserver_h
      8 #define mozilla_dom_ReportingObserver_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/AlreadyAddRefed.h"
     12 #include "mozilla/Attributes.h"
     13 #include "mozilla/RefPtr.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsCycleCollectionParticipant.h"
     16 #include "nsISupports.h"
     17 #include "nsStringFwd.h"
     18 #include "nsTArray.h"
     19 #include "nsWrapperCache.h"
     20 
     21 class nsIGlobalObject;
     22 
     23 namespace mozilla {
     24 class ErrorResult;
     25 
     26 namespace dom {
     27 class GlobalObject;
     28 class Report;
     29 class ReportingObserverCallback;
     30 struct ReportingObserverOptions;
     31 
     32 class ReportingObserver final : public nsWrapperCache {
     33 public:
     34  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ReportingObserver)
     35  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(ReportingObserver)
     36 
     37  static already_AddRefed<ReportingObserver> Constructor(
     38      const GlobalObject& aGlobal, ReportingObserverCallback& aCallback,
     39      const ReportingObserverOptions& aOptions, ErrorResult& aRv);
     40 
     41  ReportingObserver(nsIGlobalObject* aGlobal,
     42                    ReportingObserverCallback& aCallback,
     43                    const nsTArray<nsString>& aTypes, bool aBuffered);
     44 
     45  JSObject* WrapObject(JSContext* aCx,
     46                       JS::Handle<JSObject*> aGivenProto) override;
     47 
     48  nsIGlobalObject* GetParentObject() const { return mGlobal; }
     49 
     50  void Observe();
     51 
     52  void Disconnect();
     53 
     54  void TakeRecords(nsTArray<RefPtr<Report>>& aRecords);
     55 
     56  void MaybeReport(Report* aReport);
     57 
     58  MOZ_CAN_RUN_SCRIPT void MaybeNotify();
     59 
     60  void ForgetReports();
     61 
     62 private:
     63  ~ReportingObserver();
     64 
     65  nsTArray<RefPtr<Report>> mReports;
     66 
     67  nsCOMPtr<nsIGlobalObject> mGlobal;
     68  RefPtr<ReportingObserverCallback> mCallback;
     69  nsTArray<nsString> mTypes;
     70  bool mBuffered;
     71 };
     72 
     73 }  // namespace dom
     74 }  // namespace mozilla
     75 
     76 #endif  // mozilla_dom_ReportingObserver_h