| Index: extensions/browser/extension_error.cc
|
| diff --git a/extensions/browser/extension_error.cc b/extensions/browser/extension_error.cc
|
| index 8b6196c4200967605b3eb51f0653035bd4e88744..c3ec504569f82eb077a9a473fbd755ec4ed4bfce 100644
|
| --- a/extensions/browser/extension_error.cc
|
| +++ b/extensions/browser/extension_error.cc
|
| @@ -12,11 +12,20 @@
|
| #include "url/gurl.h"
|
|
|
| using base::string16;
|
| +using base::DictionaryValue;
|
|
|
| namespace extensions {
|
|
|
| namespace {
|
|
|
| +const char kTypeKey[] = "type";
|
| +const char kSourceKey[] = "source";
|
| +const char kMessageKey[] = "message";
|
| +const char kExtensionIdKey[] = "extensionId";
|
| +const char kFromIncognitoKey[] = "fromIncognito";
|
| +const char kManifestKeyKey[] = "manifestKey";
|
| +const char kManifestSpecificKey[] = "manifestSpecific";
|
| +const char kLevelKey[] = "level";
|
| const char kLineNumberKey[] = "lineNumber";
|
| const char kColumnNumberKey[] = "columnNumber";
|
| const char kURLKey[] = "url";
|
| @@ -27,7 +36,7 @@ const char kStackTraceKey[] = "stackTrace";
|
| // Try to retrieve an extension ID from a |url|. On success, returns true and
|
| // populates |extension_id| with the ID. On failure, returns false and leaves
|
| // extension_id untouched.
|
| -bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) {
|
| +bool GetExtensionIdFromGURL(const GURL& url, std::string* extension_id) {
|
| if (url.SchemeIs(kExtensionScheme)) {
|
| *extension_id = url.host();
|
| return true;
|
| @@ -52,6 +61,17 @@ ExtensionError::ExtensionError(Type type,
|
| ExtensionError::~ExtensionError() {
|
| }
|
|
|
| +scoped_ptr<DictionaryValue> ExtensionError::ToValue() const {
|
| + scoped_ptr<DictionaryValue> value(new DictionaryValue);
|
| + value->SetInteger(kTypeKey, static_cast<int>(type_));
|
| + value->SetString(kExtensionIdKey, extension_id_);
|
| + value->SetBoolean(kFromIncognitoKey, from_incognito_);
|
| + value->SetString(kSourceKey, source_);
|
| + value->SetString(kMessageKey, message_);
|
| +
|
| + return value.Pass();
|
| +}
|
| +
|
| std::string ExtensionError::PrintForTest() const {
|
| return std::string("Extension Error:") +
|
| "\n OTR: " + std::string(from_incognito_ ? "true" : "false") +
|
| @@ -60,23 +80,53 @@ std::string ExtensionError::PrintForTest() const {
|
| "\n ID: " + extension_id_;
|
| }
|
|
|
| +bool ExtensionError::IsEqual(const ExtensionError* rhs) const {
|
| + return type_ == rhs->type_ &&
|
| + extension_id_ == rhs->extension_id_ &&
|
| + source_ == rhs->source_ &&
|
| + message_ == rhs->message_ &&
|
| + IsEqualImpl(rhs);
|
| +}
|
| +
|
| ManifestParsingError::ManifestParsingError(const std::string& extension_id,
|
| - const string16& message)
|
| + const string16& message,
|
| + const string16& manifest_key,
|
| + const string16& manifest_specific)
|
| : ExtensionError(ExtensionError::MANIFEST_PARSING_ERROR,
|
| extension_id,
|
| false, // extensions can't be installed while incognito.
|
| base::FilePath(kManifestFilename).AsUTF16Unsafe(),
|
| - message) {
|
| + message),
|
| + manifest_key_(manifest_key),
|
| + manifest_specific_(manifest_specific) {
|
| }
|
|
|
| ManifestParsingError::~ManifestParsingError() {
|
| }
|
|
|
| +scoped_ptr<DictionaryValue> ManifestParsingError::ToValue() const {
|
| + scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
|
| + // All manifest errors are warnings - if it was a fatal error, we wouldn't
|
| + // get far enough to add an error for the extension.
|
| + value->SetInteger(kLevelKey, logging::LOG_WARNING);
|
| + if (!manifest_key_.empty())
|
| + value->SetString(kManifestKeyKey, manifest_key_);
|
| + if (!manifest_specific_.empty())
|
| + value->SetString(kManifestSpecificKey, manifest_specific_);
|
| + return value.Pass();
|
| +}
|
| +
|
| std::string ManifestParsingError::PrintForTest() const {
|
| return ExtensionError::PrintForTest() +
|
| "\n Type: ManifestParsingError";
|
| }
|
|
|
| +bool ManifestParsingError::IsEqualImpl(const ExtensionError* rhs) const {
|
| + // If two manifest errors have the same extension id and message (which are
|
| + // both checked in ExtensionError::IsEqual), then they are equal.
|
| + return true;
|
| +}
|
| +
|
| JavascriptRuntimeError::StackFrame::StackFrame() : line_number(-1),
|
| column_number(-1) {
|
| }
|
| @@ -94,6 +144,13 @@ JavascriptRuntimeError::StackFrame::StackFrame(size_t frame_line,
|
| JavascriptRuntimeError::StackFrame::~StackFrame() {
|
| }
|
|
|
| +bool JavascriptRuntimeError::StackFrame::operator==(
|
| + const JavascriptRuntimeError::StackFrame& rhs) const {
|
| + return line_number == rhs.line_number &&
|
| + column_number == rhs.column_number &&
|
| + url == rhs.url &&
|
| + function == rhs.function;
|
| +}
|
| JavascriptRuntimeError::JavascriptRuntimeError(bool from_incognito,
|
| const string16& source,
|
| const string16& message,
|
| @@ -106,7 +163,7 @@ JavascriptRuntimeError::JavascriptRuntimeError(bool from_incognito,
|
| message),
|
| level_(level) {
|
| ParseDetails(details);
|
| - DetermineExtensionID();
|
| + DetermineExtensionId();
|
| }
|
|
|
| JavascriptRuntimeError::~JavascriptRuntimeError() {
|
| @@ -129,10 +186,23 @@ std::string JavascriptRuntimeError::PrintForTest() const {
|
| return result;
|
| }
|
|
|
| +bool JavascriptRuntimeError::IsEqualImpl(const ExtensionError* rhs) const {
|
| + const JavascriptRuntimeError* error =
|
| + static_cast<const JavascriptRuntimeError*>(rhs);
|
| +
|
| + // We don't look at the full stack trace, because if the first frame is
|
| + // the same, it's close enough to heuristically count as a duplicate (after
|
| + // all, the same line caused the error).
|
| + // If the stack trace is empty, just compare the context.
|
| + return execution_context_url_ == error->execution_context_url_ &&
|
| + stack_trace_.size() == error->stack_trace_.size() &&
|
| + (stack_trace_.empty() || stack_trace_[0] == error->stack_trace_[0]);
|
| +}
|
| +
|
| void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| scoped_ptr<base::Value> value(
|
| base::JSONReader::Read(base::UTF16ToUTF8(details)));
|
| - const base::DictionaryValue* details_value;
|
| + const DictionaryValue* details_value;
|
| const base::ListValue* trace_value = NULL;
|
|
|
| // The |details| value should contain an execution context url and a stack
|
| @@ -151,7 +221,7 @@ void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| string16 url;
|
|
|
| for (size_t i = 0; i < trace_value->GetSize(); ++i) {
|
| - const base::DictionaryValue* frame_value = NULL;
|
| + const DictionaryValue* frame_value = NULL;
|
| CHECK(trace_value->GetDictionary(i, &frame_value));
|
|
|
| frame_value->GetInteger(kLineNumberKey, &line);
|
| @@ -164,9 +234,9 @@ void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| }
|
| }
|
|
|
| -void JavascriptRuntimeError::DetermineExtensionID() {
|
| - if (!GetExtensionIDFromGURL(GURL(source_), &extension_id_))
|
| - GetExtensionIDFromGURL(GURL(execution_context_url_), &extension_id_);
|
| +void JavascriptRuntimeError::DetermineExtensionId() {
|
| + if (!GetExtensionIdFromGURL(GURL(source_), &extension_id_))
|
| + GetExtensionIdFromGURL(GURL(execution_context_url_), &extension_id_);
|
| }
|
|
|
| } // namespace extensions
|
|
|