blob: 7e02bb33f89e18da20ddf1d696d911fcde973559 [file] [log] [blame]
[email protected]1b66fdb2013-07-26 09:57:281// 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]921237d062013-08-10 15:30:495#ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
6#define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
[email protected]1b66fdb2013-07-26 09:57:287
8#include <string>
9#include <vector>
10
11#include "base/compiler_specific.h"
12#include "base/logging.h"
[email protected]fa5fed32013-09-05 21:56:2213#include "base/memory/scoped_ptr.h"
[email protected]1b66fdb2013-07-26 09:57:2814#include "base/strings/string16.h"
[email protected]88b50b62013-09-01 23:05:0615#include "extensions/common/stack_frame.h"
16#include "url/gurl.h"
[email protected]1b66fdb2013-07-26 09:57:2817
[email protected]fa5fed32013-09-05 21:56:2218namespace base {
19class DictionaryValue;
20}
21
[email protected]1b66fdb2013-07-26 09:57:2822namespace extensions {
23
24class ExtensionError {
25 public:
26 enum Type {
[email protected]d466f782013-08-28 21:59:2327 MANIFEST_ERROR,
28 RUNTIME_ERROR
[email protected]1b66fdb2013-07-26 09:57:2829 };
30
31 virtual ~ExtensionError();
32
[email protected]fa5fed32013-09-05 21:56:2233 // Serializes the ExtensionError into JSON format.
34 virtual scoped_ptr<base::DictionaryValue> ToValue() const;
35
[email protected]1b66fdb2013-07-26 09:57:2836 virtual std::string PrintForTest() const;
37
[email protected]d466f782013-08-28 21:59:2338 // 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]1b66fdb2013-07-26 09:57:2842 Type type() const { return type_; }
[email protected]1b66fdb2013-07-26 09:57:2843 const std::string& extension_id() const { return extension_id_; }
44 bool from_incognito() const { return from_incognito_; }
[email protected]d466f782013-08-28 21:59:2345 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]1b66fdb2013-07-26 09:57:2850
[email protected]fa5fed32013-09-05 21:56:2251 // 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]1b66fdb2013-07-26 09:57:2859 protected:
60 ExtensionError(Type type,
[email protected]921237d062013-08-10 15:30:4961 const std::string& extension_id,
[email protected]1b66fdb2013-07-26 09:57:2862 bool from_incognito,
[email protected]d466f782013-08-28 21:59:2363 logging::LogSeverity level,
[email protected]1b66fdb2013-07-26 09:57:2864 const base::string16& source,
65 const base::string16& message);
66
[email protected]d466f782013-08-28 21:59:2367 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
68
[email protected]1b66fdb2013-07-26 09:57:2869 // Which type of error this is.
70 Type type_;
[email protected]921237d062013-08-10 15:30:4971 // The ID of the extension which caused the error.
72 std::string extension_id_;
[email protected]1b66fdb2013-07-26 09:57:2873 // Whether or not the error was caused while incognito.
74 bool from_incognito_;
[email protected]d466f782013-08-28 21:59:2375 // The severity level of the error.
76 logging::LogSeverity level_;
[email protected]1b66fdb2013-07-26 09:57:2877 // 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]d466f782013-08-28 21:59:2383 // The number of times this error has occurred.
84 size_t occurrences_;
[email protected]1b66fdb2013-07-26 09:57:2885
86 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
87};
88
[email protected]d466f782013-08-28 21:59:2389class ManifestError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2890 public:
[email protected]d466f782013-08-28 21:59:2391 ManifestError(const std::string& extension_id,
[email protected]b191e2d32013-09-03 21:08:3092 const base::string16& message,
93 const base::string16& manifest_key,
94 const base::string16& manifest_specific);
[email protected]d466f782013-08-28 21:59:2395 virtual ~ManifestError();
[email protected]1b66fdb2013-07-26 09:57:2896
[email protected]fa5fed32013-09-05 21:56:2297 virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE;
98
[email protected]1b66fdb2013-07-26 09:57:2899 virtual std::string PrintForTest() const OVERRIDE;
[email protected]b191e2d32013-09-03 21:08:30100
101 const base::string16& manifest_key() const { return manifest_key_; }
102 const base::string16& manifest_specific() const { return manifest_specific_; }
[email protected]fa5fed32013-09-05 21:56:22103
104 // Keys used for retrieving JSON values.
105 static const char kManifestKeyKey[];
106 static const char kManifestSpecificKey[];
107
[email protected]1b66fdb2013-07-26 09:57:28108 private:
[email protected]d466f782013-08-28 21:59:23109 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
110
[email protected]b191e2d32013-09-03 21:08:30111 // 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]d466f782013-08-28 21:59:23118 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:28119};
120
[email protected]d466f782013-08-28 21:59:23121class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:28122 public:
[email protected]d466f782013-08-28 21:59:23123 RuntimeError(bool from_incognito,
124 const base::string16& source,
125 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:06126 const StackTrace& stack_trace,
127 const GURL& context_url,
128 logging::LogSeverity level);
[email protected]d466f782013-08-28 21:59:23129 virtual ~RuntimeError();
[email protected]1b66fdb2013-07-26 09:57:28130
131 virtual std::string PrintForTest() const OVERRIDE;
132
[email protected]88b50b62013-09-01 23:05:06133 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:28134 const StackTrace& stack_trace() const { return stack_trace_; }
135 private:
[email protected]d466f782013-08-28 21:59:23136 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
137
[email protected]88b50b62013-09-01 23:05:06138 // 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]1b66fdb2013-07-26 09:57:28142
[email protected]88b50b62013-09-01 23:05:06143 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28144 StackTrace stack_trace_;
145
[email protected]d466f782013-08-28 21:59:23146 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28147};
148
149} // namespace extensions
150
[email protected]921237d062013-08-10 15:30:49151#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_