OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 class ExtensionError { | 17 class ExtensionError { |
18 public: | 18 public: |
19 enum Type { | 19 enum Type { |
20 MANIFEST_PARSING_ERROR, | 20 MANIFEST_ERROR, |
21 JAVASCRIPT_RUNTIME_ERROR | 21 RUNTIME_ERROR |
22 }; | 22 }; |
23 | 23 |
24 virtual ~ExtensionError(); | 24 virtual ~ExtensionError(); |
25 | 25 |
26 virtual std::string PrintForTest() const; | 26 virtual std::string PrintForTest() const; |
27 | 27 |
| 28 // Return true if this error and |rhs| are considered equal, and should be |
| 29 // grouped together. |
| 30 bool IsEqual(const ExtensionError* rhs) const; |
| 31 |
28 Type type() const { return type_; } | 32 Type type() const { return type_; } |
| 33 const std::string& extension_id() const { return extension_id_; } |
| 34 bool from_incognito() const { return from_incognito_; } |
| 35 logging::LogSeverity level() const { return level_; } |
29 const base::string16& source() const { return source_; } | 36 const base::string16& source() const { return source_; } |
30 const base::string16& message() const { return message_; } | 37 const base::string16& message() const { return message_; } |
31 const std::string& extension_id() const { return extension_id_; } | 38 size_t occurrences() const { return occurrences_; } |
32 bool from_incognito() const { return from_incognito_; } | 39 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; } |
33 | 40 |
34 protected: | 41 protected: |
35 ExtensionError(Type type, | 42 ExtensionError(Type type, |
36 const std::string& extension_id, | 43 const std::string& extension_id, |
37 bool from_incognito, | 44 bool from_incognito, |
| 45 logging::LogSeverity level, |
38 const base::string16& source, | 46 const base::string16& source, |
39 const base::string16& message); | 47 const base::string16& message); |
40 | 48 |
| 49 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 50 |
41 // Which type of error this is. | 51 // Which type of error this is. |
42 Type type_; | 52 Type type_; |
43 // The ID of the extension which caused the error. | 53 // The ID of the extension which caused the error. |
44 std::string extension_id_; | 54 std::string extension_id_; |
45 // Whether or not the error was caused while incognito. | 55 // Whether or not the error was caused while incognito. |
46 bool from_incognito_; | 56 bool from_incognito_; |
| 57 // The severity level of the error. |
| 58 logging::LogSeverity level_; |
47 // The source for the error; this can be a script, web page, or manifest file. | 59 // The source for the error; this can be a script, web page, or manifest file. |
48 // This is stored as a string (rather than a url) since it can be a Chrome | 60 // This is stored as a string (rather than a url) since it can be a Chrome |
49 // script file (e.g., event_bindings.js). | 61 // script file (e.g., event_bindings.js). |
50 base::string16 source_; | 62 base::string16 source_; |
51 // The error message itself. | 63 // The error message itself. |
52 base::string16 message_; | 64 base::string16 message_; |
| 65 // The number of times this error has occurred. |
| 66 size_t occurrences_; |
53 | 67 |
54 DISALLOW_COPY_AND_ASSIGN(ExtensionError); | 68 DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
55 }; | 69 }; |
56 | 70 |
57 class ManifestParsingError : public ExtensionError { | 71 class ManifestError : public ExtensionError { |
58 public: | 72 public: |
59 ManifestParsingError(const std::string& extension_id, | 73 ManifestError(const std::string& extension_id, |
60 const base::string16& message); | 74 const base::string16& message); |
61 virtual ~ManifestParsingError(); | 75 virtual ~ManifestError(); |
62 | 76 |
63 virtual std::string PrintForTest() const OVERRIDE; | 77 virtual std::string PrintForTest() const OVERRIDE; |
64 private: | 78 private: |
65 DISALLOW_COPY_AND_ASSIGN(ManifestParsingError); | 79 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(ManifestError); |
66 }; | 82 }; |
67 | 83 |
68 class JavascriptRuntimeError : public ExtensionError { | 84 class RuntimeError : public ExtensionError { |
69 public: | 85 public: |
70 struct StackFrame { | 86 struct StackFrame { |
71 size_t line_number; | 87 size_t line_number; |
72 size_t column_number; | 88 size_t column_number; |
73 // This is stored as a string (rather than a url) since it can be a | 89 // This is stored as a string (rather than a url) since it can be a |
74 // Chrome script file (e.g., event_bindings.js). | 90 // Chrome script file (e.g., event_bindings.js). |
75 base::string16 url; | 91 base::string16 url; |
76 base::string16 function; // optional | 92 base::string16 function; // optional |
77 | 93 |
78 // STL-Required constructor | 94 // STL-Required constructor |
79 StackFrame(); | 95 StackFrame(); |
80 | 96 |
81 StackFrame(size_t frame_line, | 97 StackFrame(size_t frame_line, |
82 size_t frame_column, | 98 size_t frame_column, |
83 const base::string16& frame_url, | 99 const base::string16& frame_url, |
84 const base::string16& frame_function /* can be empty */); | 100 const base::string16& frame_function /* can be empty */); |
85 | 101 |
86 ~StackFrame(); | 102 ~StackFrame(); |
| 103 |
| 104 bool operator==(const StackFrame& rhs) const; |
87 }; | 105 }; |
88 typedef std::vector<StackFrame> StackTrace; | 106 typedef std::vector<StackFrame> StackTrace; |
89 | 107 |
90 JavascriptRuntimeError(bool from_incognito, | 108 RuntimeError(bool from_incognito, |
91 const base::string16& source, | 109 const base::string16& source, |
92 const base::string16& message, | 110 const base::string16& message, |
93 logging::LogSeverity level, | 111 logging::LogSeverity level, |
94 const base::string16& details); | 112 const base::string16& details); |
95 virtual ~JavascriptRuntimeError(); | 113 virtual ~RuntimeError(); |
96 | 114 |
97 virtual std::string PrintForTest() const OVERRIDE; | 115 virtual std::string PrintForTest() const OVERRIDE; |
98 | 116 |
99 logging::LogSeverity level() const { return level_; } | |
100 const base::string16& execution_context_url() const { | 117 const base::string16& execution_context_url() const { |
101 return execution_context_url_; | 118 return execution_context_url_; |
102 } | 119 } |
103 const StackTrace& stack_trace() const { return stack_trace_; } | 120 const StackTrace& stack_trace() const { return stack_trace_; } |
104 private: | 121 private: |
| 122 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 123 |
105 // Parse the JSON |details| passed to the error. This includes a stack trace | 124 // Parse the JSON |details| passed to the error. This includes a stack trace |
106 // and an execution context url. | 125 // and an execution context url. |
107 void ParseDetails(const base::string16& details); | 126 void ParseDetails(const base::string16& details); |
108 // Try to determine the ID of the extension. This may be obtained through the | 127 // Try to determine the ID of the extension. This may be obtained through the |
109 // reported source, or through the execution context url. | 128 // reported source, or through the execution context url. |
110 void DetermineExtensionID(); | 129 void DetermineExtensionID(); |
111 | 130 |
112 logging::LogSeverity level_; | |
113 base::string16 execution_context_url_; | 131 base::string16 execution_context_url_; |
114 StackTrace stack_trace_; | 132 StackTrace stack_trace_; |
115 | 133 |
116 DISALLOW_COPY_AND_ASSIGN(JavascriptRuntimeError); | 134 DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
117 }; | 135 }; |
118 | 136 |
119 } // namespace extensions | 137 } // namespace extensions |
120 | 138 |
121 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 139 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
OLD | NEW |