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

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

Issue 22647007: Resubmit 21609003: Move ExtensionError to extensions/, add error limits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
(Empty)
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
5 #ifndef CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_EXTENSION_ERROR_H_
6 #define CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_EXTENSION_ERROR_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14
15 namespace extensions {
16
17 class ExtensionError {
18 public:
19 enum Type {
20 MANIFEST_PARSING_ERROR,
21 JAVASCRIPT_RUNTIME_ERROR
22 };
23
24 virtual ~ExtensionError();
25
26 virtual std::string PrintForTest() const;
27
28 Type type() const { return type_; }
29 const base::string16& source() const { return source_; }
30 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
34 protected:
35 ExtensionError(Type type,
36 bool from_incognito,
37 const base::string16& source,
38 const base::string16& message);
39
40 // Which type of error this is.
41 Type type_;
42 // Whether or not the error was caused while incognito.
43 bool from_incognito_;
44 // The source for the error; this can be a script, web page, or manifest file.
45 // This is stored as a string (rather than a url) since it can be a Chrome
46 // script file (e.g., event_bindings.js).
47 base::string16 source_;
48 // The error message itself.
49 base::string16 message_;
50 // The ID of the extension which caused the error. This may be absent, since
51 // we can't always know the id (such as when a manifest fails to parse).
52 std::string extension_id_;
53
54 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
55 };
56
57 class ManifestParsingError : public ExtensionError {
58 public:
59 ManifestParsingError(bool from_incognito,
60 const base::string16& source,
61 const base::string16& message,
62 size_t line_number);
63 virtual ~ManifestParsingError();
64
65 virtual std::string PrintForTest() const OVERRIDE;
66
67 size_t line_number() const { return line_number_; }
68 private:
69 size_t line_number_;
70
71 DISALLOW_COPY_AND_ASSIGN(ManifestParsingError);
72 };
73
74 class JavascriptRuntimeError : public ExtensionError {
75 public:
76 struct StackFrame {
77 size_t line_number;
78 size_t column_number;
79 // This is stored as a string (rather than a url) since it can be a
80 // Chrome script file (e.g., event_bindings.js).
81 base::string16 url;
82 base::string16 function; // optional
83
84 // STL-Required constructor
85 StackFrame();
86
87 StackFrame(size_t frame_line,
88 size_t frame_column,
89 const base::string16& frame_url,
90 const base::string16& frame_function /* can be empty */);
91
92 ~StackFrame();
93 };
94 typedef std::vector<StackFrame> StackTrace;
95
96 JavascriptRuntimeError(bool from_incognito,
97 const base::string16& source,
98 const base::string16& message,
99 logging::LogSeverity level,
100 const base::string16& details);
101 virtual ~JavascriptRuntimeError();
102
103 virtual std::string PrintForTest() const OVERRIDE;
104
105 logging::LogSeverity level() const { return level_; }
106 const base::string16& execution_context_url() const {
107 return execution_context_url_;
108 }
109 const StackTrace& stack_trace() const { return stack_trace_; }
110 private:
111 // Parse the JSON |details| passed to the error. This includes a stack trace
112 // and an execution context url.
113 void ParseDetails(const base::string16& details);
114 // Try to determine the ID of the extension. This may be obtained through the
115 // reported source, or through the execution context url.
116 void DetermineExtensionID();
117
118 logging::LogSeverity level_;
119 base::string16 execution_context_url_;
120 StackTrace stack_trace_;
121
122 DISALLOW_COPY_AND_ASSIGN(JavascriptRuntimeError);
123 };
124
125 } // namespace extensions
126
127 #endif // CHROME_BROWSER_EXTENSIONS_ERROR_CONSOLE_EXTENSION_ERROR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698