Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: extensions/browser/extension_error.h

Issue 23311011: ErrorConsole Switch, Duplicate Error Detection, Dev Mode Check (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 bool IsEqual(const ExtensionError* rhs) const;
29
28 Type type() const { return type_; } 30 Type type() const { return type_; }
31 const std::string& extension_id() const { return extension_id_; }
32 bool from_incognito() const { return from_incognito_; }
33 logging::LogSeverity level() const { return level_; }
29 const base::string16& source() const { return source_; } 34 const base::string16& source() const { return source_; }
30 const base::string16& message() const { return message_; } 35 const base::string16& message() const { return message_; }
31 const std::string& extension_id() const { return extension_id_; }
32 bool from_incognito() const { return from_incognito_; }
33 36
34 protected: 37 protected:
35 ExtensionError(Type type, 38 ExtensionError(Type type,
36 const std::string& extension_id, 39 const std::string& extension_id,
37 bool from_incognito, 40 bool from_incognito,
41 logging::LogSeverity level,
38 const base::string16& source, 42 const base::string16& source,
39 const base::string16& message); 43 const base::string16& message);
40 44
45 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
46
41 // Which type of error this is. 47 // Which type of error this is.
42 Type type_; 48 Type type_;
43 // The ID of the extension which caused the error. 49 // The ID of the extension which caused the error.
44 std::string extension_id_; 50 std::string extension_id_;
45 // Whether or not the error was caused while incognito. 51 // Whether or not the error was caused while incognito.
46 bool from_incognito_; 52 bool from_incognito_;
53 // The severity level of the error.
54 logging::LogSeverity level_;
47 // The source for the error; this can be a script, web page, or manifest file. 55 // 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 56 // This is stored as a string (rather than a url) since it can be a Chrome
49 // script file (e.g., event_bindings.js). 57 // script file (e.g., event_bindings.js).
50 base::string16 source_; 58 base::string16 source_;
51 // The error message itself. 59 // The error message itself.
52 base::string16 message_; 60 base::string16 message_;
53 61
54 DISALLOW_COPY_AND_ASSIGN(ExtensionError); 62 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
55 }; 63 };
56 64
57 class ManifestParsingError : public ExtensionError { 65 class ManifestError : public ExtensionError {
58 public: 66 public:
59 ManifestParsingError(const std::string& extension_id, 67 ManifestError(const std::string& extension_id,
60 const base::string16& message); 68 const base::string16& message);
61 virtual ~ManifestParsingError(); 69 virtual ~ManifestError();
62 70
63 virtual std::string PrintForTest() const OVERRIDE; 71 virtual std::string PrintForTest() const OVERRIDE;
64 private: 72 private:
65 DISALLOW_COPY_AND_ASSIGN(ManifestParsingError); 73 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
74
75 DISALLOW_COPY_AND_ASSIGN(ManifestError);
66 }; 76 };
67 77
68 class JavascriptRuntimeError : public ExtensionError { 78 class RuntimeError : public ExtensionError {
69 public: 79 public:
70 struct StackFrame { 80 struct StackFrame {
71 size_t line_number; 81 size_t line_number;
72 size_t column_number; 82 size_t column_number;
73 // This is stored as a string (rather than a url) since it can be a 83 // This is stored as a string (rather than a url) since it can be a
74 // Chrome script file (e.g., event_bindings.js). 84 // Chrome script file (e.g., event_bindings.js).
75 base::string16 url; 85 base::string16 url;
76 base::string16 function; // optional 86 base::string16 function; // optional
77 87
78 // STL-Required constructor 88 // STL-Required constructor
79 StackFrame(); 89 StackFrame();
80 90
81 StackFrame(size_t frame_line, 91 StackFrame(size_t frame_line,
82 size_t frame_column, 92 size_t frame_column,
83 const base::string16& frame_url, 93 const base::string16& frame_url,
84 const base::string16& frame_function /* can be empty */); 94 const base::string16& frame_function /* can be empty */);
85 95
86 ~StackFrame(); 96 ~StackFrame();
97
98 bool operator==(const StackFrame& rhs) const;
87 }; 99 };
88 typedef std::vector<StackFrame> StackTrace; 100 typedef std::vector<StackFrame> StackTrace;
89 101
90 JavascriptRuntimeError(bool from_incognito, 102 RuntimeError(bool from_incognito,
91 const base::string16& source, 103 const base::string16& source,
92 const base::string16& message, 104 const base::string16& message,
93 logging::LogSeverity level, 105 logging::LogSeverity level,
94 const base::string16& details); 106 const base::string16& details);
95 virtual ~JavascriptRuntimeError(); 107 virtual ~RuntimeError();
96 108
97 virtual std::string PrintForTest() const OVERRIDE; 109 virtual std::string PrintForTest() const OVERRIDE;
98 110
99 logging::LogSeverity level() const { return level_; }
100 const base::string16& execution_context_url() const { 111 const base::string16& execution_context_url() const {
101 return execution_context_url_; 112 return execution_context_url_;
102 } 113 }
103 const StackTrace& stack_trace() const { return stack_trace_; } 114 const StackTrace& stack_trace() const { return stack_trace_; }
104 private: 115 private:
116 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
117
105 // Parse the JSON |details| passed to the error. This includes a stack trace 118 // Parse the JSON |details| passed to the error. This includes a stack trace
106 // and an execution context url. 119 // and an execution context url.
107 void ParseDetails(const base::string16& details); 120 void ParseDetails(const base::string16& details);
108 // Try to determine the ID of the extension. This may be obtained through the 121 // Try to determine the ID of the extension. This may be obtained through the
109 // reported source, or through the execution context url. 122 // reported source, or through the execution context url.
110 void DetermineExtensionID(); 123 void DetermineExtensionID();
111 124
112 logging::LogSeverity level_;
113 base::string16 execution_context_url_; 125 base::string16 execution_context_url_;
114 StackTrace stack_trace_; 126 StackTrace stack_trace_;
115 127
116 DISALLOW_COPY_AND_ASSIGN(JavascriptRuntimeError); 128 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
117 }; 129 };
118 130
119 } // namespace extensions 131 } // namespace extensions
120 132
121 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ 133 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698