[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |
6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ | ||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | #include <vector> | ||||
10 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 11 | #include "base/file_path.h" |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 12 | #include "base/string16.h" |
13 | #include "base/values.h" | ||||
14 | |||||
15 | // Represents a Chromium extension. | ||||
16 | class Extension { | ||||
17 | public: | ||||
18 | Extension(){}; | ||||
19 | |||||
20 | // The format for extension manifests that this code understands. | ||||
21 | static const int kExpectedFormatVersion = 1; | ||||
22 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 23 | // The name of the manifest inside an extension. |
24 | static const FilePath::CharType* kManifestFilename; | ||||
25 | |||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 26 | // Keys used in JSON representation of extensions. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 27 | static const wchar_t* kFormatVersionKey; |
28 | static const wchar_t* kIdKey; | ||||
29 | static const wchar_t* kNameKey; | ||||
30 | static const wchar_t* kDescriptionKey; | ||||
31 | static const wchar_t* kContentScriptsKey; | ||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 32 | |
33 | // Error messages returned from InitFromValue(). | ||||
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 34 | static const char* kInvalidFormatVersionError; |
35 | static const char* kInvalidManifestError; | ||||
36 | static const char* kInvalidIdError; | ||||
37 | static const char* kInvalidNameError; | ||||
38 | static const char* kInvalidDescriptionError; | ||||
39 | static const char* kInvalidContentScriptsListError; | ||||
40 | static const char* kInvalidContentScriptError; | ||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 41 | |
42 | // A human-readable ID for the extension. The convention is to use something | ||||
43 | // like 'com.example.myextension', but this is not currently enforced. An | ||||
44 | // extension's ID is used in things like directory structures and URLs, and | ||||
45 | // is expected to not change across versions. In the case of conflicts, | ||||
46 | // updates will only be allowed if the extension can be validated using the | ||||
47 | // previous version's update key. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 48 | const std::string& id() const { return id_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 49 | |
50 | // A human-readable name of the extension. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 51 | const std::string& name() const { return name_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 52 | |
53 | // An optional longer description of the extension. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 54 | const std::string& description() const { return description_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 55 | |
56 | // Paths to the content scripts that the extension contains. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 57 | const std::vector<std::string>& content_scripts() const { |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 58 | return content_scripts_; |
59 | } | ||||
60 | |||||
61 | // Initialize the extension from a parsed manifest. | ||||
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 62 | bool InitFromValue(const DictionaryValue& value, std::string* error); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 63 | |
64 | // Serialize the extension to a DictionaryValue. | ||||
65 | void CopyToValue(DictionaryValue* value); | ||||
66 | |||||
67 | private: | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 68 | std::string id_; |
69 | std::string name_; | ||||
70 | std::string description_; | ||||
71 | std::vector<std::string> content_scripts_; | ||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 72 | |
73 | DISALLOW_COPY_AND_ASSIGN(Extension); | ||||
74 | }; | ||||
75 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 76 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |