[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] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame^] | 34 | static const wchar_t* kInvalidFormatVersionError; |
| 35 | static const wchar_t* kInvalidManifestError; |
| 36 | static const wchar_t* kInvalidIdError; |
| 37 | static const wchar_t* kInvalidNameError; |
| 38 | static const wchar_t* kInvalidDescriptionError; |
| 39 | static const wchar_t* kInvalidContentScriptsListError; |
| 40 | static const wchar_t* 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. |
| 48 | const std::wstring& id() const { return id_; } |
| 49 | |
| 50 | // A human-readable name of the extension. |
| 51 | const std::wstring& name() const { return name_; } |
| 52 | |
| 53 | // An optional longer description of the extension. |
| 54 | const std::wstring& description() const { return description_; } |
| 55 | |
| 56 | // Paths to the content scripts that the extension contains. |
| 57 | const std::vector<std::wstring>& content_scripts() const { |
| 58 | return content_scripts_; |
| 59 | } |
| 60 | |
| 61 | // Initialize the extension from a parsed manifest. |
| 62 | bool InitFromValue(const DictionaryValue& value, std::wstring* error); |
| 63 | |
| 64 | // Serialize the extension to a DictionaryValue. |
| 65 | void CopyToValue(DictionaryValue* value); |
| 66 | |
| 67 | private: |
| 68 | std::wstring id_; |
| 69 | std::wstring name_; |
| 70 | std::wstring description_; |
| 71 | std::vector<std::wstring> content_scripts_; |
| 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_ |