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

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

Issue 22938005: Add ErrorConsole UI for Extension Install Warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_install_warnings
Patch Set: Rebase to exclude backend 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"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 12
13 using base::string16; 13 using base::string16;
14 using base::DictionaryValue;
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace { 18 namespace {
18 19
19 const char kLineNumberKey[] = "lineNumber";
20 const char kColumnNumberKey[] = "columnNumber";
21 const char kURLKey[] = "url";
22 const char kFunctionNameKey[] = "functionName";
23 const char kExecutionContextURLKey[] = "executionContextURL";
24 const char kStackTraceKey[] = "stackTrace";
25
26 // Try to retrieve an extension ID from a |url|. On success, returns true and 20 // Try to retrieve an extension ID from a |url|. On success, returns true and
27 // populates |extension_id| with the ID. On failure, returns false and leaves 21 // populates |extension_id| with the ID. On failure, returns false and leaves
28 // extension_id untouched. 22 // extension_id untouched.
29 bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) { 23 bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) {
30 if (url.SchemeIs(kExtensionScheme)) { 24 if (url.SchemeIs(kExtensionScheme)) {
31 *extension_id = url.host(); 25 *extension_id = url.host();
32 return true; 26 return true;
33 } 27 }
34 return false; 28 return false;
not at google - send to devlin 2013/09/03 22:51:46 this looks very similar to ExtensionSet::GetExtens
Devlin 2013/09/03 23:54:22 Whoops. That's old. Gone.
35 } 29 }
36 30
37 } // namespace 31 } // namespace
38 32
33 ////////////////////////////////////////////////////////////////////////////////
34 // ExtensionError
35
36 // Static JSON keys.
37 const char ExtensionError::kExtensionIdKey[] = "extensionId";
38 const char ExtensionError::kFromIncognitoKey[] = "fromIncognito";
39 const char ExtensionError::kLevelKey[] = "level";
40 const char ExtensionError::kMessageKey[] = "message";
41 const char ExtensionError::kSourceKey[] = "source";
42 const char ExtensionError::kTypeKey[] = "type";
43
39 ExtensionError::ExtensionError(Type type, 44 ExtensionError::ExtensionError(Type type,
40 const std::string& extension_id, 45 const std::string& extension_id,
41 bool from_incognito, 46 bool from_incognito,
42 logging::LogSeverity level, 47 logging::LogSeverity level,
43 const string16& source, 48 const string16& source,
44 const string16& message) 49 const string16& message)
45 : type_(type), 50 : type_(type),
46 extension_id_(extension_id), 51 extension_id_(extension_id),
47 from_incognito_(from_incognito), 52 from_incognito_(from_incognito),
48 level_(level), 53 level_(level),
49 source_(source), 54 source_(source),
50 message_(message), 55 message_(message),
51 occurrences_(1u) { 56 occurrences_(1u) {
52 } 57 }
53 58
54 ExtensionError::~ExtensionError() { 59 ExtensionError::~ExtensionError() {
55 } 60 }
56 61
62 scoped_ptr<DictionaryValue> ExtensionError::ToValue() const {
63 scoped_ptr<DictionaryValue> value(new DictionaryValue);
64 value->SetInteger(kTypeKey, static_cast<int>(type_));
65 value->SetString(kExtensionIdKey, extension_id_);
66 value->SetBoolean(kFromIncognitoKey, from_incognito_);
67 value->SetInteger(kLevelKey, static_cast<int>(level_));
68 value->SetString(kSourceKey, source_);
69 value->SetString(kMessageKey, message_);
70
71 return value.Pass();
not at google - send to devlin 2013/09/03 22:51:46 consider using DictionaryBuilder here.
Devlin 2013/09/03 23:54:22 Will do once we have value builder in extensions/.
72 }
73
57 std::string ExtensionError::PrintForTest() const { 74 std::string ExtensionError::PrintForTest() const {
58 return std::string("Extension Error:") + 75 return std::string("Extension Error:") +
59 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") + 76 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") +
60 "\n Level: " + base::IntToString(static_cast<int>(level_)); 77 "\n Level: " + base::IntToString(static_cast<int>(level_));
61 "\n Source: " + base::UTF16ToUTF8(source_) + 78 "\n Source: " + base::UTF16ToUTF8(source_) +
62 "\n Message: " + base::UTF16ToUTF8(message_) + 79 "\n Message: " + base::UTF16ToUTF8(message_) +
63 "\n ID: " + extension_id_; 80 "\n ID: " + extension_id_;
64 } 81 }
65 82
66 bool ExtensionError::IsEqual(const ExtensionError* rhs) const { 83 bool ExtensionError::IsEqual(const ExtensionError* rhs) const {
67 // We don't check |source_| or |level_| here, since they are constant for 84 // We don't check |source_| or |level_| here, since they are constant for
68 // manifest errors. Check them in RuntimeError::IsEqualImpl() instead. 85 // manifest errors. Check them in RuntimeError::IsEqualImpl() instead.
69 return type_ == rhs->type_ && 86 return type_ == rhs->type_ &&
70 extension_id_ == rhs->extension_id_ && 87 extension_id_ == rhs->extension_id_ &&
71 message_ == rhs->message_ && 88 message_ == rhs->message_ &&
72 IsEqualImpl(rhs); 89 IsEqualImpl(rhs);
73 } 90 }
74 91
92 ////////////////////////////////////////////////////////////////////////////////
93 // ManifestError
94
95 // Static JSON keys.
96 const char ManifestError::kManifestKeyKey[] = "manifestKey";
97 const char ManifestError::kManifestSpecificKey[] = "manifestSpecific";
98
75 ManifestError::ManifestError(const std::string& extension_id, 99 ManifestError::ManifestError(const std::string& extension_id,
76 const string16& message, 100 const string16& message,
77 const string16& manifest_key, 101 const string16& manifest_key,
78 const string16& manifest_specific) 102 const string16& manifest_specific)
79 : ExtensionError(ExtensionError::MANIFEST_ERROR, 103 : ExtensionError(ExtensionError::MANIFEST_ERROR,
80 extension_id, 104 extension_id,
81 false, // extensions can't be installed while incognito. 105 false, // extensions can't be installed while incognito.
82 logging::LOG_WARNING, // All manifest errors are warnings. 106 logging::LOG_WARNING, // All manifest errors are warnings.
83 base::FilePath(kManifestFilename).AsUTF16Unsafe(), 107 base::FilePath(kManifestFilename).AsUTF16Unsafe(),
84 message), 108 message),
85 manifest_key_(manifest_key), 109 manifest_key_(manifest_key),
86 manifest_specific_(manifest_specific) { 110 manifest_specific_(manifest_specific) {
87 } 111 }
88 112
89 ManifestError::~ManifestError() { 113 ManifestError::~ManifestError() {
90 } 114 }
91 115
116 scoped_ptr<DictionaryValue> ManifestError::ToValue() const {
117 scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
118 if (!manifest_key_.empty())
119 value->SetString(kManifestKeyKey, manifest_key_);
120 if (!manifest_specific_.empty())
121 value->SetString(kManifestSpecificKey, manifest_specific_);
122 return value.Pass();
123 }
124
92 std::string ManifestError::PrintForTest() const { 125 std::string ManifestError::PrintForTest() const {
93 return ExtensionError::PrintForTest() + 126 return ExtensionError::PrintForTest() +
94 "\n Type: ManifestError"; 127 "\n Type: ManifestError";
95 } 128 }
96 129
97 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const { 130 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const {
98 // If two manifest errors have the same extension id and message (which are 131 // If two manifest errors have the same extension id and message (which are
99 // both checked in ExtensionError::IsEqual), then they are equal. 132 // both checked in ExtensionError::IsEqual), then they are equal.
100 return true; 133 return true;
101 } 134 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // other systems), the source won't match up with the final entry in the stack 198 // other systems), the source won't match up with the final entry in the stack
166 // trace. (For instance, in a browser action error, the source is the page - 199 // trace. (For instance, in a browser action error, the source is the page -
167 // sometimes the background page - but the error is thrown from the script.) 200 // sometimes the background page - but the error is thrown from the script.)
168 // Make the source match the stack trace, since that is more likely the cause 201 // Make the source match the stack trace, since that is more likely the cause
169 // of the error. 202 // of the error.
170 if (!stack_trace_.empty() && source_ != stack_trace_[0].source) 203 if (!stack_trace_.empty() && source_ != stack_trace_[0].source)
171 source_ = stack_trace_[0].source; 204 source_ = stack_trace_[0].source;
172 } 205 }
173 206
174 } // namespace extensions 207 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698