[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
| 6 | #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/compiler_specific.h" |
| 12 | #include "base/logging.h" |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 14 | #include "base/strings/string16.h" |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 15 | #include "extensions/common/stack_frame.h" |
| 16 | #include "url/gurl.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 17 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 18 | namespace base { |
| 19 | class DictionaryValue; |
| 20 | } |
| 21 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 22 | namespace extensions { |
| 23 | |
| 24 | class ExtensionError { |
| 25 | public: |
| 26 | enum Type { |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 27 | MANIFEST_ERROR, |
[email protected] | 7a755d1 | 2014-04-18 18:54:55 | [diff] [blame] | 28 | RUNTIME_ERROR, |
| 29 | NUM_ERROR_TYPES // Put new values above this. |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | virtual ~ExtensionError(); |
| 33 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 34 | // Serializes the ExtensionError into JSON format. |
| 35 | virtual scoped_ptr<base::DictionaryValue> ToValue() const; |
| 36 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 37 | virtual std::string PrintForTest() const; |
| 38 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 39 | // Return true if this error and |rhs| are considered equal, and should be |
| 40 | // grouped together. |
| 41 | bool IsEqual(const ExtensionError* rhs) const; |
| 42 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 43 | Type type() const { return type_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 44 | const std::string& extension_id() const { return extension_id_; } |
| 45 | bool from_incognito() const { return from_incognito_; } |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 46 | logging::LogSeverity level() const { return level_; } |
| 47 | const base::string16& source() const { return source_; } |
| 48 | const base::string16& message() const { return message_; } |
| 49 | size_t occurrences() const { return occurrences_; } |
| 50 | void set_occurrences(size_t occurrences) { occurrences_ = occurrences; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 51 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 52 | // Keys used for retrieving JSON values. |
| 53 | static const char kExtensionIdKey[]; |
| 54 | static const char kFromIncognitoKey[]; |
| 55 | static const char kLevelKey[]; |
| 56 | static const char kMessageKey[]; |
| 57 | static const char kSourceKey[]; |
| 58 | static const char kTypeKey[]; |
| 59 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 60 | protected: |
| 61 | ExtensionError(Type type, |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 62 | const std::string& extension_id, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 63 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 64 | logging::LogSeverity level, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 65 | const base::string16& source, |
| 66 | const base::string16& message); |
| 67 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 68 | virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 69 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 70 | // Which type of error this is. |
| 71 | Type type_; |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 72 | // The ID of the extension which caused the error. |
| 73 | std::string extension_id_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 74 | // Whether or not the error was caused while incognito. |
| 75 | bool from_incognito_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 76 | // The severity level of the error. |
| 77 | logging::LogSeverity level_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 78 | // The source for the error; this can be a script, web page, or manifest file. |
| 79 | // This is stored as a string (rather than a url) since it can be a Chrome |
| 80 | // script file (e.g., event_bindings.js). |
| 81 | base::string16 source_; |
| 82 | // The error message itself. |
| 83 | base::string16 message_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 84 | // The number of times this error has occurred. |
| 85 | size_t occurrences_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 86 | |
[email protected] | 2919a5e | 2014-04-24 08:34:05 | [diff] [blame^] | 87 | private: |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 88 | DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
| 89 | }; |
| 90 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 91 | class ManifestError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 92 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 93 | ManifestError(const std::string& extension_id, |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 94 | const base::string16& message, |
| 95 | const base::string16& manifest_key, |
| 96 | const base::string16& manifest_specific); |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 97 | virtual ~ManifestError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 98 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 99 | virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE; |
| 100 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 101 | virtual std::string PrintForTest() const OVERRIDE; |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 102 | |
| 103 | const base::string16& manifest_key() const { return manifest_key_; } |
| 104 | const base::string16& manifest_specific() const { return manifest_specific_; } |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 105 | |
| 106 | // Keys used for retrieving JSON values. |
| 107 | static const char kManifestKeyKey[]; |
| 108 | static const char kManifestSpecificKey[]; |
| 109 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 110 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 111 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 112 | |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 113 | // If present, this indicates the feature in the manifest which caused the |
| 114 | // error. |
| 115 | base::string16 manifest_key_; |
| 116 | // If present, this is a more-specific location of the error - for instance, |
| 117 | // a specific permission which is incorrect, rather than simply "permissions". |
| 118 | base::string16 manifest_specific_; |
| 119 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 120 | DISALLOW_COPY_AND_ASSIGN(ManifestError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 121 | }; |
| 122 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 123 | class RuntimeError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 124 | public: |
[email protected] | a0ed268 | 2013-09-06 08:41:07 | [diff] [blame] | 125 | RuntimeError(const std::string& extension_id, // optional, sometimes unknown. |
| 126 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 127 | const base::string16& source, |
| 128 | const base::string16& message, |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 129 | const StackTrace& stack_trace, |
| 130 | const GURL& context_url, |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 131 | logging::LogSeverity level, |
| 132 | int render_view_id, |
| 133 | int render_process_id); |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 134 | virtual ~RuntimeError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 135 | |
[email protected] | 2fb9bd2 | 2013-09-07 00:08:08 | [diff] [blame] | 136 | virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE; |
| 137 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 138 | virtual std::string PrintForTest() const OVERRIDE; |
| 139 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 140 | const GURL& context_url() const { return context_url_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 141 | const StackTrace& stack_trace() const { return stack_trace_; } |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 142 | int render_view_id() const { return render_view_id_; } |
| 143 | int render_process_id() const { return render_process_id_; } |
[email protected] | 2fb9bd2 | 2013-09-07 00:08:08 | [diff] [blame] | 144 | |
| 145 | // Keys used for retrieving JSON values. |
| 146 | static const char kColumnNumberKey[]; |
| 147 | static const char kContextUrlKey[]; |
| 148 | static const char kFunctionNameKey[]; |
| 149 | static const char kLineNumberKey[]; |
| 150 | static const char kStackTraceKey[]; |
| 151 | static const char kUrlKey[]; |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 152 | static const char kRenderProcessIdKey[]; |
| 153 | static const char kRenderViewIdKey[]; |
[email protected] | 2fb9bd2 | 2013-09-07 00:08:08 | [diff] [blame] | 154 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 155 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 156 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 157 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 158 | // Since we piggy-back onto other error reporting systems (like V8 and |
| 159 | // WebKit), the reported information may need to be cleaned up in order to be |
| 160 | // in a consistent format. |
| 161 | void CleanUpInit(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 162 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 163 | GURL context_url_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 164 | StackTrace stack_trace_; |
| 165 | |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 166 | // Keep track of the render process which caused the error in order to |
| 167 | // inspect the view later, if possible. |
| 168 | int render_view_id_; |
| 169 | int render_process_id_; |
| 170 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 171 | DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | } // namespace extensions |
| 175 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 176 | #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |