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/. */
7 #ifndef nsIConsoleReportCollector_h
8 #define nsIConsoleReportCollector_h
10 #include "nsContentUtils.h"
11 #include "nsISupports.h"
12 #include "nsStringFwd.h"
13 #include "nsTArrayForwardDeclare.h"
15 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
16 #define NS_NSICONSOLEREPORTCOLLECTOR_IID \
18 0xdd98a481, 0xd2c4, 0x4203, { \
19 0x8d, 0xfa, 0x85, 0xbf, 0xd7, 0xdc, 0xd7, 0x05 \
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
{
27 NS_DECLARE_STATIC_IID_ACCESSOR(NS_NSICONSOLEREPORTCOLLECTOR_IID
)
29 // Add a pending report to be later displayed on the console. This may be
30 // called from any thread.
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
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
43 // aStringParams An array of nsString parameters to use when localizing the
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;
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
);
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
};
74 // Flush all pending reports to the console. May be called from any thread.
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;
82 virtual void FlushReportsToConsoleForServiceWorkerScope(
83 const nsACString
& aScope
,
84 ReportAction aAction
= ReportAction::Forget
) = 0;
86 // Flush all pending reports to the console. Main thread only.
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;
98 // Flush all pending reports to the console. May be called from any thread.
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;
110 // Flush all pending reports to another collector. May be called from any
113 // aCollector A required collector object that will effectively take
114 // ownership of our currently console reports.
115 virtual void FlushConsoleReports(nsIConsoleReportCollector
* aCollector
) = 0;
117 // Clear all pending reports.
118 virtual void ClearConsoleReports() = 0;
121 NS_DEFINE_STATIC_IID_ACCESSOR(nsIConsoleReportCollector
,
122 NS_NSICONSOLEREPORTCOLLECTOR_IID
)
124 #endif // nsIConsoleReportCollector_h