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

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: License 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
« no previous file with comments | « extensions/browser/extension_error.h ('k') | extensions/browser/manifest_highlighter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ////////////////////////////////////////////////////////////////////////////////
19 // ExtensionError
18 20
19 const char kLineNumberKey[] = "lineNumber"; 21 // Static JSON keys.
20 const char kColumnNumberKey[] = "columnNumber"; 22 const char ExtensionError::kExtensionIdKey[] = "extensionId";
21 const char kURLKey[] = "url"; 23 const char ExtensionError::kFromIncognitoKey[] = "fromIncognito";
22 const char kFunctionNameKey[] = "functionName"; 24 const char ExtensionError::kLevelKey[] = "level";
23 const char kExecutionContextURLKey[] = "executionContextURL"; 25 const char ExtensionError::kMessageKey[] = "message";
24 const char kStackTraceKey[] = "stackTrace"; 26 const char ExtensionError::kSourceKey[] = "source";
25 27 const char ExtensionError::kTypeKey[] = "type";
26 // 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
28 // extension_id untouched.
29 bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) {
30 if (url.SchemeIs(kExtensionScheme)) {
31 *extension_id = url.host();
32 return true;
33 }
34 return false;
35 }
36
37 } // namespace
38 28
39 ExtensionError::ExtensionError(Type type, 29 ExtensionError::ExtensionError(Type type,
40 const std::string& extension_id, 30 const std::string& extension_id,
41 bool from_incognito, 31 bool from_incognito,
42 logging::LogSeverity level, 32 logging::LogSeverity level,
43 const string16& source, 33 const string16& source,
44 const string16& message) 34 const string16& message)
45 : type_(type), 35 : type_(type),
46 extension_id_(extension_id), 36 extension_id_(extension_id),
47 from_incognito_(from_incognito), 37 from_incognito_(from_incognito),
48 level_(level), 38 level_(level),
49 source_(source), 39 source_(source),
50 message_(message), 40 message_(message),
51 occurrences_(1u) { 41 occurrences_(1u) {
52 } 42 }
53 43
54 ExtensionError::~ExtensionError() { 44 ExtensionError::~ExtensionError() {
55 } 45 }
56 46
47 scoped_ptr<DictionaryValue> ExtensionError::ToValue() const {
48 // TODO(rdevlin.cronin): Use ValueBuilder when it's moved from
49 // chrome/common/extensions.
50 scoped_ptr<DictionaryValue> value(new DictionaryValue);
51 value->SetInteger(kTypeKey, static_cast<int>(type_));
52 value->SetString(kExtensionIdKey, extension_id_);
53 value->SetBoolean(kFromIncognitoKey, from_incognito_);
54 value->SetInteger(kLevelKey, static_cast<int>(level_));
55 value->SetString(kSourceKey, source_);
56 value->SetString(kMessageKey, message_);
57
58 return value.Pass();
59 }
60
57 std::string ExtensionError::PrintForTest() const { 61 std::string ExtensionError::PrintForTest() const {
58 return std::string("Extension Error:") + 62 return std::string("Extension Error:") +
59 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") + 63 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") +
60 "\n Level: " + base::IntToString(static_cast<int>(level_)); 64 "\n Level: " + base::IntToString(static_cast<int>(level_));
61 "\n Source: " + base::UTF16ToUTF8(source_) + 65 "\n Source: " + base::UTF16ToUTF8(source_) +
62 "\n Message: " + base::UTF16ToUTF8(message_) + 66 "\n Message: " + base::UTF16ToUTF8(message_) +
63 "\n ID: " + extension_id_; 67 "\n ID: " + extension_id_;
64 } 68 }
65 69
66 bool ExtensionError::IsEqual(const ExtensionError* rhs) const { 70 bool ExtensionError::IsEqual(const ExtensionError* rhs) const {
67 // We don't check |source_| or |level_| here, since they are constant for 71 // We don't check |source_| or |level_| here, since they are constant for
68 // manifest errors. Check them in RuntimeError::IsEqualImpl() instead. 72 // manifest errors. Check them in RuntimeError::IsEqualImpl() instead.
69 return type_ == rhs->type_ && 73 return type_ == rhs->type_ &&
70 extension_id_ == rhs->extension_id_ && 74 extension_id_ == rhs->extension_id_ &&
71 message_ == rhs->message_ && 75 message_ == rhs->message_ &&
72 IsEqualImpl(rhs); 76 IsEqualImpl(rhs);
73 } 77 }
74 78
79 ////////////////////////////////////////////////////////////////////////////////
80 // ManifestError
81
82 // Static JSON keys.
83 const char ManifestError::kManifestKeyKey[] = "manifestKey";
84 const char ManifestError::kManifestSpecificKey[] = "manifestSpecific";
85
75 ManifestError::ManifestError(const std::string& extension_id, 86 ManifestError::ManifestError(const std::string& extension_id,
76 const string16& message, 87 const string16& message,
77 const string16& manifest_key, 88 const string16& manifest_key,
78 const string16& manifest_specific) 89 const string16& manifest_specific)
79 : ExtensionError(ExtensionError::MANIFEST_ERROR, 90 : ExtensionError(ExtensionError::MANIFEST_ERROR,
80 extension_id, 91 extension_id,
81 false, // extensions can't be installed while incognito. 92 false, // extensions can't be installed while incognito.
82 logging::LOG_WARNING, // All manifest errors are warnings. 93 logging::LOG_WARNING, // All manifest errors are warnings.
83 base::FilePath(kManifestFilename).AsUTF16Unsafe(), 94 base::FilePath(kManifestFilename).AsUTF16Unsafe(),
84 message), 95 message),
85 manifest_key_(manifest_key), 96 manifest_key_(manifest_key),
86 manifest_specific_(manifest_specific) { 97 manifest_specific_(manifest_specific) {
87 } 98 }
88 99
89 ManifestError::~ManifestError() { 100 ManifestError::~ManifestError() {
90 } 101 }
91 102
103 scoped_ptr<DictionaryValue> ManifestError::ToValue() const {
104 scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
105 if (!manifest_key_.empty())
106 value->SetString(kManifestKeyKey, manifest_key_);
107 if (!manifest_specific_.empty())
108 value->SetString(kManifestSpecificKey, manifest_specific_);
109 return value.Pass();
110 }
111
92 std::string ManifestError::PrintForTest() const { 112 std::string ManifestError::PrintForTest() const {
93 return ExtensionError::PrintForTest() + 113 return ExtensionError::PrintForTest() +
94 "\n Type: ManifestError"; 114 "\n Type: ManifestError";
95 } 115 }
96 116
97 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const { 117 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const {
98 // 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
99 // both checked in ExtensionError::IsEqual), then they are equal. 119 // both checked in ExtensionError::IsEqual), then they are equal.
100 return true; 120 return true;
101 } 121 }
(...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 185 // 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 - 186 // 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.) 187 // 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 188 // Make the source match the stack trace, since that is more likely the cause
169 // of the error. 189 // of the error.
170 if (!stack_trace_.empty() && source_ != stack_trace_[0].source) 190 if (!stack_trace_.empty() && source_ != stack_trace_[0].source)
171 source_ = stack_trace_[0].source; 191 source_ = stack_trace_[0].source;
172 } 192 }
173 193
174 } // namespace extensions 194 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_error.h ('k') | extensions/browser/manifest_highlighter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698