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