Line data Source code
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 "nsTArrayForwardDeclare.h"
13 :
14 : class nsACString;
15 : class nsIDocument;
16 : class nsString;
17 :
18 : #define NS_NSICONSOLEREPORTCOLLECTOR_IID \
19 : {0xdd98a481, 0xd2c4, 0x4203, {0x8d, 0xfa, 0x85, 0xbf, 0xd7, 0xdc, 0xd7, 0x05}}
20 :
21 : // An interface for saving reports until we can flush them to the correct
22 : // window at a later time.
23 139 : class NS_NO_VTABLE nsIConsoleReportCollector : public nsISupports
24 : {
25 : public:
26 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_NSICONSOLEREPORTCOLLECTOR_IID)
27 :
28 : // Add a pending report to be later displayed on the console. This may be
29 : // called from any thread.
30 : //
31 : // aErrorFlags A nsIScriptError flags value.
32 : // aCategory Name of module reporting error.
33 : // aPropertiesFile Properties file containing localized message.
34 : // aSourceFileURI The URI of the script generating the error. Must be a URI
35 : // spec.
36 : // aLineNumber The line number where the error was generated. May be 0 if
37 : // the line number is not known.
38 : // aColumnNumber The column number where the error was generated. May be 0
39 : // if the line number is not known.
40 : // aMessageName The name of the localized message contained in the
41 : // properties file.
42 : // aStringParams An array of nsString parameters to use when localizing the
43 : // message.
44 : virtual void
45 : AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory,
46 : nsContentUtils::PropertiesFile aPropertiesFile,
47 : const nsACString& aSourceFileURI, uint32_t aLineNumber,
48 : uint32_t aColumnNumber, const nsACString& aMessageName,
49 : const nsTArray<nsString>& aStringParams) = 0;
50 :
51 : // A version of AddConsoleReport() that accepts the message parameters
52 : // as variable nsString arguments (or really, any sort of const nsAString).
53 : // All other args the same as AddConsoleReport().
54 : template<typename... Params>
55 : void
56 : AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory,
57 : nsContentUtils::PropertiesFile aPropertiesFile,
58 : const nsACString& aSourceFileURI, uint32_t aLineNumber,
59 : uint32_t aColumnNumber, const nsACString& aMessageName,
60 : Params&&... aParams)
61 : {
62 : nsTArray<nsString> params;
63 : mozilla::dom::StringArrayAppender::Append(params, sizeof...(Params),
64 : mozilla::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 {
73 : Forget,
74 : Save
75 : };
76 :
77 : // Flush all pending reports to the console. May be called from any thread.
78 : //
79 : // aInnerWindowID A inner window ID representing where to flush the reports.
80 : // aAction An action to determine whether to reserve the pending
81 : // reports. Defalut action is to forget the report.
82 : virtual void
83 : FlushReportsToConsole(uint64_t aInnerWindowID,
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
95 : FlushConsoleReports(nsIDocument* 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
107 : FlushConsoleReports(nsILoadGroup* aLoadGroup,
108 : ReportAction aAction = ReportAction::Forget) = 0;
109 :
110 :
111 : // Flush all pending reports to another collector. May be called from any
112 : // thread.
113 : //
114 : // aCollector A required collector object that will effectively take
115 : // ownership of our currently console reports.
116 : virtual void
117 : FlushConsoleReports(nsIConsoleReportCollector* aCollector) = 0;
118 :
119 : // Clear all pending reports.
120 : virtual void
121 : ClearConsoleReports() = 0;
122 : };
123 :
124 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIConsoleReportCollector, NS_NSICONSOLEREPORTCOLLECTOR_IID)
125 :
126 : #endif // nsIConsoleReportCollector_h
|