blob: 9f331681136a759910527d551291c0e0034d746b [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]1b66fdb2013-07-26 09:57:2813#include "base/strings/string16.h"
[email protected]88b50b62013-09-01 23:05:0614#include "extensions/common/stack_frame.h"
15#include "url/gurl.h"
[email protected]1b66fdb2013-07-26 09:57:2816
[email protected]1b66fdb2013-07-26 09:57:2817namespace extensions {
18
19class ExtensionError {
20 public:
21 enum Type {
rdevlin.croninc799f9f2015-03-21 00:56:3022 MANIFEST_ERROR = 0,
[email protected]7a755d12014-04-18 18:54:5523 RUNTIME_ERROR,
wittmanb3ee0482015-06-24 17:47:4024 INTERNAL_ERROR,
rdevlin.croninc799f9f2015-03-21 00:56:3025 NUM_ERROR_TYPES, // Put new values above this.
[email protected]1b66fdb2013-07-26 09:57:2826 };
27
28 virtual ~ExtensionError();
29
wittmanb3ee0482015-06-24 17:47:4030 virtual std::string GetDebugString() const;
[email protected]1b66fdb2013-07-26 09:57:2831
[email protected]d466f782013-08-28 21:59:2332 // Return true if this error and |rhs| are considered equal, and should be
33 // grouped together.
34 bool IsEqual(const ExtensionError* rhs) const;
35
[email protected]1b66fdb2013-07-26 09:57:2836 Type type() const { return type_; }
[email protected]1b66fdb2013-07-26 09:57:2837 const std::string& extension_id() const { return extension_id_; }
rdevlin.croninc799f9f2015-03-21 00:56:3038 int id() const { return id_; }
39 void set_id(int id) { id_ = id; }
[email protected]1b66fdb2013-07-26 09:57:2840 bool from_incognito() const { return from_incognito_; }
[email protected]d466f782013-08-28 21:59:2341 logging::LogSeverity level() const { return level_; }
42 const base::string16& source() const { return source_; }
43 const base::string16& message() const { return message_; }
44 size_t occurrences() const { return occurrences_; }
45 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; }
[email protected]1b66fdb2013-07-26 09:57:2846
[email protected]1b66fdb2013-07-26 09:57:2847 protected:
48 ExtensionError(Type type,
[email protected]921237d062013-08-10 15:30:4949 const std::string& extension_id,
[email protected]1b66fdb2013-07-26 09:57:2850 bool from_incognito,
[email protected]d466f782013-08-28 21:59:2351 logging::LogSeverity level,
[email protected]1b66fdb2013-07-26 09:57:2852 const base::string16& source,
53 const base::string16& message);
54
[email protected]d466f782013-08-28 21:59:2355 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
56
[email protected]1b66fdb2013-07-26 09:57:2857 // Which type of error this is.
58 Type type_;
[email protected]921237d062013-08-10 15:30:4959 // The ID of the extension which caused the error.
60 std::string extension_id_;
rdevlin.croninc799f9f2015-03-21 00:56:3061 // The id of this particular error. This can be zero if the id is never set.
62 int id_;
[email protected]1b66fdb2013-07-26 09:57:2863 // Whether or not the error was caused while incognito.
64 bool from_incognito_;
[email protected]d466f782013-08-28 21:59:2365 // The severity level of the error.
66 logging::LogSeverity level_;
[email protected]1b66fdb2013-07-26 09:57:2867 // The source for the error; this can be a script, web page, or manifest file.
68 // This is stored as a string (rather than a url) since it can be a Chrome
69 // script file (e.g., event_bindings.js).
70 base::string16 source_;
71 // The error message itself.
72 base::string16 message_;
[email protected]d466f782013-08-28 21:59:2373 // The number of times this error has occurred.
74 size_t occurrences_;
[email protected]1b66fdb2013-07-26 09:57:2875
[email protected]2919a5e2014-04-24 08:34:0576 private:
[email protected]1b66fdb2013-07-26 09:57:2877 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
78};
79
[email protected]d466f782013-08-28 21:59:2380class ManifestError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2881 public:
[email protected]d466f782013-08-28 21:59:2382 ManifestError(const std::string& extension_id,
[email protected]b191e2d32013-09-03 21:08:3083 const base::string16& message,
84 const base::string16& manifest_key,
85 const base::string16& manifest_specific);
dcheng9168b2f2014-10-21 12:38:2486 ~ManifestError() override;
[email protected]1b66fdb2013-07-26 09:57:2887
wittmanb3ee0482015-06-24 17:47:4088 std::string GetDebugString() const override;
[email protected]b191e2d32013-09-03 21:08:3089
90 const base::string16& manifest_key() const { return manifest_key_; }
91 const base::string16& manifest_specific() const { return manifest_specific_; }
[email protected]fa5fed32013-09-05 21:56:2292
[email protected]1b66fdb2013-07-26 09:57:2893 private:
dcheng9168b2f2014-10-21 12:38:2494 bool IsEqualImpl(const ExtensionError* rhs) const override;
[email protected]d466f782013-08-28 21:59:2395
[email protected]b191e2d32013-09-03 21:08:3096 // If present, this indicates the feature in the manifest which caused the
97 // error.
98 base::string16 manifest_key_;
99 // If present, this is a more-specific location of the error - for instance,
100 // a specific permission which is incorrect, rather than simply "permissions".
101 base::string16 manifest_specific_;
102
[email protected]d466f782013-08-28 21:59:23103 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:28104};
105
[email protected]d466f782013-08-28 21:59:23106class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:28107 public:
[email protected]a0ed2682013-09-06 08:41:07108 RuntimeError(const std::string& extension_id, // optional, sometimes unknown.
109 bool from_incognito,
[email protected]d466f782013-08-28 21:59:23110 const base::string16& source,
111 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:06112 const StackTrace& stack_trace,
113 const GURL& context_url,
[email protected]c934c382013-11-01 00:36:01114 logging::LogSeverity level,
115 int render_view_id,
116 int render_process_id);
dcheng9168b2f2014-10-21 12:38:24117 ~RuntimeError() override;
[email protected]1b66fdb2013-07-26 09:57:28118
wittmanb3ee0482015-06-24 17:47:40119 std::string GetDebugString() const override;
[email protected]1b66fdb2013-07-26 09:57:28120
[email protected]88b50b62013-09-01 23:05:06121 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:28122 const StackTrace& stack_trace() const { return stack_trace_; }
rdevlin.cronin86f5b702015-06-24 18:49:17123 int render_frame_id() const { return render_frame_id_; }
[email protected]c934c382013-11-01 00:36:01124 int render_process_id() const { return render_process_id_; }
[email protected]2fb9bd22013-09-07 00:08:08125
[email protected]1b66fdb2013-07-26 09:57:28126 private:
dcheng9168b2f2014-10-21 12:38:24127 bool IsEqualImpl(const ExtensionError* rhs) const override;
[email protected]d466f782013-08-28 21:59:23128
[email protected]88b50b62013-09-01 23:05:06129 // Since we piggy-back onto other error reporting systems (like V8 and
130 // WebKit), the reported information may need to be cleaned up in order to be
131 // in a consistent format.
132 void CleanUpInit();
[email protected]1b66fdb2013-07-26 09:57:28133
[email protected]88b50b62013-09-01 23:05:06134 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28135 StackTrace stack_trace_;
136
[email protected]c934c382013-11-01 00:36:01137 // Keep track of the render process which caused the error in order to
rdevlin.cronin86f5b702015-06-24 18:49:17138 // inspect the frame later, if possible.
139 int render_frame_id_;
[email protected]c934c382013-11-01 00:36:01140 int render_process_id_;
141
[email protected]d466f782013-08-28 21:59:23142 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28143};
144
wittmanb3ee0482015-06-24 17:47:40145class InternalError : public ExtensionError {
146 public:
147 InternalError(const std::string& extension_id,
148 const base::string16& message,
149 logging::LogSeverity level);
150 ~InternalError() override;
151
152 std::string GetDebugString() const override;
153
154 private:
155 bool IsEqualImpl(const ExtensionError* rhs) const override;
156
157 DISALLOW_COPY_AND_ASSIGN(InternalError);
158};
159
[email protected]1b66fdb2013-07-26 09:57:28160} // namespace extensions
161
[email protected]921237d062013-08-10 15:30:49162#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_