tor-browser

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

nsIConsoleReportCollector.h (5981B)


      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 nsIConsoleReportCollector_h
      8 #define nsIConsoleReportCollector_h
      9 
     10 #include "nsContentUtils.h"
     11 #include "nsISupports.h"
     12 #include "nsStringFwd.h"
     13 #include "nsTArrayForwardDeclare.h"
     14 
     15 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
     16 #define NS_NSICONSOLEREPORTCOLLECTOR_IID \
     17  {0xdd98a481, 0xd2c4, 0x4203, {0x8d, 0xfa, 0x85, 0xbf, 0xd7, 0xdc, 0xd7, 0x05}}
     18 
     19 namespace mozilla::net {
     20 class ConsoleReportCollected;
     21 }  // namespace mozilla::net
     22 
     23 // An interface for saving reports until we can flush them to the correct
     24 // window at a later time.
     25 class NS_NO_VTABLE nsIConsoleReportCollector : public nsISupports {
     26 public:
     27  NS_INLINE_DECL_STATIC_IID(NS_NSICONSOLEREPORTCOLLECTOR_IID)
     28 
     29  // Add a pending report to be later displayed on the console.  This may be
     30  // called from any thread.
     31  //
     32  // aErrorFlags      A nsIScriptError flags value.
     33  // aCategory        Name of module reporting error.
     34  // aPropertiesFile  Properties file containing localized message.
     35  // aSourceFileURI   The URI of the script generating the error. Must be a URI
     36  //                  spec.
     37  // aLineNumber      The line number where the error was generated. May be 0 if
     38  //                  the line number is not known.
     39  // aColumnNumber    The column number where the error was generated. May be 0
     40  //                  if the line number is not known.
     41  // aMessageName     The name of the localized message contained in the
     42  //                  properties file.
     43  // aStringParams    An array of nsString parameters to use when localizing the
     44  //                  message.
     45  virtual void AddConsoleReport(uint32_t aErrorFlags,
     46                                const nsACString& aCategory,
     47                                nsContentUtils::PropertiesFile aPropertiesFile,
     48                                const nsACString& aSourceFileURI,
     49                                uint32_t aLineNumber, uint32_t aColumnNumber,
     50                                const nsACString& aMessageName,
     51                                const nsTArray<nsString>& aStringParams) = 0;
     52 
     53  // A version of AddConsoleReport() that accepts the message parameters
     54  // as variable nsString arguments (or really, any sort of const nsAString).
     55  // All other args the same as AddConsoleReport().
     56  template <typename... Params>
     57  void AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory,
     58                        nsContentUtils::PropertiesFile aPropertiesFile,
     59                        const nsACString& aSourceFileURI, uint32_t aLineNumber,
     60                        uint32_t aColumnNumber, const nsACString& aMessageName,
     61                        Params&&... aParams) {
     62    nsTArray<nsString> params;
     63    mozilla::dom::StringArrayAppender::Append(params, sizeof...(Params),
     64                                              std::forward<Params>(aParams)...);
     65    AddConsoleReport(aErrorFlags, aCategory, aPropertiesFile, aSourceFileURI,
     66                     aLineNumber, aColumnNumber, aMessageName, params);
     67  }
     68 
     69  // An enum calss to indicate whether should free the pending reports or not.
     70  // Forget        Free the pending reports.
     71  // Save          Keep the pending reports.
     72  enum class ReportAction { Forget, Save };
     73 
     74  // Flush all pending reports to the console.  May be called from any thread.
     75  //
     76  // aInnerWindowID A inner window ID representing where to flush the reports.
     77  // aAction        An action to determine whether to reserve the pending
     78  //                reports. Defalut action is to forget the report.
     79  virtual void FlushReportsToConsole(
     80      uint64_t aInnerWindowID, ReportAction aAction = ReportAction::Forget) = 0;
     81 
     82  virtual void FlushReportsToConsoleForServiceWorkerScope(
     83      const nsACString& aScope,
     84      ReportAction aAction = ReportAction::Forget) = 0;
     85 
     86  // Flush all pending reports to the console.  Main thread only.
     87  //
     88  // aDocument      An optional document representing where to flush the
     89  //                reports.  If provided, then the corresponding window's
     90  //                web console will get the reports.  Otherwise the reports
     91  //                go to the browser console.
     92  // aAction        An action to determine whether to reserve the pending
     93  //                reports. Defalut action is to forget the report.
     94  virtual void FlushConsoleReports(
     95      mozilla::dom::Document* aDocument,
     96      ReportAction aAction = ReportAction::Forget) = 0;
     97 
     98  // Flush all pending reports to the console.  May be called from any thread.
     99  //
    100  // aLoadGroup     An optional loadGroup representing where to flush the
    101  //                reports.  If provided, then the corresponding window's
    102  //                web console will get the reports.  Otherwise the reports
    103  //                go to the browser console.
    104  // aAction        An action to determine whether to reserve the pending
    105  //                reports. Defalut action is to forget the report.
    106  virtual void FlushConsoleReports(
    107      nsILoadGroup* aLoadGroup,
    108      ReportAction aAction = ReportAction::Forget) = 0;
    109 
    110  // Flush all pending reports to another collector.  May be called from any
    111  // thread.
    112  //
    113  // aCollector     A required collector object that will effectively take
    114  //                ownership of our currently console reports.
    115  virtual void FlushConsoleReports(nsIConsoleReportCollector* aCollector) = 0;
    116 
    117  // Steal all pending reports to IPC structs. May be called from any thread.
    118  virtual void StealConsoleReports(
    119      nsTArray<mozilla::net::ConsoleReportCollected>& aReports) = 0;
    120 
    121  // Clear all pending reports.
    122  virtual void ClearConsoleReports() = 0;
    123 };
    124 
    125 #endif  // nsIConsoleReportCollector_h