[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(){}; | ||||
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 19 | Extension(const FilePath& path) : path_(path) {}; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 20 | |
21 | // The format for extension manifests that this code understands. | ||||
22 | static const int kExpectedFormatVersion = 1; | ||||
23 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 24 | // The name of the manifest inside an extension. |
25 | static const FilePath::CharType* kManifestFilename; | ||||
26 | |||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 27 | // Keys used in JSON representation of extensions. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 28 | static const wchar_t* kFormatVersionKey; |
29 | static const wchar_t* kIdKey; | ||||
30 | static const wchar_t* kNameKey; | ||||
31 | static const wchar_t* kDescriptionKey; | ||||
32 | static const wchar_t* kContentScriptsKey; | ||||
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame^] | 33 | static const wchar_t* kVersionKey; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 34 | |
35 | // Error messages returned from InitFromValue(). | ||||
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 36 | static const char* kInvalidFormatVersionError; |
37 | static const char* kInvalidManifestError; | ||||
38 | static const char* kInvalidIdError; | ||||
39 | static const char* kInvalidNameError; | ||||
40 | static const char* kInvalidDescriptionError; | ||||
41 | static const char* kInvalidContentScriptsListError; | ||||
42 | static const char* kInvalidContentScriptError; | ||||
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame^] | 43 | static const char* kInvalidVersionError; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 44 | |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 45 | // The path to the folder the extension is stored in. |
46 | const FilePath& path() const { return path_; } | ||||
47 | |||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 48 | // A human-readable ID for the extension. The convention is to use something |
49 | // like 'com.example.myextension', but this is not currently enforced. An | ||||
50 | // extension's ID is used in things like directory structures and URLs, and | ||||
51 | // is expected to not change across versions. In the case of conflicts, | ||||
52 | // updates will only be allowed if the extension can be validated using the | ||||
53 | // previous version's update key. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 54 | const std::string& id() const { return id_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 55 | |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame^] | 56 | // The version number for the extension. |
57 | const std::string& version() const { return version_; } | ||||
58 | |||||
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 59 | // A human-readable name of the extension. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 60 | const std::string& name() const { return name_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 61 | |
62 | // An optional longer description of the extension. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 63 | const std::string& description() const { return description_; } |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 64 | |
65 | // Paths to the content scripts that the extension contains. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 66 | const std::vector<std::string>& content_scripts() const { |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 67 | return content_scripts_; |
68 | } | ||||
69 | |||||
70 | // Initialize the extension from a parsed manifest. | ||||
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 71 | bool InitFromValue(const DictionaryValue& value, std::string* error); |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 72 | |
73 | // Serialize the extension to a DictionaryValue. | ||||
74 | void CopyToValue(DictionaryValue* value); | ||||
75 | |||||
76 | private: | ||||
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 77 | // The path to the directory the extension is stored in. |
78 | FilePath path_; | ||||
79 | |||||
80 | // The extension's ID. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 81 | std::string id_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 82 | |
[email protected] | 64a02b80 | 2009-01-12 19:36:42 | [diff] [blame^] | 83 | // The extension's version. |
84 | std::string version_; | ||||
85 | |||||
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 86 | // The extension's human-readable name. |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 87 | std::string name_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 88 | |
89 | // An optional description for the extension. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 90 | std::string description_; |
[email protected] | 8289126 | 2008-12-24 00:21:26 | [diff] [blame] | 91 | |
92 | // Paths to the content scripts the extension contains. | ||||
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 93 | std::vector<std::string> content_scripts_; |
[email protected] | 7713d63 | 2008-12-02 07:52:33 | [diff] [blame] | 94 | |
95 | DISALLOW_COPY_AND_ASSIGN(Extension); | ||||
96 | }; | ||||
97 | |||||
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 98 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |