OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef EXTENSIONS_COMMON_INSTALL_WARNING_H_ | 5 #ifndef EXTENSIONS_COMMON_INSTALL_WARNING_H_ |
6 #define EXTENSIONS_COMMON_INSTALL_WARNING_H_ | 6 #define EXTENSIONS_COMMON_INSTALL_WARNING_H_ |
7 | 7 |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 // A struct to describe a non-fatal issue discovered in the installation of an | |
14 // extension. | |
13 struct InstallWarning { | 15 struct InstallWarning { |
14 enum Format { | 16 InstallWarning(const std::string& message); |
15 // IMPORTANT: Do not build HTML strings from user or developer-supplied | 17 InstallWarning(const std::string& message, |
16 // input. | 18 const std::string& key); |
17 FORMAT_TEXT, | 19 InstallWarning(const std::string& message, |
18 FORMAT_HTML, | 20 const std::string& key, |
19 }; | 21 const std::string& specific); |
20 static InstallWarning Text(const std::string& message) { | 22 ~InstallWarning(); |
21 return InstallWarning(FORMAT_TEXT, message); | 23 |
24 bool operator==(const InstallWarning& other) const { | |
25 // We don't have to look at |key| or |specific| here, because they are each | |
26 // used in the the message itself. | |
27 // For example, a full message would be "Permission 'foo' is unknown or URL | |
28 // pattern is malformed." |key| here is "permissions", and |specific| is | |
29 // "foo", but these are reduntant with the message. | |
Yoyo Zhou
2013/08/15 00:25:13
redundant
Devlin
2013/08/15 16:54:17
Done.
| |
30 return message == other.message; | |
22 } | 31 } |
23 InstallWarning(Format format, const std::string& message) | 32 |
24 : format(format), message(message) { | 33 // The warning's message (human-friendly). |
25 } | |
26 bool operator==(const InstallWarning& other) const { | |
27 return format == other.format && message == other.message; | |
28 } | |
29 Format format; | |
30 std::string message; | 34 std::string message; |
35 // The manifest key to which this warning pertains (e.g., 'permissions'). | |
36 // Optional, as not all warnings need to pertain to a particular key | |
Yoyo Zhou
2013/08/15 00:25:13
I don't think you need to explain why these fields
Devlin
2013/08/15 16:54:17
Done.
| |
37 // (such as including the private key file in the extension directory). | |
38 std::string key; | |
39 // The specific portion of the key which caused the warning. For instance, a | |
40 // single faulty permission in the 'permissions' key. | |
41 // Optional, as there sometimes the full key is erroneous (or there may be no | |
42 // key). | |
43 std::string specific; | |
31 }; | 44 }; |
32 | 45 |
33 // Let gtest print InstallWarnings. | 46 // Let gtest print InstallWarnings. |
34 void PrintTo(const InstallWarning&, ::std::ostream* os); | 47 void PrintTo(const InstallWarning&, ::std::ostream* os); |
35 | 48 |
36 } // namespace | 49 } // namespace |
37 | 50 |
38 #endif // EXTENSIONS_COMMON_INSTALL_WARNING_H_ | 51 #endif // EXTENSIONS_COMMON_INSTALL_WARNING_H_ |
OLD | NEW |