[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, |
| 28 | RUNTIME_ERROR |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | virtual ~ExtensionError(); |
| 32 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame^] | 33 | // Serializes the ExtensionError into JSON format. |
| 34 | virtual scoped_ptr<base::DictionaryValue> ToValue() const; |
| 35 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 36 | virtual std::string PrintForTest() const; |
| 37 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 38 | // Return true if this error and |rhs| are considered equal, and should be |
| 39 | // grouped together. |
| 40 | bool IsEqual(const ExtensionError* rhs) const; |
| 41 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 42 | Type type() const { return type_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 43 | const std::string& extension_id() const { return extension_id_; } |
| 44 | bool from_incognito() const { return from_incognito_; } |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 45 | logging::LogSeverity level() const { return level_; } |
| 46 | const base::string16& source() const { return source_; } |
| 47 | const base::string16& message() const { return message_; } |
| 48 | size_t occurrences() const { return occurrences_; } |
| 49 | void set_occurrences(size_t occurrences) { occurrences_ = occurrences; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 50 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame^] | 51 | // Keys used for retrieving JSON values. |
| 52 | static const char kExtensionIdKey[]; |
| 53 | static const char kFromIncognitoKey[]; |
| 54 | static const char kLevelKey[]; |
| 55 | static const char kMessageKey[]; |
| 56 | static const char kSourceKey[]; |
| 57 | static const char kTypeKey[]; |
| 58 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 59 | protected: |
| 60 | ExtensionError(Type type, |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 61 | const std::string& extension_id, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 62 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 63 | logging::LogSeverity level, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 64 | const base::string16& source, |
| 65 | const base::string16& message); |
| 66 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 67 | virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 68 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 69 | // Which type of error this is. |
| 70 | Type type_; |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 71 | // The ID of the extension which caused the error. |
| 72 | std::string extension_id_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 73 | // Whether or not the error was caused while incognito. |
| 74 | bool from_incognito_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 75 | // The severity level of the error. |
| 76 | logging::LogSeverity level_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 77 | // The source for the error; this can be a script, web page, or manifest file. |
| 78 | // This is stored as a string (rather than a url) since it can be a Chrome |
| 79 | // script file (e.g., event_bindings.js). |
| 80 | base::string16 source_; |
| 81 | // The error message itself. |
| 82 | base::string16 message_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 83 | // The number of times this error has occurred. |
| 84 | size_t occurrences_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
| 87 | }; |
| 88 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 89 | class ManifestError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 90 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 91 | ManifestError(const std::string& extension_id, |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 92 | const base::string16& message, |
| 93 | const base::string16& manifest_key, |
| 94 | const base::string16& manifest_specific); |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 95 | virtual ~ManifestError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 96 | |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame^] | 97 | virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE; |
| 98 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 99 | virtual std::string PrintForTest() const OVERRIDE; |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 100 | |
| 101 | const base::string16& manifest_key() const { return manifest_key_; } |
| 102 | const base::string16& manifest_specific() const { return manifest_specific_; } |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame^] | 103 | |
| 104 | // Keys used for retrieving JSON values. |
| 105 | static const char kManifestKeyKey[]; |
| 106 | static const char kManifestSpecificKey[]; |
| 107 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 108 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 109 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 110 | |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 111 | // If present, this indicates the feature in the manifest which caused the |
| 112 | // error. |
| 113 | base::string16 manifest_key_; |
| 114 | // If present, this is a more-specific location of the error - for instance, |
| 115 | // a specific permission which is incorrect, rather than simply "permissions". |
| 116 | base::string16 manifest_specific_; |
| 117 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 118 | DISALLOW_COPY_AND_ASSIGN(ManifestError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 119 | }; |
| 120 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 121 | class RuntimeError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 122 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 123 | RuntimeError(bool from_incognito, |
| 124 | const base::string16& source, |
| 125 | const base::string16& message, |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 126 | const StackTrace& stack_trace, |
| 127 | const GURL& context_url, |
| 128 | logging::LogSeverity level); |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 129 | virtual ~RuntimeError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 130 | |
| 131 | virtual std::string PrintForTest() const OVERRIDE; |
| 132 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 133 | const GURL& context_url() const { return context_url_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 134 | const StackTrace& stack_trace() const { return stack_trace_; } |
| 135 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 136 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 137 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 138 | // Since we piggy-back onto other error reporting systems (like V8 and |
| 139 | // WebKit), the reported information may need to be cleaned up in order to be |
| 140 | // in a consistent format. |
| 141 | void CleanUpInit(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 142 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 143 | GURL context_url_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 144 | StackTrace stack_trace_; |
| 145 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 146 | DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | } // namespace extensions |
| 150 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 151 | #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |