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

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

Issue 23624002: Add UI for RuntimeErrors in the ErrorConsole (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_merge
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 #include "extensions/browser/extension_error.h" 5 #include "extensions/browser/extension_error.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return ExtensionError::PrintForTest() + 113 return ExtensionError::PrintForTest() +
114 "\n Type: ManifestError"; 114 "\n Type: ManifestError";
115 } 115 }
116 116
117 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const { 117 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const {
118 // If two manifest errors have the same extension id and message (which are 118 // If two manifest errors have the same extension id and message (which are
119 // both checked in ExtensionError::IsEqual), then they are equal. 119 // both checked in ExtensionError::IsEqual), then they are equal.
120 return true; 120 return true;
121 } 121 }
122 122
123 ////////////////////////////////////////////////////////////////////////////////
124 // RuntimeError
125
126 // Static JSON keys.
127 const char RuntimeError::kColumnNumberKey[] = "columnNumber";
128 const char RuntimeError::kContextUrlKey[] = "contextUrl";
129 const char RuntimeError::kFunctionNameKey[] = "functionName";
130 const char RuntimeError::kLineNumberKey[] = "lineNumber";
131 const char RuntimeError::kStackTraceKey[] = "stackTrace";
132 const char RuntimeError::kUrlKey[] = "url";
133
123 RuntimeError::RuntimeError(const std::string& extension_id, 134 RuntimeError::RuntimeError(const std::string& extension_id,
124 bool from_incognito, 135 bool from_incognito,
125 const string16& source, 136 const string16& source,
126 const string16& message, 137 const string16& message,
127 const StackTrace& stack_trace, 138 const StackTrace& stack_trace,
128 const GURL& context_url, 139 const GURL& context_url,
129 logging::LogSeverity level) 140 logging::LogSeverity level)
130 : ExtensionError(ExtensionError::RUNTIME_ERROR, 141 : ExtensionError(ExtensionError::RUNTIME_ERROR,
131 !extension_id.empty() ? extension_id : GURL(source).host(), 142 !extension_id.empty() ? extension_id : GURL(source).host(),
132 from_incognito, 143 from_incognito,
133 level, 144 level,
134 source, 145 source,
135 message), 146 message),
136 context_url_(context_url), 147 context_url_(context_url),
137 stack_trace_(stack_trace) { 148 stack_trace_(stack_trace) {
138 CleanUpInit(); 149 CleanUpInit();
139 } 150 }
140 151
141 RuntimeError::~RuntimeError() { 152 RuntimeError::~RuntimeError() {
142 } 153 }
143 154
155 scoped_ptr<DictionaryValue> RuntimeError::ToValue() const {
156 scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
157 value->SetString(kContextUrlKey, context_url_.spec());
158
159 ListValue* trace_value = new ListValue;
160 for (StackTrace::const_iterator iter = stack_trace_.begin();
161 iter != stack_trace_.end(); ++iter) {
162 DictionaryValue* frame_value = new DictionaryValue;
163 frame_value->SetInteger(kLineNumberKey, iter->line_number);
164 frame_value->SetInteger(kColumnNumberKey, iter->column_number);
165 frame_value->SetString(kUrlKey, iter->source);
166 frame_value->SetString(kFunctionNameKey, iter->function);
167 trace_value->Append(frame_value);
168 }
169
170 value->Set(kStackTraceKey, trace_value);
171
172 return value.Pass();
173 }
174
144 std::string RuntimeError::PrintForTest() const { 175 std::string RuntimeError::PrintForTest() const {
145 std::string result = ExtensionError::PrintForTest() + 176 std::string result = ExtensionError::PrintForTest() +
146 "\n Type: RuntimeError" 177 "\n Type: RuntimeError"
147 "\n Context: " + context_url_.spec() + 178 "\n Context: " + context_url_.spec() +
148 "\n Stack Trace: "; 179 "\n Stack Trace: ";
149 for (StackTrace::const_iterator iter = stack_trace_.begin(); 180 for (StackTrace::const_iterator iter = stack_trace_.begin();
150 iter != stack_trace_.end(); ++iter) { 181 iter != stack_trace_.end(); ++iter) {
151 result += "\n {" 182 result += "\n {"
152 "\n Line: " + base::IntToString(iter->line_number) + 183 "\n Line: " + base::IntToString(iter->line_number) +
153 "\n Column: " + base::IntToString(iter->column_number) + 184 "\n Column: " + base::IntToString(iter->column_number) +
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // other systems), the source won't match up with the final entry in the stack 217 // other systems), the source won't match up with the final entry in the stack
187 // trace. (For instance, in a browser action error, the source is the page - 218 // trace. (For instance, in a browser action error, the source is the page -
188 // sometimes the background page - but the error is thrown from the script.) 219 // sometimes the background page - but the error is thrown from the script.)
189 // Make the source match the stack trace, since that is more likely the cause 220 // Make the source match the stack trace, since that is more likely the cause
190 // of the error. 221 // of the error.
191 if (!stack_trace_.empty() && source_ != stack_trace_[0].source) 222 if (!stack_trace_.empty() && source_ != stack_trace_[0].source)
192 source_ = stack_trace_[0].source; 223 source_ = stack_trace_[0].source;
193 } 224 }
194 225
195 } // namespace extensions 226 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698