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 /* diagnostic reporting for CSS style sheet parser */
8 
9 #ifndef mozilla_css_ErrorReporter_h_
10 #define mozilla_css_ErrorReporter_h_
11 
12 #include "nsString.h"
13 
14 struct nsCSSToken;
15 class nsIURI;
16 
17 namespace mozilla {
18 class StyleSheet;
19 
20 namespace dom {
21 class Document;
22 }
23 
24 namespace css {
25 
26 class Loader;
27 
28 // FIXME(emilio): Probably better to call this ErrorBuilder or something?
29 class MOZ_STACK_CLASS ErrorReporter final {
30  public:
31   explicit ErrorReporter(uint64_t aInnerWindowId);
32   ~ErrorReporter();
33 
34   static void ReleaseGlobals();
EnsureGlobalsInitialized()35   static void EnsureGlobalsInitialized() {
36     if (MOZ_UNLIKELY(!sInitialized)) {
37       InitGlobals();
38     }
39   }
40 
41   static bool ShouldReportErrors(const dom::Document&);
42   static bool ShouldReportErrors(const StyleSheet*, const Loader*);
43   static uint64_t FindInnerWindowId(const StyleSheet*, const Loader*);
44 
45   void OutputError(const nsACString& aSource, const nsACString& aSelectors,
46                    uint32_t aLineNumber, uint32_t aColNumber, nsIURI* aURI);
47   void ClearError();
48 
49   // In all overloads of ReportUnexpected, aMessage is a stringbundle
50   // name, which will be processed as a format string with the
51   // indicated number of parameters.
52 
53   // no parameters
54   void ReportUnexpected(const char* aMessage);
55   // one parameter which has already been escaped appropriately
56   void ReportUnexpectedUnescaped(const char* aMessage,
57                                  const nsTArray<nsString>& aParam);
58 
59  private:
60   void AddToError(const nsString& aErrorText);
61   static void InitGlobals();
62 
63   static bool sInitialized;
64   static bool sReportErrors;
65 
66   nsString mError;
67   const uint64_t mInnerWindowId;
68 };
69 
70 }  // namespace css
71 }  // namespace mozilla
72 
73 #endif  // mozilla_css_ErrorReporter_h_
74